Skip to content

fix(sessions): prevent OOM from consumed input history - #196277

Merged
RomneyDa merged 2 commits into
mainfrom
fix/actor-consumed-input-hydration
Nov 10, 2026
Merged

RomneyDa merged 2 commits into
mainfrom
fix/actor-consumed-input-hydration

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Related: #191847

What Problem This Solves

Fixes session-actor worker out-of-memory failures when ordinary hydration loads a large history of consumed collected-input source messages. This is a separate non-compaction path from #194536; it does not establish that the original report had this exact cause.

User Impact

Sessions no longer load consumed source-message bodies into the actor's resident pending-input map. Exact source receipts remain in SQLite and remain available for replay checks and history reads. No configuration, schema, durable retention, or migration changes; no user action required.

Why This Change Was Made

The resident pending-input map now represents unconsumed inputs only. Hydration filters consumed rows before serializing their bodies, and consumption removes their resident copies. Missing exact keys fall back to the existing indexed durable reader; collected-source validation uses the existing batched reader when the resident set is incomplete. Restaging a consumed receipt cannot bring it back into residency.

Tradeoff: a keyed input absent from active residency needs an indexed local SQLite lookup rather than treating absence as proof that it is new. Durable preparation already enters the worker, so this adds no worker RPC or model call. Avoiding all such lookups would require complete historical membership information in memory or changed replay semantics. The read-count tests now explicitly account for that lookup. Active admitted inputs still prepare without reads. This is not a general speedup claim: cold hydration still scans the retained table, and active pending inputs still consume memory.

Evidence

  • The extended collected-input regression fails on base d5f45c66f550df85e3fe9b4eceb88aae1e0ce60f: consumption leaves source bodies resident. It also checks cold/restarted hydration, consumed-source restaging, exact retained bytes, replay rejection, and lifecycle cleanup.
  • Focused validation: 136 tests across 10 suites pass (87 tests in eight sibling suites, then 49 tests in the final consumed-input/resident-preparation rerun). The initial broader run exposed two obsolete read-count expectations; these were corrected to require the exact indexed lookups while preserving the active-input zero-read assertion and exact replay-byte assertions.
  • Core typecheck, affected test-graph typecheck, targeted lint, formatting, and diff whitespace checks pass.
  • Synthetic native-actor diagnostic: 60,000 consumed 4-KB source messages plus 40,000 short transcript events, with no compaction/reset. Base failed twice with worker OOM at its existing heap cap; patched hydration completed with about 100 MiB peak worker heap and a 1.3-KB serialized reply. Diagnostic only, not a throughput benchmark.
  • Independent correctness review and canonical local autoreview found no actionable findings. The follow-up review covers the explicit test-fixture path and read-count expectation corrections; production code is unchanged from the first reviews.
  • ClawSweeper follow-up: reproduced the kernel test's obsolete zero-read assertion, then corrected it to require exactly one pending-receipt SELECT without changing production code or weakening custody/rollback assertions. All seven kernel tests pass; independent review found no actionable findings. Targeted lint, formatting, and whitespace checks pass.
  • The separate CI timeout in team-shape-fixture.idle.test.ts passes locally (one test); its CI cause remains unestablished, not classified as unrelated.
  • Test-line allocation grants exactly this patch's 23 net test lines. The ratchet still reports 345 inherited excess lines on the selected base; this patch neither hides nor increases that debt, and does not change the shared ceiling scalar.

Gaps: no original reporter database or live Gateway/model-turn reproduction. The diagnostic exercises the real native actor acquisition/hydration boundary, not the complete user turn. The PostgreSQL variant of the shared resident-preparation suite was not run locally. Broad CI remains the PR's validation path.

Keep consumed source receipts durable without loading them into resident actor state. Use indexed canonical reads for missing historical keys and preserve replay validation.

Co-authored-by: RomneyDa <[email protected]>
@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.

@RomneyDa
RomneyDa marked this pull request as ready for review November 9, 2026 21:50
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S labels Nov 9, 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. 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. 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 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 excludes consumed input bodies from resident session actors while preserving durable receipts and replay validation.

