Skip to content

fix(codex): ignore missing mirrored session history - #99575

Closed
litang9 wants to merge 2 commits into
openclaw:mainfrom
litang9:codex/codex-history-race-warning-v2
Closed

litang9 wants to merge 2 commits into
openclaw:mainfrom
litang9:codex/codex-history-race-warning-v2

Conversation

@litang9

@litang9 litang9 commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Codex app-server harness hooks can warn with failed to read mirrored session history for codex harness hooks when they read mirrored history before the session JSONL file exists.

Current main already treats parsed-empty session history as [], so this PR focuses on the remaining transient state: ENOENT while the file-backed active transcript artifact has not been created yet.

Why This Change Was Made

A missing mirrored session file during startup means there is no history to replay yet. It should behave like empty history rather than surfacing as a failed history read.

Malformed non-empty history remains unchanged: the reader still returns undefined, so the existing warning path continues to surface real transcript corruption.

User Impact

This reduces noisy Codex embedded-runtime warnings for healthy new sessions whose mirrored history file is created after the harness hook runs.

It does not suppress warnings for malformed non-empty transcript files.

Evidence

  • Local gateway log evidence from /tmp/openclaw/openclaw-2026-07-03.log: failed to read mirrored session history for codex harness hooks appeared for yuantai cron sessions before the corresponding JSONL file's first record timestamp; after the run completed, those files parsed successfully.
  • pnpm install --frozen-lockfile completed in the rebased worktree before running validation.
  • node --import tsx --input-type=module live terminal proof passed from the patched checkout and imported the production runCodexAppServerAttempt path, not Vitest.
  • node --import tsx --input-type=module live terminal proof passed from the patched checkout and imported the production readMirroredSessionHistoryMessages wrapper, not Vitest.
  • node scripts/run-vitest.mjs extensions/codex/src/app-server/attempt-context.test.ts extensions/codex/src/app-server/session-history.test.ts passed with 12 tests.
  • git diff --check passed.

Real behavior proof

Behavior addressed: Codex harness hook history reads should not warn when the mirrored session file is temporarily missing during a new-session startup race.

Real environment tested: local OpenClaw gateway logs from 2026-07-03 under the user's active ~/.openclaw state, plus the current source checkout rebased onto upstream/main at 0420aefb1d and patched through fb7c53c51c.

After-fix production Codex attempt proof

This proof does not use Vitest. It runs a one-shot Node process from the patched checkout, imports the production runCodexAppServerAttempt implementation from extensions/codex/src/app-server/run-attempt.ts, starts an in-process app-server client double, and lets the real Codex attempt startup path proceed through thread/start, turn/start, and cleanup. The session file is intentionally missing before the attempt starts, matching the startup race that produced the gateway warning.

Exact post-patch command shape:

node --import tsx --input-type=module <<'EOF'
import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { embeddedAgentLog } from 'openclaw/plugin-sdk/agent-harness-runtime';
import { runCodexAppServerAttempt } from './extensions/codex/src/app-server/run-attempt.ts';

// Create a temp workspace with a missing session.jsonl, run the production
// Codex attempt startup path with an in-process app-server client, and count
// whether the exact harness-hook warning is emitted.
EOF

Relevant output from the patched checkout:

patched production Codex attempt proof: missing mirrored session.jsonl
  before_run_session_file_exists=no
  after_run_session_file_exists=yes
  app_server_methods=thread/start,turn/start,thread/unsubscribe
  result_keys=aborted,agentHarnessResultClassification,assistantTexts,attemptUsage,bootstrapPromptWarningSignature,bootstrapPromptWarningSignaturesSeen,cloudCodeAssistFormatError,currentAttemptAssistant,didDeliverSourceReplyViaMessageTool,didSendDeterministicApprovalPrompt,didSendViaMessagingTool,externalAbort,heartbeatToolResponse,idleTimedOut,itemLifecycle,lastAssistant,messagesSnapshot,messagingToolSentMediaUrls,messagingToolSentTargets,messagingToolSentTexts,messagingToolSourceReplyPayloads,promptError,promptErrorSource,replayMetadata,sessionIdUsed,successfulCronAdds,systemPromptReport,timedOut,timedOutDuringCompaction,timedOutDuringToolExecution,toolAudioAsVoice,toolMediaUrls,toolMetas,yieldDetected
  client_closed=no
  warning="failed to read mirrored session history for codex harness hooks" emitted=no
  total_warn_count=0

