Repository navigation
improve(sessions): reduce memory for lightweight transcript reads - #198512
Conversation
Exercise foreground presentation prewarming and report post-GC retained heap plus p95 timings. Sample heap before the debugger census to exclude inventory allocations. Validated with five paired built-worker samples, targeted lint and formatting, and the core typecheck.
Move presentation imports from foreground worker startup to explicit prewarm requests. Let Gateway warm an existing lightweight reader through the resource-owned prewarm deduplication. Keep separate worker lanes and database admission unchanged. Built Node 26.13.0, five interleaved pairs: lightweight retained heap 31,399,848 -> 20,946,464 bytes; evaluated modules 1253 -> 410; spawn through first reply median 272.25 -> 174.16 ms (p95 308.73 -> 213.22 ms). Explicit prewarm median 293.98 -> 272.53 ms (p95 311.94 -> 308.01 ms); full presentation retains about 30 MiB in either version. The first presentation request pays deferred imports; this is worker heap evidence, not whole-process RSS. Validation: regression failures on original source, green import/history integration and prewarm/pool/lane lifecycle suites, both runtime builds, targeted lint/format, core typecheck, and independent source review.
|
🦞👀 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: needs maintainer review before merge. What this changesThis PR defers transcript presentation imports until explicit prewarming or a history request needs them. Example: A fresh foreground transcript worker resolves a lightweight SQLite target.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR delivers a measured memory reduction with a documented latency tradeoff, and no actionable patch defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway session operations dispatch reads through database-owned worker lanes; lightweight requests resolve metadata, while history requests load presentation code and return transcript pages. flowchart TD
A[Gateway session requests] --> B[Database resource owner]
B --> C[Foreground worker pool]
C --> D[Lightweight metadata reads]
C --> E[History presentation imports]
F[Explicit Gateway prewarm] --> B
E --> G[Transcript page response]
Technical reviewBest possible solution: Retain demand loading and the existing explicit-prewarm owner with the documented first-presentation latency tradeoff. Do we have a high-confidence way to reproduce the issue? Current-main source eagerly imports presentation code for every foreground worker, and the supplied paired benchmark measures the resulting overhead; this review ran no target code. Is this the best way to solve the issue? The patch is a focused deferral using existing owners, preserves request-time history loading, and adds regressions for import timing and prewarming an already-started lightweight worker. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4cffd43ee043. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -16, Tests +13, Other +31. Total +28 across 9 files. Added test files: 0. 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. 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 November 13, 2026, 7:50 PM ET / November 14, 2026, 00:50 UTC. |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…enclaw#198512) * test(perf): measure foreground transcript worker memory Exercise foreground presentation prewarming and report post-GC retained heap plus p95 timings. Sample heap before the debugger census to exclude inventory allocations. Validated with five paired built-worker samples, targeted lint and formatting, and the core typecheck. * perf(sessions): load history presentation on demand Move presentation imports from foreground worker startup to explicit prewarm requests. Let Gateway warm an existing lightweight reader through the resource-owned prewarm deduplication. Keep separate worker lanes and database admission unchanged. Built Node 26.13.0, five interleaved pairs: lightweight retained heap 31,399,848 -> 20,946,464 bytes; evaluated modules 1253 -> 410; spawn through first reply median 272.25 -> 174.16 ms (p95 308.73 -> 213.22 ms). Explicit prewarm median 293.98 -> 272.53 ms (p95 311.94 -> 308.01 ms); full presentation retains about 30 MiB in either version. The first presentation request pays deferred imports; this is worker heap evidence, not whole-process RSS. Validation: regression failures on original source, green import/history integration and prewarm/pool/lane lifecycle suites, both runtime builds, targeted lint/format, core typecheck, and independent source review. * test(sessions): explain prewarm mock isolation * test(sessions): prune documented mock isolation baseline
What Problem This Solves
Lightweight transcript reads load the full history presentation graph when a foreground worker starts, even with Control UI disabled.
User Impact
Lightweight workers retain about 10 MiB less heap and finish their first lookup sooner. History presentation remains available on demand, and enabled Control UI still uses explicit prewarming. A worker that has not prepared presentation pays the deferred import cost on its first presentation request (about 160 ms in this benchmark). Fully prepared history workers retain about the same heap.
Why This Change Was Made
Move the four presentation imports into the existing prewarm request and remove eager foreground-lane startup loading. Let Gateway prewarming reach an already-started lightweight worker, using the existing per-database prewarm deduplication. Separate worker lanes, database admission, and read behavior remain intact. No configuration options are added.
Evidence
Acceptance rule: at least 20% less retained heap for a fresh foreground worker performing a lightweight read, with no 20% regression in total explicit-prewarm latency. Five interleaved baseline/candidate pairs, built runtime, Node 26.13.0, one Blacksmith host with 4 CPUs and approximately 16 GiB RAM:
The import cost moves from startup into the first presentation request: measured request-only prewarm median 5.17 → 164.91 ms. The heap result is per-worker retained JavaScript heap, not a measurement of whole-Gateway RSS.
Reproduction:
scripts/perf/worker-spawn-measure.mjs --built --build-dir <candidate> --compare-build-dir <baseline> --worker session-transcript --prewarm-history --transcript-task <sqlite-target|prewarm> --samples 5, run with Node 26.13.0 through--import ./scripts/tsx.mjs.pnpm tsgo:corepassed.Local ClawSweeper 0.3.3 completed a full committed-range review of
91046f7bbbb8..602c92076abewith no priority filter and no code findings. It identified the deliberate first-presentation latency tradeoff and requested additional live Gateway evidence covering a second foreground worker. The maintainer accepted demand loading after the measured tradeoff was presented. The additional probe now passes through the built Gateway on Node 26.13.0: Control UI disabled and enabled, each with a lightweightsessions.listfollowed by two waves of eight concurrentchat.historyrequests. Both foreground workers served history in each case; all 32 responses succeeded with nonempty seeded messages, and cold/warm message digests matched. The probe used isolated synthetic state and exercised natural request-driven loading (no prewarm tasks were observed). These instrumented functional timings are not a before/after Gateway latency benchmark. The previously queued extra Testbox was stopped; this Gateway proof ran locally in the native PR checkout.The final follow-up commits document mock isolation for the existing Gateway prewarm test and remove its obsolete baseline entry. The targeted mock-export ratchet passes; production code is unchanged from the reviewed and measured head.
One unrelated existing test (
session-message-events.test.ts, same-clock avatar revisions) failed atsubscribeMessageson both baseline and candidate. Its root cause remains outside this change; the focused worker/Gateway suites and real Gateway history proof pass.Inherited CI failure
CI job fails four native Talk cancellation variants: a new consultation after cancellation returns the fallback text instead of the expected completion. The worker/history tests in that shard pass. Reproduced all four identical expected/actual failures locally with both candidate and original worker/prewarm production source, using only main's test-fixture correction that asserts the terminal response rather than waiting forever for correct output. The unchanged original fixture times out on both versions. Temporary diagnostic changes were restored. An independent source review confirmed the inherited attribution; the voice defect remains outside this memory change. CI is retained as failed and landing uses the native inherited-failure exception, subject to remaining checks/security.