Skip to content

fix(codex): reset native context after history cuts - #155207

Merged
steipete merged 3 commits into
mainfrom
codex/fix-rewind-context389
Sep 21, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/fix-rewind-context389

Conversation

@steipete

@steipete steipete commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes native Codex conversations remembering erased turns after a successful rewind or branch switch.

User Impact

Rewinding or selecting an earlier branch now starts the next native turn from the selected conversation history. Invalid cuts and failed writes preserve the current conversation, and ordinary compaction retains native thread continuity. No configuration or data migration is required. The first turn after a history cut starts a fresh native thread and may lose native cache reuse; ordinary compaction keeps its existing continuity.

Why This Change Was Made

The local transcript rotated correctly, but its predecessor lineage allowed the native binding owner to resume the old Codex thread, including the removed context. A narrow optional harness lifecycle hook now retires that context at the successful history-cut transaction boundary. It reuses existing binding leases, rollback, and subscription cleanup; it preserves lineage and leaves compaction adoption unchanged.

Evidence

  • Live UI reproduction: rewind hid the second turn and reload preserved the shorter transcript, but the next model turn recalled the erased answer. The inspected synthetic before screenshot is attached. Live after-proof on product commit 6948b040cdd passed (successor commits change only tests and CI fixtures): the same existing native session was rewound through the Control UI, then reloaded with its restored composer text intact. Sending the identical recall prompt returned QA388_READY from retained history, instead of the erased QA389_SECOND_TURN returned before the fix.

  • Registered cross-owner regression: original production failed the native-thread assertion; the candidate passes with both a current binding and an exact recorded predecessor. The disposable diagnostic is retained as local evidence, outside product source.

  • Changed files: 63 cases pass, including failed-cut preservation, SQL rollback, active-thread refusal, and subscription cleanup before successor admission. Existing Gateway, transcript, deletion, binding, and compaction siblings: 245 cases pass in 81.313 seconds.

  • Required one-worker costs: pnpm test src/config/sessions/session-accessor.sqlite-message-cut-native.test.ts --maxWorkers=1 20.556 seconds (11 cases); pnpm test extensions/codex/src/app-server/session-retirement.test.ts --maxWorkers=1 25.636 seconds (9 cases); pnpm test extensions/codex/harness.test.ts --maxWorkers=1 10.448 seconds (43 cases). Sixteen added cases report 4.687 seconds summed test-body time; command walls include compilation/imports and are not marginal CI-cost estimates. Original hosted CI passed all three owners: 11 native-cut cases totaled 6.795 seconds, 9 retirement cases 0.059 seconds, and 43 harness cases 8.502 seconds. These are summed case durations, not whole-file wall times.

  • Final managed review is scoped-clean P0–P2. Selected checks pass, including the owning core test graph, core/extension types, scoped lint, SDK boundaries, storage and authority guards. The existing SDK surface budget now passes without changing its ceiling. Full pnpm build including Control UI assets passed in 239.850s on clean product commit 6948b040cdd. All 1,548 UI assets verified. Successor-head CI is in progress.

  • Additional real-provider proof: a fork retained the selected history without changing its parent; switching the parent to a preserved branch made its next reply recall that branch’s last answer. A subsequent tool run created a Unicode CSV and Markdown summary, computed the correct total, and opened the summary through the UI file viewer.

  • Original CI completed with 132 passing checks and 15 skips. The sole substantive failure was an unrelated Mantis fixture launch returning ETXTBSY before its timeout assertions. A controlled held-writable-descriptor reproduction fails with the original generated executable and passes with the immutable shell launcher. The repair preserves PATH lookup, process-tree termination, and every existing assertion; fake Git cleanup now correctly reports an unregistered worktree. The exact original 73-file shard passed once without changes, which is recorded as nonreproduction, not proof of a fix.

  • Fixture validation: 9 cases pass in 13.457 seconds with the required one-worker command, managed P0–P2 review is clean, and all 25 selected command statuses passed. The outer validation supervisor exited with signal 143; its original child continued, was joined, and its retained per-command summary confirms completion. The cause of the supervisor exit is unknown. Twenty standalone runs and three original-order 73-file/712-case shards all passed; 40 command/cleanup sibling cases also passed in 9.527 seconds. The first successor CI passed the repaired Mantis shard in 4m7s (9 changed cases totaled 7.497 seconds), then completed with 132 passing checks and 15 skips. Its sole substantive failure was a separate native output-fidelity assertion in an extension bundle; see the retained run.

  • Native output test repair: the pinned Codex runtime independently buffers the tool response, while its late streaming subscriber can leave the nullable completion aggregate empty. The test incorrectly required both outputs to duplicate the source. The successor retains command completion/exit-code checks and exact source, truncation, raw-response-to-next-HTTP-request, and projected-result assertions. Two added null-aggregate cases protect both event orders; discarding the raw response makes both fail. A temporary native notification diagnostic with a null aggregate passes all fidelity checks. No production or dependency changes are made, and the upstream telemetry race is not claimed fixed.

  • Output-test validation: 13 projector cases pass in 26.824 seconds wall (the two added cases total 6ms); both native cases pass in 27.986 seconds. All 20 selected checks and fresh managed P0–P2 review pass. The unchanged original 12-file plan passed 309 cases with one existing skip in 90.251 seconds, which is recorded as nonreproduction. Qualification is complete: all 20 standalone runs passed (280.157 seconds combined); all three original 12-file/two-worker shards passed 309 cases with one existing skip each (76.943 / 63.514 / 63.982 seconds); 44 owner sibling cases passed in 28.528 seconds. Source hashes remained unchanged, temporary diagnostics were restored, and all child processes were joined. The latest hosted native shard also passed all 309 cases with one existing skip; full new-head CI is still running.