What the production attempt proof verifies:

  • The session JSONL is absent before the attempt starts (before_run_session_file_exists=no).
  • The same production attempt path used by Codex embedded runtime reaches app-server startup and turn execution (thread/start, turn/start, thread/unsubscribe).
  • The exact reported warning is not emitted while the missing session file is treated as empty history.
  • The runtime creates the session file later in the turn (after_run_session_file_exists=yes), matching the observed startup race rather than a permanently invalid path.

After-fix production wrapper proof

This proof does not use Vitest. It runs a one-shot Node process from the patched checkout, imports the production readMirroredSessionHistoryMessages wrapper from extensions/codex/src/app-server/attempt-context.ts, and captures the production embeddedAgentLog.warn call site that emits failed to read mirrored session history for codex harness hooks.

Exact post-patch command shape:

node --import tsx --input-type=module <<'EOF'
import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { embeddedAgentLog } from 'openclaw/plugin-sdk/agent-harness-runtime';
import { readMirroredSessionHistoryMessages } from './extensions/codex/src/app-server/attempt-context.ts';

// Create a temp missing session.jsonl, call the production wrapper, and count
// whether the exact harness-hook warning is emitted. Then repeat with a
// malformed non-empty JSONL row to prove the real-corruption warning path stays.
EOF

Relevant output from the patched checkout:

patched production wrapper proof: missing session.jsonl
  result=[]
  warning="failed to read mirrored session history for codex harness hooks" emitted=no
patched production wrapper proof: malformed non-empty session.jsonl
  result=undefined
  warning="failed to read mirrored session history for codex harness hooks" emitted=yes

What the live wrapper proof verifies:

  • Missing session.jsonl returns [] from the same wrapper used by harness hooks.
  • embeddedAgentLog.warn is not called for that missing-file case, so the reported gateway warning is not emitted.
  • Malformed non-empty JSONL still returns undefined and calls embeddedAgentLog.warn("failed to read mirrored session history for codex harness hooks", { sessionFile }), preserving the real-corruption warning path.

Regression tests

Exact post-patch test command:

node scripts/run-vitest.mjs extensions/codex/src/app-server/attempt-context.test.ts extensions/codex/src/app-server/session-history.test.ts --reporter verbose

Relevant output:

✓ |extension-codex| ../../extensions/codex/src/app-server/attempt-context.test.ts > Codex app-server attempt context > treats missing mirrored session history as empty without hook warning 5ms
✓ |extension-codex| ../../extensions/codex/src/app-server/attempt-context.test.ts > Codex app-server attempt context > keeps malformed mirrored session history on the hook warning path 2ms
✓ |extension-codex| ../../extensions/codex/src/app-server/session-history.test.ts > readCodexMirroredSessionHistoryMessages > treats a missing mirrored session file as empty history 1ms
✓ |extension-codex| ../../extensions/codex/src/app-server/session-history.test.ts > readCodexMirroredSessionHistoryMessages > returns undefined for malformed non-empty mirrored session files 1ms

Test Files  2 passed (2)
Tests  12 passed (12)

Related

  • Follow-up to closed duplicate PR fix(codex): ignore empty mirrored session history #99567. That PR covered empty/whitespace history on the old reader; current main already handles parsed-empty history. This PR covers the missing-file transient state against the current scoped reader API.

@clawsweeper

clawsweeper Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 3, 2026, 11:34 AM ET / 15:34 UTC.

Summary
The PR changes the Codex app-server mirrored session-history reader to return empty history for a missing session file and adds reader and wrapper tests for the missing-file and malformed-history cases.

PR surface: Source +12, Tests +70. Total +82 across 3 files.

Reproducibility: yes. Source inspection shows current main reads the active Codex session file before thread startup, and an ENOENT from that read returns undefined and triggers the wrapper warning.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: extensions/codex/src/app-server/session-history.test.ts, serialized state: extensions/codex/src/app-server/session-history.ts, unknown-data-model-change: extensions/codex/src/app-server/session-history.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

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

Rank-up moves:

  • none.

Next step before merge

  • No automated repair is needed; the remaining action is ordinary maintainer review and merge decision for a clean focused PR.

Security
Cleared: The diff only changes local file-read error classification and focused tests; it does not touch secrets, dependencies, CI, package execution, or permission boundaries.

Review details

Best possible solution:

Land the ENOENT-only lower-reader fix with the added reader and wrapper regression tests, preserving malformed-history diagnostics.

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

