Repository navigation
fix(sessions): avoid excessive history copies and preserve fork provenance - #134238
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 31, 2026, 1:24 PM ET / 17:24 UTC. ClawSweeper reviewWhat this changesThis PR replaces eager session-history copies with bounded lazy context reads, strengthens Codex fork prompt verification, and preserves the host fallback when settled-turn evidence is unavailable. Merge readinessKeep open for maintainer review: the re-review resolves the prior prompt-replay finding, but the required independent Codex protocol inspection could not run because the sibling checkout is absent and GitHub DNS is unavailable. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw stores session transcripts in SQLite, then its Codex plugin reads and projects the settled tool-turn history into a restricted native finalization call. When that call cannot safely run, the embedded agent runner produces the host-owned fallback instead of replaying completed tools. flowchart LR
A[SQLite session transcript] --> B[Session context reader]
B --> C[Codex evidence projection]
C --> D[Restricted native finalizer]
D --> E[Visible final answer]
C --> F[Evidence unavailable]
F --> G[Host fallback reply]
Decision needed
Why: The source review finds no remaining discrete patch defect, but repository policy requires direct upstream Codex inspection for this dependency-sensitive behavior and that evidence is unavailable in this review environment. Before merge
Agent review detailsSecurityNone. PR surfaceSource -18, Tests +664, Docs +33, Other -3. Total +676 across 32 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the single lazy transcript reader and Codex-owned frozen projection, then complete an independent pinned Codex protocol review before landing the exact checked head. Do we have a high-confidence way to reproduce the issue? No high-confidence live reproduction was run in this read-only review. The owner-boundary tests make the reported cases source-reproducible, including oversized acquisition, prompt drift, and command-only fallback identity. Is this the best way to solve the issue? Unclear: the revised design is consistent with the local ownership and fallback boundaries, and the prior replay finding is disproved by the raw parent, but direct upstream Codex contract verification remains unavailable. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b6cd3c6de3e9. 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
HistoryReview history (1 earlier review cycle)
|
Review resolution and dependency evidenceI checked the prompt-adoption finding against the raw parent of the reviewed commit. The claimed introduced change is not present: the old implementation verifies using the adopted local This is separate from native message forking, where this PR strengthens exact attested submitted-prompt comparison. I personally inspected the pinned Codex source at The projection is a transient, frozen host-process handoff to an isolated native turn—not an OpenClaw persistent data model. There is no SQLite schema, version, retention, migration, or storage-policy change. Existing file-only import compatibility is retained. All five Before merge items reduce to the same prompt rewrite and dependency-check requests: the rewrite is declined for the source-backed reason above; the dependency inspection is complete. Focused capture/projection/finalizer tests exercise those owner boundaries. A subsequent integration repair separately preserves eligible host fallback after bounded capture rejection and obtains command-only assistant identity from the existing settled-tool-batch owner. Authentication/usage-limit exclusions and the native no-I/O guard remain intact. Updated head: @clawsweeper re-review — please account for the raw-parent |
5823476 to
e27db7b
Compare
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Land-ready verificationHead The final full build and complete changed-surface gate passed. Fresh isolated Codex autoreview reported no accepted/actionable findings at the configured P0 threshold. Production is net -21 LOC; tests/support net +667. No configuration, schema, storage policy, budget, timeout, or heap-limit changes. Exact final local commands (run in the candidate checkout): OPENCLAW_BUILD_PRIVATE_QA=1 pnpm buildpython3 - <<'PY'
import subprocess
files = subprocess.check_output(['git', 'diff', '--name-only', '-z', 'ace8a13f19ccc2805b3d458026de3ab4bbbd8878...HEAD']).decode().rstrip('\0').split('\0')
subprocess.run(['node', 'scripts/check-changed.mjs', '--', *files], check=True)
PYOPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=.artifacts/vitest-history-landing-codex node scripts/run-vitest.mjs extensions/codex/src/app-server/run-attempt.test.ts extensions/codex/src/app-server/settled-turn-finalizer.test.ts --testNamePattern 'preserves settled finalization eligibility|runCodexSettledTurnFinalization' --reporter=verboseThe native command passed 24 selected tests; 153 unrelated cases were deliberately unselected. It preserves completion/overload eligibility with normal and oversized history, excludes auth/usage failures, and rejects unavailable/foreign evidence before native I/O. OPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=.artifacts/vitest-history-landing-core node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/settled-turn-finalization.test.ts src/agents/embedded-agent-runner/run/settled-tool-evidence.test.ts --reporter=verboseThe core command passed 55 tests, including command-only fallback identity, cancellation, silence, failure-honest output, and writer-fence handling. Both integration defects were reproduced before their owner repairs. Earlier acquisition/BTW/native-fork regressions and the synthetic native/embedded runtime smoke are documented in the PR body; these overlapping counts are not an aggregate total. ClawSweeper's exact-head re-review reports no actionable finding and withdrew the prompt-replay claim after the raw-parent evidence. Its remaining rank-up requests are the pinned dependency inspection and completed CI. CI is complete; the parent directly inspected the pinned source, with public file/line citations in that response. A separate local reviewer has now independently inspected immutable Codex tag The native review artifacts validate, and Proof limits remain explicit: source and synthetic fixtures only, no authenticated provider/channel or operator data. The native QA run is runtime smoke, not independent child-history recall or visual UI proof. Navigation and one selected row can still grow with history. Separate task chips record the child-history QA assertion gap and the trusted-wrapper dependency-packaging defect. The latter was handled using a complete clean trusted-main linked checkout, with the same native locks, validators, and merge guards—not a bypass. |
|
Merged via squash.
|
…nance (openclaw#134238) * fix(sessions): bound history acquisition and preserve fork provenance * fix(agents): preserve eligible settled-turn fallback
Related: active Codex transcript overhead (#115049). This does not claim to supersede that broader work.
Additional instructions
MUST: Keep Allow edits from maintainers enabled. This is a same-repository maintainer branch.
What Problem This Solves
Long sessions could incur large, unnecessary history allocations while preparing a final answer after tools completed: settled-turn capture loaded and cloned the complete application-context prefix before the finalizer enforced its existing replay limits.
The same acquisition audit found three connected defects: native Codex forks accepted prompt drift beyond a display-text truncation boundary or normalized away whitespace changes; CLI byte-bounded history fetched oversized headers/boundaries before deciding whether they fit; and an empty BTW snapshot reloaded the already-persisted current user message.
Integration with newer main also exposed eligible finalization losing its host fallback when evidence was rejected earlier, and command-only fallback throwing despite an attributed assistant tool-call in the settled batch.
Why This Change Was Made
Reuse one canonical context-window selector and a synchronous, read-only SQLite snapshot consumer. Codex validates identities and source evidence while projecting under the existing limits, then hands off frozen native input items instead of a raw history clone. Successful capture still finishes suffix duplicate checks; host-prompt adoption remains verification-only. Core passes harness-owned evidence opaquely and retains the built-in transcript handoff.
Native fork verification compares complete attested submitted text, CLI acquisition preflights metadata before payload reads, and BTW records the exact admission parent, including an intentionally empty parent. Shared Codex mirror-origin checks replace duplicated untyped reads. This preserves the existing model-only context repair.
An explicit unavailable-evidence state preserves only the owning harness's existing finalization eligibility; it does not authorize replay. The native finalizer rejects it before provider I/O, leaving the existing no-model host fallback available. Authentication and usage-limit exclusions remain unchanged. Command-only fallback reuses assistant identity from the canonical settled-tool-batch owner, rather than fabricating model/provider metadata.
User Impact
No configuration, schema, storage-policy, retention, projection-limit, timeout, or heap-limit changes. Legacy file-only imports and upstream pagination remain unchanged. Navigation and individual selected rows still scale with the transcript; this is not a fixed process-memory ceiling.
Evidence
Candidate:
e27db7b938e7d6e6975fee1f86881aff28761a58, based on mainace8a13f19ccc2805b3d458026de3ab4bbbd8878. Both commits retained identical patches through the rebase (git range-diff). The finalOPENCLAW_BUILD_PRIVATE_QA=1 pnpm buildpassed in 6m17s, including runtime/SDK compilation, import-boundary checks, and Control UI budgets. No ineffective dynamic import warning or budget increase.Exact-head CI run 33418461319 passed, including the required
openclaw/ci-gateand the Windows lane. The previous run 33412016671 failed two pre-existing Gateway fixture checks; this candidate incorporates the existing Gateway recovery fixture repair (#134207), not a duplicate fix or a retry of the stale head.Production: +664/-685, net -21. Tests/support: +777/-110, net +667. Docs: net +33. Assertion-baseline maintenance: net -3, recording only removed violations.
The original regressions failed before production repair: native prompt drift was accepted; oversized settled context was captured and later payloads decoded; four CLI metadata fixtures acquired payloads before rejection; three real SQLite → prompt preparation → snapshot → BTW cases included the current user when the snapshot should be empty. The integration regressions also failed for their intended reasons: two eligible oversized cases lost context presence, and command-only fallback threw
Settled-turn fallback has no assistant identity.Focused validation passed 295 tests during the original repair, then 106 Codex support and 111 core snapshot/finalization/context tests after integration with main. The final eligibility/fallback repair passed 24 native tests and 55 core finalization/settled-tool-evidence tests; these groups overlap earlier coverage and are not an aggregate total. The complete changed-file gate passed again on the published candidate: all four type lanes, core/plugin/scripts lint, dead exports, import cycles, and architecture/storage guards. The SDK surface gate also passed during the original repair. Fresh isolated Codex autoreview passed at the configured P0 threshold for both the primary repair and final integration diff.
The maintained
subagent-forked-contextQA smoke passed in both embedded and actual Codex 0.151.0 runtimes against a local mock Responses server on the pre-integration head, using synthetic homes and ephemeral auth. Native process identity andcodex-app-servermirror provenance were observed; all owned processes were cleaned up. Parity reportedsessions_spawntool-result-shape drift, not zero drift. This is runtime smoke, not independent proof that a child recalled inherited history or of operator message-fork/BTW acquisition; targeted regressions own those assertions, and the child-history assertion gap is recorded separately. The harness performed an update-check Git fetch; candidate HEAD, build identity, and tracked source remained unchanged.A source-only benchmark with 20,002 synthetic messages rejected oversized history under the existing limits in both versions. Payload reads fell from 40,000 to 128; peak process RSS from about 397 MiB to 118 MiB; projection time from about 618 ms to 1.2 ms. This is an isolated stress case, not a production Gateway measurement.
Pinned Codex 0.151.0 source was personally inspected: exclusive
beforeTurnId, literal text conversion, native item validation/history-only injection, and persisted canonical fork boundaries. Source citations and ClawSweeper finding disposition explain why the proposed adopted-prompt rewrite is not applied: the previous implementation also cloned the original persisted prompt. The projection is a transient host-process handoff, not a persistent data-model change.All application proof uses source and synthetic fixtures. No operator conversations, configuration, credentials, core dumps, heaps, or running Gateway were used. Authenticated provider/channel behavior and visual UI proof are not claimed; the exercised surface is source/native-runtime synthetic evidence, not a signed-in operator flow. The separate oversized weekly skill-collection review issue remains out of scope.