Repository navigation
FIX-1690 (stop): a block can stop another request in its own session - #2538
Conversation
…n (FIX-1690) ctx.session.stopRequest(id) records the abort route's own fenced write (recordRequestStop, now shared by both callers) on a request the session's own reads would show, and answers stopped / already-finished / not-in-this-session. Requests and sessions only: no Workforce word. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cnm5DbhFmkarpesBpPQ9Dq
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
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: serverGenReqId_37553fcb-7ec2-4cf2-8077-539fb50bdd42) |
Second look + architecture passOverall: the shape is right. Extracting 1.
|
There was a problem hiding this comment.
/simplify review (FIX-1690)
Verdict: The production shape is about as small as it can be for the spec’s “one write path” plus session-scoped admission. I’m approving; what follows is optional polish and one follow-up to keep in mind—not blockers.
Did the approach go too far?
No, for runtime code. The meaningful production delta is roughly:
recordRequestStop— moves the fencedsetFieldsIfStatus+abortRequestpath out ofabort-routes.tsso the HTTP abort handler andctx.session.stopRequestcannot drift (incarnation fence was the easy thing to duplicate).requestInSessionScope— applies the existingsessionRequestScopelist filter to a singleget(id); blocks have noResolvedPrincipal, so reusingcallerReachesRequestwould be the wrong trust boundary.StopRequestOutcome(public) vsRequestStopResult(engine-internal) — keeps HTTP 204/202/404/409 separate from the three block-facing outcomes without leaking route semantics into core.
What grew the diff: retained spec + figures, atlas regen, and ~230 lines of integration tests in an already-large abort.test.ts. That’s documentation/process surface, not architectural sprawl.
Simpler alternatives considered
| Alternative | Why I’d skip it |
|---|---|
| Blocks call the abort HTTP route internally | No principal on the block path; admission is “request this session would list,” not “caller owns request id.” |
Inline the abort write only in stopRequest |
Reintroduces the duplication this PR removes from the route. |
Collapse RequestStopResult into StopRequestOutcome |
Loses fired vs recorded mapping for 204 vs 202, or leaks HTTP into blocks. |
| Third-party package for cancellation | AbortController + store fencing is already the stack; nothing off-the-shelf replaces session-scoped sibling cancel. |
Deeper dedup: one matchesSessionRequestScope shared with all request.list implementations |
Real consistency win, but a cross-adapter store refactor—bigger than this issue; fine as a follow-up if list vs predicate ever drift. |
Optional cleanups (non-blocking)
- Tests:
makeStoppableFlowmirrorsmakeBlockingFlow(~L990) with the same abort-aware wait handler plus astopaction. ExtendingmakeBlockingFlow(optionalstopaction / shared delay helper) would drop ~40 lines and keep one flow factory. - Comments:
record-request-stop.tsrepeats the file header in the inline block (~L43–67); trimming to one invariant line would match BP-007 without behavior change. - Types in tests: Prefer importing
StopRequestOutcomefrom@flow-state-dev/coreover theAwaited<ReturnType<...>>alias. - Follow-up (if block-driven cancels get hot):
stopRequestdoesrequest.getthen scope check; on Postgres,getcan pull items for a long sibling run. Same pattern as abort today, but this PR adds a new call site—worth a metadata-only read later, not required here.
What not to simplify
- Merging session scope checks with
callerReachesRequest/ routing throughhandleAbortRequest. - Folding
goneinto a distinct public outcome (would weaken the uniform"not-in-this-session"story for out-of-scope ids).
Nice extraction on the abort route; tests cover local stop, cross-process heartbeat, session/tenant refusal, unknown id, and terminal request.
Sent by Cursor Automation: Review For Best Approach
There was a problem hiding this comment.
Code Snob. A smaller test shape exists. Production stays.
makeStoppableFlow copies makeBlockingFlow's wait-for-abort promise (already-aborted signal, then a timer raced against abort). That body should live once. The banner above the new describe restates the test name, and StopOutcome rebuilds StopRequestOutcome via Awaited<ReturnType<...>>.
Fold that subtraction from #2542 (completedNaturallyUnlessAborted). Same six stopRequest cases, and the cross-process suite that uses makeBlockingFlow, still pass. abort.test.ts is 28 insertions / 54 deletions against this head. Calling defineFlow twice to reuse actions.run registers the kind twice, so that lost. A stop flag on makeBlockingFlow is a one-caller option.
recordRequestStop, requestInSessionScope, and stopRequest are already the contract: one fenced write, six session keys on a single get, three returns. Do not shrink those.
Agent on this PR: fold the subtraction, then close the POC unmerged after this lands. The POC does not merge.
Sent by Cursor Automation: Code Snob
A parity test holds requestInSessionScope to the stores' own listing for a record that differs on each key (session, tenant, owner, org, flow kind, flow instance), on two stores and for bound and legacy sessions. A block naming its own request is pinned as stopping itself. Test helper reuse and review nits. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cnm5DbhFmkarpesBpPQ9Dq
|
Re: the second look + architecture pass. Changes are in 23b4e83.
The cross-process path is still the module-reset simulation here. The Generated by Claude Code |
… stream (FIX-1690) The kept line can reach the transcript over the session's live stream before the post's next status poll answers, and only that answer clears the draft. Under CI load the stream won and the same-tick assertion read the draft still set. Reproduced on main by delaying the status answer 400 ms: red 3/3; green 3/3 with the wait. Control: a composer that never clears its draft still fails. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cnm5DbhFmkarpesBpPQ9Dq
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: serverGenReqId_c13a1c9e-1a3d-4a8e-9434-cd3d31d29b6b) |
|
CI on 23b4e83 was red; 50f2510 fixes it. What failed: Cause (a race in the test, on main): the kept line can reach the transcript over the session's live stream before the post's next Proof it's main's, and that the fix holds:
The fix waits for the draft to clear ( Standing down on one more: the engine's
Generated by Claude Code |
Post-merge amendment of the retained closure spec (original review #2426): - names, paths and commands follow the Shift Manager rename (#2588) - leg c sweeps the promised set: message, reasoning, tool, code block and ask cards, plus the devtool page (#2532) - a4 targets eng.coder's running task session (FIX-1690: #2538/#2544/#2565) - Part 4's Inbox reply is graded on FIX-1690's test seat (#2525) - a2 runs without --devtool; Shift Manager serves its own (#2531) Recorded in DECISIONS -> How it got here, and a new EVOLUTION.md. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cnm5DbhFmkarpesBpPQ9Dq


The problem
A person in App Lab can't send a line to a coding run that is working: nothing can stop a run from inside its own session so the run can continue with what they said. The abort route can stop a request, but only for a client that names it over HTTP. An action that takes a person's message has no way to make room for it.
What this does
The first of three PRs for FIX-1690. It adds one generic hook and nothing else: a block may stop another request running in its own session.
It is the abort route's own write, not a copy. The fenced
abortRequestedwrite moved out of the route intorecordRequestStop, and both callers use it: the route after its owner and tenant check, the hook after checking the request is one the session's own reads would show. A request in another process stops on its next heartbeat, as an abort does. Any id outside the session, including one that doesn't exist, answersnot-in-this-sessionand writes nothing.This PR is the "generic stop hook" box only. The door (
door) and the composers (lab) follow.What's asked of you
Nothing new: this implements the approved spec's S1 and S2. Core and Engine gain no Workforce, task, harness or seat word (ER-7).
Parts worth reviewing closely
For the code reviewer.
requestInSessionScopeinpackages/engine/src/context/session-request-scope.tsappliessessionRequestScope(the filter every session read uses) to one record. Session id, tenant, owner, org and flow must all match.handleAbortRequestnow mapsrecordRequestStop's four results to 404 / 409 / 204 / 202. All 98 existing abort tests pass unchanged.vi.resetModules) so its abort registry has never seen the target's controller. It asserts that precondition, but it's still a simulation, not two OS processes.Part of FIX-1690 (S1, S2) · spec:
specs/issues/FIX-1690/· spec PR #2525 · epic FIX-1649 · next:door, thenlab. Checks here: V1 (unit level); the goal check lands withlab.How to review this
Engineering calls
ctx.sessionasstopRequest, returning a string union. DOCS.md left the name to the implementer. If wrong: a rename before 1.0.flowIdfences on flow kind alone, matching howsessionRequestScopealready treats it. If wrong: a legacy session could stop a same-kind request of another instance under its own session id, which today's admission already refuses to create.aborted, which is what the call says. Nothing in the spec covers it.docs-writer/docs-editorwere not run on theflows.mdparagraph.Verification
V1 (
packages/engine/test/abort.test.ts,ctx.session.stopRequest — …), six cases: same session in process →stopped, targetaborted; another process via heartbeat →stopped, targetaborted; another session →not-in-this-session, target completes naturally, noabortRequested; another tenant under the same session id → same; unknown id →not-in-this-session; finished →already-finished, record version unchanged.Red before the change: all six failed with
ctx.session.stopRequest is not a function.Negative control (session fence removed from the hook): the other-session and other-tenant cases fail,
expected 'stopped' to be 'not-in-this-session'; the other four stay green.pnpm typecheck: 74/74 tasks pass.pnpm --filter @flow-state-dev/core test: 2255 passed.pnpm --filter @flow-state-dev/engine test: 3327 passed, 1 failed:session-stream-conformanceBR-23 on the filesystem store, a 10 s timing test. It fails the same way onmainwithout this change, and passes on a rerun with it.pnpm knip:ci,pnpm lint: clean.Files
packages/core/src/types/scope.ts:StopRequestOutcome,SessionScopeHandle.stopRequest.packages/engine/src/execution/record-request-stop.ts: the shared fenced write.packages/engine/src/routes/abort-routes.ts: calls it.packages/engine/src/context/session-request-scope.ts:requestInSessionScope.packages/engine/src/context/createExecutionContext.ts: the hook.apps/docs/docs/fundamentals/flows.md,docs/architecture/execution-and-errors.md: docs..changeset/session-stop-request.md: core, engine minor.🤖 Generated with Claude Code
https://claude.ai/code/session_01Cnm5DbhFmkarpesBpPQ9Dq
Generated by Claude Code
Note
Medium Risk
Touches request cancellation and session-scoped authorization on the execution path; behavior is shared with
/abortvia a refactor, with broad test coverage but real multi-process risk.Overview
Adds
ctx.session.stopRequest(requestId)onSessionScopeHandle, so a block can cancel another in-session request the same way HTTP/abortdoes—enabling flows (e.g. message intake) to stop an in-flight run before continuing.The fenced
abortRequestedwrite is centralized inrecordRequestStop; the abort route and the session hook both call it after their own admission checks (owner/tenant vsrequestInSessionScope). Outcomes arestopped,already-finished, ornot-in-this-session(unknown or foreign ids are indistinguishable). Cross-process stops still land on the target’s next heartbeat.Core exports
StopRequestOutcome; docs and a changeset note the minor bump. Engine tests cover local/remote stop, session/tenant fencing, and parity between the predicate and store listings; App Lab’s composer test waits for the status poll before asserting the draft clears.Reviewed by Cursor Bugbot for commit 50f2510. Configure here.