Repository navigation
fix(memory): preserve file changes during indexing - #157163
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: blocked before merge. Reviewed September 24, 2026, 6:01 AM ET / 10:01 UTC (Revision 4). ClawSweeper reviewWhat this changesMemory Core now probes watched folders asynchronously, carries file edits into a follow-on indexing pass, and joins accepted watcher work during shutdown. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 5 items remain Current main still has the watcher traversal and indexing race this PR addresses. The reviewed source shows no definite correctness defect, and the preceding-head Linux proof remains relevant because production blobs are unchanged. Merge readiness remains limited by an invalid startup-stall comparison and an observed startup wall-time increase. Priority: P1 Review scores
Verification
How this fits togetherThe Memory Core plugin watches workspace and remote-host memory files, then updates a SQLite index used by memory search. Watch notifications and file reads enter the indexing manager; committed index rows feed later recall. flowchart LR
A[Memory files] --> B[File watchers]
B --> C[Settle changes]
C --> D{Index pass active?}
D -->|Yes| E[Follow-on pass]
D -->|No| F[Current pass]
E --> G[SQLite memory index]
F --> G
Decision needed
Why: The current measurement establishes slower startup but does not establish whether Gateway event-loop stalls improve enough to justify it. Before merge
Agent review detailsSecurityNone. PR surfaceSource +307, Tests +905. Total +1212 across 13 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep lossless watcher generations and asynchronous traversal, then qualify the startup responsiveness tradeoff with a comparable paired measurement and record each changed test file's cost. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main joins an active sync promise for later watch events and performs synchronous watcher traversal. The branch includes a committed-row regression scenario, but this read-only review did not execute it. Is this the best way to solve the issue? Yes for the indexing race: the change stays with the Memory Core watcher and sync owners. The broader asynchronous traversal still needs a valid responsiveness comparison before its performance tradeoff is accepted. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 20590155d1bf. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Merged via squash.
|
* fix(memory): preserve file changes during indexing * test(memory): model native watch capacity errors * test(memory): align worker fixture formatting
What Problem This Solves
Native watcher traversal blocks other Gateway work while probing large memory folders. Separately, an edit arriving after an active indexing pass planned its sources can join that old pass and remain unindexed.
User Impact
Directory probes use asynchronous I/O; newer edits receive a follow-on indexing pass; shutdown joins accepted watcher work. Linux correctness and static checks passed at the preceding head; the new head changes only one test's formatting. Responsiveness is now measured at the current head: maximum callback-free startup fell from 13.444 to 1.667 ms in one fixed instrumented pair. Total startup increased from 13.444 to 26.417 ms. This is a responsiveness and indexing-correctness change; no throughput, startup-speed or memory improvement is claimed.
Why This Change Was Made
The existing watcher resource owner owns startup, settling, bounded reconciliation, overflow rescans and joined close. The file watcher owns native coverage and generations. The manager waits for readiness outside database write admission; the remote worker joins shutdown when input closes.
Production: +578/-271 (net +307), justified by asynchronous traversal and joined resource ownership. Tests/helpers: +1013/-108 (net +905). Broad dirty callbacks and string notifications remain unchanged. Generations and queues are process-local: there is no schema, persisted data-model, configuration, public SDK or protocol change, and no migration is required.
Evidence
Current candidate
e3a034e6fdd5d67ea7c2648705d8ec351b922d5f, tree302a8802de31474f77a5346fd8ef43f8c98fee71; baseline61214694cc150a11e551c0e97fbeaaa01a2b8141. The completed Linux proof below belongs to preceding head813d922cb05cbc0a27e4be3bf66da66067ef219d, tree4e93b7cf9608a4bffc0e8d2e8c26e95aa2b9adb1. All production bytes and 12 of 13 touched files are identical; only remote-worker test formatting differs.dd923846daacff892730d9ed61b355eafb15eb16162914c5356dce69fc3c4430.remote/memory-files-worker.test.tsfailed formatting. The current commit applies 0.68's six-line formatting delta, including a trailing comma. Pinned 0.68 formatting passes; both remote-worker cases also passed locally on Node 26.7. No production code changed. New-head CI/review remain required.syscall: "watch"from a synthetic capacity error; the current head corrects it. No production bytes changed for that correction.One fixed baseline → candidate screen used 500 directories and 5,000 files:
This qualifies synchronous-I/O removal and coverage, not a speedup. Heap/RSS deltas include retaining Vitest spies, asynchronous Promise observers and GC timing; they do not establish production memory cost or peaks.
The original histogram result is withdrawn: Node 24.19's implementation clears its previous timestamp on reset, so the next tick only seeds an anchor. Its 0.786 → 2.640 ms maxima do not measure comparable startup stalls.
The corrected responsiveness run 35984525942 executed once at exact current head e3a034e, Linux x64 Node 24.19.0/pnpm 12.4.0, with the same 500-directory/5,000-file workload. A scalar 1 ms timer is armed immediately before startup; its first post-settlement callback captures terminal blocking too. Both measurement cases passed without retries or skips:
Maintainer landing decision: accept this measured startup tradeoff for nonblocking traversal and lossless indexing. Other Gateway work can run during traversal, while traversal itself takes longer in this screen. This single pair establishes yielding under the tested workload, not a stable speedup multiplier or production memory footprint. Both variants covered all 501 directories, opened 502 native watches, delivered one real-change notification and closed every handle. Synchronous probes fell from 1,507 to zero. Driver/wrapper exited zero, child groups joined, source hashes restored, lease stopped and capsule removed. This supplements the original slower startup result above.
Exact-head CI 35983852335 passed. Its retained verbose logs expose rounded case durations, not full per-file wall times:
These sums exclude import/transform/setup overhead. Standalone Linux proof retained the aggregate 85.06-second phase wall, not per-file wall; that optional profiling detail remains unavailable. No extra repeat of six already passing files was run merely to fill a timing column. The shared watcher-test-support.ts helper is covered through its consuming suites.
The exact-head ClawSweeper review at e3a034e has no actionable code/security findings. Its Linux lifecycle/committed-row proof, corrected responsiveness and explicit startup/CPU tradeoff requests are fulfilled above. Per-file cost evidence and its limitation are recorded explicitly. The automated data-model checkbox is addressed by the unchanged persistence contract above. The newer required security/status publication remains a separate landing gate.
Related contributor work remains separate: lost-watcher recovery and initially missing extra paths.