fix(mcp): reply instead of hanging when a command exits non-zero - #444
Merged
Conversation
Any MCP tool call whose flow subprocess exited non-zero left the client
waiting on a request that never got a response, until it hit an idle timeout.
The target passed to errors.As was exec.ExitError, a value. ExitError's Error
method has a pointer receiver, so the value type does not implement error, and
errors.As panics on such a target ("*target must be interface or implement
error"). That panic killed the tool handler's goroutine before it could reply.
Nothing about the failure was visible from outside: the subprocess had already
run and recorded its terminal status in flow's history, and the server kept
serving other requests normally — only the one request was lost.
The one-character fix is *exec.ExitError, matching tests/utils/runner.go, which
had it right. This also restores the behavior the comment always described:
a non-zero exit is a normal outcome whose detail is already in the captured
output, so it returns as output with a nil error.
Affects every tool that shells out — execute, run_command, run_executable,
get_execution_logs, sync_executables — for any failing command.
The regression test drives the real FlowCLIExecutor against a stand-in binary
via FLOW_CLI_BINARY; it fails with the original panic before the fix.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R328pa3FUUfga4gYah1iQi
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 1/2. Base:
main. Independent of the Python stack (#439–#443).Summary
Any MCP tool call whose
flowsubprocess exited non-zero left the client waiting on a request that never got a response, until it hit an idle timeout. A failing test, a script that raises, an executable that is not found — each one hung the agent instead of reporting the failure.internal/mcp/command_executor.gopassed a value toerrors.As:ExitError.Error()has a pointer receiver, soexec.ExitErrordoes not implementerror, anderrors.Aspanics on such a target —errors: *target must be interface or implement error. That panic killed the tool handler's goroutine before it could reply.The fix is
*exec.ExitError, matchingtests/utils/runner.go:35, which already had it right. That was the only other occurrence in the repo.Notable Changes
nilerror. Real failures (binary missing, context cancelled) still surface as errors.execute,run_command,run_executable,get_execution_logs,sync_executables, andwrite_flowfile's post-write sync.Why it was invisible
Nothing looked wrong from outside the process:
flow logsshowed the run recorded with its terminalfailedstatus and error message, about a second in.get_inforesponded while the call was stuck) — only the one request was lost, so it read as a slow command rather than a crash.The existing MCP tests all use a mocked
CommandExecutor, so none of them ever exercised the real exit path.Testing
TestExecuteContext_NonZeroExitReturnsOutputNotPanicdrives the realFlowCLIExecutoragainst a stand-in binary viaFLOW_CLI_BINARY. Verified it fails with the original panic when the fix is reverted, and passes with it.flow validatepasses (generate → lint → unit + e2e → schema validation).🤖 Generated with Claude Code
https://claude.ai/code/session_01R328pa3FUUfga4gYah1iQi