Skip to content

improve(ui): reduce typing latency during streamed replies - #158963

Closed
steipete wants to merge 16 commits into
mainfrom
perf/l82-transcript-layout-batch
Closed

steipete wants to merge 16 commits into
mainfrom
perf/l82-transcript-layout-batch

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Long streamed replies interrupt typing and scrolling when pane commits force synchronous transcript layout inside animation-frame callbacks.

User Impact

Pane commits remain batched while input gets its rendering opportunity first. The measured comparison reduces p95 input-to-next-frame latency from 35.05 to 12.35 ms, renderer task time 10.8%, and long tasks 5.6%. Reader position, native footer clamps, prefills, voice controls, and responsive navigation retain their contracts.

Why This Change Was Made

The existing Lit scheduling boundary resumes connected pane commits through a MessageChannel task after the input frame. Cancellation closes both ports and releases the owned waiter; retired deliveries cannot release newer work. Initial rendering and visibility catch-up remain immediate. The transcript still observes geometry synchronously around each actual DOM commit, preserving native-clamp versus reader-motion authority.

The affected owners now preserve their asynchronous contracts:

  • Captured reader anchors finish measured prepend corrections before another paint; a dependency-free touch-state type keeps this handoff acyclic.
  • Route-prefill cleanup waits for the consuming pane's commit and rechecks presentation ownership. Menu insertion updates the native editor immediately so another keystroke cannot overwrite it from stale text.
  • A quick voice tap reconciles the actual readonly attribute through Lit's existing live directive, even when the intermediate pressed state never renders.
  • Responsive sidebar focus restoration waits for the active, presented pane to create its navigation toggle, then rechecks connection, route, pane and focus ownership.
  • Comment deletion and save restore focus after the attachment commit and sibling pin geometry work; retiring a pane or newer user focus cancels the pending restoration. This fixes first-of-two deletion losing focus when an unkeyed list removes the old second-row button.
  • Composer submenu focus follows the committed view and the dropdown item’s own update completion. It preserves newer focus intent instead of focusing an outgoing item in the earlier input frame. Native show/hide events always update the owner; stale rendered props cannot discard a close event and reopen the attachment picker.

Paused-clock E2E fixtures explicitly deliver one virtual render frame; the compaction test retains exactly 177 seconds total. Other affected fixtures wait for their visible row, retired marker, or detached rail before taking snapshots. Existing behavioral assertions remain; no production scheduler bypass, real sleep, timeout increase, or new polling was added. The stream-event scheduler remains because it also batches persistence and input-arrival work before Lit invalidation.

Evidence

Final candidate: 8e704b16db0674b83440a0d0685334561a3f0a0a, source tree d6e1026699955830c2290ce79ecc117f897cc46d. Performance measurements below use scheduling-equivalent parent 389a0f07c186; the final repairs only change submenu/comment focus and E2E synchronization, with no scheduling changes.

Interleaved A/B/A/B on one Blacksmith Testbox, Chromium 144 at 4× CPU throttle, production bundles, unchanged l72 mock-Gateway harness. The control restores the unbatched pane owner from then-current main c0e6951d6f02; all other controls match the candidate. Each trial renders the same 16,201-character reply in 676 chunks while typing.

Median metric Unbatched control Batched owner (389a0f07c186)
Runtime 64.36 s 56.34 s
Long tasks 368.50 348.00
Worst task per run 215.00 ms 188.50 ms
p95 frame gap 125.00 ms 133.35 ms
p95 input-to-next-frame 35.05 ms 12.35 ms
Renderer task time 62,036.84 ms 55,347.41 ms
Style time 13,639.64 ms 14,155.55 ms
Layout time 12,928.10 ms 13,238.03 ms

Tradeoff: p95 frame gap is 8.35 ms higher in this block. This improves input responsiveness without claiming uniformly smoother animation. The producer is browser-owned and slows under load; this is fixed-reply UI proof, not Gateway capacity. Input latency measures event-to-next-animation-frame delay rather than physical display latency.

A separate interleaved published-parent/389a0f07c186 comparison confirms the interaction repairs preserve the existing fast-input behavior: 86302ff19d2a → 389a0f07c186 runtime 51.87 → 50.49 s; long tasks 347.5 → 329.5; worst task 163.5 → 179.5 ms; p95 frame gap 116.70 → 124.95 ms; p95 input 11.15 → 11.25 ms. Absolute timings vary between blocks; use their matched controls. All eight trials delivered 676 chunks and the final sentinel, had no page errors, and finished at zero bottom distance.

Validation on the final source:

  • All 220 focused pane/anchor/composer/page/navigation/comment cases passed, 17.56 s wall; browser ownership/annotations 23/23 passed, 9.86 s.
  • All 233 targeted mock-Gateway E2E cases across 32 files passed: the previous 80-case set in 129.34 s, the 61-case menu/tool/comment/retirement/selection set in 105.44 s, and the latest 92-case failure cohort in 72.42 s.
  • The latest reported regressions reproduced as 18 failures / 92 cases on the published head; the same source with the unbatched pane passed 92/92. Product repairs fix menu event admission and commit-aware focus. Fixture repairs await committed panels, disclosure bodies, selected models, closed dialogs, and keyboard-history updates, while retaining existing value/focus/resource assertions and exact virtual-time budgets.
  • The avatar alignment fixture returned {} for the required membership response, causing the sharing header to throw before committing the transcript. It now supplies the required membership fields; no production avatar, geometry, or fallback change was added.
  • A broader Testbox sweep retained 357 passing files across an interrupted run and a bounded follow-up. Exact-head hosted CI supplies the complete UI E2E inventory check; its discovered failures are included in the targeted cohort above.
  • pnpm check:import-cycles && pnpm check:madge-import-cycles: zero runtime and type cycles, 43.36 s.
  • Full-branch changed-lane gate passed in 1,140.55 s with 0 warnings and 0 errors. The final ten-file repair also passed its changed-lane gate against that verified head in 469.07 s, with 0 warnings and 0 errors.
  • Production UI build/startup budget passed, 0.18 s: startup JS 370,984 B / 371,332 B, 348 B headroom; startup CSS 50,247 B / 51,200 B.
  • Deslop clean; independent Codex review of the full candidate and subsequent repairs clean through P2. Existing E2E cases reproduce the product regressions; no new cases or timeout increases were added.

A separate cron fixture typecheck failure reproduced on main and was fixed upstream in c0e6951d6f02, which this branch includes. No duplicate cron repair was added. The main-refresh commit published concurrently had exactly the same source tree as the locally tested merge; its work was preserved.

Total PR delta: production +219/−76 (net +143), tests +329/−153 (net +176), including an intact scenario extraction required by the existing file-size cap. Necessary growth owns cancellation and draft/focus authority across deferred commits; superseded microtask cleanup, duplicate lookup logic, and a redundant navigation condition were removed. The assertion ratchet also shrank by one stale zero-count row after the old menu cast was deleted. No Gateway protocol, config options, or database changes.

Remote proof: provider blacksmith-testbox; final lease tbx_01m3g4zves4x6ge7tppm5vk7bw (Testbox run). Earlier evidence used tbx_01m3fysyga6305zgkb5etpm9gt, tbx_01m3frgf7e6xhc8n6qb869qs4m, and tbx_01m3fjgqkmch3mtrkqvhy7sfyq; replacements followed provider-ended leases. Commands: targeted node scripts/run-vitest.mjs invocations, both cycle checks, node scripts/check-changed.mjs, production UI builds, pnpm ui:check-performance, and the l72 A/B harness.

Inspected synthetic before/after captures

The capabilities action preserves the unbatched baseline appearance. Crops omit unrelated lower composer controls; the unchanged E2E assertions prove focus, insertion, and every-frame history anchoring. Captured on the initial repair before the behavior-preserving owner extraction.

Before (unbatched baseline):

Capabilities prompt before batching

After (deferred commits with lifecycle repair):

Capabilities prompt after repair