Example: A session contains 60,000 consumed collected-input messages of 4 KB each.

  • Before: Actor hydration serializes their retained bodies into worker memory and can exceed the worker heap limit.
  • After: Hydration excludes consumed bodies, while exact replay checks retrieve the required receipts from SQLite.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused implementation appears correct and the earlier finding is resolved; confidence is limited to source inspection, regression coverage, and the reported native-actor diagnostic while broad CI remains pending.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate: its body reports a real native-actor diagnostic, while the inspected prepared screenshots belong to an older browser recovery flow and do not establish this patch's behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Large sessions can exhaust the SQLite worker while loading already-consumed source messages, interrupting agent turns.
Reason: The maintainer-authored change addresses a concrete owned allocation path with a small cutover and explicitly accepts the additional exact-key lookup cost; Related wording correctly avoids claiming the broader incident is resolved.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR repairs a source-confirmed memory problem still present on main, and the earlier read-budget finding is fixed; no new actionable defect was found.

Priority: P1
Reviewed head: b1c7019d592e0ed9137997a8bbe4331c4b2c0ade

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No current-head Gateway/model turn with a large consumed-input history is supplied; the reported diagnostic exercises native actor acquisition and hydration.
Agent review details

How this fits together

The session actor hydrates worker-resident session facts from SQLite, prepares accepted inputs, and publishes committed snapshots to callers; durable receipts remain the source for historical replay checks.

flowchart LR
  A[Accepted input] --> B[Session worker]
  B --> C[Resident unconsumed inputs]
  B --> D[SQLite receipts]
  D --> E[Exact replay lookup]
  E --> B
  B --> F[Transcript commit]
Loading

Technical review

Best possible solution:

Keep consumed receipts in durable storage, retain only unconsumed actor custody, and finish the current-head CI gates before landing.

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

Current-main hydration includes consumed message bodies, and consumption retains collected-source rows; the PR reports a matching synthetic native-actor failure on base and success after the fix, but this review ran no target code.

Is this the best way to solve the issue?

The patch fixes residency at its existing producer and mutation owners, preserves transaction isolation and durable bytes, and reuses canonical readers instead of adding another historical-membership cache.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 06ecfc06b4ef.

Provenance checked

  • Actor hydration and consumed-source residency changes intended behavior with a stated reason (d5173cc: The actor introduction retained pending-input facts for transaction-local reuse and scoped receipt publication.)
  • Resident pending-input preparation changes intended behavior with a stated reason (3b34924: Complete resident pending maps avoided exact receipt rereads; this PR explains why historical bodies must leave residency and why missing keys require canonical reads.)
  • Rollback isolation keeps the original intent (49b372d: Copy-on-write collections avoid cloning unchanged payloads while preserving rollback preimages; the changed deletion retains that owner and isolation mechanism.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current-main defect remains: Current main still hydrates pending-input bodies without filtering consumed receipts and retains collected-source rows in the actor map after consumption. (src/config/sessions/session-actor-hydration.worker.ts:238, 06ecfc06b4ef24e0e1e46e1e46e1cc81189fb1580cd57)
  • Complete residency cutover: The introduced diff filters consumed rows during hydration, removes them at consumption, prevents restaging from restoring residency, and routes absent keys and incomplete collected-source sets through existing durable readers. (src/config/sessions/session-accessor.sqlite-pending-inputs.ts:490, b1c7019d592e)
  • Earlier finding resolved: The follow-up changes the obsolete zero-read assertion to exactly one pending-receipt SELECT while retaining committed-state, custody, and rollback assertions. (src/config/sessions/session-actor-kernel.test.ts:266, b1c7019d592e)
  • Accepted lookup tradeoff: The maintainer-authored body explicitly accepts indexed lookups for keys absent from active residency, reports a synthetic native-actor OOM comparison, and disclaims general throughput and complete incident-resolution claims. (b1c7019d592e)
  • Original ownership and intent: The actor introduction added retained consumed-source residency; perf(sessions): reuse resident facts for durable turn preparation #175770 later reused the complete pending map to avoid reads while retaining canonical historical idempotency checks. (src/config/sessions/session-accessor.sqlite-pending-inputs.ts:709, 06ecfc06b4ef)
  • Required CI remains pending: The current-head CI gate is pending, including changed-node and PostgreSQL checks; no current-head failing check establishes another contributor-fixable defect. (b1c7019d592e)

Likely related people:

  • Peter Steinberger: Raw commit d5173cc adds src/config/sessions/session-accessor.sqlite-pending-inputs.ts:708 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d5173ccc77b9; files: src/config/sessions/session-accessor.sqlite-pending-inputs.ts)

