Repository navigation
fix(react): a stop pressed at any point in a turn stops it (FIX-1956) - #3269
Conversation
useSession.abortRequest lost a stop in three places: - mid-stream: it closed the stream and showed its own stop record, but the next snapshot read (Kitchen Sink reads one as the turn stops streaming) could land before the engine wrote its stop item, erased the hook's record, and left the latest request reading in_progress, so the turn read as running. This is the Kitchen Sink e2e flake. - while the turn's POST was out: the abort could reach no request yet, and the POST's stream was attached when it answered, so the turn ran on. - on a turn resumed on mount: the hook held no request id, so the stop returned early. The hook now remembers the requests the person stopped. It keeps its own stop record across snapshot reads until one holds the server's, and drops it on a 409 (the turn finished first). A stop during the POST is sent again once the POST answers, and the turn is not attached. The mount resume sets the active request id. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017pp7wCd87NW4BH7XVuF9Gv
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: 9d6b4beb-0ff4-4440-a251-11483841c6e8) |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: 56f5cf0e-f17b-49e0-bfef-318f35fba12c) |
There was a problem hiding this comment.
/simplify review (FIX-1956)
Parallel read-only passes (code quality, performance, reuse) on the scoped diff. No local code changes from this automation — feedback only.
Verdict on approach
The three failure modes (stop while POST is in flight, stop on mount-resumed turn, stop erased by an early snapshot) are real. Given how useSession already works — optimistic items, held reconciliation in applySnapshot, and client-owned ids until the server snapshot agrees — a stoppedRequestsRef latch plus re-upsert of the synthetic stop item is a proportionate fix, not an over-engineered parallel state machine. Performance on the new applySnapshot loop is negligible (small S, infrequent path vs sort/network).
Simpler architectures considered (likely not worth this PR):
| Alternative | Why it is heavier or worse here |
|---|---|
| Server-only stop visibility | Flicker / “still streaming” until snapshot; needs engine ordering guarantees |
| One boolean “user stopped” | Does not cover POST-vs-stream timing, mount resume, or per-request history |
| Push stop code into client transport | Still need react-side optimistic item + snapshot race handling for UX |
| Third-party package | No off-the-shelf fit for FSD item/snapshot merge semantics |
Optional follow-up hygiene (not blocking the core design): centralize system.request_aborted (+ a small status-item predicate) in @flow-state-dev/contracts so engine, kitchen-sink, and react stop duplicating literals; keep abortItemIdOf in react (server ids are random).
Requested change (correctness)
On 409, you correctly drop the request from stoppedRequestsRef, but injectSyntheticAbortItem still runs and abortRequest does not call refreshSnapshot() (unlike dismissRequest). That can leave a phantom “Request was stopped” on a turn that already finished until some later refresh. The new test only asserts after refresh(). Consider skipping synthetic inject on 409 (and/or mirroring dismiss’s immediate refresh) and asserting zero stop items immediately after abortRequest in that test.
Nits / optional (your call)
sendActionafter stop-during-POST still returnsstatus: "in_progress"while the hook does not attach the stream — fine if callers only look atisStreaming/ items; worth a one-line hook doc if anything reads the return value.dismissRequestvsabortRequest: only the latter usesstoppedRequestsRef; if dismiss is another stop entry point, snapshot races may differ — unify later if both need the same latch.- Trim a few restate-the-code comments (
activeRequestIdRefmount line, duplicate “until snapshot” prose). - Test mock duplication with
useSession-continueRequest.test.tsmatches repo convention; shared hoisted mock helper is optional when a third file appears.
What looks good
- Symmetry with
optimisticIdOf/abortItemIdOf. - Setting
activeRequestIdRefwhen attaching on mount so stop reaches resumed turns. - Post-POST branch: cancel body, second abort, no stream attach.
- Four behavioral tests map cleanly to the bugs + 409 race.
- Changeset is accurate.
Happy to approve after the 409 + synthetic-stop interaction is tightened (small diff).
Sent by Cursor Automation: Review For Best Approach
When the server answers a stop with 409 the turn already finished, so abortRequest no longer injects the local stop item it would otherwise show until the next read. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017pp7wCd87NW4BH7XVuF9Gv
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: fb9b2cc7-cf8e-4701-9213-198753bc622e) |
There was a problem hiding this comment.
Code Snob.
The stop set, the snapshot put-back, the second abort, and the mount assignment are the contract. refused is the 409 skip for the synthetic item; leave it.
Two things around that are extra.
sendAction builds the same in-progress response twice: the stop that landed during the POST, and the POST that comes back as an event stream. One accepted value covers both. The 202 path still returns the server body.
Comments that say the same thing as the next lines: the STOP_CODE line, the snapshot-loop note, the three-line POST note (one line stays: the first stop may have reached nothing), the test header's three moments, and the test comments that preview the next assertion. The line "Nothing claims a stop, not even before the next read." stays.
Net −34 against 45ad26b. The four stop tests passed, including the immediate 409 assertion. React typecheck passed.
POC, does not merge: #3273
Fold that subtraction into this PR, then close the POC unmerged.
Left as recorded: the fix stays in the hook, the stream is not held open for the aborted event, dismissRequest is unchanged, the set clears on a session change, only a 409 drops the id, a refused stop adds no item, the stopped POST returns in progress and attaches no stream, and the snapshot check reads unfiltered nextSnapshot.items. abortItemIdOf keeps the comment optimisticIdOf already has. The set's note, the mount line, and the 409 note stay. The changeset stays one sentence.
Sent by Cursor Automation: Code Snob
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017pp7wCd87NW4BH7XVuF9Gv
|
On the Code Snob review: I took the single Generated by Claude Code |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: 8514c22a-b982-4918-a5be-adddd0f9c3f2) |
|
Test (1/3) failed at 787cf98 in one test: shift-manager's Generated by Claude Code |
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 787cf98ab9
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Update: Test (1/3) failed again on the re-run, but the failure isn't this PR's. Shift-manager's Generated by Claude Code |
…fter the POST (FIX-1956) A 409 to a stop means either the request finished or it was resumed before the stop reached it. The hook now sends the stop once more and treats only a second 409 as finished. A stop pressed during the POST that the finished turn refuses drops the view's stop record and reads the finished turn, instead of claiming a stop forever. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017pp7wCd87NW4BH7XVuF9Gv
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: 89baf638-6d28-4073-925c-f52b94b08385) |
The same one-line change as #3281; it no-ops once main carries it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017pp7wCd87NW4BH7XVuF9Gv
|
I merged main and ported #3281's one-line test fix ( Generated by Claude Code |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: d2743ec1-7b98-487a-9204-49a4a1e1d16d) |