Batch connected pane DOM commits while preserving the synchronous end-anchor distinction between footer clamps and reader movement. Release pending frame waits when hidden or disconnected; preserve immediate initial renders and visibility catch-up.
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 26, 2026 15:15
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 9:54 PM ET / September 27, 2026, 01:54 UTC (Revision 11).

ClawSweeper review

What this changes

The Control UI defers streamed chat transcript commits until after an input frame and updates focus, draft, scroll, and browser-test handoffs for the delayed commits.

Merge readiness

✅ Ready for maintainer review

Current main still uses the earlier chat-pane update scheduler. This PR addresses a distinct Control UI latency problem, with convincing browser measurements and focused interaction coverage; the merged Gateway garbage-collection work does not replace it.

Priority: P2
Reviewed head: 8e704b16db0674b83440a0d0685334561a3f0a0a

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Measured browser behavior, focused interaction validation, and a coherent owner-level change provide strong review confidence.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The changed chat-pane scheduler is covered by interleaved Chromium production-bundle trials that stream 676 chunks while typing and report lower input-frame latency; final-source focus and lifecycle checks supplement that browser result. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The changed chat-pane scheduler is covered by interleaved Chromium production-bundle trials that stream 676 chunks while typing and report lower input-frame latency; final-source focus and lifecycle checks supplement that browser result. No stored-data contract changes.
Evidence reviewed 9 items Introduced scheduling behavior: The PR's pane scheduler waits for an animation frame and a MessageChannel task before a connected pane commit, while preserving immediate initial and detached updates.
Current main remains different: The fetched main revision parks hidden updates but has no input-frame delay for visible connected pane commits.
Deferred interaction handoffs: Route draft cleanup waits for the active pane's commit, and menu visibility follows dropdown show and hide events. The final head also preserves reader-position restoration and comment focus across deferred commits.
Findings None None.
Security None None.

How this fits together

Gateway reply chunks and user input update the Control UI chat pane. Its Lit scheduler commits the transcript and controls to the browser, affecting typing responsiveness, reading position, and focus.

flowchart LR
A[Gateway reply chunks] --> C[Chat pane updates]
B[Composer input] --> C
C --> D{Pane visible?}
D -->|Yes| E[Input frame then DOM commit]
D -->|No| F[Wait for visibility]
E --> G[Transcript and controls]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +143, Tests +176, Other -1. Total +318 across 38 files.

View PR surface stats
Area Files Added Removed Net
Source 13 219 76 +143
Tests 24 329 153 +176
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 38 548 230 +318

Review metrics

Metric Value Why it matters
Input-frame latency p95 35.05 → 12.35 ms The interleaved browser comparison measures the user-facing responsiveness this PR targets.
Frame-gap tradeoff p95 125.00 → 133.35 ms The PR records a narrower input benefit alongside a measurable animation-frame cost.
Production versus test LOC production +219/−76; tests +329/−153 The production growth has a stated lifecycle and focus-ownership purpose, while the test delta includes a scenario extraction.

Technical review

Best possible solution:

Keep typing responsive during long streams while preserving per-pane reader position, drafts, menu state, and keyboard focus.

Do we have a high-confidence way to reproduce the issue?

Yes. The PR gives a specific Chromium A/B scenario with a fixed streamed reply and concurrent typing, and current main retains the earlier pane scheduler; this read-only review did not rerun the scenario.

Is this the best way to solve the issue?

Yes. The chat pane already owns DOM scheduling, and the branch updates the affected focus, draft, and scroll handoffs at their existing owners.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2b4a2749587e.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The change improves Control UI responsiveness during long streamed replies with a bounded, measured user impact.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The changed chat-pane scheduler is covered by interleaved Chromium production-bundle trials that stream 676 chunks while typing and report lower input-frame latency; final-source focus and lifecycle checks supplement that browser result. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed chat-pane scheduler is covered by interleaved Chromium production-bundle trials that stream 676 chunks while typing and report lower input-frame latency; final-source focus and lifecycle checks supplement that browser result. No stored-data contract changes.

