Skip to content

fix(memory): large session exports exhaust workers - #196158

Merged
obviyus merged 5 commits into
openclaw:mainfrom
ericcaiwx-star:codex/fix-196132-memory-export-working-set
Nov 9, 2026
Merged

obviyus merged 5 commits into
openclaw:mainfrom
ericcaiwx-star:codex/fix-196132-memory-export-working-set

Conversation

@ericcaiwx-star

@ericcaiwx-star ericcaiwx-star commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Closes #196132

What Problem This Solves

One large session could exhaust the capped memory-index export worker while it retained the projected transcript, sanitized string backing stores, rendered lines, and final joined output together. Export grouping and acknowledgement already bounded batches, but did not release these intermediates within an individual export.

Why This Change Was Made

The existing renderer now consumes records only from private, uncached worker snapshots and flattens rendered text in groups. Reset boundaries are captured before consumption. Cached, actor/caller-owned, and observer snapshots retain their existing behavior. Late generated-session classification clears both buffered and flushed text plus aligned metadata.

This keeps the repair in the current export owner. Complete content, order, hashes, source line mappings, timestamps, provenance, snapshot fences, cold behavior, and whole-entry acknowledgement remain intact. No heap increase, truncation, disabled memory feature, public SDK export, configuration option, schema, or streaming protocol was added. Necessary production growth is 36 lines net for explicit ownership and intermediate release.

User Impact

Large historical sessions can finish cross-conversation memory indexing and remain searchable while other sessions continue to work. The existing full-output API and per-message allocation still cost O(result); 256 KiB is a text flush threshold plus one message, not a universal peak-memory bound.

Evidence

Current head: 20d5573d6540f0a74319c623abf1ba9829bba1ea. The follow-up commit adds only the dedicated test-line allocation. Runtime and all test blobs are byte-identical to implementation 924fb74a2e120778c23b5f2d9ed132e0df5b774b, where all behavior evidence below was executed; it is reused on that explicit basis, not claimed as a rerun. Named main base: 6edcaa28edb7817efda38eccc4f0c7fd13ad148c. Runtime: Node 26.7.0, macOS arm64. Production worker limits remain 512 MiB old / 32 MiB young generation.

Real-worker red / green

The added production-pool regression persists one 12,460-message session, 15,000 characters per message (186,900,000 text bytes, 178.24 MiB), with spaced text and distinct ordered markers. It checks full expected output length, every message marker in order, aligned metadata, and a subsequent successful export.

# Named-base production with the added regression, through ocpr prove --phase pre:
node scripts/run-vitest.mjs src/config/sessions/session-memory-working-set.test.ts --maxWorkers=1 -t 'one 178 MiB'
FAIL ERR_WORKER_OUT_OF_MEMORY: Worker terminated due to reaching memory limit
[task=sessionTranscript.session-entries admittedInputBytes=750 exchanges=0 stage=running]
exit 1

# Implementation head 924fb74a2e120778c23b5f2d9ed132e0df5b774b, through ocpr prove --phase post:
node scripts/run-vitest.mjs src/config/sessions/session-memory-working-set.test.ts --maxWorkers=1
PASS exports every medium transcript through the production 512 MiB worker (6052ms)
PASS classifies a message-bearing large transcript without retaining its complete raw history (1922ms)
PASS exports one 178 MiB transcript through the capped worker and serves another request (6979ms)
3/3 passed; wall 34.56s; exit 0

The initial solid-text control passed and is not represented as a failure. The reproduced failure is worker OOM; the reporter's separate Gateway exit 134 was not reproduced.

Real Gateway: startup catch-up and post-compaction indexing

Task-owned Node Gateways used isolated state/free ports, active memory-core, sessions/FTS-only indexing, and a real local Gemma3 model on an independently owned Ollama service with verified 32K context. No reporter fork was executed, no direct manager sync supplied the result, and no production Gateway/state/model daemon was changed.

Startup catch-up used a fresh Gateway and an unindexed 178.24 MiB transcript. Public resident memory.search acquired the default manager and its automatic startup catch-up; this is cold manager acquisition, not a claim of eager indexing at process-ready time. The source and 37,381 chunks were published, all head/middle/tail sentinel searches returned independently identified source ranges, and real sibling turns succeeded before and after indexing. Gateway survived; cleanup joined.

