Skip to content

fix(agent): finish interrupted turns promptly - #285

Merged
fcoury-oai merged 1 commit into
mainfrom
fcoury/fast-agent-stop
Aug 18, 2026
Merged

fcoury-oai merged 1 commit into
mainfrom
fcoury/fast-agent-stop

Conversation

@fcoury-oai

Copy link
Copy Markdown
Collaborator

Stopping a running Codex turn could leave the Agent pane stuck because Red discarded the active turn ID when it sent turn/interrupt, then ignored the matching terminal notification. The elapsed status also kept counting from the beginning of the turn, which made cancellation look slower than it was.

This change keeps the active turn authoritative until turn/completed, tracks and coalesces a pending interrupt separately, and reports the cancellation request to the pane as soon as it is dispatched. It also handles cancellation before turn/start returns and keeps both cancellation/completion event orderings from stranding the busy state.

The Stopping… status now restarts its elapsed timer so it measures cancellation latency rather than total turn duration.

How to Test

  1. Start a long-running Agent request and press Ctrl-c. Expect Stopping… to appear immediately with a fresh elapsed timer, then clear when Codex confirms the interruption.
  2. Submit another prompt after cancellation. Expect Red to start a replacement session with the interrupted conversation recap rather than leaving the prompt queued behind a stuck turn.
  3. Press Ctrl-c repeatedly, or cancel while a turn is starting or completing. Expect one interrupt request for the active turn and an idle pane after the terminal event, regardless of event ordering.

Focused automated coverage:

  • cargo test codex::tests
  • cargo test bundled_agent_rotates_when_completion_wins_the_cancellation_race
  • cargo test bundled_agent_rotates_when_cancellation_wins_the_completion_race
  • cargo clippy --all-targets --all-features -- -D warnings

@fcoury-oai
fcoury-oai merged commit ed140dd into main Aug 18, 2026
12 checks passed
@fcoury-oai
fcoury-oai deleted the fcoury/fast-agent-stop branch August 18, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant