Skip to content

fix(usage): avoid retaining decoded incognito transcript payloads - #156673

Merged
obviyus merged 5 commits into
openclaw:mainfrom
HerbertHuerto:fix/usage-worker-transcript-oom
Oct 23, 2026
Merged

obviyus merged 5 commits into
openclaw:mainfrom
HerbertHuerto:fix/usage-worker-transcript-oom

Conversation

@HerbertHuerto

@HerbertHuerto HerbertHuerto commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Incognito usage refresh retains every decoded transcript message while computing small usage totals. Large conversations therefore incur an unnecessary second decoded-text allocation during refresh.

What Changed

Project each parsed event into the existing canonical navigation fields and its usage contribution immediately, rather than retaining its message payload. Preserve the canonical hash of the last raw event before dropping it. Branch selection, rewind/side appends, totals and checkpoint semantics are unchanged. This updates the contributor's repair for the current actor-owned memory route; it does not restore the retired worker/cursor implementation.

Evidence

Built Gateway CLI, Node 24.22.1 in isolated Linux Docker, fresh state per arm. State was created only through authenticated shipped RPCs: sessions.create(incognito: true), a real chat.send against a local streaming provider, 48 chat.inject document appends per session, then keyed sessions.usage. Eight sessions each contain 36 MiB of appended text. A small real model turn and refresh calibrated the scanner boundary before the large workload.

Two completed main-baseline runs consistently retained 50 decoded messages (37,749,447 text characters) per measured scan. The candidate retained zero message payloads at the same production scanner boundary. Forced-GC inspector samples at that boundary showed roughly 151 MB additional heap on main versus 75–76 MB on the candidate. These are retained-boundary observations, not peak-RSS measurements or a claim that total session memory is bounded. The actor transcript and immutable serialized snapshot still scale with input size; one event is still parsed whole.

All eight normalized public usage responses were identical between baseline and candidate: 101 input / 7 output tokens, 50 messages (one user, 49 assistant), identical costs and model/tool totals. Both completed main runs and candidate stayed on one authenticated connection. An earlier baseline attempt timed out collecting inspector GC and is not counted.

  • Full candidate build passed.
  • Two focused scanner tests passed, including branch rewind/side append and the canonical raw-tail anchor.
  • Focused formatting and lint passed.
  • Real OpenAI gpt-5-mini turn through the built CLI returned LIVE_GATE_OK, exit 0. The first setup attempt could not resolve the model before catalog refresh; the corrected shipped catalog-refresh sequence succeeded.

Simplification reuses projectTranscriptNavigationFields, removing the contributor's duplicate navigation-field projection. Whole production delta: +20/-7 lines; regression tests: +93 lines. Growth is the per-event usage/navigation projection and raw-tail hash needed to release decoded payloads without changing branch or checkpoint behavior. No SDK, configuration, schema or permissions change.

Merge Risk

Two-way door: reverting restores the previous scan behavior without a migration. Blast radius is incognito usage refresh and its branch/checkpoint accounting; durable transcript scanners and provider behavior are unchanged.

@clawsweeper

clawsweeper Bot commented Sep 23, 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 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 23, 2026
@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR retains compact navigation and usage records instead of decoded message payloads during incognito usage refresh.

Example: Refresh usage for an incognito session containing 36 MiB of appended text.

  • Before: The supplied Gateway baseline retained 50 decoded messages containing 37,749,447 text characters at the scanner boundary.
  • After: The candidate retained zero message payloads there while returning identical usage totals of 101 input tokens, 7 output tokens, and 50 messages.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused repair with supplied shipped-entry-point evidence, preserved navigation and checkpoint contracts, and no actionable findings; current-head CI remains in progress.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied built-Gateway proof exercises authenticated incognito creation, real chat transport, document appends, and keyed sessions.usage in isolated Linux Docker on Node 24.22.1; scanner-boundary observations show decoded payload retention falling from 50 messages to zero while all eight normalized public usage responses remain identical.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Large incognito conversations allocate an unnecessary second decoded transcript while refreshing usage totals.
Reason: The repair removes measured allocation waste while preserving report output, branch semantics, and existing ownership.

Merge readiness

✅ Ready for maintainer review

Keep open: current main still retains decoded incognito transcript payloads during usage refresh, and this PR provides a focused repair with no actionable introduced defects found.

Priority: P2
Reviewed head: ca95d72d1d6dc642708e920169650668157895e2

Before merge

None.

Findings

None.

Agent review details

How this fits together

The incognito usage scanner consumes immutable transcript snapshots from the session actor and produces branch-aware usage rollups and checkpoints for Gateway usage reports.

flowchart LR
  A[Gateway usage request] --> B[Session actor snapshot]
  B --> C[Parse and project events]
  C --> D[Select visible branch]
  D --> E[Aggregate usage and checkpoint]
  E --> F[Actor usage report]
Loading

Technical review

Best possible solution:

Keep the immediate projection in the existing memory scanner, preserving canonical navigation fields, usage contributions, and the raw-tail checkpoint hash.

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

