Skip to content

fix: prevent prompt loop hang when cancel races with first result#458

Merged
benbrandt merged 1 commit intoagentclientprotocol:mainfrom
tbounsiar:fix/cancel-hang
Mar 24, 2026
Merged

fix: prevent prompt loop hang when cancel races with first result#458
benbrandt merged 1 commit intoagentclientprotocol:mainfrom
tbounsiar:fix/cancel-hang

Conversation

@tbounsiar
Copy link
Copy Markdown
Contributor

Fixes #442

Summary

  • When cancel() was called immediately after a prompt, the result message arrived before promptReplayed was set to true
  • The !promptReplayed check consumed it as a "background task result", making the session.cancelled check unreachable
  • The loop then blocked forever on query.next() since no further messages would arrive
  • Fix: move the session.cancelled check before the !promptReplayed check so cancellation is always detected

Test plan

When cancel() was called immediately after a prompt, the result message
arrived before promptReplayed was set to true. The !promptReplayed check
consumed it as a background task result, making the cancelled check
unreachable and blocking the loop forever on query.next().

Move the cancelled check before the promptReplayed check so cancellation
is always detected regardless of replay state.

Fixes agentclientprotocol#442
@cla-bot cla-bot bot added the cla-signed label Mar 23, 2026
@benbrandt benbrandt enabled auto-merge (squash) March 24, 2026 21:19
@benbrandt benbrandt merged commit 91d629d into agentclientprotocol:main Mar 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Immediately cancelling after prompt is sent hangs agent forever

3 participants