Repository navigation
fix(memory): reduce memory use when indexing long sessions - #157278
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, 2:55 PM ET / 18:55 UTC (Revision 3). ClawSweeper reviewWhat this changesThe branch reduces the event data retained during memory indexing and gives conversation recall a background-worker read of reset-boundary metadata. Merge readiness⛔ Blocked before merge - 1 item remains Current main still materializes full SQLite transcript events for memory indexing and builds a full export for recall reset checks. This PR addresses those costs with measured improvement and remains useful. The linked performance report also covers full-scan transaction duration, which this PR does not claim to eliminate. Priority: P2 Review scores
Verification
How this fits togetherMemory Core turns session transcripts into searchable entries and filters search hits against the current conversation reset. SQLite transcript reads feed both paths; the resulting entries and reset cutoff affect indexing and recall visibility. flowchart LR
A[SQLite transcript] --> B[Background reader]
B --> C{Requested read}
C -->|Index session| D[Project export fields]
C -->|Check reset| E[Read reset navigation]
D --> F[Searchable memory entry]
E --> G[Recall visibility]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +172, Tests +64, Docs +8, Other 0. Total +244 across 16 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep the bounded read-time projection and reset lookup, then track any continuing full-scan transaction holds in the linked performance issue. Do we have a high-confidence way to reproduce the issue? Yes. Current-main source shows full-event materialization and a full export for reset checks; the PR reports before/after measurements from an isolated SQLite fixture. This reviewer did not execute the fixture. Is this the best way to solve the issue? Yes for the scoped allocation problem. The projection uses the existing transcript reader and preserves the export fields; the separate question of full-history scan duration remains with the linked report. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 78398c5854c2. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
5e7d43a to
478f89a
Compare
Main and the session snapshot change each remove one assertion. Preserve both reductions in the rebased baseline. Co-authored-by: jalehman <[email protected]>
|
Reviewed current head The generated “data-model compatibility proof” checkbox is inapplicable: these changes add read options and in-memory projections, with no DDL, persisted transcript-byte, schema-version, migration, or writer changes. This agrees with ClawSweeper’s own detailed existing-state compatibility assessment. The snapshot/fence, observer, reset-ordinal, export-hash, and fail-closed visibility contracts remain covered. Exact-head CI and Security Review passed. A fresh independent P2 code review found no actionable issues; current-main composition is conflict-free. The contributor’s real SQLite before/after evidence supports lower retained heap and cheaper reset lookups, not a fixed total-memory bound or elimination of all full-scan transaction holds. Accepting the scoped optimization; the remaining full-scan concern stays with the linked issue. |
|
Merged via squash.
|
…157278) * fix(memory): reduce long-session snapshot memory use * chore: shrink assertion baseline after memory fix * fix(memory): avoid shadowed projection parameter * chore: reconcile assertion baseline after rebase Main and the session snapshot change each remove one assertion. Preserve both reductions in the rebased baseline. Co-authored-by: jalehman <[email protected]> --------- Co-authored-by: jalehman <[email protected]>
Upstream moved collectRawSessionText into session-entry-projection.ts (openclaw#157278), which both the JSONL session-file path and the SQLite snapshot path now go through. The block-type predicate lives there now, and the session-message-text.ts module extracted by this branch is dropped.
What Problem This Solves
Long SQLite transcripts retain large tool-result, attachment, and replay payloads while preparing much smaller memory exports. Conversation recall also builds the entire export just to check the current reset boundary.
Related: #157092.
User Impact
Lower memory pressure during session indexing and cheaper reset checks during conversation recall. Exported content, hashes, provenance, raw line ordinals, snapshot fences, and observer messages stay unchanged. No configuration, schema, retention, or update changes.
Why This Change Was Made
Reduce each decoded event to the fields memory consumes before retaining the snapshot. Observers keep the full snapshot and run after the transaction closes. Recall visibility requests the existing reset-navigation projection through the same background worker pool instead of preparing indexed content.
Full indexing still scans and decodes all events; output and navigation memory still scale with transcript size. This does not introduce a fixed total-memory limit or attribute the reporter's production warnings to a particular session/caller.
Evidence
Synthetic isolated SQLite fixture on macOS arm64 / Node 24.19.0: 25,394 events, 177,811,487 JSON bytes, producing 38,847 export bytes. Baseline:
a533ff8f836.Measurements instrument the same in-process implementation used by the worker, sample heap after every 100 large JSON parses, and force GC before each run. They are sampled heap deltas, not total allocations or worker RSS. Full worker calls also passed output/cutoff assertions (1,249 ms before, 1,216 ms after including startup; warm metadata call 93 ms). No stable full-indexing speedup or >1-second transaction hold was reproduced locally.
The output hash was identical before/after:
d997e0624111a1ec065927d82463240a93622de2bccdb0d6ef6bf157f758ac4a.Validation and Review
runWithSessionTranscriptReadFence(request.admission, ...), and the real-worker admitted-input regression passes. No actionable findings remain.pnpm buildpassed in an isolated checkout. Final equivalent coercion cleanup was covered by core/extension production and test typechecks (all 25 core-test shards); the subsequent parameter rename passed scoped lint and formatting.