Repository navigation
perf(memory): reduce cold first-turn retrieval waits - #158563
Conversation
Move cold retrieval module initialization into the existing idle lifecycle without opening databases or initializing embedding providers. Keep request-time retrieval and worker retirement authoritative.
|
🦞👀 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: blocked before merge. Reviewed September 25, 2026, 10:09 PM ET / September 26, 2026, 02:09 UTC. ClawSweeper reviewWhat this changesAfter Gateway readiness, the branch warms the active Memory Core search worker during idle time and documents and tests when that warmup runs. Merge readiness⛔ Blocked before merge - 1 item remains Current main lacks memory-worker warmup, and the related open Gateway prewarm PR addresses different first-use work. The recorded retrieval measurements give this focused PR a distinct reason to remain open. Priority: P2 Review scores
Verification
How this fits togetherMemory Core searches indexed SQLite memory for agent turns. Gateway startup schedules optional idle work, which can prepare the search worker before an eligible request arrives. flowchart LR
A[Gateway ready] --> B[Idle scheduler]
B --> C{Memory Core active?}
C -- Yes --> D[Retrieval worker pool]
D --> E[Search worker]
F[Agent memory request] --> D
E --> G[Memory results]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +31, Tests +27, Docs +5. Total +63 across 7 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: The first eligible search after Gateway startup should reuse a prepared worker, while request-time retrieval and normal worker retirement remain authoritative. Do we have a high-confidence way to reproduce the issue? Yes: alternating cold and warmed retrieval against seeded project memory is a specific repeatable comparison, and the PR records its results. This read-only review did not rerun it. Is this the best way to solve the issue? Yes: the existing idle scheduler and retrieval worker pool provide a narrow place to move initialization without changing search results or stored data. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b03cf209ea6b. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…#158563) Move cold retrieval module initialization into the existing idle lifecycle without opening databases or initializing embedding providers. Keep request-time retrieval and worker retirement authoritative.
What Problem This Solves
The first Control UI prompt can wait for cold memory retrieval initialization before contacting the model. A traced run spent 1.574 seconds in its first project-memory worker task, versus 14.5/5.2 ms on later tasks.
User Impact
After idle warmup, the first project-memory retrieval uses an initialized worker and returns the same eligible memory entries. Readiness and retrieval semantics are unchanged. An immediate request, or one after the worker's normal idle retirement, can still pay cold initialization.
Why This Change Was Made
The dominant cold cost is worker module initialization: a built probe that could not open any database took 919 ms on its first request, including only 12.8 ms to reach worker
online, and 0.79 ms on repeat. Curated recall does not initialize an embedding provider.Memory Core now exposes a lazy worker warmup entry point. One registration in the existing post-ready idle scheduler calls it only for active Memory Core. Its private acknowledgment loads the retrieval code without opening an index, creating a manager, indexing files, or starting a provider. The existing pool owns admission, reuse, retirement, and cleanup; normal requests remain authoritative. No protocol, configuration, database schema, or upgrade behavior changes.
Related: #158555 changes the same idle scheduler and test fixture, but does not warm memory. The second PR landed will need a rebase retaining both sets of registrations and adopting its
getConfigtest fixture. This PR remains based on main rather than stacking the two changes.Evidence
Five alternating cold/warmed pairs on the same Blacksmith Testbox, using the built candidate and an isolated seeded project-memory entry:
All ten returned identical entries. Warmup itself took a median 172.08 ms with 5.31 ms of main-thread CPU, paid before retrieval. This is component proof (35.9× faster first retrieval), not a full concurrent-client latency claim. Five interleaved source-level pairs on the busy development host independently showed 10.13 s → 39.96 ms; those include TypeScript loading.
node scripts/run-vitest.mjs src/gateway/server-startup-handler-prewarm.test.ts extensions/memory-core/src/memory/manager-retrieval-offthread.test.ts --maxWorkers=1: both files passed, 30.92 s command wall; file durations 1.13 s and 26.97 s. The changed idle-owner file has eight passing cases.pnpm build: passed, 6m04.8s for the final committed candidate. An earlier dirty-candidate build also passed in 9m19.4s. The build reports an untouched UI startup-size warning (363.0 KiB gzip versus 362.6 KiB); no budget was changed.node scripts/check-changed.mjs -- <the seven changed files>: passed in 1,880.57 s (31m20.6s), including core/extension production and test types, lint, boundaries, dead exports, and storage guards.Remote proof used provider
blacksmith-testbox, leasetbx_01m3djqtv2fgeeymw2bv4g3ttw, hydration run. Initial missing dependencies were installed. Unpublished-commit sync fallback timed out; publishing the reviewed branch let Testbox fetch the exact commit and complete validation. A local retrieval-suite attempt was stopped during slow worker-fixture preparation; the remote run supplies its passing result. The local idle-owner file independently passed all eight cases in 26.52 s. Hosted PR CI is pending.