Fix replay state for long-lived unified exec commands#187
Open
jflam wants to merge 3 commits intozed-industries:mainfrom
Open
Fix replay state for long-lived unified exec commands#187jflam wants to merge 3 commits intozed-industries:mainfrom
jflam wants to merge 3 commits intozed-industries:mainfrom
Conversation
Resolves merge conflicts between the unified exec replay fix and upstream additions (abort_pending_interactions, exec approval tests, MCP elicitation tests, blocked approval tests, shutdown tests). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
I've been running the fix below locally for a few days now and it feels solid now. All the important parts were done by gpt-5.4/xhigh :)
Summary
This fixes a replay/resume bug for long-lived unified-exec commands in
codex-acpand adds regression tests that capture the failure mode.At a high level:
write_stdinpolling is routed back onto the original exec tool call during replayProblem
A long-lived
exec_commandstarted through unified exec persists a nonterminal startup response likeProcess running with session ID <id>. That command can then be polled viawrite_stdinand eventually complete with a real terminal exit.When a session containing such a command is resumed through ACP replay:
ResponseItem::FunctionCall/ResponseItem::FunctionCallOutputexec_commandis effectively completed too early during replaywrite_stdinpoll output and/or the eventual liveExecCommandEndhave no active command to attach toThis leaves any ACP client in an indeterminate state — the command is still running, but replay has already collapsed the tool call, so later output and terminal completion cannot be mapped back to the original command.
Root cause
The root cause is in replay/resume, not the live unified-exec event contract.
The backend already uses a single real
ExecCommandEndfor the long-lived PTY lifecycle. The problem is that replay rebuilds command state fromResponseItems in a way that cannot distinguish:Process running with session ID ...)So replay synthesizes terminal completion too early and drops the state that later live events still need.
Fix
Treat replayed unified-exec commands as real in-flight command state:
PromptStatefor unfinished turns even without a live response channelexec_commandcalls and rehydrates the original active commandFunctionCallOutputpayloads to distinguish nonterminal startup output (with a session id) from terminal completion (with an exit code)write_stdinpolling back onto the original exec tool call by session/process id instead of materializing it as a separate logical commandExecCommandOutputDelta/ExecCommandEnd, those live events attach to the same replayed active commandThis keeps the command lifecycle coherent across initial startup, intermediate polling, replay after interruption, and final live completion.
Regression tests
test_replay_unified_exec_routes_write_stdin_to_original_commandReplays an
exec_commandstartup response, awrite_stdinpoll on the same session, and a terminal poll response with an exit code. Asserts that only the originalexec_commandtool call is treated as the command, that polls attach to it, and that completion lands on it.test_replay_unified_exec_preserves_active_command_for_live_terminal_endReplays a nonterminal unified-exec startup response, then feeds live
ExecCommandOutputDeltaandExecCommandEndevents. Asserts that the replayed command remains active, live output lands on it, and the live terminal end completes it.Both regressions go red on pre-fix code and green with the fix applied. Full test suite passes (19/19).