Yes. Source inspection shows current main reads the active Codex session file before thread startup, and an ENOENT from that read returns undefined and triggers the wrapper warning.

Is this the best way to solve the issue?

Yes. Handling only ENOENT in the lower mirrored-history reader is narrower than muting the wrapper warning and preserves diagnostics for malformed non-empty history.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against f3eccb0dfdec.

Label changes

Label justifications:

  • P3: The PR fixes noisy Codex harness warnings during a healthy startup race without changing user data, auth, provider routing, or message delivery behavior.
  • 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 (terminal): The PR body includes after-fix terminal output through the production Codex attempt path and wrapper, showing missing session files no longer warn while malformed non-empty history still warns.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal output through the production Codex attempt path and wrapper, showing missing session files no longer warn while malformed non-empty history still warns.
Evidence reviewed

PR surface:

Source +12, Tests +70. Total +82 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 13 1 +12
Tests 2 75 5 +70
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 88 6 +82

What I checked:

  • Root AGENTS.md read and applied: Root repository review policy was read fully; the Codex dependency-source gate and extension-boundary review guidance affected this review. (AGENTS.md:1, f3eccb0dfdec)
  • Scoped extension policy read: The extensions boundary guide was read; the change stays inside the Codex plugin and imports through plugin SDK/local module boundaries. (extensions/AGENTS.md:1, f3eccb0dfdec)
  • Current reader conflates missing file with corrupt history: Current main reads target.sessionFile and catches all errors by returning undefined, so fs.readFile ENOENT is indistinguishable from malformed history at this boundary. (extensions/codex/src/app-server/session-history.ts:32, f3eccb0dfdec)
  • Wrapper warns on falsy reader result: The harness-hook wrapper logs the reported warning when readCodexMirroredSessionHistoryMessages returns undefined; returning [] avoids the warning without muting real undefined failures. (extensions/codex/src/app-server/attempt-context.ts:87, f3eccb0dfdec)
  • Attempt startup reads mirrored history before thread start: runCodexAppServerAttempt builds an active transcript target and reads mirrored history before the later startCodexAttemptThread call, so a newly allocated session path can be read before the rollout file exists. (extensions/codex/src/app-server/run-attempt.ts:897, f3eccb0dfdec)
  • PR patch is ENOENT-only: The diff adds an isMissingFileError guard and returns [] only for errors whose code is ENOENT; other exceptions still return undefined. (extensions/codex/src/app-server/session-history.ts:16, fb7c53c51c51)

Likely related people:

  • jalehman: Authored and merged the transcript mirror refactor that introduced the current scoped Codex session-history reader, attempt-context wrapper, and run-attempt integration surface. (role: current implementation owner; confidence: high; commits: 258b83c4386c; files: extensions/codex/src/app-server/session-history.ts, extensions/codex/src/app-server/attempt-context.ts, extensions/codex/src/app-server/run-attempt.ts)
  • steipete: Merged nearby Codex replay sanitization work in the same session-history reader path, making them a useful routing candidate for mirrored-history behavior. (role: adjacent area contributor; confidence: medium; commits: 71b79f008d1d; files: extensions/codex/src/app-server/session-history.ts, extensions/codex/src/app-server/image-payload-sanitizer.ts)
  • 100yenadmin: Authored a recently merged Codex app-server recovery PR touching run-attempt behavior near this startup/runtime surface. (role: recent adjacent contributor; confidence: medium; commits: 414ecd2b9689; files: 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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 3, 2026
@litang9

litang9 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@litang9

litang9 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added 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. 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 Jul 3, 2026
@litang9

litang9 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@litang9
litang9 marked this pull request as ready for review July 3, 2026 15:22
@vincentkoc

Copy link
Copy Markdown
Member

Thanks @litang9. I validated the startup race, preserved your two commits and Alex Tang's authorship, and landed the narrowed current-main version through #100484 as 17ba49742424ca0963b040a9849614541ed0aab6.

The replacement was necessary because GitHub's createCommitOnBranch mutation returned HTTP 499 while updating this fork branch after the required current-main rebase. The landed change keeps the intended behavior: only a missing mirrored transcript is treated as empty history; malformed or otherwise unreadable existing history still follows the warning path.

Focused local and Testbox tests passed 11/11, pnpm check:changed passed, fresh autoreview was clean, and exact-head CI run 28757417968 succeeded.

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

Labels

extensions: codex P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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