Post-compaction proof retained the same full 178.24 MiB raw history. The declared prior-history fixture used SessionManager.appendCompactionAsync with the existing atomic compaction/accounting persistence owner, following the repository's precompacted-history test pattern. Its prior summary is synthetic input, not claimed model-generated evidence. A small active tail and a 4 KiB test-profile byte trigger exercised the next real compaction without asking a local model to summarize millions of historical tokens from scratch. This changes the trigger size, not the transcript export size or worker limits.

# Through ocpr prove --phase post, unchanged published head:
env -i PATH=/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin HOME=/private/tmp/oc196132-gateway-launch-home /opt/homebrew/bin/node --import ./scripts/tsx.mjs /private/tmp/oc196132-gateway-proof-precompacted.mts --out /private/tmp/oc196132-gateway-candidate-post-precompacted --messages 12460 --chars 15000 --phase postcompaction --deadline-ms 300000
seeded compactions: 1
actual model turn: ok; persisted compactions: 2 (a new runtime boundary)
continuation turn: ok
new source revision published after continuation; chunks: 37,398
seed message coverage: expected 12,460; seen 12,460; missing []
head/middle/tail plus new continuation sentinel: all 4 searchable by source range
real sibling turn: ok; Gateway alive; cleanup joined; exit 0

Observed native export tasks completed after the new boundary and continuation. Both flows kept complete raw historical content available to export. Repeated filler fragments can share existing chunk IDs, so stored chunk character totals are not a raw-byte equality oracle; full export length/order and independent per-message index coverage provide that evidence.

Paired diagnostic observations: startup worker observed heap maximum 430.4 MiB; post-compaction 431.6 MiB across three successful export tasks, with unchanged resource limits (observed V8 aggregate heap limit 560 MiB). Gateway status samples observed main-heap maxima 1159.3/1163.2 MiB and process RSS maxima 3938.2/4122.3 MiB for startup/post-compaction. RSS is process-wide, heap is isolate-local; sparse instrumented samples are not exact peaks, a latency benchmark, or a constant-memory claim. No new host accumulator was introduced.

Coverage limits and preserved setup failures: the real Gateway used synthetic persisted history and FTS-only indexing, not external embedding services or live user data. Initial model setup had a mismatched context/output-budget contract; the task route was corrected to the provider's supported settings. Two all-active-history compaction attempts timed out during multi-request real-model summarization, before a compaction result; they are not passing proof or export failures. The passing post-compaction flow proves new compaction → complete historical export/indexing, not first-time summarization throughput for 178 MiB of active context.

Checks and independent review

  • 49/49 affected worker/cache/fence/delivery, SQLite read-hold/export-budget, and SDK content/reset/provenance tests passed.
  • Core production typecheck emitted no diagnostics; supported changed-test typechecks passed packages and agents-sessions. Scoped type-aware lint, format, and git diff --check passed.
  • Normal isolated-profile CLI build passed in 67.5s, reporting OpenClaw 2026.11.2 (924fb74).
  • Fresh independent source P0–P2 review found no issues. Canonical AutoReview completed scoped-clean, no findings, both for the local candidate before commit and through the source-bound clean exact-head monitor review (--mode branch --base 6edcaa28edb7817efda38eccc4f0c7fd13ad148c --engine codex --max-priority P2). The reviewer inspected code and did not execute tests; runtime evidence above was executed separately.

Maintainer update (head 7378aa2)

  • Gateway proof on a built Gateway in Docker (node 24.22.1): with the reporter's 178 MB flood session, openclaw memory search aborts the Gateway on main (exit 134, V8 heap limit, twice). This head completes the export twice with identical index rows, and the controls match main exactly. Details: fix(memory): large session exports exhaust workers #196158 (comment)
  • Tests: the allocation file is removed, and the 178 MiB, reset-parity and cache-transition tests above are no longer in the branch. Two compact regressions are folded into existing cases with net 0 test lines. The worker delivery test now renders a session above the 4 MB retention limit twice in one batch and checks the complete output. The dreaming-provenance test now uses a fragment that flushes a text chunk before the reset.
  • Production is unchanged from 924fb74 (+41/-5).

Author-side checks and actionable reviews are complete. The PR remains open and unmerged for maintainer review; no merge is performed by this contributor workflow.

@clawsweeper

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

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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. labels Nov 9, 2026
@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR releases private transcript records during export and joins rendered text in smaller groups to reduce worker memory use.

