Skip to content

fix(memory): stream session memory exports in bounded pages - #196480

Merged
obviyus merged 4 commits into
mainfrom
fix/streamed-session-memory-export
Nov 11, 2026
Merged

obviyus merged 4 commits into
mainfrom
fix/streamed-session-memory-export

Conversation

@obviyus

@obviyus obviyus commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #196132, follow-up to #196158

What Problem This Solves

Fixes: the session memory export (used by memory indexing, dreaming ingestion and memory-forget) still runs its 512 MB transcript worker out of memory once a session holds about 240 MB of message text. #196158 halved the peak, but the export still built the whole session as one string in the worker and returned it to the main thread.

User Impact

User impact: very large sessions no longer crash the export worker or abort the Gateway during memory sync or dreaming, regardless of session size. Indexed content and stored hashes are unchanged.

Why This Change Was Made

  • The renderer emits ~1 MB pages over the existing session-entries worker channel and never builds the whole text. Transcripts over 4 MB are read in 2 MiB slices.
  • The persisted entry hash and dreaming prefix hash are computed incrementally and stay byte-identical to the previous formula, so existing indexes and dreaming checkpoints stay valid.
  • buildSessionEntry / buildSessionEntries keep their shape (they collect pages). Memory indexing, startup eligibility, dreaming ingestion and memory-forget move to streamSessionEntry / streamSessionEntries. The memory-core-host-engine-sessions subpath is private-local, so dropping matchesSessionEntryPrefixHash there is not a public break.
  • If the transcript changes between slices, the export restarts (up to 3 times) and tells consumers to discard partial pages.
  • Snapshot-based export paths made dead by the cutover are removed; export readers move to session-accessor.sqlite-export-read.ts (line cap).

Evidence

Incognito authority per page (src/config/sessions/session-actor-memory-search.test.ts, real session actor owner, runWithSessionActorStorage with a selected authority): a two-message transcript of 600k chars each spans two export pages; the consumer's first onPage callback revokes authority. Recorded on head 6b5c7e4, clean env:

✓ Memory export from the session actor > blocks the next export page when a page consumer revokes permission 6ms
✓ Memory export from the session actor > blocks the next transcript disclosure when permission is revoked by a consumer callback 1ms
Tests  8 passed (8)

The stream rejects with Memory disclosure was revoked and the consumer received exactly one page (["User: first"]). Before the per-page check (5db31b7), the same test delivered 3 pages after revocation. The check runs immediately before every page and reset delivery in buildSessionEntryFromSnapshot, so successive deliveries are each gated on live authority.

  • New real-worker regression session-files-large-export.test.ts (20,000 messages x 15,000 chars, ~300 MB; runs with OPENCLAW_SESSION_EXPORT_STRESS=1):
    • parent 625945b: fails with ERR_WORKER_OUT_OF_MEMORY in sessionTranscript.session-entries.
    • this branch: passes in ~5 s; 380,000 lines, same hash and prefix hash from buildSessionEntries, buildSessionEntry and the paged API; >400 pages, none over 600K chars. Worker heap peaked at ~63-70 MiB (temporary probe, removed).
  • Equivalence manager-session-export-equivalence.test.ts: mixed session (user/assistant/tool calls and results, heartbeat, compaction, two resets, appends, long wrapped messages). Indexed chunks with provenance, source and entry hashes, and dreaming candidates across first scan, append, capped continuation and prefix mismatch are byte-identical to the parent; the test pins that fingerprint.
  • Suites (clean env): packages/memory-host-sdk/src/host 157 passed; extensions/memory-core 1830 passed / 67 skipped; src/config/sessions/session-memory-entry.worker.test.ts and related worker tests pass.
  • pnpm check:changed: everything passes except Plugin SDK surface budget (identical 3877 > 3865 on origin/main) and the dead export scan (no hits in changed files).

Remaining limits, not addressed here:

  • Memory indexing still holds a session's prepared chunks on the main heap until it publishes them, because publishing replaces a session's rows at once. Bounding that needs batched publication in memory-core.
  • A changed session is read twice when indexed (change check, then chunking); a concurrent change is picked up on the next sync.
  • Archived JSONL/zst files still load the raw file text in-process; only rendered output is paged.

@clawsweeper