Evidence

What I checked:

  • Introduced scheduling behavior: The PR's pane scheduler waits for an animation frame and a MessageChannel task before a connected pane commit, while preserving immediate initial and detached updates. (ui/src/pages/chat/chat-pane-base.ts:111, 8e704b16db06)
  • Current main remains different: The fetched main revision parks hidden updates but has no input-frame delay for visible connected pane commits. (ui/src/pages/chat/chat-pane-base.ts, 2b4a2749587e)
  • Deferred interaction handoffs: Route draft cleanup waits for the active pane's commit, and menu visibility follows dropdown show and hide events. The final head also preserves reader-position restoration and comment focus across deferred commits. (ui/src/pages/chat/route-draft-focus-handoff.ts:57, 8e704b16db06)
  • Existing chat contract: The Control UI documentation says streaming output and layout adjustments preserve reading mode and that assistant text remains visible while streaming. Public docs: docs/web/control-ui/chat.md. (docs/web/control-ui/chat.md:592, 8e704b16db06)
  • Behavioral coverage: The introduced pane test checks that the input frame precedes the DOM commit and that hide or disconnect settles pending work. E2E fixture changes wait for observable committed UI states. (ui/src/pages/chat/chat-pane-suspension.test.ts:19, 8e704b16db06)
  • Real browser proof: The PR body reports interleaved Chromium 144 A/B trials on production bundles with the same 676-chunk reply and concurrent typing. Median p95 input-to-next-frame latency fell from 35.05 to 12.35 ms; p95 frame gap rose from 125.00 to 133.35 ms. The final repairs did not change the scheduler, and the author reports focused final-source interaction validation. (8e704b16db06)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Marvinthebored: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vyctor H. Brzezowski: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-26T17:25:10.310Z sha 58cffd4 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T17:47:26.111Z sha 58cffd4 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T19:09:46.489Z sha 470282c :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T19:22:09.801Z sha 470282c :: needs changes before merge. :: [P2] Remove the reverse type import that fails the architecture gate
  • reviewed 2026-09-26T20:11:54.062Z sha 86302ff :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T20:31:52.744Z sha 86302ff :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T21:44:25.097Z sha 389a0f0 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T23:40:47.673Z sha 5423fc9 :: needs maintainer review before merge. :: none

Resume pane updates from a cancellable message task after the animation frame. Keep synchronous end-anchor ownership and release pending frame/task work when hidden or disconnected.
@steipete
steipete marked this pull request as draft September 26, 2026 16:46
@clawsweeper clawsweeper Bot added merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 26, 2026
@steipete steipete changed the title improve(ui): reduce pauses while streaming chat replies improve(ui): reduce typing latency during streamed replies Sep 26, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Sep 26, 2026
@steipete
steipete marked this pull request as ready for review September 26, 2026 17:42
@steipete
steipete enabled auto-merge (squash) September 26, 2026 17:49
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 26, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 26, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 26, 2026
@steipete
steipete disabled auto-merge September 27, 2026 01:56
@steipete

Copy link
Copy Markdown
Contributor Author

Closing for now (branch kept).

The measured win is real — at 4× CPU throttle, p95 input-to-next-frame 45 → 12 ms and ~15% fewer long tasks while a reply streams — but six CI rounds each surfaced a different transcript behavior that changes when pane commits are batched behind the input frame: model/reasoning chat flow, menu visibility, history-anchor corrections, nested tool-activity collapse after history reload, and recovered-text transcript search. Those are user-visible transcript semantics, not incidental timing, so this needs a design pass over the transcript commit pipeline rather than more spec-by-spec repairs.

If we revisit: keep synchronous commits for state that other transcript features read (menus, search index, history anchors, collapse state) and defer only the pure geometry/paint work behind the input frame, then re-measure input latency and long tasks with the same 4× throttle harness.

@steipete steipete closed this Sep 27, 2026
@RomneyDa
RomneyDa deleted the perf/l82-transcript-layout-batch branch October 22, 2026 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant