Repository navigation
fix(gateway): prevent silent delivery loss on closing connections - #128144
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 4:37 AM ET / 08:37 UTC. ClawSweeper reviewWhat this changesThe PR prevents Gateway direct replies and broadcasts from treating closing WebSockets as deliverable, while preserving node drain and worker-handshake cleanup. Merge readinessKeep open for maintainer handling: current main still reports sends to closing transports as successful, while the PR adds the missing readiness admission at the direct-response and fanout owners. No blocking patch defect was found; merge should wait for a current-main refresh and exact-head checks. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherGateway WebSocket connections carry direct RPC responses and ordered event fanout to Control UI clients and nodes. The connection handler owns direct-send availability, and the broadcaster owns per-client event sequencing and delivery eligibility. flowchart LR
A[Gateway RPC or event] --> B[Direct response handler]
A --> C[Event broadcaster]
B --> D[WebSocket readiness check]
C --> D
D --> E[Open transport]
D --> F[Closing transport]
E --> G[Response or ordered event]
F --> H[Node drain and cleanup]
Decision needed
Why: The protected maintainer label requires an explicit maintainer merge decision even though the review found no blocking correctness defect. Before merge
Agent review detailsSecurityNone. PR surfaceSource +15, Tests +293. Total +308 across 14 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the shared OPEN-state invariant at the direct-response and broadcast owners, preserve node-drain retention, then merge only after a current-main refresh and green exact-head validation. Do we have a high-confidence way to reproduce the issue? Yes—current-main source exposes the missing direct and broadcast readiness checks, and the branch contains focused closing/closed and real-loopback regressions; this review could not rerun them locally because dependencies are absent. Is this the best way to solve the issue? Yes—the shared OPEN-state admission extends the existing Node registry invariant at the actual generic send owners, while retaining the node-drain lifecycle contract rather than deleting a closing node early. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2175a1502099. LabelsLabel changes:
Label 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 (1 earlier review cycle)
|
|
ClawSweeper rank-up follow-through: the required exact-head CI gate is now green for ba8c8b3, and the focused real-WebSocket and Gateway lifecycle suites pass. Skipping the suggested moving-main refresh because this PR remains mergeable and nonconflicting, the affected Gateway owners are unchanged, and repository maintainer policy explicitly says not to rebase solely because main advanced. Refreshing would invalidate the already-reviewed, green exact head without reducing merge risk. Verification: 596 focused Gateway and lifecycle tests passed; 67 plugin-list cold-import and routing tests passed; the independent ClawSweeper real-WebSocket proof passed all 60 tests. The earlier startup-memory failure was independently shown to be runner variance and passed on a failed-jobs-only rerun without code or threshold changes. |
|
Merged via squash.
|
…enclaw#128144) * fix(gateway): reject sends on closing websocket transports * fix(gateway): share websocket readiness without eager imports
- Break import cycles: extract GatewayOperatorRoleActor leaf contract; merge session-group-mutation-targets into session-sharing-target-input. - Split sessions-suggestions.test.ts (max-lines) into a visibility suite. - Add users.setRole to the 2026.8 train registry test and regenerate the Kotlin protocol client. - Startup UNAVAILABLE gating now precedes session authorization: session stores are not loaded during startup, so authorization reads would deny with a misleading non-retryable error. - sessions.assignOwner keeps its documented visibility-authorized contract when no operator role caps the caller; view/suggest-capped roles still cannot reassign foreign session ownership. - Test stubs updated for main's socket readyState guard (#128144) and the system-authority arg on channel-native resets.
- Break import cycles: extract GatewayOperatorRoleActor leaf contract; merge session-group-mutation-targets into session-sharing-target-input. - Split sessions-suggestions.test.ts (max-lines) into a visibility suite. - Add users.setRole to the 2026.8 train registry test and regenerate the Kotlin protocol client. - Startup UNAVAILABLE gating now precedes session authorization: session stores are not loaded during startup, so authorization reads would deny with a misleading non-retryable error. - sessions.assignOwner keeps its documented visibility-authorized contract when no operator role caps the caller; view/suggest-capped roles still cannot reassign foreign session ownership. - Test stubs updated for main's socket readyState guard (#128144) and the system-authority arg on channel-native resets.
) * feat(gateway): generic operator roles for non-maintainer access Adds gateway.roles: named role bundles over a closed capability set — sessions.others (none/view/suggest/write), an agents allowlist, and an operator-scope ceiling. Roles are person-level (additive user_profiles.role column, SQLite stays at v9); users.setRole (admin-only) assigns them. With no gateway.roles config, behavior is unchanged for solo deployments. Enforcement is deny-by-default from a host-minted actor identity (system vs operator+profileId on server-only client.internal, never accepted from the wire) and covers every entry point: WS RPCs, OpenAI-compat and Responses HTTP, tools invocation, cron, questions, usage, task suggestions, session catalog/sharing/reads. The agents allowlist gates both session creation and run-start on existing sessions. Subagent completion announce and descendant wake mint explicit system authority so role boundaries never silently drop parent notifications. The enforcement surface is expressed through a narrow policy vocabulary (operatorSessionCap, hasOperatorBoundary, authorizeSessionSharing) rather than per-handler policy internals. * fix(gateway): heal PR CI after rebase onto main - Break import cycles: extract GatewayOperatorRoleActor leaf contract; merge session-group-mutation-targets into session-sharing-target-input. - Split sessions-suggestions.test.ts (max-lines) into a visibility suite. - Add users.setRole to the 2026.8 train registry test and regenerate the Kotlin protocol client. - Startup UNAVAILABLE gating now precedes session authorization: session stores are not loaded during startup, so authorization reads would deny with a misleading non-retryable error. - sessions.assignOwner keeps its documented visibility-authorized contract when no operator role caps the caller; view/suggest-capped roles still cannot reassign foreign session ownership. - Test stubs updated for main's socket readyState guard (#128144) and the system-authority arg on channel-native resets. * test(gateway): chat.send pending-profile dispatch carries its required session target chat.send requires a non-empty sessionKey at the protocol level; the mutation pipeline now rejects targetless frames before profile-dependent dispatch, so the pending-profile test must send a realistic frame.
…claw#128548) * feat(gateway): generic operator roles for non-maintainer access Adds gateway.roles: named role bundles over a closed capability set — sessions.others (none/view/suggest/write), an agents allowlist, and an operator-scope ceiling. Roles are person-level (additive user_profiles.role column, SQLite stays at v9); users.setRole (admin-only) assigns them. With no gateway.roles config, behavior is unchanged for solo deployments. Enforcement is deny-by-default from a host-minted actor identity (system vs operator+profileId on server-only client.internal, never accepted from the wire) and covers every entry point: WS RPCs, OpenAI-compat and Responses HTTP, tools invocation, cron, questions, usage, task suggestions, session catalog/sharing/reads. The agents allowlist gates both session creation and run-start on existing sessions. Subagent completion announce and descendant wake mint explicit system authority so role boundaries never silently drop parent notifications. The enforcement surface is expressed through a narrow policy vocabulary (operatorSessionCap, hasOperatorBoundary, authorizeSessionSharing) rather than per-handler policy internals. * fix(gateway): heal PR CI after rebase onto main - Break import cycles: extract GatewayOperatorRoleActor leaf contract; merge session-group-mutation-targets into session-sharing-target-input. - Split sessions-suggestions.test.ts (max-lines) into a visibility suite. - Add users.setRole to the 2026.8 train registry test and regenerate the Kotlin protocol client. - Startup UNAVAILABLE gating now precedes session authorization: session stores are not loaded during startup, so authorization reads would deny with a misleading non-retryable error. - sessions.assignOwner keeps its documented visibility-authorized contract when no operator role caps the caller; view/suggest-capped roles still cannot reassign foreign session ownership. - Test stubs updated for main's socket readyState guard (openclaw#128144) and the system-authority arg on channel-native resets. * test(gateway): chat.send pending-profile dispatch carries its required session target chat.send requires a non-empty sessionKey at the protocol level; the mutation pipeline now rejects targetless frames before profile-dependent dispatch, so the pending-profile test must send a realistic frame.
…eam features - Dockerfile: adopt upstream bun 1.4.0, keep fork NPM_REGISTRY mirror config - gateway ws-connection: merge controlUi auth params (fork) + workerNodeSetup (upstream) - gateway ws-connection send: adopt upstream fix for silent delivery loss (openclaw#128144) - connect-auth: use upstream device-pairing-tokens import + pendingSharedAuthFailure, keep fork controlUiAuthPolicy in return type alongside upstream startupPending - server-startup-finish: adopt upstream pluginRuntimeClaim architecture, merge controlUi + workerNodeSetup params - message-handler-types: merge all three auth param fields + both return fields
… features - Dockerfile: adopt upstream bun 1.4.0, keep fork NPM_REGISTRY mirror config - gateway ws-connection: merge controlUi auth params (fork) + workerNodeSetup (upstream) - gateway ws-connection send: adopt upstream fix for silent delivery loss (openclaw#128144) - connect-auth: use upstream device-pairing-tokens import + pendingSharedAuthFailure, keep fork controlUiAuthPolicy in return type alongside upstream startupPending - server-startup-finish: adopt upstream pluginRuntimeClaim architecture, merge controlUi + workerNodeSetup params - message-handler-types: merge all three auth param fields + both return fields - plugin-sdk-surface-report: keep zerotoken branch export counts (web-model, browser auth)
What Problem This Solves
Fixes an issue where operators using the Gateway or Control UI would silently lose responses, live updates, and worker connection handshakes when a WebSocket entered its closing state before the close event reached the Gateway. The existing WebSocket dependency accepts those send calls without throwing even though it never delivers the frames, so callers previously reported successful delivery and broadcasts consumed misleading sequence numbers.
Why This Change Was Made
Admit direct responses and fanout only while the actual WebSocket is OPEN, stop worker handshake progression before recreating a credential-expiry timer after synchronous transport closure, and keep unavailable broadcasts from advancing healthy-client sequencing. Connection ownership remains with the Gateway: closing nodes with admitted lifecycle work stay discoverable throughout their existing drain so device-pairing and token revocation can still fence the exact live node before the owner retires it.
User Impact
Operators receive truthful delivery outcomes when a Gateway connection disappears, healthy peers continue receiving ordered live updates, and workers no longer appear connected or leave expiry timers behind after their hello cannot be delivered. Existing node result delivery and pairing/token revocation behavior remain intact while disconnect cleanup drains pending work.
Evidence
Regression-first proof on the unmodified owners failed for both CLOSING and CLOSED transports, including real loopback WebSocket peers: direct responses incorrectly returned
sent, broadcast silently accumulated 79 discarded bytes, and closed worker hellos still advanced to ready.A separate regression proved that prematurely deleting a closing node prevents pairing/token revocation from finding it while an admitted node result is still draining. The repaired owner retains that exact node through both pre-close and close-drain fanout and removes it only after the lifecycle work completes.
Final focused and sibling proof: 20 Vitest project files, 340 tests passed, including real healthy/closing peers, async WebSocket callbacks, direct responses, targeted and global fanout, sequence continuity, slow-consumer backpressure, worker timer cleanup, and the existing real pairing-revocation-during-node-drain integration:
Core production typecheck, assertion-safety ratchet, max-lines ratchet, focused oxlint, formatting,
git diff --check, independent source review, and authenticated committed-branch Codex review all passed.The broader core-test typecheck reaches only pre-existing shared-install dependency gaps unrelated to this change: missing
@panzoom/panzoomand@types/pako. Focused Gateway tests and touched-source lint are green; no dependency install or reconciliation was performed in the linked worktree.