clawsweeper Bot commented Nov 10, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core scripts Repository scripts size: XL labels Nov 10, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Streams session memory exports in acknowledged pages and migrates indexing, dreaming ingestion, and memory-forget to consume them.

Example: Export a session containing 20,000 messages of 15,000 characters each.

  • Before: The supplied baseline run exhausts the 512 MiB transcript worker.
  • After: The supplied candidate run exports 380,000 lines in bounded pages while preserving content and hashes.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful and coherent, with no actionable source finding; supplied validation reaches real workers and actor owners but lacks a shipped-entry-point run for this change.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (terminal): For this collaborator-authored PR, the applicable authority proof exercises the real session actor and selected authority: the first page is allowed, its consumer revokes permission, and the next disclosure rejects; message-observer revocation is also covered.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Very large conversations stop contributing to memory when their export exhausts the transcript worker.
Reason: The maintainer-authored direction addresses a demonstrated remaining allocation problem; the growth supports one coherent producer-to-consumer cutover.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a remaining large-session export failure on main, and inspection found no actionable introduced defect.

Priority: P1
Reviewed head: 73430f6ec222ad68b212aeb49526026e64a05e0c

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied large-export validation uses production workers and manager fixtures rather than a built CLI or running Gateway.
Agent review details

How this fits together

Session storage supplies transcript records to the memory export worker; its renderer produces text, provenance, and hashes for indexing, dreaming, and forgetting.

flowchart TD
  A[Session storage] --> B[Transcript export worker]
  B --> C[Shared renderer and incremental hashes]
  C --> D[Acknowledged export pages]
  D --> E[Memory index chunker]
  D --> F[Dreaming ingestion]
  D --> G[Memory forget]
Loading

Technical review

Best possible solution:

Complete the existing export owner's paged cutover while preserving hashes, reset boundaries, backpressure, and live disclosure authority.

Do we have a high-confidence way to reproduce the issue?

Main still constructs complete exports, and the PR records a baseline worker OOM with a roughly 300 MB transcript; this read-only review did not rerun it.

Is this the best way to solve the issue?

Paging through the existing worker exchange removes the remaining whole-export allocation at its owner and updates the affected consumers together without adding a competing renderer.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2b4ca2dcdc28.

Provenance checked

  • Complete-entry export and acknowledgement changes intended behavior with a stated reason (1bb6763: Bound export groups and downstream indexing while preserving complete, ordered entries.)
  • Renderer intermediate release changes intended behavior with a stated reason (e64c351: Reduce the working set inside an individual export without changing its full-output contract.)
  • Short transcript read transactions keeps the original intent (471a768: Release SQLite snapshots before decoding large payloads so WAL checkpoints can progress.)
  • Dreaming append checkpoints keeps the original intent (8716689: Validate the complete prior snapshot prefix before resuming consumption to prevent replay after seen-message history rolls over.)
  • Worker-owned rendering keeps the original intent (516a142: Keep transcript workers independent of heavyweight Gateway initialization and retain one shared renderer.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Jason (Json): Raw commit 1bb6763 adds src/config/sessions/session-memory-entry.worker.ts:124 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1bb67632b182; files: src/config/sessions/session-memory-entry.worker.ts)
  • Mitchell Etzel: Raw commit 471a768 adds src/config/sessions/session-accessor.sqlite-export-slices.ts:65 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 471a768fa058; files: src/config/sessions/session-accessor.sqlite-export-slices.ts)

PR surface

Source +536, Tests +653, Docs +3, Other +5. Total +1197 across 50 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 29 1536 1000 +536
Tests 17 723 70 +653
Docs 1 6 3 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 3 9 4 +5
Total 50 2274 1077 +1197

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Large real sessions can stop memory updates through worker exhaustion, with related reports also demonstrating Gateway termination.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (7 earlier review cycles)
  • reviewed 2026-11-10T06:30:49.914Z sha 8a11e4a :: needs real behavior proof before merge. :: [P1] [P1] Avoid holding both pipeline stages behind one compute permit | [P1] [P1] Revalidate incognito authority before delivering each page
  • reviewed 2026-11-10T09:07:13.272Z sha 9b788e5 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-10T09:15:33.218Z sha 9b788e5 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-11T03:25:19.790Z sha 6b5c7e4 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-11T03:39:52.124Z sha 6b5c7e4 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-11T03:47:27.319Z sha 6b5c7e4 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-11T04:22:46.334Z sha ea47716 :: needs maintainer review before merge. :: none

