Repository navigation
improve: copy less session data when restoring warm prompt caches - #206384
Conversation
Select eligible keys inside the retained worker's read snapshot. Preserve recent prewarms and canonical session validation while avoiding the transfer of every saved summary to the Gateway.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
Codex review: passed. What this changesSelect warm-cache recovery candidates inside the session worker and return their keys instead of every session summary. Example: A store contains 133 sessions, with two eligible for warm-cache recovery.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR removes a concrete data-transfer cost, preserves candidate selection, and has no identified code defects. Reviewed head: Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherCron maintenance discovers session stores after startup; the retained session reader selects eligible keys, which the existing scheduler uses to resume prompt-cache prewarming. flowchart LR
A[Cron maintenance] --> B[Recovery reader]
B --> C[Retained session worker]
C --> D[SQLite or PostgreSQL]
D --> C
C --> E[Eligible session keys]
E --> F[Existing prewarm scheduler]
Technical reviewBest possible solution: Keep candidate selection in the existing session worker while preserving the current scheduler, validation, and persisted format. Do we have a high-confidence way to reproduce the issue? Current-main source clearly transfers every session summary before filtering; the supplied native-worker comparison reports matching selected keys and substantially smaller serialized replies, but this review executed no target code. Is this the best way to solve the issue? Filtering at the existing worker boundary is a focused solution: both storage paths share eligibility, and the obsolete Gateway-side filter is removed. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9e787b7b0c0a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +97, Tests +213, Docs +1. Total +311 across 10 files. Added test files: 2. 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:
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 HistoryReview history (1 earlier review cycle)
Reviewed November 27, 2026, 12:21 AM ET / 05:21 UTC (Revision 2). |
|
@clawsweeper re-review The feature branch now includes the PostgreSQL fixture isolation from #206391 at |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…enclaw#206384) * improve: copy less session data when restoring warm prompt caches Select eligible keys inside the retained worker's read snapshot. Preserve recent prewarms and canonical session validation while avoiding the transfer of every saved summary to the Gateway. * test: clarify the PostgreSQL recovery observation
* fix(runtime): defer optional work under host memory pressure * style(infra): format memory pressure admission * style(gateway): format the deferred prewarm check (cherry picked from commit 9f50802) Companion audit: #207993 selected later for publication fixture isolation. #206779 required if the new Cron host-memory fixture spoofs platform: preserve native SQLite namespace. #206041/#206230/#206308/#206746 are separate cgroup detection and optimization changes; #206322 is service-aware cron run budget, #206483 forks chat and #206384 changes a main-only warmer. Release adaptation: Extend the stable optional-memory owner and its existing callers only. Preserve cgroup/Bun/macOS behavior and upstream threshold cases; omit main-only prompt warmer, cgroup diagnosis, and Cron platform-spoof changes. Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
When the Gateway first checks which prompt caches to keep warm, it requests every saved session’s summary. A store with hundreds of inactive sessions sends their metadata back to the Gateway even if only a few sessions qualify.
User Impact
The Gateway can resume an existing keep-warm series or find a recently active chat by receiving only the matching session keys. This reduces the amount of data copied into the Gateway after startup. Existing installations pick up the change automatically.
Why This Change Was Made
The session worker already owns database selection and canonical validation. It now checks the original activity and last-ping timestamps before returning keys. A single read snapshot and ordered 64-row pages bound the candidate scan, including on PostgreSQL, which buffers each query. The worker still checks cold rows for invalid delivery aliases. Memory-only sessions use their existing actor and permissions.
Evidence
On Linux x64 with Node 24.22.1, both readers selected the same two keys from 133 synthetic sessions. The original worker returned 133 summaries. The new response contained those two keys and zero summaries. Serializing the complete returned objects with Node V8 measured 189,142 bytes versus 330 bytes. This measures response size. Peak process RSS was outside this test.
The original full list, the key-only read, a repeat key-only read and a repeat full list took 40.90, 3.46, 1.62 and 1.36 ms in one retained worker. These ordered timings include a first read and cached repeats.
The focused Node suites passed all 11 cases, including the exact cutoff, a recent preserved ping with old activity, stale side-column values, a dirty alias elsewhere in the store, memory-only actor ownership, and deferral under host memory pressure.
PostgreSQL 17 read 130 persisted sessions in pages of 64, 64 and 2, returned the three expected keys in order, and opened one repeatable-read, read-only transaction. The unmodified canonical admission may still scan an unreconciled store before this selection.
All nine TypeScript files passed lint. Core typechecking and the affected session tests’ typecheck passed.
Local autoreview covered the full branch at signed head
2bb29a1de72589a07360a07de68ef8f5d62ef032against535f39d01f699955e245f7ef6a5dfcd665b63604, priorities P0–P2. It reported no actionable findings.The new conformance test passed on the first hosted PostgreSQL run. Its addition placed two existing tests on the same database shard, exposing an unscoped schema comparison. The fixture repair is included in the new base. The complete feature source and test patch is byte-identical to the original native proof.
The broader NAS memory report remains open. #192547
The hosted review suggested an isolated Gateway restart as an additional demonstration. The scoped proof uses the real retained session worker, both database engines and the scheduler tests. A populated Gateway restart and process memory measurement remain open follow-ups for the NAS report.