Requested by Jake · project thread
The problem
A person presses Stop early in a turn. Sometimes the page does not show the turn as stopped, or the turn continues. The Kitchen Sink e2e test "a stop before Claude Code names a conversation reads as stopped" fails about 3 times in 20 on
main.The issue said that
abortRequestreturns early because the request id is not set yet. The repro shows a different cause for the e2e failure. In that test, the abort reaches the server (204), and the server stops the run. The failure is in the view:abortRequestcloses the stream and adds its own stop record toitems.latestRequeststill saysin_progress. So the turn reads as running, and no notice shows.The early-stop gap that the issue names is also real, in two other places:
abortRequestreturned early and did nothing.What this does
useSessionnow keeps a set of the requests that the person stopped.All three changes are in
packages/react/src/hooks/useSession.ts. The client and the server abort contract do not change. Theclientpackage has no way to cancel a send that is still out. This fix does not need one, because the abort route stops the request once the request exists.What's asked of you
Nothing here is yours to decide. This is a bug fix, so this PR is the gate.
Parts worth reviewing closely
applySnapshot: the loop that puts the stop record back. It checks the unfilterednextSnapshot.itemsfor the server's stop item (detail.code === "system.request_aborted").sendAction: the early return after the POST answers for a stopped request. It returns anin_progressresponse and attaches no stream.abortRequest: only a 409 removes the request from the set. A 404 keeps it, because a stop during the POST can get a 404 before the request exists.Linear: FIX-1956 · no spec (bug, direct route) · merges after review
How to review this — altitude, what's in scope, what's deliberately unsettled
Engineering calls — what was decided while building
abortedevent. That design also works, but it changes whenisStreaminggoes false after a stop, and the hook needs a timeout for a 202 stop that runs in another process. Keeping the stop record changes less.dismissRequestdoes not change. It refreshes the snapshot andlatestRequestitself, and it can target a request that the server does not have (404). Keeping its record could show a stop that did not happen.Everything else — verification
Unit test, red on
main:packages/react/test/useSession-stop.test.ts. The first three tests fail without the fix:With the fix, all 4 pass.
Kitchen Sink e2e,
claude-code-mode.spec.ts -g "a stop before Claude Code" --repeat-each=20 --retries=0, on a production test-mode build:--workers=1mainThe full e2e suite passed once on this branch: 32 passed. The Codex twin test that the issue names is not on
main, so this PR does not run it.Local note: the sandbox cannot download the Chromium build that Playwright 1.59 wants. The runs used the installed
chromium_headless_shell-1194through a scratch config that was not committed. The full Chromium build in this sandbox also requests/favicon.icoand logs a 404, which theconsoleErrorsfixture catches. The headless shell does not do this.Other checks:
pnpm typecheck,pnpm knip:ci, andnode scripts/check-retired-terms.mjspass. The react tests (356), client tests (174), and kitchen-sink unit tests pass.Changeset:
.changeset/stop-early-in-a-turn.md, patch for@flow-state-dev/react, names FIX-1956.🤖 Generated with Claude Code
https://claude.ai/code/session_017pp7wCd87NW4BH7XVuF9Gv
Generated by Claude Code
Note
Medium Risk
Changes core session streaming and abort timing in
useSession, which affects all consumers’ stop UX and race handling; behavior is well covered by new tests but regressions could still show up in e2e stop flows.Overview
useSession().abortRequestnow reliably stops a turn and keeps the UI showing “stopped” across POST-in-flight, mount auto-resume, and snapshot refresh races (FIX-1956).The hook tracks stopped request IDs in
stoppedRequestsRef, re-applies localsystem.request_abortedstatus items inapplySnapshotuntil the server snapshot includes the same stop, and usesserverRefusedStop(up to twoabortRequestcalls on HTTP 409) so a finished turn does not keep a synthetic stop.sendActionre-aborts and skips attaching SSE when the POST returns after an early stop; auto-resume setsactiveRequestIdRefso stop works on reload mid-turn.Adds
packages/react/test/useSession-stop.test.tsand a patch changeset for@flow-state-dev/react. Shift Manager’sproject-workstreamstest updates scripted coordinator tooling fromhandOfftodispatchTask.Reviewed by Cursor Bugbot for commit 5f70c3e. Configure here.