Skip to content

fix(site/src/api): abort chat history requests when the query is cancelled - #30542

Merged
ibetitsmike merged 1 commit into
mainfrom
mike/chat-history-abort-signal
Oct 11, 2026
Merged

ibetitsmike merged 1 commit into
mainfrom
mike/chat-history-abort-signal

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Chat history requests now honor React Query's abort signal. getChatMessages takes an optional signal, and chatMessagesForInfiniteScroll passes the query's signal to the first page request and to every turn fill request.

Stack context

Stacked on #30524, which loads whole chat turns per history page by following the first page request with fill requests back to the turn's prompt.

Why

A review question on #30524 asked whether the fill loop bypasses React Query. It does not (the merged page is cached under chatMessagesKey and a refetch reruns the queryFn per page), but no history request received the abort signal, so a cancelled query kept its HTTP requests running. With this change, leaving a chat or cancelChatMessages in the edit mutation aborts the in-flight page and fill requests. An aborted fill is caught by the existing catch/break, and React Query discards the result.

Behavior change: because the queryFn now reads signal, unmounting the last observer cancels and reverts an in-flight history fetch instead of letting it finish in the background.

Testing

  • pnpm exec vitest run src/api/queries/chats.test.ts: 247 passed.
  • New test aborts the page and fill requests when the query is cancelled; the existing first-request and per-page-cap assertions now expect the signal.
  • Red-green: removing the signal from the first request, from the fill request, or from the queryFn each fails the new test.
  • pnpm lint:types, biome check --error-on-warnings, oxlint --deny-warnings on touched files: clean. Pre-commit hook passed.

Frontend review

  • frontend-review FE1 to FE10: all pass.
  • coder-frontend-review round 1: SD1 (single-use history binding in the new test) fixed. TN3 (wrap the factory in infiniteQueryOptions) declined: the hand-typed queryFn context is pre-existing on main, and converting it would change the factory's type and every direct queryFn call in tests, which is outside this change. All other roles: no findings.

Xum opened this PR on behalf of @ibetitsmike.

@ibetitsmike
ibetitsmike added this pull request to stack #30543 October 9, 2026 11:00
@ibetitsmike ibetitsmike changed the title mike/chat history abort signal fix(site/src/api): abort chat history requests when the query is cancelled Oct 9, 2026
Base automatically changed from mike/codagt-1372-whole-turn-pages to main October 9, 2026 11:32
@ibetitsmike
ibetitsmike force-pushed the mike/chat-history-abort-signal branch from cf99705 to d51e219 Compare October 9, 2026 11:32
@ibetitsmike
ibetitsmike marked this pull request as ready for review October 9, 2026 11:32
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T11:34:45.162039Z d51e219 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pr-queue-manager
pr-queue-manager Bot requested a review from jakehwll October 9, 2026 11:33
@ibetitsmike
ibetitsmike merged commit 2d96e88 into main Oct 11, 2026
33 checks passed
@ibetitsmike
ibetitsmike deleted the mike/chat-history-abort-signal branch October 11, 2026 10:13
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants