free the acp prompt slot before the response leaves - #3347
Merged
Merged
Conversation
The ACP turn settle sends its response through the async FrameSink and only then clears the connection's prompt slot: the writer task can put the response on the wire while the turn task still waits on the connection mutex, so a client that prompts again the instant it reads the response races the slot clear and gets the still-set slot's 'A prompt turn is already running' refusal — the CI-wave flake shape behind acp_threshold_auto_compaction_publishes_the_compaction_meta's second prompt (registered red-acp-auto-compaction-20261002-1, stopReason null at acp_mode_e2e.rs:1729). Clear the slot before every settle-path send, matching the daemon-attached path's release_turn_slot ordering. The turn-failure text now also echoes to stderr (a stop-reason assert loses the internal_error message), the failing test prints the whole response envelope on mismatch, and a new test opens the admission window on twenty sequential prompts.
Main's single-daemon-path migration (#3264) deleted the in-process ACP transport whose settle raced its prompt-slot clear behind the response (the flake this lane pinned): the surviving daemon path releases the turn slot before the reply leaves, so the fix rides the merge and the lane keeps the regression tests plus the settle-failure stderr echo on the surviving path.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ae6b431. Configure here.
snimu
approved these changes
Oct 5, 2026
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.

Note
Low Risk
Changes are limited to e2e assertions and stderr logging on error paths; no production control-flow changes in the diff.
Overview
This PR pins the ACP contract that a settled turn must admit the next
session/promptimmediately (no race where the slot stays held until after the JSON-RPC reply).It adds
acp_settled_prompt_immediately_admits_the_next_prompt, which runs 20 back-to-back prompts on one session and requires every response to havestopReason: end_turn, with a message that dumps the full envelope when admission races the settle.Test ergonomics: a shared
assert_end_turnhelper replaces barestopReasonchecks in the auto-compaction e2e so failures print the entire response (not justnullwhen aninternal_errorpath loses the failure text in the assertion).Daemon diagnostics: on failed turns in
prompt_turn, the handler now **eprintln!**spa-daemon: acp turn failed: {failure}before returning the internal error, so harnesses that dump child stderr show the underlying worker failure.Reviewed by Cursor Bugbot for commit 729f390. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Free the ACP prompt slot before the response leaves
assert_end_turnhelper that checks a settled ACP response has anend_turnstop reason and prints the full response envelope on failure; reuses it in the compaction-meta test in acp_mode_e2e.rsend_turnacp.prompt_turnhandler in daemon.rs that prints provider failure text with apa-daemon: acp turn failed:prefix before returning the internal errorMacroscope summarized 729f390.