Repository navigation
fix(engine): abort reaches every live run of a request (FIX-1665, part 1 of 3) - #2971
Conversation
…g keeps the other's controller (FIX-1665) The abort registry held one controller per request id, so when the stale sweep and /continue left two runs of one request live in a process, the second registration replaced the first, and whichever run ended first deregistered the survivor's controller. The survivor could then no longer be aborted. The registry now holds one controller per live run under the id: an abort fires all of them, and a run deregisters only its own controller. `deregisterAbortController` keeps its id-only form (removes all). Also adds a repro of the cross-process half of FIX-1665 (a run in another process finalizes and deregisters the id while this one still writes), marked it.fails: fencing it needs a store-contract decision. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DME8pzA4e4Rc7fRLGsYavW
|
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: cd20964f-ad54-4844-8151-b9ae1a3e376c) |
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: 86ef412c-dc5c-4e1c-84f0-86a2585c4d43) |
There was a problem hiding this comment.
Simplify / architecture read
Problem (plain terms): After stale sweep + /continue, two run attempts can share one request id in the same process. The old abort registry was last-writer-wins: one attempt finishing called deregisterAbortController(requestId) and removed the slot, so abort could miss the sibling still running.
Did this go too far? For the in-process slice (part 1 of 3), no. Map<string, Registered[]> plus deregisterAbortController(requestId, controller?) is the smallest API-stable fix: abort fans out to every live controller under the id; teardown removes only this attempt’s controller. Composite keys (requestId:attemptId) would still need a secondary index or fan-out for unfenced “abort this id” callers. Store-backed live-attempt counting is the right direction for cross-process finalize (your it.fails test says that explicitly) and is correctly out of scope here—not a simpler substitute for this bug.
What looks right
abortRequestfiltering + per-controllerfiredBypreserves incarnation fencing when multiple slots share an id.runActionpassingregisteredon every exit path and deregistering a rejectedabortHandoffcontroller avoids phantom second attempts.- Transport
deregisterAbortController(requestId, queuedAbort)matches the new semantics. - Unit tests in
abort.test.ts+ integration inrequest-attempt-overlap.test.tsencode the regression; tests pass locally.
Simplify follow-ups (non-blocking)
- Test harness duplication:
makeParkedFlowinrequest-attempt-overlap.test.tsis almost the same shape asoverlap()inrequest-finalization-overlap.test.ts(gates, parked,onFinishedhold whenfinishing === 2). Worth a sharedpackages/engine/test/fixtures/overlapping-runs.ts(or exporting one builder from the finalization file) with options likecaptureSignalsandkind—would shrink this PR and keep overlap scenarios from drifting. - Docs at the top of
abort-registry.ts: Lines 3–6 still read like one controller per request until terminal state; the new paragraph at 14–18 is the accurate model—I'd align the opening blurb so readers don't infer single-slot semantics. deregisterAbortController(requestId)withoutcontroller: Still deletes all attempts under the id (fine for tests/afterEach). A one-line JSDoc nudge (“tests / bulk clear only”) would reduce the risk of a future production call during overlap.- Imports in the new test file: Mixed
../srcvs../src/execution/abort-registryis a minor consistency nit; barrel-only is fine if those symbols are re-exported. - Micro:
deregistercould splice in-place on the existing array instead offilter+set—irrelevant at k≈2, optional.
Skipped (larger than this diff)
- Requiring
controlleron every deregister (breaking / follow-up). - Consolidating overlap + abort + finalization under store-level live-attempt records (parts 2–3).
Verdict: Direction is sound; complexity matches the failure mode. Approving—optional cleanups above are polish, not blockers.
Sent by Cursor Automation: Review For Best Approach
There was a problem hiding this comment.
Code Snob
request-attempt-overlap.test.ts copies the parked-run harness already in request-finalization-overlap.test.ts (two gates, the second onFinished hold, interrupt, then /continue). Fold the abort checks onto that harness and delete the new file. About 100 lines come out. The assertions stay: one run ending leaves the other's controller, one abort reaches both live runs, and the cross-process case stays it.fails.
The registry is already the small shape. A nested map in place of the list does not get shorter, and the id-only deregister is the compatibility this PR kept.
POC, does not merge: #2982
Fold that subtraction into this PR. Close the POC unmerged after this lands.
Sent by Cursor Automation: Code Snob
… harness; align abort-registry docs (FIX-1665) The abort checks and the cross-process repro (still it.fails) now reuse the parked-run harness in request-finalization-overlap.test.ts, and the duplicate request-attempt-overlap.test.ts is gone. The abort-registry file header now describes one controller per run attempt, and the id-only deregisterAbortController form is documented as a bulk clear. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DME8pzA4e4Rc7fRLGsYavW
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: 689856eb-e90d-43fe-88ba-5df4f826ed0a) |
|
@claude CI failures |
|
On it. The one real failure is This PR's source changed only in comments since the last green head (920adc3). Even so, that test cancels through the abort path this PR changes, so I'm not calling it a flake. The test is being run 20+ times on this branch and on main:
Generated by Claude Code |
Brings in FIX-1840 (#2983): the coordinator conversation's CAS retry budget, which fixes the coordinator-rounds.test.ts:602 failure that turned Test (2/3) red on this branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XMg2dz8sMEdyzCQTRsaMTV
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: aa93e2d6-8ea2-427c-a4c6-393d986a6922) |
|
Follow-up on the CI failures. Merged
Also checked on the merged head: engine tests pass (275 files, 3649 passed, 6 skipped, with the cross-process Generated by Claude Code |
|
Root cause: the coordinator's internal Fix: none exists yet. The likely fix is Generated by Claude Code |
|
@codex review |
1 similar comment
|
@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: 546ad31e2c
ℹ️ 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".
| /** Controllers of the live attempts of each request id, in registration order. */ | ||
| const controllers = new Map<string, Registered[]>(); |
There was a problem hiding this comment.
Update the abort lifecycle contract for concurrent attempts
When a stale sweep and /continue leave two runs live—the exact scenario this patch supports—the authoritative architecture document still says each request has three controllers and diagrams a single registry controller (docs/architecture/execution-and-errors.md:186-220). That is now false because the registry holds one controller per attempt and abort fans out across them; leaving the contract unchanged risks subsequent execution work restoring the old replacement or bulk-cleanup semantics. Update the architecture documentation alongside this core execution behavior change.
AGENTS.md reference: AGENTS.md:L203-L208
Useful? React with 👍 / 👎.


Problem
One request can have two runs live at once: the stale sweep marks a slow but live run
interrupted, and/continuestarts a second run under the same id. The abort registry kept one controller per request id, so the second run replaced the first's controller, and whichever run ended first removed the survivor's. After that, aborting the request did nothing to the run still going.What this does
deregisterAbortController(requestId, controller?)gains an optional controller. The id-only form still removes everything, so existing callers keep working.runActiondeclines a handed-over queued controller, it removes that controller instead of leaving it next to its own.What's asked of you
Review the registry change. This PR covers one of the three holes in FIX-1665. The other two need a decision before they can be built, and that decision has been escalated to the coordinator rather than made here:
RequestStoreandActiveRequestRegistrycontracts that custom stores implement. A repro is included, markedit.fails.Parts worth reviewing closely
replaceAbortControllernow swaps the controller in place within the run's own entry. It no longer competes for a single slot.runAction(same object, deregistered by both, idempotently) or removed whenrunActionstarts on a fresh one.abort.test.tsassumed that registering replaced the earlier controller. They now model a finished request the way the code does, by deregistering it.Evidence
Red, on
origin/mainwith only the new test file: the 3 new tests intest/request-finalization-overlap.test.tsfail (they reuse its parked-run harness). The in-process abort tests fail withexpected false to be truebecause the survivor's controller is gone. The cross-process test fails withfinalizedAtMs: <number>, registered: falsewhile the other run is still inonFinished.Green: the two in-process tests pass. The cross-process test stays red and is held as
it.fails.pnpm --filter @flow-state-dev/engine typecheck: cleanpnpm --filter @flow-state-dev/engine test: 273 files, 3624 passedpnpm --filter @flow-state-dev/integration-tests test: 41 files, 153 passednode scripts/validate-changeset-refs.mjsandnode scripts/check-mailbox-rename.mjs: passSecond-path checklist: no persisted field changes, so there is no legacy read path. The public API stays backward compatible. On the concurrent path, two runs register, one ends, and abort still reaches the other (tested). On the cancel and setup-error paths, each deregister passes the run's own controller. Multi-tenant fencing is unchanged, because it still goes through the incarnation match.
Changeset:
abort-every-live-attempt.md(engine, patch).Links: FIX-1665
🤖 Generated with Claude Code
https://claude.ai/code/session_01DME8pzA4e4Rc7fRLGsYavW
Generated by Claude Code
Note
Medium Risk
Changes in-process cancellation registry and all run teardown paths; behavior is well covered by new overlap tests but affects concurrent continuation/stale-sweep scenarios.
Overview
Fixes FIX-1665 where overlapping runs under one request id could not be aborted reliably: a second run used to replace the first run’s
AbortController, and the first run to finish cleared the registry for everyone.The in-process abort registry now stores one controller per live run attempt (array per
requestId).abortRequestaborts all matching attempts (still respects incarnation fencing).deregisterAbortController(requestId, controller?)removes only that attempt’s controller; the id-only form still bulk-clears for tests.runActionand the inbound host’s queued pre-start path pass the specific controller on every cleanup, and drop a rejected abort handoff so it does not linger as a phantom second attempt.Tests cover multi-attempt abort/deregister and overlapping continuation scenarios; cross-process finalize overlap remains
it.fails(documented follow-up).Reviewed by Cursor Bugbot for commit 546ad31. Configure here.