Repository navigation
perf(ui): overlap chat startup with Gateway connection - #185683
Conversation
Adopt the existing authenticated transport and initial subscription after a bounded event handoff. Preserve live event ordering, foreground ownership, and normal reconnect recovery while the renderer loads.
|
🦞👀 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d38608a0fc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| route?.kind !== "literal" || | ||
| route.namespace !== "chat" |
There was a problem hiding this comment.
Exclude unresolved name links from early Gateway startup
For display-name links such as /chat/roboclaw/deploy-monitor, sessionRefFromPath returns kind: "literal" with a slugCandidate, so this guard incorrectly treats the name as an exact session key. loadChatRoute subsequently resolves that name through the Gateway and canonicalizes the URL to the actual session. The early handoff then encounters a different URL or session key: takeSubscription either forces a reconnect immediately or leaves events buffered until the ten-second timeout forces one. This adds an unnecessary connection restart and discards buffered delivery on supported name-link navigation. Keep targets with slugCandidate on ordinary startup until the existing route owner resolves their identity.
AGENTS.md reference: ui/AGENTS.md:L16-L16
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Keeping the bounded route-guess behavior here deliberately: if the existing route owner resolves a different session or URL, the early handoff is retired and ordinary startup reconnects. A possible extra reconnect for a name-shaped literal is an accepted fallback; the transport does not add a second route resolver or cache. I clarified the source comment and PR description so they no longer imply that every literal candidate is already an exact identity. Short-ID references continue on ordinary startup.
|
Codex review: needs changes before merge. What this changesThis PR starts the Gateway connection and initial transcript subscription before evaluating the Control UI renderer. Example: Open Chat on desktop with the synthetic 100 ms network profile.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 3 items remain Keep open for focused repair: this maintainer-authored optimization has clear value, but the patch is not ready to merge. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe browser entry resolves connection settings, starts the existing Gateway client, and transfers its subscription and buffered events to the application and chat pane. flowchart LR
A[Browser document] --> B[Startup settings]
B --> C[Existing Gateway client]
C --> D[Bounded event handoff]
A --> E[Deferred application renderer]
D --> E
E --> F[Chat subscription and transcript]
Technical reviewBest possible solution: Keep the existing client and subscription coordinator, exclude unresolved name links from early startup, and migrate the remaining test consumers. Do we have a high-confidence way to reproduce the issue? Source establishes the premature name-link admission, and exact-head CI independently records both broken test consumers; no target code was executed during this read-only review. Is this the best way to solve the issue? The small entry and bounded handoff address the serialized startup work using existing transport owners; the inspected extractions preserve their implementations without adding another authentication or subscription policy. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 60aaedd81245. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +433, Tests +436, Docs +11, Other +73. Total +953 across 29 files. Added test files: 2. View PR surface stats
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 27, 2026, 4:48 AM ET / 08:48 UTC. |
Preserve the existing protocol retry and its error receipt until the app attaches. Hold every startup descriptor in the stream fixture, and label the two recovery send waits for targeted CI diagnostics. Keep the startup ratchet at the final measured size.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9abdb1ccbe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| void (early ? early.transport.client.initialConnectSent : Promise.resolve()) | ||
| .then(() => import("./main.runtime.ts")) | ||
| .then(({ startControlUi }) => startControlUi(initial, early)); |
There was a problem hiding this comment.
Let warm reloads render before the connect request is sent
On a warm reload of an exact chat link, if the Gateway connection stalls before delivering its challenge (for example, a blackholed connection during a network outage), initialConnectSent remains pending until the early transport's ten-second timeout stops the client. Because the renderer import now waits for that receipt, the cached shell, conversation, and drafts cannot appear during those ten seconds, even when all assets and retained data are available locally. Previously, bootstrapApplication admitted the warm boot and restored those views independently of the handshake. Keep warm-cache rendering independent of this network-dependent receipt, while retaining the early connection optimization.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ddea67a. The credential owner now exposes its existing boot-record admission, and admitted cached reloads skip the network-dependent renderer wait. The matching warm-reload test withholds the first challenge, proves cached shell/transcript/draft restoration before connect on one socket, then releases the challenge and verifies reconciliation. It fails on the old path and passes with the fix; cold startup retains the early-connect ordering.
|
Merged via squash.
|
* perf(ui): overlap chat startup with the Gateway connection Adopt the existing authenticated transport and initial subscription after a bounded event handoff. Preserve live event ordering, foreground ownership, and normal reconnect recovery while the renderer loads. * perf(ui): ratchet measured boot sizes and use owned listeners * perf(ui): pin final measured boot budgets * fix(ui): preserve startup errors through early handoff * test(ui): preserve window events in reload fixture * fix(ui): retain retryable admission during early handoff Preserve the existing protocol retry and its error receipt until the app attaches. Hold every startup descriptor in the stream fixture, and label the two recovery send waits for targeted CI diagnostics. Keep the startup ratchet at the final measured size. * docs(ui): clarify early route guess fallback * perf(ui): ratchet integrated startup size to measurement * fix(ui): preserve early observer across history changes * fix(ui): restore cached views before Gateway challenge
Related: #185464
What Problem This Solves
Chat startup waits for the renderer graph before connecting to the Gateway and loading the initial transcript. This keeps module evaluation and network round trips on the same critical path.
User Impact
Chat becomes ready sooner by overlapping the Gateway handshake and initial subscription with application loading. Cached reloads continue rendering when the Gateway is unreachable.
Why This Change Was Made
Start the existing
GatewayBrowserClientbefore renderer evaluation, then let the application adopt that same client and subscription. The transport retains ordered events until attachment, bounded to 256 events, 2 MiB, and 10 seconds. It preserves one connection and the existing authentication, admission, retry, and authority owners.Pre-attach authentication errors reach the login owner; retryable rejection retains the protocol client and its retry budget. Rejected subscriptions reach the pane's existing read-retry policy. A changed history request discards only the stale prefetched snapshot, preserving live delivery while the history owner requests the correct shape. Cached views use the credential owner's existing boot-record admission and never wait for a missing Gateway challenge.
Route/credential mismatch, overflow, and timeout fall back to ordinary startup. Native handoffs, ingress documents, short references, and confirmation-required Gateways retain their existing path. A name-shaped literal remains a guess: if the route owner resolves a different target, the bounded handoff retires and ordinary startup reconnects. This accepted extra reconnect avoids a second route resolver. No protocol change or new dependency.
Evidence
Performance
The final comparison against main
979c8decf7dfe07616aac6243f7bcf78d505be58passed 480/480 observations: 20 interleaved pairs for cold/warm boot, Chromium/WebKit, and localhost/100 ms, including an identical-base A/A control. Immutable production bundles use identical build metadata, all 37 matching plugin inputs, and all 61 matching emitted plugin files. Values are median / p95 readiness in milliseconds.Every readiness p95 improves. Chromium local script CPU improves 11.7% cold / 10.3% warm; all script and task p95s improve. Warm/100 ms task CPU moves +2.1% against an A/A +1.9%, within the acceptance band, with p95 -4.4%. Local warm Chromium A/A p95 moves -6.0%; CPU and twenty-pair results qualify that noisy tail. No affected CPU regression exceeds the band. WebKit has no untraced CPU counter; its readiness is elapsed time.
Earlier qualified matrices add 1,440 observations and 16 separate profiler captures: 1,920 valid untraced observations overall. An 86-observation intermediate run was stopped and excluded after main changed route prewarming. The 100 ms profile delays each HTTP request and inbound mock Gateway frame; it is synthetic latency, not physical-network or live-provider RTT. Warm means a same-context reload retaining IndexedDB; mocked routing disables HTTP caching. Every final observation uses one connection.
The remote engine ratios are below 1.3×; local ratios remain 1.52× cold / 1.84× warm. Earlier WebKit Timeline/ScriptProfiler/CPUProfiler and Chromium CDP/source-map captures identify remaining transcript layout, virtualization, and Solid work; this PR does not claim the residual gap is exclusively engine-internal.
Strict performance comparison passes. The startup ratchet matches the measured 90,195 B. The largest chunk remains below its existing 571,274 B cap. Full-route requests decrease by one; plugin stylesheet URLs stay lazy.
Correctness and validation
ci:full, current headd4291e0dd875151efe2ed9f43839f28be7acc800: 40493570441: 47 jobs passed, 23 skipped, no failuresEarlier CI exposed and drove repairs to error delivery, retryable admission, and saved-startup live delivery. Run 40489643508 passed the saved-recovery case but failed “real chat route recovers current account state after complete snapshot ordering”: Account B arrived, but the picker was closed at assertion time. That exact case passed separately on both the base and repaired head. This integration also includes main's authoritative-readiness test correction from #185745; the failure is not described as inherited or as proven fixed solely by a passing replay. Current-head full CI passed all required jobs, including all UI browser and real-Gateway shards.
The directly coupled mock now tracks observer IDs independently; releasing one same-session subscription no longer silences another. Original recovery ACK fixtures and assertions are preserved.
All browsers are headless. No remote leases or local Docker. Reports and captures are under the lane's
.artifacts/; no report is committed.Physical LOC across touched files: production UI 2,798 → 3,247 (+449); tests 4,404 → 5,070 (+666); harness/build/docs 4,899 → 5,015 (+116); total 12,101 → 13,332 (+1,231). The added code implements the bounded transport handoff and its ordering/error proof. Domain and protocol ownership remain unchanged.
Before / after
Inspected synthetic fixtures only; rendered UI is preserved.