qa389-native-rewind-before

qa389-native-rewind-after

@clawsweeper

clawsweeper Bot commented Sep 21, 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.

@steipete
steipete marked this pull request as ready for review September 21, 2026 21:29
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling extensions: codex size: L maintainer Maintainer-authored PR labels Sep 21, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. 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 21, 2026
@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 7:10 PM ET / 23:10 UTC (Revision 5).

ClawSweeper review

What this changes

The PR resets Codex’s native conversation context after successful rewinds and branch switches, documents the optional harness hook, and repairs supporting test fixtures.

Merge readiness

✅ Ready for maintainer review

This remains a useful, distinct fix absent from current main and the latest release. The inspected behavior proof supports it, and no blocking correctness or security findings remain.

Priority: P1
Reviewed head: f63a61f6e3ff428836103b0298fc3b5d61d5beab

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused lifecycle repair with convincing visible proof, preserved ownership safeguards, and no actionable patch findings.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): Inspected before/after Control UI screenshots and the captured real-provider account demonstrate corrected recall after rewinding an existing native session. All six changed production files match the demonstrated product revision; supplied branch-switch, fork, rollback, and fixture qualification evidence covers the relevant siblings.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (screenshot): Inspected before/after Control UI screenshots and the captured real-provider account demonstrate corrected recall after rewinding an existing native session. All six changed production files match the demonstrated product revision; supplied branch-switch, fork, rollback, and fixture qualification evidence covers the relevant siblings.
Evidence reviewed 10 items Introduced change and current-main necessity: The pinned introduced diff adds context-reset preparation around same-key history cuts and commits retirement after cut validation. Current main still performs the transcript transaction without that lifecycle hook.
Latest-release check: The v2026.9.5 message-cut implementation still uses the original write transaction and preserves predecessor lineage without the new native context-reset hook.
Transaction and ownership safeguards: The implementation reuses conditional binding deletion, lease ownership, rollback, active-thread refusal, supervision checks, and subscription cleanup. Context resets exclude repository-workspace deletion and initialization rollback; the recorded predecessor is checked again at commit.
Findings None None.
Security None None.

How this fits together

OpenClaw stores the selected conversation history while its Codex plugin maintains a separate native thread. History cuts must invalidate that thread so the next model turn uses the selected history.

flowchart TD
  A[Rewind or branch switch] --> B[Validate selected history]
  B --> C[Prepare native binding retirement]
  C --> D[Commit transcript change]
  D -->|Failure| E[Restore native binding]
  D -->|Success| F[Release old subscription]
  F --> G[Start fresh native thread from selected history]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +114, Tests +203, Docs +16. Total +333 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 6 181 67 +114
Tests 7 366 163 +203
Docs 2 16 0 +16
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 563 230 +333

Review metrics

Metric Value Why it matters
Net code growth Production +114 lines; tests and fixtures +203 lines Production growth implements transactional context retirement by reusing existing lifecycle ownership, with separate rollback and native-boundary coverage.
Plugin contract 1 optional lifecycle hook; 0 new settings or schema migrations The documented addition preserves existing harness implementations and scopes changed behavior to intentional history cuts.

Technical review

Best possible solution:

Keep transcript cuts and native-context retirement under the existing transactional lifecycle owner while preserving compaction continuity and failed-cut recovery.

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

