Skip to content

fix(chat): recover reliably after Stop when a turn stalls - #595

Draft
Is14w wants to merge 15 commits into
Stack-Cairn:mainfrom
Is14w:fix/chat-stop-recovery
Draft

fix(chat): recover reliably after Stop when a turn stalls#595
Is14w wants to merge 15 commits into
Stack-Cairn:mainfrom
Is14w:fix/chat-stop-recovery

Conversation

@Is14w

@Is14w Is14w commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Linked issue

Closes #583

Summary

Fix a chat lifecycle failure where pressing Stop can leave the conversation stuck in Vibing... and prevent subsequent user messages from starting.

The recovery path now releases the local chat runtime when Stop intersects with independently blocking work, including provider streaming, retry and failover work, terminal history persistence, memory extraction, compaction, and diagnostic persistence. It also prevents late callbacks from an aborted run from mutating a newer run for the same conversation.

For responses that were already terminally committed before Stop, preserve the completed outcome instead of publishing a spurious cancelled Gateway state or Cancelled error.

Change scope

  • Modules: agent-gui / agent-ui
  • Key paths:
    • crates/agent-gui/src/pages/chat/runtime/useSendChatTurn.ts
    • crates/agent-gui/src/pages/chat/runtime/chatRunFinalization.ts
    • crates/agent-gui/src/pages/chat/turns/runAgentConversationTurn.ts
    • crates/agent-gui/src/pages/chat/turns/runTextConversationTurn.ts
    • crates/agent-gui/src/lib/providers/runtime/streamRetry.ts
    • crates/agent-gui/src/lib/providers/runtime/providerFailover.ts
    • crates/agent-gui/src/lib/cancellation/abortRace.ts
    • crates/agent-gui/src/lib/chat/compaction/controller.ts
    • crates/agent-ui/src/pages/chat/ChatComposerBar.tsx
    • crates/agent-gui/test/chat/
    • crates/agent-gui/test/providers/

Screenshots / preview

Verification

  • Added focused regression coverage for:

    • Stop during stalled provider iteration and provider result completion.
    • Retry backoff and provider failover cancellation.
    • Stalled terminal history persistence after a completed response.
    • Agent-mode memory extraction and follow-up history persistence after Stop.
    • Hosted-search cleanup, trajectory persistence, debug persistence, and compaction cleanup.
    • Stale callbacks from an aborted run after a replacement run starts.
    • Gateway terminal projection after Stop following a completed response.
    • Edit-and-resend atomicity, including cross-platform source-line-ending handling.
  • Passed:

    pnpm --filter liveagent build
    
    cd crates/agent-gui
    node --test `
      test/providers/provider-failover.test.mjs `
      test/providers/text-only-failover.test.mjs `
      test/providers/stream-retry.test.mjs `
      test/chat/chat-stop-timing.test.mjs `
      test/chat/agent-turn-cancelled-history.test.mjs `
      test/trajectory/text-mode.test.mjs `
      test/chat/runtime-slot-convergence.test.mjs `
      test/chat/edit-resend-atomic.test.mjs `
      test/chat/workbench-window-session.test.mjs
    

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.

[Bug] Chat can remain stuck in Vibing... after Stop and block follow-up messages

1 participant