Skip to content

fix(codex): stop injecting mirrored history into prompts#88262

Merged
steipete merged 2 commits into
mainfrom
codex/remove-mirrored-history-projection
May 30, 2026
Merged

fix(codex): stop injecting mirrored history into prompts#88262
steipete merged 2 commits into
mainfrom
codex/remove-mirrored-history-projection

Conversation

@steipete

@steipete steipete commented May 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Stop Codex app-server turns from injecting the mirrored OpenClaw transcript back into Codex model-input surfaces.

The important split is:

  • Codex native app-server threads own Codex conversation continuity.
  • The mirrored OpenClaw transcript is persistence/search/display state for Codex runs.
  • Explicit non-legacy context-engine projection still owns the alternate path that assembles OpenClaw history, but that output is rendered into the Codex prompt/developer instructions rather than passed as a parallel history transcript.

Detailed explainer

Before this change, a default Codex run without an active context engine could still call the context-engine projection helper and rewrite the current prompt with mirrored OpenClaw history. A same-area rotation path could do the same after starting a fresh native thread. Those fallbacks were intended as bridges for transient/native-disabled startup states, but they mean Codex can receive a second shadow transcript even though Codex already maintains its own native thread state.

That is the source of the context bloat: the OpenClaw mirror contains records useful for OpenClaw bookkeeping, search, display, and failure snapshots, but it is not the authoritative Codex conversation. Re-injecting it into the current turn makes the prompt larger, can duplicate history, and can pollute prompt/cache behavior without adding real Codex thread continuity.

This PR removes that fallback and makes the model-input surfaces explicit:

  • Default/no-context-engine Codex runs do not project mirrored history into the prompt.
  • The post-rotation fresh-thread path also does not project mirrored history.
  • before_prompt_build receives no mirrored history as model-input messages.
  • llm_input receives no mirrored history as model-input messages.
  • Captured model-call diagnostics use the same model-input history as the actual Codex turn, so diagnostics do not imply stale mirrored context was sent.
  • Turn-start failure snapshots still preserve OpenClaw-side mirrored messages for failure reporting/persistence; that is not model input.
  • Active non-legacy context-engine projection remains supported through rendered prompt/developer-instruction content and context-engine finalization.

Verification

  • node scripts/run-vitest.mjs run --config test/vitest/vitest.extension-codex.config.ts extensions/codex/src/app-server/run-attempt.context-engine.test.ts extensions/codex/src/app-server/attempt-context.test.ts extensions/codex/src/app-server/run-attempt.hooks.test.ts extensions/codex/src/app-server/run-attempt.test.ts -t "context-engine|fires llm_input|emits gated model-call content diagnostics|applies before_prompt_build|does not inject mirrored history|does not inject newer mirrored history|does not project mirrored messages|stale thread-bootstrap|reads and compares thread-bootstrap"
  • git diff --check
  • pnpm exec oxfmt --check --threads=1 extensions/codex/src/app-server/attempt-context.test.ts extensions/codex/src/app-server/attempt-context.ts extensions/codex/src/app-server/run-attempt.context-engine.test.ts extensions/codex/src/app-server/run-attempt.hooks.test.ts extensions/codex/src/app-server/run-attempt.test.ts extensions/codex/src/app-server/run-attempt.ts
  • .agents/skills/autoreview/scripts/autoreview --mode local --prompt-file /tmp/codex-mirror-projection-autoreview.md

Real behavior proof

Behavior addressed: Codex app-server turns no longer inject mirrored OpenClaw transcript history into Codex prompt/model-input surfaces; active context-engine output remains available through the rendered prompt/developer-instruction path.

Real environment tested: local OpenClaw Codex extension Vitest harness in this checkout.

Exact steps or command run after this patch: the focused Vitest command, diff whitespace check, oxfmt check, and local autoreview commands listed above.

Evidence after fix: focused Vitest passed 31 tests across 4 files; diff check and oxfmt passed; autoreview reported no accepted/actionable findings.

Observed result after fix: tests assert default Codex startup/resume, stale thread-bootstrap fallback, before_prompt_build, llm_input, and model-call diagnostics do not contain mirrored prior context, while context-engine projection lifecycle tests still pass.

What was not tested: full repository CI was not run locally before PR creation.

@clawsweeper

