Repository navigation
fix(reef): release inbox sockets before shutdown completes - #197717
Conversation
Terminate the inbox WebSocket and join its close event so a relay that withholds the close reply cannot retain TLS and the ws close timer after account shutdown. Preserve serialized inbox handling and cursor writes. Generic Gateway shutdown already awaits account teardown. Related: #197382.
|
🦞👀 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 Summary: ✅ CompletedThis 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. |
|
Codex review: needs maintainer review before merge. What this changesThis PR terminates abandoned Reef inbox sockets and waits for their close event before account teardown completes. Example: The Gateway stops while a Reef relay withholds its WebSocket close reply.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR makes a focused repair to Reef shutdown, and source review found no actionable correctness defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Reef inbox transport receives relay messages over WebSocket, serializes delivery and cursor persistence, and exposes an account task that Gateway shutdown awaits. flowchart TD
A[Gateway shutdown] --> B[Channel manager]
B --> C[Reef account lifecycle]
C --> D[Inbox transport]
D --> E[Terminate relay socket]
D --> F[Drain serialized inbox work]
E --> G[Account completion]
F --> G
Technical reviewBest possible solution: Keep teardown in ReefInboxConnection, terminate abandoned sockets, and preserve the existing serialized delivery and cursor-persistence drain. Do we have a high-confidence way to reproduce the issue? Current main exposes the premature-settlement path, and the committed real-TLS regression targets it directly; this read-only review did not execute the reproduction. Is this the best way to solve the issue? The patch repairs the transport owner directly without adding a Gateway workaround, new state owner, configuration, or redundant regression layer. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against edc890bd243d. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests +157, Docs +4. Total +161 across 5 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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 Reviewed November 12, 2026, 7:28 AM ET / 12:28 UTC. |
|
ClawSweeper reviewed Command: OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs test/plugins/reef-shutdown.gateway.test.ts --maxWorkers=1Original transport from Fixed transport, final committed source: The assertions run after the actual Gateway close handler and before fixture cleanup. They verify the real TLS client is destroyed and the TCP/TLS/Timeout resource census returns to its empty pre-start baseline. The local TLS peer withholds its close reply; fixture-owned handles are unreferenced. The final regression also passed pinned Bun. Exact-head CI run 43215689570 and |
|
Merged via squash.
|
…197717) Terminate the inbox WebSocket and join its close event so a relay that withholds the close reply cannot retain TLS and the ws close timer after account shutdown. Preserve serialized inbox handling and cursor writes. Generic Gateway shutdown already awaits account teardown. Related: openclaw#197382.
What Problem This Solves
Fixes Gateway processes remaining alive after shutdown when a Reef relay does not acknowledge WebSocket closure.
User Impact
Stopping Reef or shutting down the Gateway releases the inbox socket without waiting for the relay. In-flight inbox handling and cursor persistence still finish before the account stops. No configuration or migration is required.
Why This Change Was Made
Reef called
ws.close()and settled its account task while the TLS socket and WebSocket library's 30-second close-handshake timer remained alive. The transport now terminates abandoned sockets and joins their close event. Generic Gateway shutdown already awaits account teardown, so core production code is unchanged.Related: #197382.
Evidence
TCPSocketWrapandTimeoutremaining; with the fix the active-resource census returns to its empty baseline before fixture cleanup.Codex autoreview of the final local patch against
83e3641e092125c009d3421e60560fda8af75c86was scoped-clean through P2, with no accepted/actionable findings.pnpm check:changedcompleted: own Promise-executor and sorting lint findings were corrected and affected lint/format checks rerun successfully. The only unresolved local failure is seven unused exports in untouched Rerank/TypeSafe files, reproduced on the exact base by lane 2435 and introduced by #197615 (81ec45243fd6); #197679 (c06331c4b8e6) already repairs this main regression. All other checks passed. Final Node replay after the mechanical lint corrections passed (2.383 s body). Production LOC delta is zero. Exact-head CI 43215689570 andopenclaw/ci-gatepassed. Hosted Codex review found no issues; ClawSweeper reviewed the final head with zero findings and no open items. Red/green terminal excerpts show TLS destruction and the resource census before cleanup.