Repository navigation
fix(control-ui): prevent extra connections on cached reloads - #185886
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 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 maintainer review before merge. What this changesThis PR defers unresolved session-link lookups until the Gateway connects and refreshes retained links when hello arrives. Example: Reload cached chat containing /chat/main/d0effac9 while device identity preparation is pending.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes a source-backed reconnect defect through existing owners, and no actionable patch defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Control UI session-link titler consumes registered Markdown links, session roster data, and Gateway connection state; it resolves missing identities through Gateway RPC and decorates links with titles. flowchart LR
CachedMarkdown --> RegisteredLinks
RegisteredLinks --> SessionLinkTitler
GatewaySnapshot --> CapabilityCheck
CapabilityCheck --> SessionLinkTitler
GatewayHello --> ExistingSubscription
ExistingSubscription --> SessionLinkTitler
SessionLinkTitler --> GatewayRPC
GatewayRPC --> TitledLinks
Technical reviewBest possible solution: Keep admission in the existing titler and hello notification in the existing provider subscription, preserving immediate cached rendering. Do we have a high-confidence way to reproduce the issue? Current-main source permits sessions.resolve before hello, matching the supplied real-Gateway INVALID_REQUEST and 1008 traces; this read-only review did not execute the reproduction. Is this the best way to solve the issue? The patch addresses request admission at its existing owner and retries deferred decoration through an existing subscription, without delaying cached content or adding competing machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5bf0c41a03f1. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +17, Tests +309. Total +326 across 5 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 27, 2026, 8:45 AM ET / 12:45 UTC. |
cbd3733 to
8532a9a
Compare
8fb8143 to
eecd3c8
Compare
a6f388c to
5626e9c
Compare
5626e9c to
9087178
Compare
…he first frame (openclaw#185886) openclaw#185558 rendered cached chats before the Gateway connects; cached session-link title decoration (SessionLinkTitler.resolveReference) then sent sessions.resolve before connect. The Gateway rejected it (INVALID_REQUEST) and closed the socket with 1008 "invalid handshake: first request must be connect", so warm reloads reconnected: on the real-Gateway proof rig, 10/11 dashboard warm reloads sent two connect frames and hello moved 494 -> 1,615 ms (bisected to 7dc64a0; parent 0/11). The gateway client now owns the invariant that connect is the first frame on every socket: requests issued before hello admission are held with their abort signals/timeouts and released in order after hello for the current socket generation; connect itself bypasses the hold; requests on a socket that already closed still fail with the typed not-connected outcome. Cached session links no longer interrupt a reconnect. Package README documents the contract. Regressions: handshake-queue unit tests (held requests are not sent before connect and resolve after hello; reentrant hello requests stay behind earlier held work) and a real-Gateway warm-connect e2e asserting exactly one connect and no 1008 close per warm reload. Test fixtures that issued requests before hello now complete the handshake first. All test suites green on the exact head; the test-lines ratchet is over its ceiling on main already (+473) and this PR adds +587 lines of regression coverage — the ceiling is being set to the exact observed total separately (openclaw#185853). Release-note context: Control UI reloads no longer drop and reopen their first Gateway connection when cached session links are present.
What Problem This Solves
Fixes the extra connection on warm chat/dashboard reloads introduced by #185558. Cached content can mount while device identity is being prepared. Session-link decoration then issues
sessions.resolvebeforeconnect; the Gateway rejects it withINVALID_REQUEST, closes the socket with 1008, and the browser reconnects.The introducing-commit bisect found no failures in 11 parent reloads and 10 failures in 11 introducing-commit reloads. The native regression reproduces the first-frame violation on both routes without changing the early cached-content rendering.
Why This Change Was Made
The shared Gateway protocol client now enforces the handshake boundary. Ordinary requests enter the existing pending-request map immediately, retaining their original deadline and abort handling, but stay unsent until hello is accepted and published. The internal connect request alone bypasses that hold. The map drains in FIFO order, including reentrant requests from hello/onSent callbacks, and checks current socket authority before each send. Close/stop rejects held requests without replaying writes on a replacement socket.
This replaces consumer-specific readiness policy with one transport owner. Browser and Node adapters share the invariant; cached session titles remain available while live resolution waits for hello. No protocol field, schema, configuration option, or second queue is added.
User Impact
The cached page still renders before the connection is ready, while the first socket completes its handshake normally. The unchanged offline regressions retain cached transcript, board, and reconnect-indicator coverage when the socket is unavailable.
Evidence
Native regression
Both chat and dashboard cases render an unresolved cached session link while native identity work is held, then release the handshake and perform another natural warm reload. Each candidate reload must have one socket, exactly one connect, zero closes, and connect as its first request. Main fails with
sessions.resolvefirst and a native 1008 close. There is no client close call in the failing trace. The controlled hold prevents main's first connect from reaching the wire before the close, isolating the same violation behind natural two-connect reloads.The new protocol regression also fails against the baseline and passes with the fix. Its distinct boundaries cover opening/signing, hello publication, FIFO/reentrancy, original timeout, cancellation, close/stop, asynchronous Node acceptance, and retirement during queue draining.
Size and simplification
Application runtime delta: +28 LOC. Requested non-test diff: +34 LOC, including six README lines. The existing pending map owns the hold and its cleanup; the initial consumer guard is removed. Runtime growth is required to enforce the first-frame contract while preserving cancellation, deadlines, and live socket authority.
Tests/support add 587 net lines. The existing test-line ceiling increases by exactly 587, preserving main's allowance without additional slack. Fixtures that previously injected private transport state or treated hello receipt as publication now complete the real protocol lifecycle. Four shell transport cases and the existing Talk catalog cases move into focused files without duplication; main's newer history fixture is retained intact.
Review and proof
Independent local review is clean through P2 for the complete transport/fixture cutover and subsequent narrow repairs. Broad UI unit/browser proof passed 1,899 files and 20,973 tests, with three existing skips, on the same production fix before the final metadata/rebase changes. The final head is separately covered below by focused/native tests, full UI e2e, and exact-head CI.
Final candidate:
9087178ddeb5e41f82c0f435f4dee3e92c91f2c8; pinned main:7a95ec8a4d64d8f34bc3c025aabb89d95878b1b1. AWSc7a.4xlarge, leasecbx_64f25b0ec7d9, runrun_80adc9c8d1b3654601864789d33fbe37. Chromium 156.0.8078.4; 3,000 retained sessions; nine tall assistant rows including table/image; Details open on chat; signed-in admission; 80 ms CDP network shaping; eleven interleaved AB/BA warm pairs per route. Quiet-host sample: 93.06% CPU idle across 16 CPUs. CDP shaping is not calibrated per-RPC wire RTT.Candidate: 22/22 one-connect warm loads, zero 1008 closes, connect first on every socket.
Chat timings
Median [Q1, Q3]; deltas are candidate minus main. Lower is better.
Dashboard timings
Median [Q1, Q3]; deltas are candidate minus main. Lower is better.
The row metric is the rig's DOM/rAF proxy, not audited compositor paint. Last visual change uses the compositor-frame visible-change census. Representative chat and dashboard side-by-side sheets were inspected; they contain only the synthetic fixture. These counts include all page regions and are not a claim that the separate two-state paint-holding goal is complete.
Open secondary: chat last visual change is +57.42 ms by paired median, worse in 9/11, meeting the declared regression threshold. Every final change is in the sidebar. Main-pane region timing has mixed signs; hello/first rows are essentially unchanged. The fresh A/B repeat and same-code A/A control below show a similarly directed arm difference with identical code; causal attribution to the transport remains inconclusive. No chat settle improvement is claimed. Dashboard hello is 657.49 ms on this newer base; this comparison does not establish the historical 494 ms absolute target.
Validation and inherited failures
Exact-head CI run is complete. Every leaf check passes except test-line baseline ratchets; the aggregate CI gate consequently fails. The job's merge target is main
bc197791931b3e98dd09a19c68ae3077478c5e2a. Its only changes since the pinned main are two production files; ratchet code, ceiling, and all counted test/support inputs are identical.Matched controls use the same checker and common reference
c168d2b0b7fb11f4cd463191a4f508c6775fbc9bwith--no-merge-base, so both arms include their actual growth rather than receiving the zero-delta exemption:The PR reserves its own 587 lines and leaves the inherited 1,060-line debt visible. No CI rerun or unrelated budget increase is used to chase green.
Main also reproduces the changed-check dead-export failure:
runPrompt/scheduleLineinextensions/knowledge/src/scribes-catalog.ts, andSessionColdOversizedinsrc/config/sessions/session-accessor.sqlite-archive-types.ts. The final changed-file run is still in progress; the earlier run passed types, lint, formatting, and all other listed guards, with only those same unused exports failing.Merge status: merged externally as
a6c11850723c4c47fa30eba37d7a58dff9ef8ec4at 16:31:42 UTC while this final-head proof run was active. The validation and open secondary above remain explicit.Synthetic before/after
Main is on the left and candidate on the right. Chat shows the open late-facts secondary; dashboard shows the reconnecting baseline versus the connected candidate.
Fresh chat repeat and A/A control
Both use the same retained AWS
c7a.4xlarge(cbx_a731d41e659f), 11 interleaved warm pairs, the same signed-in synthetic Team-scale fixture and 80 ms CDP shaping. Fresh A/B compares the same pinned source heads as above. A/A serves the candidate UI in both arms; the UI index hashes are identical. No Mac timings are included.The original chat last-visual result (+57.42 ms paired, 9/11 worse) remains visible above. Fresh A/B gives +41.79 ms paired, 7/11 worse with overlapping IQRs. A/A gives +32.60 ms paired, 9/11 worse; the arm medians themselves rise 55.91 ms despite identical code. Thus this sidebar-settle metric is arm-sensitive and the original result does not establish a causal transport regression. It remains inconclusive; this report does not claim a chat settle improvement. Hello remains essentially unchanged. All warm chat loads in both experiments send exactly one connect with zero 1008 closes. Representative filmstrips were inspected; late Details, image, and sidebar facts remain outside this fix.
Fresh A/B chat
Candidate/candidate A/A chat
Full-UI failure controls
Each of the seven retained failed files was run once on pre-fix main and once on transport head, one worker at a time on
cbx_a731d41e659f. Pending handoff (consumed-prompt assertion), outbox migration (roster readiness), startup priority (hidden refresh count), header subagents (Details wait), all three module-boundary placement-recovery variants (roster readiness), and the QA automation second case (private-mutation-boundary setup error) reproduce on main. The QA main control additionally rejects its capture directory outside the detached checkout in its first case; that additional setup error is not a product verdict.The cached-anchor file passes on main (24.01 s) and fails on the transport head (31.92 s) at its obsolete wait for an unsubscribe before releasing connect. All cached display and geometry assertions passed before the wait. The test-only correction landed upstream in #185839 (
5949887220258626159b602e1f6ada8962bac885), preserving held hello and every display/reconciliation assertion. #186131 and #186132 strengthen the no-prehello-subscription assertions. No duplicate PR is needed.The original full-UI invocation completed with exit 1 after 4,531.49 s. Its final summary was lost when the non-retained lease released; the retained partial log identifies the seven files above. The original full-suite invocation remains failed proof with no invented final pass counts. The fixture correction has passing exact-head upstream CI, documented below. Queue regression wall time with
pnpm test packages/gateway-client/src/protocol-client.handshake-queue.test.ts --maxWorkers=1: 3.32 s, passing.Upstream fixture repair and closeout
Current main already incorporates the needed cached-anchor fixture correction from #185839, with added first-frame assertions from #186131/#186132. The two transport runtime owners and native warm-connect/offline regression files are byte-identical between tested transport head
9087178ddeb5e41f82c0f435f4dee3e92c91f2c8and inspected main161c376d51b886186e1a6527775350d4a07f86ab.Upstream #185839 exact-head CI is independently verified: head
eb316f339372f20d5c05b09078a489d62b4fdc60, run 40554442758, completed successfully. Its retained PR evidence also records the corrected anchor case passing once (4.223-second case / 18.374-second total). This does not relabel the original transport head's inherited ratchet failure or claim a passing full-UI-suite replay.No further source change or duplicate follow-up PR was made. This session did not merge the transport PR or deploy a Gateway.