Repository navigation
fix(memory): avoid redundant repairs and heavyweight read imports - #186483
Conversation
|
🦞👀 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 removes heavyweight imports from memory readers and reuses completed index repairs while their schema and write receipts remain current. Example: Run 100 unchanged warm memory searches over an indexed corpus.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR delivers measured memory-search improvements, and no actionable introduced defect was found at the reviewed head. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherMemory readers and publication workers sit between Gateway memory requests and agent databases, returning search results and committed index facts through existing private SDK seams. flowchart LR
A[Gateway memory request] --> B[Memory manager]
B --> C[Publication worker]
C --> D[Schema admission and write receipt]
D --> E[Repair when stale]
B --> F[Read worker]
F --> G[Agent database]
E --> G
Technical reviewBest possible solution: Reuse existing admission facts and lightweight helper owners while preserving committed-write invalidation, live request admission, and explicit repair. Do we have a high-confidence way to reproduce the issue? Current-main source shows unconditional admitted-schema repair, and the supplied compiled Gateway diagnostic records repeated repair across unchanged searches; no target code was run during this review. Is this the best way to solve the issue? The patch follows the smallest complete approach: redirect imports to existing private owners and retain repair completion on existing option-keyed admission rather than adding a separate cache or lifecycle. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4b0da43dded7. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +86, Tests +259, Other +71. Total +416 across 25 files. Added test files: 0. View PR surface stats
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 HistoryReview history (1 earlier review cycle)
Reviewed October 28, 2026, 1:30 AM ET / 05:30 UTC (Revision 2). |
|
@clawsweeper re-review Final head: f3f8c55. The PR body now contains the completed five-pair compiled-worker and real Gateway results, the unchanged 20% regression gate, full response/SQL/shutdown audit, and the historical failed candidate. The new schema-repair reuse and SQLite receipt changes also have 82 focused passing tests, a passing packaged build, and clean independent review. Please review this exact head. |
|
🦞👀 Re-review progress:
|
…enclaw#186483) * fix(memory): avoid loading provider and writer runtimes for reads * test(memory): measure compiled search worker and gateway resources * test(perf): avoid conditional map spread in search census * test(memory): document database mock isolation * test(perf): capture warm search CPU across workers * fix(sqlite): include pending schema changes in write receipts * perf(memory): reuse completed index schema repairs across reads
* commit '04681a3efcb110ecf073fb610eed6e4ea4f87fed': fix(memory): avoid redundant repairs and heavyweight read imports (#186483) fix(doctor): report held agent stores in doctor --json (#186535) fix(ci): complete maintained script and export discovery (#186466) perf(control-ui): restore the Details panel from the cached pane in one step (#185242)
What Problem This Solves
Memory search and index reads load provider discovery and writable database infrastructure even though they only need pure format and read helpers. Request-owned search managers also repeat provenance and FTS repair on every read: a compiled diagnostic captured 100 repair transactions across 100 unchanged warm searches.
User Impact
Removes unnecessary runtime dependencies from memory read workers and reuses completed index repair while the existing schema admission and scoped write receipt remain current. Tracked writes, changed options, failed repair, and revoked requests retain their existing repair/authority paths. No new configuration, cache, worker, schema version, or operator action. The original import-only candidate reduced worker heap but failed the warm process-CPU p95 gate; the new repair candidate passes the same five-pair compiled qualification, with the remaining limits below.
Why This Change Was Made
Reuse the existing private memory host SDK seams for the same helper functions. This removes the provider-loader path from embedding format checks and the writable-store path from read-only queries. All three reindex callers use the same pure helper export; origin and forget reads retain their existing read-only owners.
The repair receipt is one field on the existing option-keyed schema admission; it adds no registry or independently managed cache. The SQLite receipt owner predicts the schema generation published by native COMMIT, including caught savepoint rollback. Existing schema-owner state and plain types move to leaf modules to avoid dependency cycles; state is not duplicated. The worker records successful repair only after commit, using its captured receipt rather than certifying a later writer's generation.
Production delta: +86 lines in total (+6 for import boundaries, +23 for the SQLite receipt prerequisite, +57 for completed-repair reuse); tests: +259; existing benchmark helpers: +71. Positive production growth implements the existing commit-receipt and worker-repair ownership boundary. The per-read BEGIN, provenance backfill, and FTS reconciliation path is skipped only when its completed work is still current.
Evidence
Independent source review and fresh autoreview: clean, no actionable findings. The final review includes the SQLite receipt prerequisite and successful-repair publication boundary.
Native commit hooks, targeted formatting, private-data scan, and
git diff --check: passed.Exploratory source import census: 2,110 reachable local modules before, 524 after. Writable store, agent execution owner, and plugin loader paths are absent after the change. This excludes external packages and bundler chunk behavior; it is not an RSS measurement.
Expanded the existing retrieval import regression to reject provider and writable-store facades and cover index, reindex-state, origin, and forget reads.
Focused native validation: all 4 files / 73 tests passed on runtime-change commit
dc0ed34889d4ca73f1536299c0f947ae7ea7a1a9: retrieval imports, index reads, reindex state, and search worker behavior. Later commits add benchmark coverage, a benchmark lint fix, and one test-isolation annotation; the runtime change is unchanged.The original baseline and import-only candidate packaged builds passed under Node 26.12.1. Their five-pair campaign is historical evidence; its failed gate is preserved below. The new candidate packaged build and five-pair campaign passed. The owned Testbox request queued and was stopped; validation continued through PR CI and the native review checkout's successful frozen dependency install. Cancelled validation allocation.
New repair validation: 82 focused tests passed across write receipts, native schema facts, scoped writes, memory schema admission and publication admission. Coverage includes successful COMMIT, outer/savepoint rollback, TEMP schema, tracked sibling writes/imports, option changes, failed FTS repair and request revocation.
New repair static checks: zero import cycles; scoped core and plugin lint, formatting and hooks passed. Public plugin SDK subpaths remain 160; the new helpers use an existing private seam.
Performance acceptance rule (before scored runs)
Use Node 26.12 or newer; the native worker harness needs the per-isolate allocation counter. Compare exact baseline
b61ab6deb40cc640aec077b6e6a7b93a44b5422cand the selected compiled candidate using compiled workers and an isolated Gateway. Reuse committed worker-memory and realmemory.searchworkloads, fixed synthetic inputs, the same runtime and host, with at least five interleaved baseline/candidate samples. Keep cold initialization and warm search results separate; record host load, loaded-module counts, worker retained heap, total process RSS, CPU, and latency median/p95 with spread. Require correct search results and reduced unnecessary module loading plus a measurable memory gain without worsening user-facing metrics; a 20% regression in any metric stops landing. Source-only counts and instrumented historical heap samples do not satisfy this gate.The original scored campaign is complete for compiled candidate
3fdc54fcb109683949d19a723f59646d2755f972. Its warm process-CPU p95 exceeds the 20% regression threshold, so it remains a historical HOLD. Diagnostic profiling is complete and motivated the additional repair change; it does not replace scored results or waive the gate. New runtime candidatef3f8c553646a1f9f08af722b58d32e39204f3dc6passes its packaged build and five-pair scored campaign under that unchanged rule.For the new campaign, both helper files come from
f3f8c553646a1f9f08af722b58d32e39204f3dc6; its runtime is compared with the same frozen baseline and unchanged acceptance rule.The owned review checkout runs both frozen revisions serially with its qualified frozen install; package manifests, lockfile, workspace configuration, and patches match. For the new campaign, on the baseline only, the two benchmark files are copied from helper commit
f3f8c553646a1f9f08af722b58d32e39204f3dc6; runtime sources remain at the baseline SHA. No source overlay runs inside compiled workers.Run the same committed helpers for both builds, serially, with a new output directory for every invocation:
The native worker probe measures the import floor, not a search workload; its no-op prewarm timings are diagnostic only. User-facing latency gates apply to cold and warm real Gateway searches. Use the real Gateway search run for correctness and timing; instrumented runs report CPU and synchronous process memory snapshots, not peak RSS or fresh Gateway-worker heap.
Current five-pair results: completed-repair candidate (PASS)
Baseline
b61ab6deb40cc640aec077b6e6a7b93a44b5422c; candidate and helpersf3f8c553646a1f9f08af722b58d32e39204f3dc6; Node 26.12.1, macOS arm64, 18 available logical CPUs. Serial order B/C, C/B, B/C, C/B, B/C; 1,000 documents and separate timing/resource passes of 101 queries per arm. All 2,020 query assertions and count budgets passed; all 1,010 paired full responses match exactly. Host one-minute load was 11.57–28.45; shared-host results, not an isolated-capacity claim.Cells show the median of five runs and their minimum–maximum spread. Warm rows first compute the named nearest-rank quantile over each run's 100 warm queries. For five run-level samples, nearest-rank p95 equals the maximum.
Performance verdict: PASS. No scored median or run-level p95 regresses by 20%. Readiness RSS rises 2.59%; worst-run indexing, warm p99 and warm CPU p95 rise 9.77%, 5.10% and 8.04%, respectively. The worker import-floor reduction is stable; whole-Gateway after-search RSS falls 6.93%, while the still-large 1.69 GiB median remains follow-up work. These phase snapshots are neither peak RSS nor drained/GC retention proof.
The independent run audit confirms all 20 valid configurations, 1,000-file indexes and clean Gateway shutdowns (63–191 ms), with matching known fixture-warning inventories and no new plugin/service failure counters. Across 1,000 warm queries per arm, repeated repair statements fall from 4,000 to zero and publication-backend native calls from 9,020 to 1,010; authoritative facts reads remain 1,000 and search-worker calls remain 5,000. The repeated eight-call repair/transaction sequence is removed.
Telemetry limitation: 10 candidate passes and one baseline pass record a post-query catalog task rejection. No warm-query worker/diagnostic failure appears. Existing shutdown intentionally rejects unfinished catalog work, but this observer records no error class or retirement reason, so these are consistent with shutdown retirement rather than proof of successful catalog completion. No peak-RSS, continuous-readiness, background-quiescence or leak-freedom claim is made.
Earlier import-only candidate: failed gate and diagnostic evidence
Historical five-pair results: import-only candidate (HOLD)
Baseline
b61ab6deb40cc640aec077b6e6a7b93a44b5422c; candidate and scored helpers3fdc54fcb109683949d19a723f59646d2755f972; Node 26.12.1, macOS arm64, 18 available logical CPUs. Serial order: B/C, C/B, B/C, C/B, B/C. Each arm used 1,200 worker prewarms, then separate default and resource passes with 1,000 documents and 101 searches. All 2,020 Gateway searches returned the expected top result, all full-status count budgets were zero, and all Gateway processes shut down cleanly. Host one-minute load ranged from 16.05 to 47.49; this was a shared, busy host.Cells are the median of five runs followed by the minimum–maximum spread. For five run-level observations, nearest-rank p95 equals the reported maximum. Warm latency/CPU rows first compute the named quantile over 100 queries within each run, then summarize the five run values.
Performance verdict: HOLD. Worker heap and loaded-code reductions are consistent, and overall search CPU and latency improve. Warm process-CPU p95 rises 26.12%, readiness RSS rises 8.13%, median warm p99 rises 0.53%, and run-level readiness p95 rises about 5.1%. These are reported rather than dismissed as spread. RSS snapshots are phase observations, not peak or drained/GC retention measurements.
The first three pairs exposed an attribution gap: candidate warm queries begin 0.76–0.95 seconds after readiness, baseline 2.23–5.37 seconds. Readiness does not await
server-startup-handler-prewarm.ts; startup imports can run between requests. The counter covers every Gateway thread. The separate diagnostic captured 23 of 23 CPU profiles per arm without profile errors. Native counter retirement left only 17 baseline and 18 candidate matched worker targets, and capture windows differed, so matched counters do not reconcile to whole-process CPU. Candidate catalog work overlapped warm searches; this is evidence of startup/background overlap, not proof that the import change introduced that work or permission to waive the gate.Both diagnostic arms executed identical warm SQL: 900 agent-writer statements plus 500 search-worker statements, including 100 repair transactions, 100 FTS reconciliations, 100 path backfills, and 200 provenance backfills. This exposed the repeated repair now removed by the additional candidate. The receipt contract covers tracked Gateway writers and workers; outside writers must use Gateway or exclusive offline custody, as documented in the existing database ownership contract.
Named follow-ups