clawsweeper Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed May 30, 2026, 3:06 AM ET / 07:06 UTC.

Summary
The branch removes default Codex app-server mirrored-history projection and updates hook, diagnostic, and regression tests so only active non-legacy context engines supply history to Codex model-input surfaces.

PR surface: Source -75, Tests -39. Total -114 across 6 files.

Reproducibility: yes. source inspection gives a high-confidence reproduction path: append mirrored session messages, start default Codex without an active context engine or usable binding, and current main can project that history into turn/start input. I did not run the harness because this review was read-only.

Review metrics: 2 noteworthy metrics.

  • Runtime fallback changed: 1 default no-context history-projection fallback removed. Fallback removal affects Codex session continuity and needs explicit pre-merge acceptance.
  • Current-base conflict: 1 Codex app-server merge conflict. The PR predates current-main context changes, so maintainers need a refreshed branch before judging the final merge result.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦐 gold shrimp
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Rebase on current main and handle the native-thread rotation projection path.
  • [P1] Add real Codex app-server diagnostic or log proof with private details redacted, or get a maintainer proof override.
  • [P2] Document maintainer acceptance of the default fallback removal before merge.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body provides focused Vitest, formatting, and autoreview output, but no real Codex app-server run, terminal/log output, or linked artifact showing the changed runtime behavior after the patch. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] The branch is dirty against current main and must be rebased through Codex app-server context conflicts before it is a landing candidate.
  • [P2] Removing the default mirrored-history fallback can change upgrade/runtime behavior for sessions without a usable native Codex binding or with native tool-surface fallback states.
  • [P1] The PR proof is limited to mocked/focused harness tests; a real Codex app-server run or maintainer proof override is still missing.

Maintainer options:

  1. Rebase and prove the new continuity split (recommended)
    Resolve the current-main conflicts, remove the rotation fallback too, and show a real Codex app-server turn where default input excludes mirrored history while explicit context-engine projection still works.
  2. Accept the fallback removal explicitly
    Maintainers can intentionally accept the upgrade behavior change if Codex native thread continuity is the only supported default path for these sessions.
  3. Pause until the continuity policy is settled
    If native-disabled or missing-binding continuity should still be preserved, pause this PR and decide the replacement policy before deleting the fallback.

Next step before merge

  • [P2] Protected maintainer-labeled PR needs human/owner review after rebase because it removes a Codex runtime fallback and lacks real behavior proof.

Security
Cleared: The diff only changes Codex app-server runtime logic and tests; I found no new security or supply-chain surface.

Review findings

  • [P2] Resolve the current-main projection conflict — extensions/codex/src/app-server/run-attempt.ts:759-762
Review details

Best possible solution:

Rebase onto current main, remove both no-context mirrored-history projection paths while preserving explicit context-engine projection, keep focused startup/resume/rotation/hook coverage, and add real Codex app-server diagnostic proof or a maintainer proof override.

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

Yes, source inspection gives a high-confidence reproduction path: append mirrored session messages, start default Codex without an active context engine or usable binding, and current main can project that history into turn/start input. I did not run the harness because this review was read-only.

Is this the best way to solve the issue?

Not yet as submitted: the direction is plausible, but the branch is stale against current main and the fallback-removal policy needs explicit maintainer acceptance plus real behavior proof.

Full review comments:

  • [P2] Resolve the current-main projection conflict — extensions/codex/src/app-server/run-attempt.ts:759-762
    Current main added a second no-context projection path in native-thread rotation after this branch's base. This PR removes the helper/import and the first projection call, but the current-main merge conflicts and can either leave the rotation path calling deleted code or keep mirrored-history injection for rotated threads, so rebase and remove/update that path too before landing.
    Confidence: 0.86

Overall correctness: patch is incorrect
Overall confidence: 0.82

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 26bf8f0dc87b.

Label changes

