Skip to content

Cancel the in-flight QA request and keep failed turns out of the history - #323

Open
joei4cm wants to merge 1 commit into
CopilotKit:mainfrom
joei4cm:fix/228-qa-chat-concurrent-sends
Open

joei4cm wants to merge 1 commit into
CopilotKit:mainfrom
joei4cm:fix/228-qa-chat-concurrent-sends

Conversation

@joei4cm

@joei4cm joei4cm commented Dec 3, 2026

Copy link
Copy Markdown

Closes #228.

Two defects in the QA chat hook (apps/web/src/hooks/use-qa-chat.ts):

  1. A second question overwrote the in-flight AbortController instead of cancelling it, so the old stream kept writing into the same state. The new question now cancels the previous request, the superseded turn stops writing, and every write is keyed to the request that owns the transcript.
  2. The error placeholder written into the message list ("Sorry, something went wrong...") was replayed to the model as assistant history on the next question. conversationHistory now holds only the turns the model actually answered; a failed turn stays visible in the transcript but is not conversation.

Also fixed in the same place: a cancelled turn left the user's question in the transcript with no answer, the request was not aborted on unmount, and the history was read from a stale render closure.

Tests:

  • apps/web QA chat hook suite — 9/9 passed. The three new tests (concurrent send cancels the previous request, the superseded turn leaves the transcript, the error placeholder is not replayed as history) fail on the previous implementation.
  • Full apps/web suite — 1216 passed, 26 skipped, 0 failed
  • apps/web typecheck, ESLint, Prettier, git diff --check passed
  • Built-in medium code-review fallback, authorized by the user because copilotkit-internal:cr-loop is unavailable; its findings (stale token writes, a superseded turn that could linger when the cancelled request never settles, and the unbounded unanswered-id set) are addressed.

🤖 Generated with Claude Code

Two defects in the QA chat hook:

- A second question overwrote the in-flight AbortController instead of
  cancelling it, so the old stream kept writing into the same state.
- The error placeholder written into the message list was replayed to the
  model as assistant history on the next question.

The new question now cancels the previous request, the superseded turn
leaves the transcript instead of leaving a question without an answer, and
conversationHistory holds only the turns the model actually answered. The
request is also aborted on unmount, and the transcript is read from a
mirror rather than a stale render closure.

Co-Authored-By: Claude Code <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

QA chat SSE: no cross-chunk buffer silently drops the metadata frame (sources + confidence)

1 participant