Example: Index a session containing 12,460 assistant messages with 15 KB of text each.

  • Before: Memory search aborts the baseline Gateway with exit 134 and leaves the session unindexed.
  • After: The candidate indexes all 12,460 source lines twice with identical results while the Gateway keeps serving.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused repair with production-entry-point failure and recovery evidence, output-parity controls, and no actionable source findings; pending CI is not a passing gate.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The supplied macOS Gateway startup and post-compaction runs and obviyus's built-Gateway Docker memory-search runs exercise the production export owner; the candidate completes the large transcript and preserves control indexes, and its production blobs are unchanged at the reviewed head.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A large historical conversation can crash the Gateway during memory indexing and remain unavailable to memory search.
Reason: The demonstrated crash is repaired without changing configuration, heap limits, public APIs, storage formats, or exported content.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it provides a focused, demonstrated repair for a current Gateway crash, with no actionable findings; required CI remains pending.

Priority: P1
Reviewed head: 7378aa25007878c1411e1af7d9bf2e184c02b831

Before merge

None.

Findings

None.

Agent review details

How this fits together

The session export worker reads admitted transcript snapshots, renders conversation text and aligned metadata, and delivers complete entries to the memory indexer.

flowchart LR
  A[Memory search or catch-up] --> B[Transcript export worker]
  B --> C[Admitted database snapshot]
  C --> D[Shared session renderer]
  D --> E[Complete text and metadata]
  E --> F[Acknowledged host delivery]
  F --> G[Memory index]
Loading

Technical review

Best possible solution:

Land the existing owner-local repair once the reviewed head satisfies required CI.

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

Supplied built-Gateway Docker logs reproduce exit 134 twice on baseline main using the reporter's 12,460-message fixture; source inspection confirms the responsible allocation path remains on fetched main.

Is this the best way to solve the issue?

The patch removes simultaneous retention at the existing renderer and worker owners while preserving complete output, cached snapshots, observer behavior, reset metadata, and acknowledgement; no smaller complete repair was identified.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 25e722837249.

Provenance checked

  • Serial export delivery and snapshot retention keeps the original intent (1bb6763: Bound export batches and acknowledge each complete entry before preparing later work.)
  • Shared session rendering keeps the original intent (516a142: Share rendering between snapshot and file readers while separating transcript workers from unrelated host code.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Jason (Json): Raw commit 1bb6763 adds src/config/sessions/session-memory-entry.worker.ts:143 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)

PR surface

Source +36, Tests 0. Total +36 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 41 5 +36
Tests 2 11 11 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 52 16 +36

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.

Review metrics

Metric Value Why it matters
Production versus test LOC Production +41/-5; tests +11/-11 Production growth implements explicit snapshot consumption and bounded text flattening within existing owners; regressions extend existing cases without net test growth.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #196132
Summary: This PR repairs the canonical report's single-export working-set failure; the earlier merged repair bounded batches rather than individual transcript intermediates.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: A demonstrated large-session export can abort the Gateway and interrupt every agent and channel it serves.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • 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 (3 earlier review cycles)
  • reviewed 2026-11-09T18:08:41.142Z sha 924fb74 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-09T18:33:13.574Z sha 924fb74 :: needs changes before merge. :: [P2] Add the allocation for the new regression-test lines
  • reviewed 2026-11-09T18:55:31.403Z sha 20d5573 :: needs maintainer review before merge. :: none

Reviewed November 9, 2026, 2:59 PM ET / 19:59 UTC (Revision 4).

@ericcaiwx-star
ericcaiwx-star marked this pull request as ready for review November 9, 2026 18:11
@ericcaiwx-star

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The Evidence section now includes the completed real Gateway startup catch-up and post-compaction acceptance at unchanged head 924fb74a2e120778c23b5f2d9ed132e0df5b774b, in addition to the formal capped-worker red/green and clean independent reviews. Both Gateway flows retain the full 178.24 MiB raw transcript; the post-compaction run records a new real-model compaction beyond the declared seed baseline, all 12,460 message prefixes indexed, searchable original/new sentinels, a successful sibling turn, paired memory observations, and joined cleanup. The synthetic prior-history checkpoint, smaller test trigger, FTS-only scope, and failed setup attempts are disclosed in the body.

Separately, the current CI, CodeQL, Critical Quality, Security Review, and Periphery summary pages report Internal server error. There is no executed failing build/test step; CI preflight passed, but the required openclaw/ci-gate never ran. For example, CI correlation ID is 2e9bd743-26b4-4ce1-b324-9789b644f8dd.

Could someone with Actions write access retry those workflows at this head? My repository access is read-only. These failures remain a delivery blocker; this is not a request to waive CI or merge.

@clawsweeper

clawsweeper Bot commented Nov 9, 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 9, 2026
@ericcaiwx-star

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the test-budget P2 in 20d5573d6540f0a74319c623abf1ba9829bba1ea: the dedicated config/test-lines-allocations/session-memory-export-working-set.txt grants exactly the PR's 117 net regression lines. The shared scalar is unchanged; the body explains each distinct regression boundary.

The requested test-line check reproduced the failure before the record and now passes (6,602,929 lines, ceiling 6,602,932, slack 3). Formal exact-head proof also passed the full-PR whitespace check and verified that runtime and all test blobs are byte-identical to 924fb74, where the accepted real-worker/Gateway evidence was executed. The evidence section preserves that execution SHA and its limits. A fresh source-bound canonical P0–P2 review at 20d5573 is scoped-clean with no findings.

Exact-head changed-test shards, lint, production types, Security Review, and Critical Quality have passed. The remaining main-CI/CodeQL jobs are still running; this request does not claim author delivery or passing aggregate CI. Push/body dispatches reported deduped: true with review_request_required, and no re-review has yet been requested for this head.

@clawsweeper

clawsweeper Bot commented Nov 9, 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. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 9, 2026
@obviyus

obviyus commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Maintainer proof for the out-of-memory crash in #196132 (built Gateway, secretless Docker, node 24.22.1).

Setup: the reporter's seed.cjs flood fixture (12,460 assistant messages of 15 KB, 178 MB of message text, 183 MB session), imported with openclaw doctor --session-sqlite import. Config: memory.search.provider: "none", rememberAcrossConversations: true. No changed heap limits; the export worker runs with the shipped 512 MB limit. openclaw memory search against the running Gateway syncs the session source, which runs the memory-index session export. Worker heap was sampled with worker.getHeapStatistics() every 200 ms.

Run Result Export worker heap Index
main e23c587, run 1 Gateway aborted, exit 134, FATAL ERROR: Reached heap limit (Mark-Compact 615.6 -> 612.9 MB) above 512 MB at the abort empty
main, run 2 same abort, exit 134 (Mark-Compact 622.6 -> 612.9 MB; sampled 622 MB) above 512 MB at the abort empty
PR head 20d5573, run 1 search rc 0, same Gateway pid still serving sampled peak 494 MB 1 source, 236,702 chunks, lines 1-12,460
PR head, run 2 search rc 0, same Gateway pid still serving sampled peak 436 MB identical to run 1

Controls:

  • Small mixed session (49 events: user, assistant, thinking, tool calls and results): main and PR produce identical index rows (31 chunks, same sha256).
  • 8,000-message flood (114 MB of text), which main still exports: main and PR produce identical index rows (151,962 chunks, same sha256). Main peaks at 422 MB, the PR at 335 MB.
  • The 8,000 fixture is a deterministic prefix of the 12,460 fixture. All 151,961 non-tail chunks that main indexes for it match the PR's large-session chunks at the same positions, and the PR's large export runs to the last message (line 12,460).

Test changes: the allocation file is removed. The regressions are folded into existing cases with net 0 test lines. The worker batch test now grows a cached session past the 4 MB retention limit and checks that the whole consumed export comes back (6,250 wrapped lines). The dreaming-provenance test now uses a fragment large enough to flush a text chunk before the reset.

Run summaries:

base-large-1: ref=base sha=e23c587c16f3836e01f2a2c15e5fdaa3e1bc394e fixture=flood12460 start=19:37:46
  memory search rc=1 end 19:38:43; gatewayAlive=no pidNow= pidBoot=7569; gateway exit=134 at 19:38:43
  export worker sampled peak heap 431 MB (512 MB old-gen limit); gateway peak RSS 2409 MB
  V8: Mark-Compact 615.6 (649.5) -> 612.9 (646.8) MB, pooled: 22 MB, 32.36 / 0.00 ms (average mu = 0.938, current mu = 0.823) allocation failure; scavenge might not succeed FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
  index: sources=0 chunks=0 textChars=0 maxEndLine=0 sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