Yes: rewind an existing native conversation, reload, and ask for the previous answer. Current-main source preserves the native resume path, and the supplied before screenshot shows recall of the erased turn; this review did not execute a reproduction.

Is this the best way to solve the issue?

Yes: a transactional lifecycle hook addresses both successful cuts and rollback without misusing ordinary reset or disrupting compaction adoption.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: Native conversations can recall erased turns after a successful user-requested rewind, contradicting the selected conversation history.
  • merge-risk: 🚨 compatibility: The optional harness contract changes native continuity after cuts; its fresh-thread/cache tradeoff is explicitly documented in the maintainer-authored proposal and supported by existing-session proof.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): Inspected before/after Control UI screenshots and the captured real-provider account demonstrate corrected recall after rewinding an existing native session. All six changed production files match the demonstrated product revision; supplied branch-switch, fork, rollback, and fixture qualification evidence covers the relevant siblings.
  • proof: sufficient: Contributor real behavior proof is sufficient. Inspected before/after Control UI screenshots and the captured real-provider account demonstrate corrected recall after rewinding an existing native session. All six changed production files match the demonstrated product revision; supplied branch-switch, fork, rollback, and fixture qualification evidence covers the relevant siblings.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. Inspected before/after Control UI screenshots and the captured real-provider account demonstrate corrected recall after rewinding an existing native session. All six changed production files match the demonstrated product revision; supplied branch-switch, fork, rollback, and fixture qualification evidence covers the relevant siblings.

Evidence

What I checked:

  • Introduced change and current-main necessity: The pinned introduced diff adds context-reset preparation around same-key history cuts and commits retirement after cut validation. Current main still performs the transcript transaction without that lifecycle hook. (src/config/sessions/session-accessor.sqlite-message-cut.ts:202, f63a61f6e3ff)
  • Latest-release check: The v2026.9.5 message-cut implementation still uses the original write transaction and preserves predecessor lineage without the new native context-reset hook. (src/config/sessions/session-accessor.sqlite-message-cut.ts:149, ec9c1a13db89)
  • Transaction and ownership safeguards: The implementation reuses conditional binding deletion, lease ownership, rollback, active-thread refusal, supervision checks, and subscription cleanup. Context resets exclude repository-workspace deletion and initialization rollback; the recorded predecessor is checked again at commit. (extensions/codex/src/app-server/session-retirement.ts:70, f63a61f6e3ff)
  • Inspected real behavior proof: Both prepared screenshots were inspected. The identical recall prompt returns QA389_SECOND_TURN before the fix and QA388_READY afterward. The captured PR body describes rewinding and reloading an existing native session, plus branch-switch and fork checks. All six changed production files have identical blob IDs at the demonstrated product commit and the reviewed head; subsequent changes concern tests and fixtures. (6948b040cdde)
  • Documented SDK and compatibility tradeoff: The maintainer-authored proposal explicitly documents one optional transactional lifecycle hook and accepts fresh native-thread startup, including possible cache-reuse loss, after intentional history cuts. Existing hooks remain intact; ordinary compaction retains continuity. No schema, config, or data migration is introduced. (src/agents/harness/types.ts:485, f63a61f6e3ff)
  • Dependency inspection applies: The changed native output-fidelity test launches the pinned Codex runtime and assesses its command-completion and raw-response protocol. The plugin pins @openai/codex 0.154.0, making direct dependency-contract inspection relevant. (extensions/codex/src/app-server/event-projector.output-fidelity.native.test.ts:250, f63a61f6e3ff)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • VACInc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-21T21:38:47.874Z sha 6948b040cddebc106acb325dc3f3542d3cfd53cf :: needs maintainer review before merge. :: none
  • reviewed 2026-09-21T22:14:53.193Z sha 2bd0ef7e0ac790089f98f6629525a116ad7bb03f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-21T22:30:09.163Z sha d8fd5140e5bc5436a817a1a5de5e106b3e1fc937 :: needs changes before merge. :: none
  • reviewed 2026-09-21T22:42:27.723Z sha d8fd5140e5bc5436a817a1a5de5e106b3e1fc937 :: needs maintainer review before merge. :: none

@VACInc

VACInc commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

#155127 does not supersede this PR. The merged PR handles continuity after tool-heavy thread rotation caused by a fresh native start. This PR handles intentional transcript rewind/branch cuts and retires native context so erased turns cannot be recalled. The triggers, lifecycle boundary, and correctness requirements are distinct; please keep this PR open for its own verification and landing decision.