Reviewed November 11, 2026, 12:59 AM ET / 05:59 UTC (Revision 8).

@obviyus
obviyus force-pushed the fix/streamed-session-memory-export branch from 8a11e4a to 9b788e5 Compare November 10, 2026 08:57
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 10, 2026
obviyus and others added 4 commits November 11, 2026 11:23
The session memory export rendered a whole session into one string inside
the 512 MB transcript worker and returned it to the main thread. #196158
halved the peak, but sessions above roughly 240 MB of message text still
exhausted the worker, and the full text still landed on the main heap.

The renderer now emits ~1 MB pages over the existing session-entries
channel, reads large transcripts in 2 MiB slices, and computes the persisted
entry hash and dreaming prefix hash incrementally (byte-identical to the
previous formula). buildSessionEntry/buildSessionEntries keep their shape;
memory indexing, startup eligibility, dreaming ingestion and memory-forget
move to streamSessionEntry/streamSessionEntries. Snapshot-based export paths
made dead by the cutover are removed.

Refs #196132

Co-authored-by: obviyus <[email protected]>
The session export worker holds the shared compute permit while it waits for
indexing to take each page. Indexing in the shared pool then waited for that
permit, so one-permit hosts (two CPUs) deadlocked. Chunk session pages in a
one-worker pool that runs under the export's permit, and dispatch the chunker
only once its export delivers, so a queued chunker never waits on a queued export.

Co-authored-by: obviyus <[email protected]>
A consumer that revoked the selected actor's authority inside onPage still
received later pages because authority was checked only after rendering.
Assert live authority immediately before every page and reset delivery.

Co-authored-by: obviyus <[email protected]>
@obviyus
obviyus force-pushed the fix/streamed-session-memory-export branch from ea47716 to 73430f6 Compare November 11, 2026 05:53
@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 11, 2026
@obviyus
obviyus merged commit e881eb8 into main Nov 11, 2026
170 of 173 checks passed
@obviyus
obviyus deleted the fix/streamed-session-memory-export branch November 11, 2026 06:23
@syxscott

Copy link
Copy Markdown
Contributor

Heads-up: this change appears to break two memory-core integrity regressions, deterministically.

  • extensions/memory-core/src/cli.test.ts > fails index --force when the memory index has orphaned provenance — the forced index now succeeds (exit code 0) where the test expects the SQLite foreign_key_check failure (exit 1): AssertionError: expected +0 to be 1. The orphaned provenance is seeded, so the corruption is no longer detected and the index silently proceeds.
  • extensions/memory-core/src/memory/manager-publication-admission.test.ts > retains reindexed memory admission with a invalid seal without skipping required integrity — the sibling integrity case in the same area.

Both point at the same rewritten region: this change replaces the index preparation with a worker-backed streaming path and rewrites lineProvenance handling (entry.lineProvenance → readonly MemoryEntryProvenance[], and the provenance/line-map plumbing in manager-index-source.ts and session-ingestion.ts), which is exactly what the orphaned-provenance fixture seeds.

Evidence (tree = main + one unrelated DNS change; the DNS files cannot reach the memory index path):

  • Both tests failed on the same tree, on two consecutive CI runs of that tree: 43150330315 (jobs checks-node-changed-extensions-bundle-21-1 and -24-1) and the earlier run of the same head.
  • The regression is invisible on this PR's own CI: its changed scope ran only checks-node-changed-extensions-bundle-1/2/3, which do not contain extensions/memory-core/src/cli.test.ts or manager-publication-admission.test.ts, and main's push runs skip the changed lanes. The breakage surfaced on the first tree whose changed scope covered the memory-core bundles after this landed.

I could not reproduce locally (the extension test bundles need the pinned Bun runtime and the extension build, which do not run on this Windows host), so this report is CI-log evidence only — but it is deterministic on the affected tree, not a flake.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 12, 2026
…#196480)

* fix(memory): stream session memory exports in bounded pages

The session memory export rendered a whole session into one string inside
the 512 MB transcript worker and returned it to the main thread. openclaw#196158
halved the peak, but sessions above roughly 240 MB of message text still
exhausted the worker, and the full text still landed on the main heap.

