Skip to content

fix(memory): reduce memory use when indexing long sessions - #157278

Merged
roboclaw-bot merged 4 commits into
openclaw:mainfrom
sahilsatralkar:codex/fix-session-entry-snapshot
Sep 24, 2026
Merged

roboclaw-bot merged 4 commits into
openclaw:mainfrom
sahilsatralkar:codex/fix-session-entry-snapshot

Conversation

@sahilsatralkar

@sahilsatralkar sahilsatralkar commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

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.

Measurement Before After
Index preparation sampled JS heap growth, two runs 214 / 199 MiB 43 / 47 MiB
Index preparation time, two runs 442 / 413 ms 494 / 389 ms
Reset-cutoff preparation time Full entry: 442 / 413 ms Metadata: 82 ms
Large payloads parsed for reset lookup 25,392 0
Reset lookup sampled heap growth Full entry: 214 / 199 MiB Metadata: 17 MiB

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.

  • Regression negative control: restoring full-payload loading makes the metadata test fail with “Reset metadata must not hydrate message payloads.”
  • Focused tests cover SQLite/archive/worker parity, full observer payloads, callback snapshot consistency, redaction retries, incognito/missing stores, raw cutoff ordinals, prefix-hash reset invalidation, admitted-input fence transport, and recall visibility.
  • Materially changed test costs: snapshot/reset integration file 10 tests / 7.2 s test time; recall visibility file 14 tests / 37 ms (compiler/setup excluded).

Validation and Review

  • 76 focused tests passed across session files, provenance, reset integration, recall visibility, worker responsiveness, and reset races.
  • Core and extension typechecks passed in an isolated checkout; documentation links and coercion checks passed.
  • Independent review completed. Its fence concern was rejected: the dispatch is already inside runWithSessionTranscriptReadFence(request.admission, ...), and the real-worker admitted-input regression passes. No actionable findings remain.
  • Full pnpm build passed 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.
  • All selected changed-file gates passed across the initial run and resumed checks: formatting, baselines, SDK/plugin boundaries, typechecks, dead exports, lint, database/runtime/import-cycle/security guards. The initial runner stopped on sandbox access to pnpm's cache; that scan and remaining gates passed when resumed. CI's one shadowed-parameter error was fixed and verified locally.
  • The build printed UI bundle-budget warnings despite exiting successfully. UI sources are unchanged; baseline attribution was not established. Remote CI on the latest commit is separate and may still be pending.

@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@sahilsatralkar
sahilsatralkar marked this pull request as ready for review September 24, 2026 12:20
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 24, 2026, 2:55 PM ET / 18:55 UTC (Revision 3).

ClawSweeper review

What this changes

The 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
Reviewed head: e483ca3d3dceda4b29068febe64bbc26b809950a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has focused boundary coverage and measured real-path improvement, while its remaining full-scan limitation is stated clearly.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body reports before/after results from a real isolated SQLite transcript fixture exercising the indexing implementation and full worker calls, with lower sampled heap growth and an unchanged output hash. Regression tests supplement that observation; the diff changes no stored-data contract, so migration compatibility is not applicable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body reports before/after results from a real isolated SQLite transcript fixture exercising the indexing implementation and full worker calls, with lower sampled heap growth and an unchanged output hash. Regression tests supplement that observation; the diff changes no stored-data contract, so migration compatibility is not applicable.
Evidence reviewed 7 items Current main retains the reported cost: The current-main export path reads a full transcript snapshot; recall visibility calls the full entry builder to obtain reset metadata.
Introduced indexing projection: The PR projects decoded events before retaining the snapshot, while keeping full events for observer callbacks.
Reset read and snapshot fence: The new worker request uses the existing session-entry reader pool and carries the transcript admission fence; the SQLite reader selects reset-navigation data.
Findings None None.
Security None None.

How this fits together

Memory 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]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +172, Tests +64, Docs +8, Other 0. Total +244 across 16 files.

View PR surface stats
Area Files Added Removed Net
Source 12 207 35 +172
Tests 2 91 27 +64
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 2 0
Total 16 308 64 +244

Review metrics

Metric Value Why it matters
Production and test LOC production +209/−35; tests +91/−27 The production growth adds a projection and worker read path to reduce retained payloads; the changed tests cover export parity and reset fencing.

Stored data model

Persistent data-model change detected: unknown-data-model-change: packages/memory-host-sdk/src/host/session-entry-projection.ts, vector/embedding metadata: extensions/memory-core/src/session-search-visibility.ts, vector/embedding metadata: packages/memory-host-sdk/src/host/openclaw-runtime-session.ts, vector/embedding metadata: packages/memory-host-sdk/src/host/session-entry-projection.ts, vector/embedding metadata: packages/memory-host-sdk/src/host/session-files.ts, vector/embedding metadata: packages/memory-host-sdk/src/host/session-reset-recall-read.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #157092
Summary: This PR is a candidate fix for the linked issue's allocation and reset-lookup costs; the issue's full-scan transaction-duration concern remains separately assessable.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The PR addresses memory pressure in long-session indexing with a limited, measured improvement.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports before/after results from a real isolated SQLite transcript fixture exercising the indexing implementation and full worker calls, with lower sampled heap growth and an unchanged output hash. Regression tests supplement that observation; the diff changes no stored-data contract, so migration compatibility is not applicable.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports before/after results from a real isolated SQLite transcript fixture exercising the indexing implementation and full worker calls, with lower sampled heap growth and an unchanged output hash. Regression tests supplement that observation; the diff changes no stored-data contract, so migration compatibility is not applicable.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vitor Cepeda Lopes: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-24T12:28:22.117Z sha 6610a432908c59a1664afc49d0ac3bf9e1f6f98b :: blocked before merge. :: none
  • reviewed 2026-09-24T13:05:35.638Z sha 5e7d43ab5c3f47bcf109d0e65cb0be3d0838f9f4 :: blocked before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core size: M labels Sep 24, 2026
@roboclaw-bot
roboclaw-bot force-pushed the codex/fix-session-entry-snapshot branch from 5e7d43a to 478f89a Compare September 24, 2026 18:43
Main and the session snapshot change each remove one assertion. Preserve both reductions in the rebased baseline.

Co-authored-by: jalehman <[email protected]>
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Reviewed current head e483ca3d3dceda4b29068febe64bbc26b809950a for landing.

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.

@roboclaw-bot
roboclaw-bot merged commit 30e67db into openclaw:main Sep 24, 2026
209 checks passed
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
…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]>
namest504 added a commit to namest504/openclaw that referenced this pull request Sep 28, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants