Repository navigation
fix(control-ui): Control UI drops its pending connection when the tab wakes during a busy Gateway - #172864
Conversation
Tab wake recovery replaced the client whenever the socket was not yet open, dropping an in-flight upgrade while a stalled Gateway was still answering it (Gateway logged closed before connect code=1006 phase=ws_upgrade_started). The protocol client now reports an opening socket and wake recovery leaves it alone; the browser opening timeout still bounds a stuck upgrade. Same-Gateway reconnects on the logs page now resume logs.tail from the loaded cursor instead of re-reading and re-redacting the full window. Related: #172507
|
🦞👀 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 SummaryThis 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 changes before merge. What this changesThis PR preserves pending Control UI connections during tab wake and resumes log reads from the existing cursor after reconnecting. Example: A tab becomes visible 5 seconds into a pending Gateway WebSocket upgrade.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: the connection repair is useful and remains absent from current main, but the shared mock change introduces a confirmed CI failure. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe Control UI adapts the shared Gateway protocol client to browser WebSockets; page activation consumes connection state, while the logs page requests redacted log windows through logs.tail. flowchart TD
A[Tab activation] --> B[Browser Gateway client]
B --> C[Shared protocol lifecycle]
C --> D[Browser WebSocket]
D --> E[Gateway]
F[Logs page] --> B
E --> G[Redacted log tail]
Technical reviewBest possible solution: Keep the focused production repair and update the Gateway broadcast fixture to open its socket before sending requests. Do we have a high-confidence way to reproduce the issue? Source establishes that current-main wake recovery replaces a socket whose upgrade is pending; supplied regression results support that path, but the reporter's complete outage was not reproduced. Is this the best way to solve the issue? The production approach fixes client-side abandonment at the existing lifecycle owner and reduces redundant log reads without adding another retry mechanism. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 148a19f69f2c. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceAcceptance criteria:
What I checked:
PR surfaceSource +8, Tests +43. Total +51 across 7 files. Added test files: 0. View PR surface stats
Review metrics
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 October 15, 2026, 3:05 AM ET / 07:05 UTC. |
) Tab wake recovery replaced the client whenever the socket was not yet open, dropping an in-flight upgrade while a stalled Gateway was still answering it (Gateway logged closed before connect code=1006 phase=ws_upgrade_started). The protocol client now reports an opening socket and wake recovery leaves it alone; the browser opening timeout still bounds a stuck upgrade. Same-Gateway reconnects on the logs page now resume logs.tail from the loaded cursor instead of re-reading and re-redacting the full window. Related: #172507 (cherry picked from commit 1f862d1)
…claw#172864) Tab wake recovery replaced the client whenever the socket was not yet open, dropping an in-flight upgrade while a stalled Gateway was still answering it (Gateway logged closed before connect code=1006 phase=ws_upgrade_started). The protocol client now reports an opening socket and wake recovery leaves it alone; the browser opening timeout still bounds a stuck upgrade. Same-Gateway reconnects on the logs page now resume logs.tail from the loaded cursor instead of re-reading and re-redacting the full window. Related: openclaw#172507
The #172864 backport (1a5bdbd) made same-Gateway reconnects resume logs.tail from the loaded cursor, but release/2026.10.5 lacks main's boot-scoped cursor from #172828. After a Gateway restart that rewrote the log file in place, the next poll resumed the old byte offset and appended the new tail to retired rows (ui/src/e2e/logs-lifecycle.e2e.test.ts). Record the hello server bootId with each cursor and read from the start when it changes, retaining stale rows until the replacement succeeds. A boot-change read counts as a reset so it supersedes the reconnect's pending invalidation run instead of waiting for the next poll.
The openclaw#172864 backport (1a5bdbd) made same-Gateway reconnects resume logs.tail from the loaded cursor, but release/2026.10.5 lacks main's boot-scoped cursor from openclaw#172828. After a Gateway restart that rewrote the log file in place, the next poll resumed the old byte offset and appended the new tail to retired rows (ui/src/e2e/logs-lifecycle.e2e.test.ts). Record the hello server bootId with each cursor and read from the start when it changes, retaining stale rows until the replacement succeeds. A boot-change read counts as a reset so it supersedes the reconnect's pending invalidation run instead of waiting for the next poll. (cherry picked from commit ddd39ec) Co-authored-by: RomneyDa <[email protected]>
) Tab wake recovery replaced the client whenever the socket was not yet open, dropping an in-flight upgrade while a stalled Gateway was still answering it (Gateway logged closed before connect code=1006 phase=ws_upgrade_started). The protocol client now reports an opening socket and wake recovery leaves it alone; the browser opening timeout still bounds a stuck upgrade. Same-Gateway reconnects on the logs page now resume logs.tail from the loaded cursor instead of re-reading and re-redacting the full window. Related: #172507 (cherry picked from commit 1f862d1)
The #172864 backport made same-Gateway reconnects resume logs.tail from the loaded cursor, but 2026.10.10 lacked main's boot-scoped cursor. After a Gateway restart that rewrote the log file in place, the next poll resumed the old byte offset and appended the new tail to retired rows. Record the hello server bootId with each cursor and read from the start when it changes, retaining stale rows until the replacement succeeds. Release adaptation: ports the logs-page hunk of main 65023f7 (#172828) instead of the 2026.10.5 Lit adaptation ddd39ec, since 2026.10.10 carries main's Solid logs page. (cherry picked from commit ddd39ec) (partial cherry pick from commit 65023f7)
Related: #172507
What Problem This Solves
Fixes: the Control UI drops its own pending WebSocket upgrade, and shows "disconnected", when the tab regains focus or the network comes back while a busy Gateway is still answering the upgrade.
User Impact
User impact: a Control UI tab that is reconnecting to a stalled Gateway keeps its in-flight connection instead of abandoning it, and reconnecting to the same Gateway no longer re-reads the full 250 KB logs window.
Why This Change Was Made
Tab wake recovery (
visibilitychange,online) askedneedsWakeReconnect, which treated any socket that was not yet open as needing replacement. A socket waiting for the Gateway's101response is not stale: replacing it made the browser drop the TCP connection, and once the stalled main thread caught up the Gateway loggedclosed before connect code=1006 phase=ws_upgrade_startedwithin milliseconds. A fresh upgrade then queued behind the same stall. The protocol client now exposesopening(socket created, not yet open), and wake recovery leaves that socket alone. The existing 30 s browser opening timeout still bounds a stuck upgrade, reconnect backoff is still skipped on wake, and Safari page-cache restores still force a fresh client.The logs page also reset
logs.tailto a full window on every same-Gateway reconnect, costing the Gateway one log read plus a synchronous redaction pass per reconnect. It now resumes from its cursor; identity changes and manual refresh still reset. Poll ownership was already single (one interval, no overlapping reads), so reconnects do not multiply poll loops.Version diff note: the Gateway WS handshake path, keepalive, gateway-client reconnect, and Control UI socket code are identical between v2026.10.1 and v2026.10.3, so 10.3 introduced no new deadline. The report's increase lines up with longer Gateway stalls; one measured contributor is egress redaction in
logs.tail, about 3x slower since the 10.3 redaction rewrite (real 250 KB tail: ~31 ms on 10.1 vs ~93-104 ms on main), plus a whole-file backward PEM-context scan on every poll. That redaction cost is tracked as a separate follow-up because it touches the secret-redaction boundary.Evidence
keeps an in-flight upgrade through tab wake while the Gateway is stalled(ui/src/api/gateway-heartbeat.node.test.ts) fails on the original code (expected true to be false) and passes with the fix; it also asserts backoff still counts as a wake reason.resumes the loaded cursor after a same-gateway reconnect(ui/src/pages/logs/logs-page.test.tsx) fails on the original code and passes with the fix.MockWebSocketnow startsCONNECTINGlike a real browser socket; seven chat-delivery tests that sent requests on a never-opened socket now open it first.pnpm check:changed: all ratchets pass except the inherited env-var budget (main already has 455OPENCLAW_*vars against a 454 budget; this diff adds none). Codex autoreview: scoped-clean at P0-P2.