Repository navigation
fix(gateway): drain admitted node results before disconnect - #119246
Conversation
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed August 4, 2026, 12:09 PM ET / 16:09 UTC. ClawSweeper reviewWhat this changesThe PR drains already-admitted node progress and result handling briefly during Gateway WebSocket close so a valid terminal result can settle before unresolved invokes are rejected. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep this protected Gateway repair open for maintainer review. The supplied exact-head evidence supports the repair and prior review found no remaining defect, but local source/history inspection was blocked before execution and the delayed-unregister authority boundary needs an owner decision. Priority: P1 Review scores
Verification
How this fits togetherGateway node connections deliver lifecycle messages that settle operator-initiated remote work. Connection teardown normally unregisters the node and rejects pending work; this change coordinates that teardown with lifecycle messages already admitted from the socket. flowchart LR
A[Paired node] --> B[Gateway WebSocket]
B --> C[Admitted progress or result]
C --> D[Pairing and generation validation]
D --> E[Operator invocation outcome]
B --> F[Physical socket close]
F --> G[Bounded lifecycle drain]
G --> H[Unregister node and reject unresolved work]
Decision needed
Why: This is an intentional teardown and authority-lifetime contract, not a mechanical correctness choice that can be resolved from the supplied diff alone. Before merge
Agent review detailsSecurityNone. PR surfaceSource +94, Tests +273. Total +367 across 8 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the bounded, per-connection drain only after the Gateway owner confirms the retained-client revocation contract and the exact-head checks complete successfully. Do we have a high-confidence way to reproduce the issue? Unclear. The supplied PR describes a deterministic real-WebSocket reproduction and focused regression proof, but this review could not independently run or inspect the current-head path because the read-only sandbox failed before command execution. Is this the best way to solve the issue? Unclear. The supplied design is narrowly scoped to already-admitted lifecycle work and prior exact-head review found no defect, but independent owner-boundary and history verification was unavailable. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against 50a30b7373d7. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
9057ca4 to
75b99b2
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Land-ready proof for exact head The root cause is physical-close cleanup unregistering a node before an already-admitted terminal result finished asynchronous pairing validation. The connection now owns a bounded drain for only admitted ClawSweeper found one P1 in the initial candidate: removing the client from the shared set before the drain weakened pairing/token revocation. The corrected head retires transport I/O immediately but retains the client in the revocation index until drain and unregister complete. The real-WebSocket regression now proves both sides of the contract: result-before-close succeeds, while close followed by pairing removal rejects the invocation with the pairing-changed outcome. Replacement-connection ownership and generation fences remain covered. Owner-boundary decision: accept the bounded retained-client window. It exists only while admitted lifecycle work is active, is capped at one second, cannot admit new socket I/O, and preserves pairing/token/replacement authority throughout. This is the narrowest safe connection-lifecycle owner boundary and introduces no protocol, config, storage, fallback, or retry surface. Proof:
Final surface: 8 files, production +109/-15 (net +94), tests +273/-0. Risk is medium-low: teardown is delayed only for admitted lifecycle work, bounded to one second, and all authority fences remain active. |
|
Merged via squash.
|
…#119246) * fix(gateway): drain admitted node results on close * fix(gateway): keep idle node cleanup synchronous * fix(gateway): preserve node revocation during drain * refactor(gateway): keep websocket handler within line budget
Closes #116363
What Problem This Solves
A node could send a valid terminal
node.invoke.resultand then close its WebSocket, but disconnect cleanup could synchronously settle the operator invocation asDISCONNECTEDwhile the already-received result was still awaiting pairing validation. Retrying the apparently failed operation could repeat a remote side effect.Root Cause
Authenticated WebSocket request dispatch intentionally runs asynchronously so one connection can process independent requests concurrently. The physical-close handler, however, immediately unregistered the node and consumed every pending invoke. That let cleanup overtake a terminal result frame whose dispatch had already been admitted from the same connection.
The deterministic current-main reproduction holds the result's persisted-pairing read after frame admission, terminates the real authenticated socket, and lets disconnect cleanup run. Current main returns:
DISCONNECTED: node disconnected (camera.list)The result handler later sees the pairing/session as stale and cannot recover the already-consumed invocation.
What Changed
node.invoke.progressandnode.invoke.resultrequests enter that tracker; unrelated RPCs retain their existing concurrency and no new request queue is introduced.No grace sleep, pairing-check bypass, config, protocol, storage, dependency, or user-data contract change.
Observed Behavior
The real-WebSocket regression now proves:
node.invoke;Evidence
Exact head:
75b99b29d4aa83e2d628ad6ebd0878c8efd7082e.node scripts/run-vitest.mjs src/gateway/server/ws-connection.test.ts src/gateway/server/ws-connection/node-lifecycle-dispatch.test.ts src/gateway/server.node-result-close.test.ts src/gateway/server/ws-connection/message-handler.post-connect-health.test.ts src/gateway/server/ws-connection/message-handler.suspension-admission.test.tstbx_01kz6dajj97ncjadh7r6r2bdes, https://github.com/openclaw/openclaw/actions/runs/30911085825:tbx_01kz6etnqnqsaam9a9e9pf8dvm, https://github.com/openclaw/openclaw/actions/runs/30913200657:pnpm check:changedpassed thecoreandcoreTestslanes.pnpm buildpassed, including the production Control UI build and performance guard.openclaw/ci-gate.main; targeted oxlint is green without a max-lines suppression. Fresh exact-head CI and ClawSweeper re-review are pending.git diff --check, targetedoxfmt, targetedoxlint, and the focused tests passed.Repair Doctrine Summary
AI-assisted: yes.