Repository navigation
fix(gateway): keep the typed state-contention Stop outcome on sessions.abort - #159282
wangmiao0668000666 wants to merge 2 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. What this changesThis PR shares the typed state-contention response between chat.abort and sessions.abort. Example: Stop for agent:main:main encounters a typed SQLite busy error.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 2 items remain Keep this PR open: current main still needs the session Stop classification, but both added contention tests fail in exact-head CI and need repair. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway Stop RPC handlers authorize cancellation, read session state, cancel owned work, and return an outcome that the Control UI presents. flowchart LR
A[Control UI Stop] --> B[Gateway RPC authorization]
B --> C[Session abort handler]
C --> D[Session and cancellation owners]
D --> E[Shared contention guard]
E --> F[Typed Stop notice]
Technical reviewBest possible solution: Retain the shared Stop classifier and repair both fixtures to exercise contention through the current production owners. Do we have a high-confidence way to reproduce the issue? Current source establishes the unguarded sessions.abort route, and supplied Gateway traces demonstrate the typed-error difference; this read-only review executed no target code. Is this the best way to solve the issue? Sharing the existing classifier at both RPC boundaries preserves cancellation uncertainty without replaying Stop, but the tests must target current readers and a genuinely contended operation. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6315f8adc18a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
PR surfaceSource +28, Tests +343, Docs +1, Other 0. Total +372 across 8 files. Added test files: 2. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (18 earlier review cycles; latest 8 shown)
Reviewed October 12, 2026, 7:30 PM ET / 23:30 UTC (Revision 19). |
a7540f7 to
a3ea138
Compare
250dddf to
5019077
Compare
83bf724 to
9e5e04e
Compare
|
Rebased onto current main ( Absorption check first: main's #156067 added the typed contention outcome to Adaptation notes
Verification on the rebased head (local runner, Node v24.18.0,
|
9e5e04e to
0214010
Compare
|
Real-lock proof re-anchored for main's storage evolution ( What CI surfaced: on the first rebased head, Re-anchor: the lock child now holds Verification on this head (local runner, Node v24.18.0,
|
0214010 to
df0ddf8
Compare
|
@clawsweeper re-review Rebased onto current Changes since the last reviewed head:
Local verification on the rebased head:
Note: |
|
🦞👀 Re-review progress:
|
|
Closing this to keep room for fixes with a clearer path to landing. The finding is unchanged: It is currently CONFLICTING against main with Branch |
…s.abort chat.abort preserves the typed state-contention outcome at the RPC boundary (openclaw#156067): when a session read fails while cancellation still takes effect, Stop answers UNAVAILABLE with the contention errorKind instead of replaying or claiming it had no effect. sessions.abort calls the same lifecycle but sat outside that guard, so the same busy-window read failure surfaced as an untyped internal error from the other Stop entry point. Extract the contention response into respondToAbortStateContention and share it through withAbortStateContentionGuard, then wrap the sessions.abort handler so both Stop entry points return the identical typed outcome. The fast dispatch proof covers the guard on both entry points; the real-lock proof (real Gateway, foreign BEGIN EXCLUSIVE on the live shared-state database) joins the release-only runtime inventory. Co-Authored-By: Claude Code <[email protected]>
df0ddf8 to
56cdbff
Compare
Closing — handoff (the proof this PR depends on no longer holds on current
|
Closes #160004
What Problem This Solves
A Stop that meets state contention on
sessions.abortescapes unclassified, so the Control UI cannot render the uncertainty-preserving notice the server already knows how to produce.handleChatAbortRequest(src/gateway/server-methods/chat-abort-handler.ts) turns typed contention intoUNAVAILABLEwithdetails.errorKind, butsrc/gateway/server-methods/sessions-abort.tscallshandleChatAbortRequestWithLifecycledirectly and never passes through that wrapper.sessions.abortis the only route that can cancel a recovered embedded run (src/gateway/chat-abort.ts:60-64,sessionAbortable), so it is the route that most needs the typed outcome.Precedent: #156067 (same classification, same wording and authority rules; that PR only added it to
chat.abort).Why This Change Was Made
The classification now lives in one owner and both Stop routes use it:
respondToAbortStateContention(options, error)— the single typed-contention responder, so wording,ErrorCodes.UNAVAILABLE, anddetails.errorKindcannot drift between routes.withAbortStateContentionGuard(handler)— wraps a Stop handler: classify, otherwise rethrow.chat.abortkeeps its existing behavior (handleChatAbortRequestis now the guardedhandleChatAbortRequestWithLifecycle), andsessions.abortregisterswithAbortStateContentionGuard(...)around its existing body.The whole handler is wrapped rather than just the delegated call because the typed error can be thrown by the handler's own session read (
sessions-abort.tsloadSessionEntry) as well as by the delegated lifecycle call. The own-read site is the one a real Gateway reaches first (proved below under a real foreign lock, and in the Control-UI proof); the delegated site needs an unconfigured agent with a live run, and is covered by the mocked regression. A partial wrap would leave one of the two sites unclassified, so there is no second defensible shape.Production LOC is
+54/-24. Test LOC is+331/-1(+45fast regression at the RPC boundary,+284live real-lock proof,+2/-1keeping an existing suite's partial mock in step with the module's exports). Routing is+2(one release-only inventory line, one doc bullet). No new option, configuration, validator, or persistence surface.Classification:
behavior-completingUser Impact
chat.abortbehavior is unchanged; its two pinned contention contracts still pass.Evidence
Product head:
56cdbffe98don maine8b8942affd(rebased; see the rebase note below for what moved). The traces in this section were captured on the pre-rebase head83bf7249114; the rebased-head run is in the next section.Rebase note — integration with the current main handlers
Main rewrote both handler files since the previous base
6e0e17d27e5(#161124worker-side repository reads,#157413's transaction change for ordinary state writes, and the abort-handler refactors), so the PR's 8 commits were replayed as one commit carrying the same net diff.The only conflict was the
sessions-abort.tsimport block. Main now takesabortControlledSubagents/descendantAbortErrorfromchat-abort-descendants.js,abortQueuedCollectorSessionfromchat-abort-runtime.js, and theChatSessionEmbeddedAbortOutcometype fromchat-abort-runtime.types.js. The resolution keeps main's import sources and addswithAbortStateContentionGuardto thechat-abort-handler.jsimport, so nothing main landed is reverted.chat-abort-handler.tsauto-merged: the guard is intact —respondToAbortStateContention(:699),withAbortStateContentionGuard(:718), andhandleChatAbortRequestas the guarded lifecycle handler (:732) — andsessions.abortregisters it (sessions-abort.ts:162). Net diff after the rebase: production+56/-28in the two handler files, tests+342/-1, routing+2;oxfmt --checkis clean on both production files.Known interaction:
#166269(open,status: 🚀 automerge armed) also editssessions-abort.ts, in the dedupe-payload region around:640-680. This change wraps the handler at:162and closes it at the end of the handler object, and does not touch that region, so a rebase after it lands is mechanical.Rebased-head RED → GREEN (this revision)
Same host, same command, same test file; the only variable is the two handler files (main's content versus this head). Node v24.18.0, through the repository's own runner:
The RED payload is the unclassified raw SQLite error (no
details.errorKind) that the Control UI cannot render; the GREEN payload is the typed outcome.What the production contention actually is (post-#157413)
Revision 12's finding said the real-lock test "does not exercise the production state-owner lock". The premise needed correcting, and the test now drives the real production trigger:
openclaw.sqliteitself. The state-owner file lock (acquireFileLockSync,state.<hash>.lock) only guards startup/schema/maintenance now, and its contention errors are plain strings ("offline maintenance" / "could not be verified") thatisSqliteLockError(src/infra/sqlite-error-diagnostics.ts) deliberately does not classify — it matches onlySQLITE_BUSY/SQLITE_LOCKED.state-lifecyclecoordinator file used by the first version of the test can no longer produce this error class at all.sessions.abort-contention.real-lock.test.tstherefore now holdsBEGIN EXCLUSIVEon the liveopenclaw.sqlitefrom a separate OS process while a Control-UI client issues a realsessions.abortfor a live run. The lock is asserted real in-test: a fresh connection cannot start a write transaction while the child holds it.Real-Gateway RED → GREEN terminal trace (current head, Node v24.18.0)
Control-UI before/after Stop screenshots (real built Gateway, real Chromium, real run adoption)
What is real in these runs: the production build of this head (and of main
6e0e17d27e5for the "before") boots as a real Gateway with a credential-free stalled loopback provider; a headlessagentRPC starts a real embedded run on the main session (embedded-registry-owned — the exact ownership that routes Control-UI Stop tosessions.abort, verified in the WebSocket frames: the Stop click sends{"method":"sessions.abort","params":{"key":"agent:main:main","runId":"…"}}); the real built Control UI runs in real Chromium; the real Stop button is clicked.What is substituted, and why it has to be: only the
sessions.aborterror response frame, replaced at a WebSocket MITM with the byte-exact error payload captured from the real-Gateway real-lock RED/GREEN runs above. The natural trigger window provably never coexists with a clickable Stop — each half verified on this head:src/state/openclaw-agent-worker-store.ts), so the 30-minute idle eviction can never fire while the run lives. Verified with a zero-client-traffic 32-minute window (browser fully closed; the gateway's handle onopenclaw-agent.sqlitenever closed, and an open UI poll re-arms the idle timer on everysessions.list).database is lockedand the UI renders "Gateway unreachable" — no Stop button ever appears.The committed real-lock test therefore closes the agent databases explicitly before taking the lock — the only window in which the typed refusal is reachable, and the state a foreign writer during a restart/eviction overlap produces.
Before Stop (identical in both builds — the run is adopted from history recovery and Stop is armed; the
runIdis the embedded run's):Before — Stop on unmodified main (
6e0e17d27e5): the rawdatabase is lockedtext escapes into the generic danger notice:After — Stop on this head (
83bf7249114): the typed outcome renders the warning-styled "Check status" notice:Driver logs (frames, injection, timings): mitm-before.log, mitm-after.log. Both runs used identical state dirs, config, provider, and timing; the UI bundle is byte-identical between the two builds (this PR changes no UI code), so the rendered difference is exactly the wire-payload difference.
Fast regression and sibling contracts
Scoped
tsgoon the three touched test files on the remote lane: 0 errors in the PR's files (the lane's tree pins older dependency types in unrelated files — pre-existing, not this PR).Review response (ClawSweeper revision 12)
83bf7249114. The test now drives the actual post-fix: prevent temporary-file exhaustion from SQLite coordination #157413 production trigger (foreign write transaction on the realopenclaw.sqlite— see the mechanism section above for why the state-owner file lock is not the classifiable surface), and every trace on this page was re-captured on this exact head: the RED/GREEN terminal runs above and the Control-UI screenshots below.Verification
sessions.abort-contention.real-lock.test.ts1 passed, and 1 failed against main's handler files with the raw-error payload above — the RED/GREEN pair in the rebase section.sessions.abort-agent-scope.test.tsfails 4 of its cases withTypeError: Cannot read properties of undefined (reading 'dev')raised insidesameFileIdentity→preparePluginModule→resolveProviderModelPolicySurface(src/plugins/plugin-module-loader-cache.ts:391), andsessions.abort-contention.test.tsfails before the handler is reached withUser profile catalog is not readyfromcaptureResidentUserProfileAccessduringauthorizeGatewayMethod. Both throw outside the code this PR changes; the remote-lane results below cover them.sessions.abort-contention.real-lock.test.ts— 1 passed on the pre-rebase head (83bf7249114), 1 failed against the unmodified main handlers (6e0e17d27e5), same command:node scripts/run-vitest.mjs run src/gateway/server-methods/sessions.abort-contention.real-lock.test.tssessions.abort-contention.test.ts— 1 passed;sessions.abort-agent-scope.test.ts— 33 passed (remote Docker lane)tsgo(tsconfig.pr159282.json, the three touched test files) — 0 errors in the PR's files on the remote lanesessions.abortwith the exactrunIdin the captured WebSocket frames; only the error response frame is substituted (byte-exact payload from the real-lock runs), for the reasons proven in the screenshot sectionoxfmt --checkon the changed files — cleanScope and risk
src/gateway/server-methods/chat-abort-handler.tshandleChatAbortRequestbecomes the guarded lifecycle handlerchat.abortbehavior pinned by its two contention tests; non-contention errors still rethrowsrc/gateway/server-methods/sessions-abort.tswithAbortStateContentionGuard(+3 import lines)src/gateway/server-methods/sessions.abort-contention.test.tssrc/gateway/server-methods/sessions.abort-agent-scope.test.tschat-abort-handler.jsin the existing partial mock so it does not pin the module's export listsrc/gateway/server-methods/sessions.abort-contention.real-lock.test.tssessions.abort+ foreignBEGIN EXCLUSIVEon the real state DB)scripts/lib/ci-proof-test-inventory.mts,docs/ci/scope-and-routing/node-test-lanes.mdresolveStateContentionPresentationhelper,ErrorCodes.UNAVAILABLE, and the same message/authority ruleschat.abortalready shipped. No new validator, option, config, or storage surface.