Current-main source directly shows whole-transcript decoded retention, corroborated by the supplied matched Gateway observations and constrained-heap failure; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch removes the unnecessary retained payloads at their producer and reuses existing navigation and aggregation owners without adding a competing path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 37df1431d43d.

Provenance checked

  • Actor-owned memory usage scanner changes intended behavior with a stated reason (cbc2017: Prepare usage consumers for immutable actor-memory transcript snapshots before the coordinated incognito cutover.)
  • Compact usage projection and branch-aware aggregation keeps the original intent (23dee30: Avoid repeated decoding and retain navigation plus small usage contributions in durable refreshes while preserving branch rebuilds.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit cbc2017 adds src/infra/session-cost-usage-rollup-scan.ts:129 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cbc201727b66; files: src/infra/session-cost-usage-rollup-scan.ts)

PR surface

Source +13, Tests +93. Total +106 across 2 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 20 7 +13
Tests 1 93 0 +93
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 113 7 +106

Review metrics

Metric Value Why it matters
Production versus regression-test growth Production +20/-7 lines; tests +93 lines The production growth performs immediate projection and preserves the raw-tail anchor; the tests cover constrained-heap retention and branch/checkpoint correctness.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This removes unnecessary memory retention during large incognito usage refreshes; prevention of the historically reported wider Gateway crashes remains unproven.
  • 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 (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-27T08:38:58.943Z sha c494c6d91643c8bcd71c591a08589caed47d8c5d :: needs maintainer review before merge. :: none
  • reviewed 2026-09-27T08:46:03.022Z sha c494c6d91643c8bcd71c591a08589caed47d8c5d :: needs maintainer review before merge. :: none
  • reviewed 2026-10-08T14:30:04.872Z sha c494c6d91643c8bcd71c591a08589caed47d8c5d :: blocked before merge. :: none
  • reviewed 2026-10-08T14:41:27.973Z sha c494c6d91643c8bcd71c591a08589caed47d8c5d :: blocked before merge. :: none
  • reviewed 2026-10-08T18:18:26.900Z sha 24cb681d836e259262dd60a93e0c32e56fe87db5 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-08T18:30:42.668Z sha 24cb681d836e259262dd60a93e0c32e56fe87db5 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-18T15:32:51.085Z sha a6b683e :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-18T16:26:13.113Z sha a6b683e :: needs maintainer review before merge. :: none

Reviewed October 23, 2026, 7:06 AM ET / 11:06 UTC (Revision 10).

@HerbertHuerto

Copy link
Copy Markdown
Contributor Author

Production follow-up: fatal Gateway process crashes, not only stale usage totals

The unpatched deployment at 8ba18cf19ad11e6171b2fbbb30e536b865f02f91 (Linux, Node 24.19.0) has now experienced seven fatal Gateway process crashes between September 23 23:43 and September 24 00:50 CEST (UTC+02:00). This PR is not deployed there.

The operator reports that interacting with the iPhone app, including pressing Connect, precedes the failures. The Gateway remained on the same PID for approximately 50 minutes between 23:55:49 and 00:45:31; the operator reported another Connect attempt immediately before the latter crash. This is an observed trigger correlation, not a controlled reproduction or proof that the connection handler itself is defective.

Sanitized journal sequence for the three most recent fatal events (CEST):

usage.cost response Worker transcript read Fatal V8 heap OOM systemd result
00:45:25.609 00:45:30, incremental read, non-main thread 00:45:31 SIGABRT/core dump; restart counter 5
00:48:16.656 00:48:22, incremental read, non-main thread 00:48:23 SIGABRT/core dump; restart counter 6
00:50:04.702 00:50:10, incremental read, non-main thread 00:50:11 SIGABRT/core dump; restart counter 7

The fatal signature is FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory, with GC heaps around 509–528 MiB. systemd records Main process exited, code=dumped, status=6/ABRT, then automatically restarts the Gateway. The host still has approximately 19 GiB available RAM; this is not evidence of host-wide memory exhaustion. Earlier fatal events were at 23:43:18, 23:44:54, 23:54:02 and 23:55:43 CEST.

Importantly, there are also worker-only failures: usage-cost-cache reports ERR_WORKER_OUT_OF_MEMORY at 23:57:27 and 00:51:58 while the Gateway process survives. Those must not be conflated with the fatal events above.

Scope and remaining uncertainty: The repeated temporal sequence strongly implicates the usage/transcript worker path and warrants revisiting the assumption that impact is confined to stale cost statistics. However, we have not yet established the exact failing worker/RPC causal chain, explained why some OOMs are contained and others abort the process, or proven that this PR prevents the iPhone-associated fatal crashes. The existing synthetic before/after worker-memory proof remains valid; it is not live proof of this wider failure mode. No deliberate production crash reproduction was performed.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 26, 2026
@HerbertHuerto
HerbertHuerto force-pushed the fix/usage-worker-transcript-oom branch from a0e38bf to c494c6d Compare September 27, 2026 08:19
@HerbertHuerto HerbertHuerto changed the title fix(usage): prevent worker OOM on large conversation payloads fix(usage): prevent worker OOM on large incognito conversations Sep 27, 2026
@HerbertHuerto

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated on current main in c494c6d91643c8bcd71c591a08589caed47d8c5d, preserving #156937's SQLite implementation and narrowing this PR to incognito paging and cursor cleanup. The PR body now includes a real-worker synthetic incognito before/after proof (OOM before, full assertions passing after with the same 512 MiB heap), 44 passing focused tests, and the explicit stress timeout/cost. Full changed checks and exact-head CI are still in progress; no production/iPhone crash-resolution claim is made.

@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. and removed P1 High-priority user-facing bug, regression, or broken workflow. labels Oct 8, 2026
@HerbertHuerto
HerbertHuerto force-pushed the fix/usage-worker-transcript-oom branch from c494c6d to 24cb681 Compare October 8, 2026 18:11
@HerbertHuerto

Copy link
Copy Markdown
Contributor Author

Rebased the focused three-file repair onto main a2a7752c9b9a; new head: 24cb681d836e259262dd60a93e0c32e56fe87db5.

The current actor routes, authorization/currentness checks and compute-scope cleanup remain intact. The same 648 MiB fixture OOMs on the unpatched base and passes with this patch at the unchanged 512 MiB worker limit. All 79 focused tests passed, including the current actor-compute and reconciliation suites. The PR body contains the commands, timings and proof boundaries.

Static checks and new-head CI are still running. The local catalog performance failure remains explicitly unresolved; no catalog changes or assertions were folded into this repair.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 8, 2026
@HerbertHuerto
HerbertHuerto force-pushed the fix/usage-worker-transcript-oom branch from 24cb681 to a6b683e Compare October 18, 2026 15:26
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 18, 2026
@HerbertHuerto

Copy link
Copy Markdown
Contributor Author

Added the requested shipped-Gateway behavior proof to the PR body; code head remains a6b683e75f6bd153071740e0bcb584f1fe04c939, with its exact-head CI passing.

Both base and head were executed from the built Gateway CLI with matching Control UI, a real incognito session, one local synthetic-provider turn and 48 actor-owned document appends (36 MiB of text). The production keyed sessions.usage RPC returned the same correct totals on both: 100 input + 20 output tokens, cost 0.00014, 50 messages, no tools/errors. All result assertions passed.

The body includes captured stdout, exact revisions, fixture/ownership path and memory method: in this single matched pair, head's observed refresh RSS peak was 39.29 MiB lower and observed V8 heap peak 8.73 MiB lower. These are observations, not statistical benchmarks or a claim that resident actor/snapshot memory is bounded. The separate constrained scanner OOM proof remains clearly distinguished.

The aggregate Usage page returned zero on both revisions; that screenshot is explicitly not offered as successful UI-total proof. The new evidence is the real keyed Gateway refresh, with that separate aggregate behavior recorded for investigation. Native-build environment failures and the unused minimal-inventory CLI-help metadata limitation are also disclosed. No production data, credentials, or installation was used.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 18, 2026
@obviyus

obviyus commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 23, 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-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@obviyus
obviyus merged commit a247b26 into openclaw:main Oct 23, 2026
117 of 118 checks passed
@obviyus

obviyus commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Landed in a247b26. Thanks @HerbertHuerto. Incognito usage refresh no longer holds every transcript in memory at once.

@obviyus

obviyus commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Merged with the current actor-memory scanner repair and shipped-Gateway proof. Thanks @HerbertHuerto for the fix and the earlier investigation; usage totals and navigation/checkpoint behavior remain preserved while decoded message payloads are released during refresh.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 24, 2026
…enclaw#156673)

fix(usage): don't hold every decoded transcript in memory during keyed incognito usage refresh

Keyed incognito usage refresh decoded every transcript payload and kept all of them in memory at once before summing usage, which added avoidable heap pressure and risked Gateway out-of-memory failures on large histories. It now reads and drops each payload as it goes; the usage results are unchanged.

Evidence: built Gateway, eight incognito sessions each filled with 48 × 768 KiB chat.inject appends through the shipped RPC. During a keyed usage refresh, main retained 50 decoded messages (about 37.7 million characters) at the scanner boundary (twice); with this change it retains none (twice), and the reported usage is identical.

Thanks @HerbertHuerto.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 28, 2026
…56673)

fix(usage): don't hold every decoded transcript in memory during keyed incognito usage refresh

Keyed incognito usage refresh decoded every transcript payload and kept all of them in memory at once before summing usage, which added avoidable heap pressure and risked Gateway out-of-memory failures on large histories. It now reads and drops each payload as it goes; the usage results are unchanged.

Evidence: built Gateway, eight incognito sessions each filled with 48 × 768 KiB chat.inject appends through the shipped RPC. During a keyed usage refresh, main retained 50 decoded messages (about 37.7 million characters) at the scanner boundary (twice); with this change it retains none (twice), and the reported usage is identical.

Thanks @HerbertHuerto.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit a247b26)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit a56591b2a49a5fba692d71d1a3b1eb9debc40ea7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. 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.

2 participants