Repository navigation
fix: reduce memory spikes when preparing long session histories - #133753
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 11:18 PM ET / August 31, 2026, 03:18 UTC. ClawSweeper reviewWhat this changesThe branch projects selected session context from SQLite so Codex prompts, Workshop reviews, and prompt hooks do not hydrate storage-only transcript payloads. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessThe PR remains necessary. Its direct SQLite projection is a coherent repair, but the changed prompt-hook payload contract and required Codex runtime contract remain unverified for merge. Priority: P2 Review scores
Verification
How this fits togetherSQLite transcript events retain complete replay evidence, while prompt preparation and detached reviews need only the selected model-visible context. The new projection reader supplies that reduced view to model-facing consumers. flowchart LR
A[SQLite transcript events] --> B[Model context reader]
B --> C[Context window selection]
C --> D[Storage field projection]
D --> E[Codex prompt preparation]
D --> F[Workshop experience review]
D --> G[Prompt hooks]
Decision needed
Why: This changes data exposed to third-party hook handlers and substantially expands production code; local source cannot prove whether installed plugins depend on the removed fields. Before merge
Agent review detailsSecurityNone. PR surfaceSource +406, Tests +864, Docs +6, Other -1. Total +1275 across 28 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Confirm the documented prompt-hook contract, inspect the required Codex source, and explicitly accept the projection owner's production growth before exact-head merge gates run. Do we have a high-confidence way to reproduce the issue? Yes, from source: the replaced eager full-history clone is directly visible and focused regression tests specify the synthetic scenario, though this review did not execute it. Is this the best way to solve the issue? Unclear: projection before hydration is the right owner-boundary direction for inspected OpenClaw paths, but plugin compatibility and the Codex integration contract remain unverified. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 62b41feb1d81. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Landing verification for the long-history allocation repair. Native review/artifact validation and The allocation owner is the model-context reader, not the native evidence store: select the existing branch/reset/compaction/admission window and project storage-only fields before hydration, then clone only when a message-consuming prompt-hook registration exists. Exact stored bytes and native fork/replay evidence remain unchanged. The documented prompt-hook snapshot is an intentional narrowing; third-party hooks depending on incidental private fields may need adjustment. No installed-plugin compatibility claim or production rollout is implied. The ClawSweeper review and rank-up moves are addressed in the PR body, including personal sibling and pinned Codex source inspection, the compatibility caveat, and why the net +392 production lines are needed for the missing acquisition owner. Tests/support are +876/-12. The corrected four-file SQL change uses schema-checked column references without changing the JSON projection semantics or weakening guards. The corrected source head |
|
Merged via squash.
|
…claw#133753) * fix(sessions): project model history before hydration * fix(sessions): follow canonical transcript identity reader * fix(sessions): type projection column references
Closes #133738 — prompt preparation and detached experience review copy storage-only history payloads.
Additional instructions
This is a same-repository maintainer branch and remains editable by maintainers.
What Problem This Solves
Fixes an issue where users continuing long native Codex conversations, or running detached Skill Workshop experience reviews, would incur large memory spikes when the stored transcript contains substantial native replay metadata. Model-only readers acquired those private payloads before selecting context, and prompt preparation could clone them even when no message-consuming hook existed.
The issue and proof use synthetic data only. This change repairs demonstrated allocation boundaries; it does not attribute or claim to resolve every separately reported Gateway OOM.
Why This Change Was Made
The session owner now supplies a detached model-context view that selects the existing branch/reset/compaction window before hydrating payloads. Query-time SQLite projection excludes storage-only native prompt text and tool-result details, and skips invalidated retained-prefix replay checkpoints. It reuses the existing tree, context-window, and occurrence-based tool-pairing algorithms rather than introducing a history cutoff.
Prompt-hook dispatch owns isolated snapshots after actual registration filtering. Registrations within a dispatch retain their existing ordering and shared-event behavior; separate prepare, ordinary, authorized, and rebuild dispatches cannot mutate the caller's history. Codex no longer clones eagerly, and Workshop no longer opens and clones the complete foreground transcript. Retained-tail statistics and append-parent resolution also use narrow navigation facts while preserving exact raw-byte accounting.
Native mirror attestations, fork drift validation, settled-turn replay, exports, and doctor operations retain full-fidelity evidence. No stored conversation bytes, schema, persisted projection, configuration, dependency, heap/timeout limit, or feature-enable setting changes.
Production LOC after main integration and CI repair: +535/-143 (net +392). Tests/support: +876/-12 (net +864). Growth establishes the missing read/projection ownership boundary and equivalent SQL/in-memory field contract; existing selection algorithms are reused and the raw acquire-then-clone paths are removed. The assertion baseline only shrinks.
User Impact
Long-history prompt preparation and detached reviews avoid allocating private native replay text that is not part of their model context. Hook isolation, visible content, reset/compaction retained tails, tool pairing, sender/media/taint facts, and admission fencing remain intact. Ordinary acquisition failures in experience review now receive the existing recorded failure outcome and cleanup.
Full-fidelity native evidence readers, direct legacy file-only reads, BTW captured-leaf reads, and CLI reseed-budget paths keep their different contracts. This PR does not silently migrate them or promise constant memory for arbitrarily large genuine model-visible output.
Evidence
Failing before, passing after
excludeFromContext. The acquisition owner now follows the existing reset-kept contract; all nine user/assistant/paired-result cases across reset, compaction, and ordinary history pass.The independent pre-integration boundary rerun passed 98 tests, covering selected context, retained tools, opaque/leaf ancestry, admission tampering and post-admission reset/compaction, incognito, absent/stale index state, cursor cleanup, hook isolation, native fingerprints, settled-turn matching, and fork drift rejection. After integrating main, the expanded boundary run passed 107 tests, plus six actual Codex attempt cases. This includes main's sparse retained-tail batching and transcript import/store coverage. All five synthetic HTTP Workshop E2E outcomes also passed before integration: proposal, no-op, interrupted, rejected, and failed. The last retained-reset predicate correction was reverified with focused tests rather than another unrelated full runtime preparation.
node scripts/run-vitest.mjs extensions/codex/src/app-server/run-attempt.test.ts -t 'keeps private native history|applies before_prompt_build|rebuilding'Focused core/plugin production and affected test types, type-aware lint, formatting, assertion/max-lines/schema guards, and
git diff --checkpassed before integration. Independent architecture checks found zero runtime import cycles and passed the session-accessor, transcript-reader, and SQLite transaction boundaries. These are scoped checks, not a claim that the entire repository suite ran locally.Integration base:
237f23b4589795a91dc63778c41d27624bb336dc. Main's retained-history batching (#133680), import identity query compilation reuse (#133689), and legacy codec validation optimization (#133641) are preserved. The new append-parent reader now imports identity lookup from the canonicalsession-accessor.sqlite-read.tsowner. The expected stale import failed the post-rebase core typecheck with TS2459 before that correction; the same typecheck then passed. Post-integration focused lint, formatting, andgit diff --checkpassed.Independent isolated Codex autoreview of the complete integrated candidate returned
scoped-cleanwith no findings at its P0-only reporting threshold. This is not an all-priority review certificate.pnpm buildpassed before integration (22m47s) and again on the corrected integrated candidate (5m14s). Post-integration commands also passed:CI repair
Initial exact-head CI failed only the runtime-topology architecture job and its aggregate gate. The Kysely guard identified raw column references and SQLite JSON exceptions attached to declarations rather than the primitive expressions.
The correction passes schema-checked
eb.ref(...)column expressions into the projection owner, which accepts KyselyExpression<string>and retains typed results. It removes raw identifier snippets; the eight JSON primitive templates, interpolations, and value-parameter order are unchanged. Existing narrowly justified SQLite JSON exceptions now attach directly to their expressions. No casts, guard changes, or allowlist/baseline expansion were used. The formerly failingpnpm lint:kysely, fullpnpm check:architecture, 113 boundary/native tests, core typecheck, focused lint/formatting, andpnpm build(5m16s) pass after the correction. Fresh isolated review of the correction is alsoscoped-cleanat P0 with no findings.Final head:
83fd69c4bfbc01eaa07ce6a3b5ee38218f99877e. Exact-head pull-request CI run 33354235862 completed success on attempt 1, including the required openclaw/ci-gate, repaired runtime architecture gate, built artifacts, and SQLite session lifecycle proof. Native prepare and merge completed without rewriting this head; landed as c09f1360bbe49e3f8cf28926c47e4998b6d37bf0. A post-merge rerun on that exact commit passed 38 model-context, transcript-store/import, and retained-tail tests, including the overlapping mainline identity-insert optimization. Issue closure proof and the post-merge command are recorded; the issue is closed as completed.Synthetic allocation measurement
Fixed 24 small visible user messages; only native metadata grows to 1 MiB per message (24 MiB aggregate). Fresh Node v26.8.1 processes; imports and fixture seeding are outside the timer. No heap limit was raised. Baseline is source
0b392310b92d90bd37b884c4469b0ec799ad2521; these samples precede mechanical main integration.These are individual synthetic samples, not a production peak/soak guarantee. SQLite still processes stored bytes, so query-time projection spends additional CPU to avoid aggregate JavaScript allocation.
Native contract inspection and limits
Personally inspected the sibling Codex source and then the public source for the pinned
@openai/codex0.151.0 tag, which resolves to78c290807ce710180111df227df3b7a4fe845452:Those contracts require exact native evidence; the model-only view does not replace it. No native protocol behavior changed and no live native-provider request is claimed as proof. The real runner/SQLite proof uses synthetic fixtures and a local HTTP provider. No production state was accessed or modified, and no historical crash caller or production stability soak is claimed.
ClawSweeper review disposition
The review and rank-up moves have been read. They contain no concrete code or security finding, but request these maintainer decisions and evidence:
content, notdetails. This deliberately narrows incidental storage-field exposure. Third-party prompt hooks reading privateupstreamUserTextor tool-resultdetailsmay need adjustment. No installed-plugin or production inventory was inspected, and universal backward compatibility is not claimed. Full-fidelity evidence readers and tool/persistence hook owners are unchanged.SELECTprojection and read-snapshot ownership, with exact stored-byte fingerprint regression proof. A data migration would be inappropriate.Exact-head CI remains a separate gate and is not inferred from these dispositions. No additional code change is required by the published rank-up moves.
Docs: session management, plugin hooks, and self-learning.