refactor(memory): simplify source-state queries - #138709
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
Live validation for #138709 (head Native live proof passed on combined commit
The Gateway wire payload digest was This proof uses synthetic native SQLite/CLI/Gateway data, with FTS-only memory and Logbook capture disabled. It makes no screenshot, external provider, dashboard rendering, or cross-platform claim. Memory still reads the original bulk rows; the saving is the discarded hash-map allocation. |
|
Codex review: blocked before merge. Reviewed September 4, 2026, 9:07 PM ET / September 5, 2026, 01:07 UTC. ClawSweeper reviewWhat this changesMemory Core’s source readers stop building unused hash maps, reuse existing typed SQLite query helpers, and replace database mocks with real-SQLite coverage. Merge readiness⛔ Blocked before merge - 1 item remains Keep open with no blocking findings. The allocation cleanup remains absent from current main and the supplied latest release, and the native evidence supports preserving indexing, diagnostics, and pruning behavior. Priority: P3 Review scores
Verification
How this fits togetherMemory Core compares workspace files and session transcripts with their indexed SQLite records to decide what needs indexing or removal. The changed reader supplies snapshots to diagnostic status, startup reconciliation, and synchronization. flowchart TD
A[Workspace files and session transcripts] --> B[Memory Core inspection and sync]
C[Indexed SQLite source records] --> D[Source snapshot reader]
D --> B
B --> E{Changed or removed sources?}
E --> F[Report diagnostic state]
E --> G[Index changes or prune stale entries]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -3, Tests -35, Other -1. Total -39 across 6 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep one canonical row reader and construct lookups only where consumers need them, preserving full snapshots and existing query timing. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: this is behavior-preserving cleanup, and current source directly shows the unnecessary eager map allocation. Is this the best way to solve the issue? Yes. Removing the unused result structure at its producer avoids flags or parallel readers, while retaining consumer-owned snapshots; narrowing targeted queries would be separate work with different snapshot semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against bf9cbcfb064d. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
The automated data-model compatibility prompt is a false positive for this read-only cleanup. The changed result shape is a private in-memory return value: callers receive the same Compatibility is covered by the native before/after and CLI proof: the same prepopulated 20,000 SQLite rows retain their complete digest, source filtering and query counts; existing file/session indexing and deletion preserve surviving entries; a fresh process reopens and searches the durable store successfully. The follow-up commit changes only the responsiveness test fixture. Its actual SQLite regression and unchanged responsiveness assertions pass, and current-head CI run 33932828535 succeeded. I reviewed the complete latest ClawSweeper result: no code/security findings or rank-up moves remain. Direct installed Kysely 0.29.5 compiler/query-builder inspection and a fresh independent P0–P2 review also passed. The requested compatibility evidence is satisfied by unchanged persistent contracts and existing-store/reopen proof above; no schema or upgrade change is being waived. |
|
Merged via squash.
|
* refactor(memory): simplify source-state queries * test(memory): use SQLite for synchronization yield coverage
What Problem This Solves
Memory source inspection and session reconciliation built a complete path-to-hash map even when their callers used only the source rows. Several callers immediately built the different lookup structure they actually needed, retaining unnecessary work for large indexed corpora.
Why This Change Was Made
The source-state reader now returns its rows directly. Memory-file synchronization builds its required hash map at the original snapshot boundary; status inspection, startup catchup, session planning, and targeted cleanup stop constructing and discarding an extra map.
Both ordinary source-state queries now use the existing synchronous Kysely helpers. This removes the mock-shaped database interface, handwritten SQL, result casts, and impossible undefined-array fallback. The full row projection, source predicates, snapshot precedence, and query timing are preserved. No schema, configuration, retention, migration, or SDK surface changes are introduced.
User Impact
Memory status and session reconciliation allocate less intermediate state while keeping the same dirty-state detection, indexing, and pruning behavior. Production code is three lines smaller, and the SQL-string mock tests are replaced with shorter real-SQLite coverage.
Evidence
All required changed checks passed, including extension/test typechecks, lint, boundaries, and runtime import-cycle checks.
The focused source-state, session-planning, startup-catchup, and update/forget-race suites passed 66 tests. Three additional public manager cases passed for offline source edits, canonical session discovery, and pruning removed sessions without re-embedding survivors.
OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/run-vitest.mjs \ extensions/memory-core/src/memory/manager-source-state.test.ts \ extensions/memory-core/src/memory/manager-session-sync-state.test.ts \ extensions/memory-core/src/memory/manager-sync-ops.startup-catchup.test.ts \ extensions/memory-core/src/memory/manager-session-update-race.test.ts OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/run-vitest.mjs \ extensions/memory-core/src/memory/index.test.ts \ -t 'detects offline source edits|diagnostic status uses canonical session discovery|prunes removed sessions'A native probe on Node 24.20.0 read 20,000 synthetic indexed source rows before and after the change. The complete row digest was identical. Both versions used one bulk query, zero queries for supplied snapshots, and three scoped point queries. The reader's unused hash map went from 20,000 entries to zero. Source separation, fractional modification times, an empty snapshot, fresh point reads, and a quoted missing path retained their behavior; SQLite integrity remained healthy. These are allocation-structure and query-count observations, not wall-clock or peak-RSS measurements.
Removing the two raw result casts also removes this file's grandfathered assertion-baseline entry. Targeted archive cleanup still reads the full source snapshot; narrowing that query is a separate follow-up requiring explicit large-target and snapshot semantics.
Independent Codex review of the complete frozen patch and owner/caller/dependency context was scoped-clean through P2. The composed native CLI/Gateway proof passed all six phases, including offline edits, indexing, deletion, canonical-session pruning and fresh-process reopen.
CI caught an older responsiveness fixture whose fake database lacked native iteration. That fixture now uses the real SQLite schema already used by its cache-seeding sibling, with explicit connection ownership and unchanged yield assertions. The original failure reproduced locally; the repaired fixture and source-state suite passed all 8 tests, required changed checks passed, and a fresh full-patch independent review was scoped-clean through P2. The repair changes tests only; the production files exercised in the live proof are unchanged. Overall production net−3, tests net−35, assertion baseline−1. Exact-head hosted CI is rerunning.