Disposition: DO NOT CLOSE.

@steipete

Copy link
Copy Markdown
Contributor Author

The native output-fidelity fixture incorrectly required the completed command telemetry aggregate to duplicate all stdout. Codex 0.154.0 exposes that aggregate as nullable and fills it through a streaming subscriber independently of the canonical tool-response buffer. The observed CI completion retained exit code 0 but returned a null aggregate. This repair keeps completion/exit-code checks and directly verifies source/full-or-truncated raw response, the next actual provider HTTP request, and OpenClaw projected result. It adds null-aggregate coverage in both event orders. No production or dependency behavior changes.

The original 12-file, two-worker shard passed locally unchanged (309 passed, one existing skip; 90.251s wall), so the upstream schedule was not reproduced. A controlled raw-response-drop mutation failed both new null-order cases; a synthetic native null-completion diagnostic passed both strict response budgets. Neither is a claim to fix Codex streaming telemetry.

Measured one-worker costs: native two-case file 27.986s wall; unit 13-case file 26.824s wall, with the two added null-order cases 3ms each (6ms summed). Compilation dominates these cold command costs. Hosted successor proof passed: all 13 unit cases totaled 76ms, including 6ms for the two new null-aggregate cases. Both native cases passed; their exact durations were removed by the hosted log sanitizer, and no native file wall was printed. The owning 12-file shard passed 309 cases with one existing skip in 141.52s; that is a shard cost, not a file cost. Managed P0–P2 review is scoped-clean (0.94); all 20 selected checks passed (267.908s). All 20 standalone runs passed (280.157s combined), and all three original 12-file/two-worker shard runs passed 309 tests plus one existing skip (76.943s / 63.514s / 63.982s). Two projector sibling files passed all 44 cases (28.528s). Source hashes remained unchanged throughout.

This completes the sole pending qualification item in the latest review. The remaining CI failure is a separate current-main workflow guard that mistakenly matches the observational REPLAY_PNPM_VERSION variable as a legacy version selector; it is being repaired at its test owner before refreshing this PR.

steipete added a commit that referenced this pull request Sep 21, 2026
Match the standalone legacy PNPM_VERSION identifier without rejecting the
Windows replay workflow's observed REPLAY_PNPM_VERSION. Keep the separate
pnpm-version input and pnpm/action-setup prohibitions intact.

The exact current-main guard fails before this change and passes afterward;
an injected legacy pin still fails. All 561 package acceptance tests pass
(172.662s wall), with no production or workflow change.

Repairs the current-main failure observed in CI run 35662101752 while
validating #155207. Managed review is clean through P2.
Retire the native binding only when a local rewind or branch switch commits, so the next turn uses selected OpenClaw history. Reuse existing lease, rollback, and subscription cleanup ownership while preserving predecessor lineage and compaction continuity.
Launch generated command scripts through an immutable shell fixture so inherited write descriptors cannot cause ETXTBSY before process deadline tests start. Preserve real PATH lookup and process-tree assertions; model unregistered worktree cleanup accurately.
@steipete
steipete force-pushed the codex/fix-rewind-context389 branch from d8fd514 to f63a61f Compare September 21, 2026 22:47
@steipete
steipete merged commit f0cc42f into main Sep 21, 2026
183 checks passed
@steipete
steipete deleted the codex/fix-rewind-context389 branch September 21, 2026 23:13
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 22, 2026
Match the standalone legacy PNPM_VERSION identifier without rejecting the
Windows replay workflow's observed REPLAY_PNPM_VERSION. Keep the separate
pnpm-version input and pnpm/action-setup prohibitions intact.

The exact current-main guard fails before this change and passes afterward;
an injected legacy pin still fails. All 561 package acceptance tests pass
(172.662s wall), with no production or workflow change.

Repairs the current-main failure observed in CI run 35662101752 while
validating openclaw#155207. Managed review is clean through P2.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 22, 2026
* fix(codex): reset native context after history cuts

Retire the native binding only when a local rewind or branch switch commits, so the next turn uses selected OpenClaw history. Reuse existing lease, rollback, and subscription cleanup ownership while preserving predecessor lineage and compaction continuity.

* test(qa-lab): avoid writable executable races in Mantis fixtures

Launch generated command scripts through an immutable shell fixture so inherited write descriptors cannot cause ETXTBSY before process deadline tests start. Preserve real PATH lookup and process-tree assertions; model unregistered worktree cleanup accurately.

* test(codex): assert output fidelity independently of telemetry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: codex extensions: qa-lab maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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