The renderer now emits ~1 MB pages over the existing session-entries
channel, reads large transcripts in 2 MiB slices, and computes the persisted
entry hash and dreaming prefix hash incrementally (byte-identical to the
previous formula). buildSessionEntry/buildSessionEntries keep their shape;
memory indexing, startup eligibility, dreaming ingestion and memory-forget
move to streamSessionEntry/streamSessionEntries. Snapshot-based export paths
made dead by the cutover are removed.

Refs openclaw#196132

Co-authored-by: obviyus <[email protected]>

* fix(memory): keep session export indexing live under one compute permit

The session export worker holds the shared compute permit while it waits for
indexing to take each page. Indexing in the shared pool then waited for that
permit, so one-permit hosts (two CPUs) deadlocked. Chunk session pages in a
one-worker pool that runs under the export's permit, and dispatch the chunker
only once its export delivers, so a queued chunker never waits on a queued export.

Co-authored-by: obviyus <[email protected]>

* fix(memory): revalidate incognito authority before each export page

A consumer that revoked the selected actor's authority inside onPage still
received later pages because authority was checked only after rendering.
Assert live authority immediately before every page and reset delivery.

Co-authored-by: obviyus <[email protected]>

* test: allocate test lines for paged session memory export coverage

Co-authored-by: obviyus <[email protected]>

---------

Co-authored-by: obviyus <[email protected]>
RomneyDa pushed a commit that referenced this pull request Nov 15, 2026
* fix(memory): stream session memory exports in bounded pages

The session memory export rendered a whole session into one string inside
the 512 MB transcript worker and returned it to the main thread. #196158
halved the peak, but sessions above roughly 240 MB of message text still
exhausted the worker, and the full text still landed on the main heap.

The renderer now emits ~1 MB pages over the existing session-entries
channel, reads large transcripts in 2 MiB slices, and computes the persisted
entry hash and dreaming prefix hash incrementally (byte-identical to the
previous formula). buildSessionEntry/buildSessionEntries keep their shape;
memory indexing, startup eligibility, dreaming ingestion and memory-forget
move to streamSessionEntry/streamSessionEntries. Snapshot-based export paths
made dead by the cutover are removed.

Refs #196132

Co-authored-by: obviyus <[email protected]>

* fix(memory): keep session export indexing live under one compute permit

The session export worker holds the shared compute permit while it waits for
indexing to take each page. Indexing in the shared pool then waited for that
permit, so one-permit hosts (two CPUs) deadlocked. Chunk session pages in a
one-worker pool that runs under the export's permit, and dispatch the chunker
only once its export delivers, so a queued chunker never waits on a queued export.

Co-authored-by: obviyus <[email protected]>

* fix(memory): revalidate incognito authority before each export page

A consumer that revoked the selected actor's authority inside onPage still
received later pages because authority was checked only after rendering.
Assert live authority immediately before every page and reset delivery.

Co-authored-by: obviyus <[email protected]>

* test: allocate test lines for paged session memory export coverage

Co-authored-by: obviyus <[email protected]>

---------

Co-authored-by: obviyus <[email protected]>
(cherry picked from commit e881eb8)
Co-authored-by: RomneyDa <[email protected]>

(cherry picked from commit 9c7100ce7686c74daf4b644e96666c64c2dde192)

Co-authored-by: vincentkoc <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 16, 2026
Release-specific port of openclaw#196480 and its type-boundary companion. Preserve complete-entry SDK builders while memory indexing uses paged exports, bounded slices and generation reset. Retain cold, archive and incognito paths. Independent local review waived by Dallin; exact-head CI pending. Observer reset concern remains assigned for an incremental correction before qualification.

(cherry picked from commit e881eb8)
Type-boundary companion d2b99a1.

Co-authored-by: RomneyDa <[email protected]>
KCNyu pushed a commit to KCNyu/openclaw that referenced this pull request Nov 22, 2026
Backport-of: openclaw#196158 and openclaw#196480. Only the rendered export remains materialized for the existing consumer.
KCNyu added a commit to KCNyu/openclaw that referenced this pull request Nov 22, 2026
Backport-of: openclaw#196158 and openclaw#196480. Only the rendered export remains materialized for the existing consumer.
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 P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL 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