base-large-2: ref=base sha=e23c587c16f3836e01f2a2c15e5fdaa3e1bc394e fixture=flood12460 start=19:40:56
  memory search rc=1 end 19:41:53; gatewayAlive=no pidNow= pidBoot=8304; gateway exit=134 at 19:41:53
  export worker sampled peak heap 622 MB (512 MB old-gen limit); gateway peak RSS 2693 MB
  V8: Mark-Compact 622.6 (656.2) -> 612.9 (647.1) MB, pooled: 22 MB, 37.85 / 0.00 ms (average mu = 0.946, current mu = 0.891) allocation failure; scavenge might not succeed FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
  index: sources=0 chunks=0 textChars=0 maxEndLine=0 sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
cand-large-1: ref=cand sha=20d5573d6540f0a74319c623abf1ba9829bba1ea fixture=flood12460 start=19:38:50
  memory search rc=0 end 19:40:35; gatewayAlive=yes pidNow=7922 pidBoot=7922; gateway stayed up until stopped
  export worker sampled peak heap 494 MB (512 MB old-gen limit); gateway peak RSS 3227 MB
  index: sources=1 chunks=236702 textChars=264991235 maxEndLine=12460 sha256=4a1430608d6c3ce95fbd5e1b07673183539a5e34dc06fdf65fc2a4cc6fd01dca
cand-large-2: ref=cand sha=20d5573d6540f0a74319c623abf1ba9829bba1ea fixture=flood12460 start=19:42:00
  memory search rc=0 end 19:43:45; gatewayAlive=yes pidNow=8651 pidBoot=8651; gateway stayed up until stopped
  export worker sampled peak heap 436 MB (512 MB old-gen limit); gateway peak RSS 3282 MB
  index: sources=1 chunks=236702 textChars=264991235 maxEndLine=12460 sha256=4a1430608d6c3ce95fbd5e1b07673183539a5e34dc06fdf65fc2a4cc6fd01dca
base-small: ref=base sha=e23c587c16f3836e01f2a2c15e5fdaa3e1bc394e fixture=small start=19:44:04
  memory search rc=0 end 19:45:01; gatewayAlive=yes pidNow=9031 pidBoot=9031; gateway stayed up until stopped
  export worker sampled peak heap 49 MB (512 MB old-gen limit); gateway peak RSS 2324 MB
  index: sources=1 chunks=31 textChars=38718 maxEndLine=49 sha256=9c4e1312dadb62a9df86e4539df25d4202501365e4df3b5ed56d2f1a4ad6c89f
cand-small: ref=cand sha=20d5573d6540f0a74319c623abf1ba9829bba1ea fixture=small start=19:45:09
  memory search rc=0 end 19:46:05; gatewayAlive=yes pidNow=9391 pidBoot=9391; gateway stayed up until stopped
  export worker sampled peak heap 51 MB (512 MB old-gen limit); gateway peak RSS 2317 MB
  index: sources=1 chunks=31 textChars=38718 maxEndLine=49 sha256=9c4e1312dadb62a9df86e4539df25d4202501365e4df3b5ed56d2f1a4ad6c89f
base-8000: ref=base sha=e23c587c16f3836e01f2a2c15e5fdaa3e1bc394e fixture=flood8000 start=19:46:22
  memory search rc=0 end 19:47:46; gatewayAlive=yes pidNow=9768 pidBoot=9768; gateway stayed up until stopped
  export worker sampled peak heap 422 MB (512 MB old-gen limit); gateway peak RSS 2839 MB
  index: sources=1 chunks=151962 textChars=170123503 maxEndLine=8000 sha256=b802c81f54db9238cce7e0a82c47c7bb646f88bc3a676b2765d1a648e738f22f
cand-8000: ref=cand sha=20d5573d6540f0a74319c623abf1ba9829bba1ea fixture=flood8000 start=19:47:56
  memory search rc=0 end 19:49:21; gatewayAlive=yes pidNow=10128 pidBoot=10128; gateway stayed up until stopped
  export worker sampled peak heap 335 MB (512 MB old-gen limit); gateway peak RSS 2807 MB
  index: sources=1 chunks=151962 textChars=170123503 maxEndLine=8000 sha256=b802c81f54db9238cce7e0a82c47c7bb646f88bc3a676b2765d1a648e738f22f