Label changes:

  • add P2: This is a normal-priority Codex prompt/session-state bugfix with limited blast radius but real compatibility implications.
  • add merge-risk: 🚨 compatibility: The diff removes a default fallback path that existing Codex sessions may rely on when native thread binding is missing, stale, oversized, or unavailable.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body provides focused Vitest, formatting, and autoreview output, but no real Codex app-server run, terminal/log output, or linked artifact showing the changed runtime behavior after the patch. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P2: This is a normal-priority Codex prompt/session-state bugfix with limited blast radius but real compatibility implications.
  • merge-risk: 🚨 compatibility: The diff removes a default fallback path that existing Codex sessions may rely on when native thread binding is missing, stale, oversized, or unavailable.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body provides focused Vitest, formatting, and autoreview output, but no real Codex app-server run, terminal/log output, or linked artifact showing the changed runtime behavior after the patch. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source -75, Tests -39. Total -114 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 2 15 90 -75
Tests 4 24 63 -39
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 39 153 -114

What I checked:

  • Repository policy applied: Root and scoped extension policy were read; the review applied the OpenClaw guidance that plugin/runtime fallback behavior and session/context state are compatibility-sensitive, and that maintainer-labeled PRs stay open for explicit handling. (AGENTS.md:18, 26bf8f0dc87b)
  • Current main injects mirrored history without an active context engine: Current main calls shouldProjectMirroredHistoryForCodexStart when no active context engine is selected, so mirrored history can still be projected into the Codex turn prompt on the default path. (extensions/codex/src/app-server/run-attempt.ts:776, 26bf8f0dc87b)
  • Current main has a second projection path after thread rotation: Current main also retries the no-context mirrored-history projection after oversized native thread rotation, which the stale PR branch does not contain and must account for during rebase. (extensions/codex/src/app-server/run-attempt.ts:847, 26bf8f0dc87b)
  • Projection helper behavior on main: The helper currently returns true for forced projection, missing startup bindings, newer visible history, or incompatible dynamic-tool fingerprints, which is the fallback the PR intends to remove for default Codex runs. (extensions/codex/src/app-server/attempt-context.ts:84, 26bf8f0dc87b)
  • PR branch narrows model-input history: On the PR head, default/no-context-engine runs set codexModelInputHistoryMessages to an empty array and pass that to before_prompt_build, llm_input, and model-call diagnostics. (extensions/codex/src/app-server/run-attempt.ts:759, e2be8eb71986)
  • Current-base conflict: The PR head is based on bba8015, while current main added Codex app-server context work afterward; merge-tree reports changed-in-both conflicts in run-attempt.ts and related tests. (extensions/codex/src/app-server/run-attempt.ts:773, e2be8eb71986)

Likely related people:

  • Jason (Json): Introduced the current native-thread rotation path and the applyMirroredHistoryProjectionForFreshThread helper that overlaps this PR's intended fallback removal. (role: recent area contributor; confidence: high; commits: 81505ada186f; files: extensions/codex/src/app-server/run-attempt.ts, extensions/codex/src/app-server/run-attempt.context-engine.test.ts)
  • Dmitry Golubev: Recently changed the same Codex app-server context files after the PR base, moving stable context handling into developer instructions. (role: recent area contributor; confidence: medium; commits: 3fbd2432b696; files: extensions/codex/src/app-server/run-attempt.ts, extensions/codex/src/app-server/attempt-context.ts)
  • Ayaan Zaidi: Current blame on the helper and surrounding context-projection code traces through the grafted main snapshot, though the shallow history makes ownership less precise. (role: current source provenance; confidence: low; commits: 56fc17be7809; files: extensions/codex/src/app-server/attempt-context.ts, extensions/codex/src/app-server/run-attempt.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels May 30, 2026
@steipete
steipete force-pushed the codex/remove-mirrored-history-projection branch from e2be8eb to 04a4427 Compare May 30, 2026 07:08

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 04a4427d0c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Codex app-server threads own conversation continuity. The mirrored
// OpenClaw transcript is persistence/search state. Context-engine output is
// rendered into the prompt/developer instructions, not parallel history.
const codexModelInputHistoryMessages: typeof historyMessages = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve context for transient Codex starts

When the native tool surface is disabled (for example toolsAllow: [], node exec, or an active OpenClaw sandbox), thread-lifecycle.ts deliberately ignores any existing binding and starts a transient thread instead of resuming Codex history. With the mirrored-history projection removed and codexModelInputHistoryMessages hard-coded to [], those transient no-context-engine turns now send only the current prompt, so users continuing a restricted/sandboxed Codex conversation lose all prior context. Keep the mirrored projection for this non-native path, or make the transient start resume/receive equivalent history.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant