Repository navigation
test: commit ACP replay status before the agent's answers leave - #1010
Merged
Merged
Conversation
The ACP replay agent sent each inbound frame before recording it in its
status file, and rewrote the status in place. A client that reacted to
the final answer could stop the agent or read the status first, seeing
an earlier cursor ("did not consume all frames") or a truncated file
("Failed to decode ACP replay status").
The agent now consumes a batch of inbound frames (and a trailing runtime
exit), commits the status atomically via rename, then sends the batch.
Mismatches are recorded before the error answer is sent.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
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.
Root cause
The "agent's own mode picker" tests in
AcpRegistryAdapterV2.test.ts(and every ACP registry/Grok replay that checks completeness) depend onapps/server/scripts/acp-replay-agent.ts. That script had two races. Both were in the harness, not in the adapter.emit_inboundentry the agent wrote the frame to stdout and only then ranadvance()→writeStatus(). A trailingruntime_exitadvanced the cursor again after that. When the client receives the final answer,openSessioncompletes, the scope closes, the agent is killed, and the status is read. If the client gets there first, it reads an earlier cursor (ACP replay did not consume all frames for stored-mode-pick, cursor 5/6 on run 37165516635), or the kill lands before the last write.writeFileSynctruncates the file and then writes it. A reader in between, or a kill in between, sees an empty file (Failed to decode ACP replay status,SyntaxError: Unexpected end of JSON inputon run 37159438983 and PR feat(web): update providers on all connected machines (upstream) #992).The adapter does not drop or reorder requests. The adapter-side
assertCompletepath inAcpAdapterV2is exposed to race 2 as well, because it reads the status while the agent is still alive. Every checked-in ACP fixture ends with an inbound answer plusruntime_exit, so no transcript has a trailing client frame that needs a separate wait.Fix
runtime_exit. It commits the status, then sends the batch. A client that has seen a frame therefore always reads a status that counts it.renameSync, so readers never see a partial file. A kill mid-write leaves the previous complete status.apps/server/scripts/acp-replay-agent.test.ts. It reads the status synchronously the moment each answer arrives, SIGKILLs the agent on the final answer as teardown does, and asserts the status counts every frame seen.Repro rate
AcpRegistryAdapterV2.test.ts, 8–16 parallel loops + 12 CPU hogs (macOS, 18 cores)Validation
vp run -F t3 typecheck: passes; it coversscripts/.vp lint/vp fmt --checkon the changed files: clean.OrchestratorReplayFixtures.integration.test.ts: all ACP registry and Grok fixtures pass. Locally,claude_result_is_error/claudeAgentfails with or without this change, because my shell'sCLAUDE_CONFIG_DIRleaks into the expected message.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.