Comparisons:
  base-small vs cand-small: identical chunk rows=true
  base-8000 vs cand-8000: identical chunk rows=true
  cand-large-1 vs cand-large-2: identical chunk rows=true
  base-8000 chunks[0..151960] equal to cand-large-1 chunks at the same positions: 151961/151961; cand-large-1 extends to line 12460 (base-8000 to 8000)
  base-8000 chunks[0..151960] equal to cand-large-2 chunks at the same positions: 151961/151961; cand-large-2 extends to line 12460 (base-8000 to 8000)

@obviyus

obviyus commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 9, 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 9, 2026
@obviyus

obviyus commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Maintainer override: check-lint-core-4 is an inherited red, not caused by this PR.

  • It fails only on max-lines in six files this PR does not touch: chat-sidebar-region.runtime.tsx (703), board-widget-frame.tsx (710), sessions-page.test.ts (1031), activity-page.test.ts (1229), settings-layout.e2e.test.ts (1151) and src/auto-reply/reply/session-event-handoff.ts (783).
  • This PR changes only packages/memory-host-sdk/src/host/session-entry-render.ts, src/config/sessions/session-memory-entry.worker.ts and two test files.
  • The same six files are already over the limit on current main (d325e9e: 736, 760, 1076, 1306, 1229 and 829 lines).
  • The same job fails with identical annotations on an unrelated PR run: https://github.com/openclaw/openclaw/actions/runs/42688293335/job/129403268736
  • Every other CI job passed, including the three PostgreSQL conformance jobs. The exact-head review is 5/6 with no findings.

@obviyus
obviyus merged commit e64c351 into openclaw:main Nov 9, 2026
121 of 125 checks passed
@obviyus

obviyus commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Landed in e64c351. Thanks @ericcaiwx-star. Large session exports no longer crash the Gateway.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 10, 2026
fix(memory): keep large session exports under the worker memory limit

One large session could make the memory-index session export worker exceed its 512 MB heap limit. The whole Gateway then aborted with exit 134 and the index stayed empty. The renderer now releases intermediate data while it exports, so peak memory stays under the limit. Exported content is unchanged.

Evidence: a built Gateway in Docker on node:24.22.1 with no heap changes, using the reporter's own seed script (12,460 messages of 15 KB, about 178 MB of text), indexed through openclaw memory search. On main the Gateway aborted twice with exit 134 ("Reached heap limit"); the export worker was at about 615 to 622 MB. With this change the search succeeds twice on the same Gateway process, the session is fully indexed (236,702 chunks), both runs give identical rows, and the worker peaked at 436 to 494 MB. A small mixed session and an 8,000-message session give identical index rows on main and this change, and the 8,000-message chunks match the large export at the same positions. Details: openclaw#196158 (comment).

check-lint-core-4 is an inherited max-lines red in six untouched files: openclaw#196158 (comment)

Thanks @ericcaiwx-star.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Nov 10, 2026
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]>
obviyus added a commit that referenced this pull request Nov 11, 2026
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]>
obviyus added a commit that referenced this pull request Nov 11, 2026
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]>
obviyus added a commit that referenced this pull request Nov 11, 2026
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]>
obviyus added a commit that referenced this pull request Nov 11, 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]>
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): keep large session exports under the worker memory limit

One large session could make the memory-index session export worker exceed its 512 MB heap limit. The whole Gateway then aborted with exit 134 and the index stayed empty. The renderer now releases intermediate data while it exports, so peak memory stays under the limit. Exported content is unchanged.

Evidence: a built Gateway in Docker on node:24.22.1 with no heap changes, using the reporter's own seed script (12,460 messages of 15 KB, about 178 MB of text), indexed through openclaw memory search. On main the Gateway aborted twice with exit 134 ("Reached heap limit"); the export worker was at about 615 to 622 MB. With this change the search succeeds twice on the same Gateway process, the session is fully indexed (236,702 chunks), both runs give identical rows, and the worker peaked at 436 to 494 MB. A small mixed session and an 8,000-message session give identical index rows on main and this change, and the 8,000-message chunks match the large export at the same positions. Details: #196158 (comment).

check-lint-core-4 is an inherited max-lines red in six untouched files: #196158 (comment)

Thanks @ericcaiwx-star.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit e64c351)
Co-authored-by: RomneyDa <[email protected]>

(cherry picked from commit 574ac6c27c0df9683bf7546c6db798062cbcc073)

Co-authored-by: vincentkoc <[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]>
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

P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

[Bug]: memory-index session export exhausts its 512 MB worker, and can abort the Gateway, once a session holds about 140 MB of message text

2 participants