PR surface

Source +6, Tests +23, Docs +4, Other +1. Total +34 across 11 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 18 12 +6
Tests 3 27 4 +23
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 11 50 16 +34

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:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Unbounded consumed-input residency can exhaust the session worker and interrupt agent turns in large sessions.
  • 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.

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 (1 earlier review cycle)
  • reviewed 2026-11-09T22:06:46.048Z sha 0b841b3 :: needs changes before merge. :: [P2] Update the kernel read budget for the canonical receipt lookup

Reviewed November 9, 2026, 8:39 PM ET / November 10, 2026, 01:39 UTC (Revision 2).

@RomneyDa

Copy link
Copy Markdown
Member 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. 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
@RomneyDa
RomneyDa merged commit 472d778 into main Nov 10, 2026
135 of 136 checks passed
@RomneyDa
RomneyDa deleted the fix/actor-consumed-input-hydration branch November 10, 2026 03:54
RomneyDa added a commit that referenced this pull request Nov 10, 2026
Keep consumed source receipts durable without loading them into resident actor
state. Use indexed canonical reads for missing historical keys and preserve
replay validation.

Release adaptation: port to release/2026.11.3 baseline
40223c5. Keep the baseline direct append
reader (there is no preparedInputs optimization), apply all-source resident
coverage before canonical fallback, and preserve the existing describe fixture.
Supply the baseline actor factory's physical identity, birthtime and native
location. Omit session-turn-resident.test-support.ts, a later-main harness
absent from the release; memory-owner behavior is unchanged.

Companion audit pinned at 472d778:
no later same-path commits or #196277 mentions. Baseline reader, custody,
transaction rollback, publication, worker hydration and lifecycle contracts are
present-equivalent; selected changes close durable residency and replay. Other
reported documentation, inventory, historical changelog, performance and sibling
references require no prerequisite changes. No schema, retention or config change.

Regression allocation: 32 net test lines cover consumed actor exclusion before
and after restart/replay plus the retained exact-key lookup expectation. The
extra baseline-native fixture identity setup explains the allocation adaptation.

Validation: the owning collected-input regression fails on the pinned baseline
(two consumed rows remain) and passes after the port. 38 consumed-input tests
and 25 actor/pending-operation/memory sibling tests pass with one worker.
Targeted TypeScript, type-aware lint, format, and diff checks pass. Independent
P0-P2 review found no defects; full release qualification remains parent-owned.

(cherry picked from commit 472d778)

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 10, 2026
* fix(sessions): prevent OOM from consumed input history

Keep consumed source receipts durable without loading them into resident actor state. Use indexed canonical reads for missing historical keys and preserve replay validation.

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

* test(sessions): account for retained receipt lookup

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

---------

Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 10, 2026
Release adaptation: Keep the release SQLite planner helper private and omit
agent-port-projections.ts, which does not exist on this release line. Preserve
all baseline assertions by materializing four small test fixtures, and exercise
lazy payload reads through the actual SQLite planner rather than a fake source.
Allocate the exact 64 net test lines. No schema, config, or authority changes.

Later same-path followups through 568d89f: 8633af9 (#194591) is the
non-applicable PostgreSQL surrogate repair; b6ed907 (#193682) is the
non-applicable schema41 hydration migration. Neither is a streaming prerequisite.
Existing #195028 and #196277 repair contracts remain intact.

Verified: baseline lazy-read regression fails; 32 focused tests pass across
five suites, including compiled-worker publication and authority boundaries.
Targeted types, lint, format, and whitespace checks pass. Fresh independent
read-only review found no P0-P2 issues.

(cherry picked from commit 7bc0ae7)

Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 12, 2026
Backport source 472d778 (#196277). Preserve durable source receipts and indexed replay validation while retaining only unconsumed actor custody. Adapt regression acquisition to the canonical explicit physical identity contract and cover SQLite/PostgreSQL actor hydration.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
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 P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

1 participant