Skip to content

fix(agents): Codex sessions stop dead-ending on the transcript byte fuse with a wrong context warning - #137752

Closed
zhangguiping-xydt wants to merge 7 commits into
openclaw:mainfrom
zhangguiping-xydt:feat/issue-137697
Closed

zhangguiping-xydt wants to merge 7 commits into
openclaw:mainfrom
zhangguiping-xydt:feat/issue-137697

Conversation

@zhangguiping-xydt

@zhangguiping-xydt zhangguiping-xydt commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #137697

What Problem This Solves

Fixes an issue where users chatting with OpenClaw on Codex hosted models could have every later turn in a session rejected with "⚠️ Context is too large and auto-compaction could not recover this turn. Try again, use /compact, or use /new" — while the context reading was actually small (the report shows 26k/272k, 10%) — and /compact was skipped with "native compaction is unavailable for a host-isolated Codex session". The only way out was /new, losing the session.

Why This Change Was Made

When a Codex session's active transcript crossed the configured agents.defaults.compaction.maxActiveTranscriptBytes, the preflight sent the session into required native compaction. The Codex plugin intentionally declines that operation for host-isolated or policy-restricted bindings — compaction is a separate Codex operation without the turn-scoped restricted environment — and that decline is an intentional no-op, not a compaction failure. Preflight treated it as a hard failure, threw, and the turn-admission caller formatted it as a generic context-exhausted reply recommending the same unavailable /compact.

This change classifies the plugin's two documented decline reasons (the host-isolated restriction and Codex-owned automatic compaction) as a benign skip at the shared compaction-reason layer — matched exactly, and only for successful (ok: true) results — so preflight skips instead of throwing and the turn is admitted. ok: false failures whose wording overlaps the decline phrasing (sandbox and node-host policy blocks, locked-harness fallback) still fail required preflight, with regressions preserving that. The byte-triggered attempt itself is unchanged: supervised, context-engine thread-bootstrap, and unrestricted Codex bindings keep their configured native recovery, and restricted bindings are enforced by the documented startup-binding rotation, which caps native rollout transcripts at the same threshold and restarts oversized threads fresh on the next ordinary turn. Non-Codex runtimes are untouched, and the native-tool restriction is preserved exactly.

User Impact

A medium-running Codex session no longer dead-ends behind a misleading context warning. When the transcript byte fuse trips, the next message is admitted as usual; bindings that can compact natively still do, and oversized restricted threads restart fresh through the documented rotation, so the conversation continues in the same session instead of requiring /new.

Evidence

Red on pinned main (ddb6a70c044) at the admission owner, with the exact reporter failure produced by feeding the real plugin's decline into the real preflight gate:

Error: Preflight compaction required but failed:
       native compaction is unavailable for a host-isolated Codex session

Green after the fix, driven end to end with real functions:

  1. Real plugin decline (captured artifact): the real maybeCompactCodexAppServerSession ran against a real policy-restricted binding (real binding store, real on-disk session file) under the preflight trigger shape (trigger: "budget", non-manual native request allowed) — no fake client, since the decline precedes any app-server connection:
    { "ok": true, "compacted": false,
      "reason": "native compaction is unavailable for a host-isolated Codex session",
      "result": { "details": { "backend": "codex-app-server", "skipped": true,
                                "reason": "native_tool_policy_restricted", "expectedThreadId": "thread-1" } } }
  2. Real admission gate: the real runSessionCompactionIfNeeded, backed by a real SQLite store with the transcript over the threshold, consumed that exact captured artifact on this head: the byte-triggered attempt runs once (preflightRequired: true, transcript_bytes), the decline is a benign skip, the turn is admitted, and no byte latch is written. The committed regression asserts the same flow, and a second committed regression asserts the byte-triggered native attempt still runs for Codex runtimes generally — preserving supervised, context-engine, and unrestricted recovery.
  3. Rotation owner: a real policy-restricted binding with a real 2 MB on-disk rollout is cleared by the real rotateOversizedCodexAppServerStartupBinding, so the next ordinary turn proceeds on a fresh thread; the existing real-plugin suite still verifies restricted bindings send no native compact RPC.
  4. Linked joined exact-head trace: one sequential run at head 0cc4a186 joining the complete reporter path — restricted binding over the byte fuse → real plugin decline → rotation clears the oversized binding for a fresh thread → the following ordinary turn is admitted by the reply preflight gate → ok:false policy-block failures still fail required preflight: https://gist.github.com/zhangguiping-xydt/9662dfa8a90eaf939142ba0bdf818bcd (captured plugin result and per-step logs: https://gist.github.com/zhangguiping-xydt/9adb4ab97188e71359289e5b9c273dd5)
  5. Failures stay failures: an ok: false policy-block result whose wording overlaps the decline phrasing still fails required byte preflight (committed regression still fails required byte preflight when native compaction fails), preserving locked-harness and sandbox/node-host failure semantics.

Affected suites: agent-runner-memory 107 passed, compact-reasons 49 passed (including new classification tests), codex app-server runtime shard 27 files / 1222 passed (three transport-process-snapshot failures reproduced once under parallel load and pass 30/30 in isolation with and without this branch — timing flake, unrelated), codex compact 52 passed, cli-compaction + failure-reply 43 passed, embedded overflow-compaction 27 passed; tsgo core/extensions/test typechecks, oxlint, and oxfmt clean. A live hosted Codex turn was not possible from this environment (no Codex credentials); the blocked-turn decision happens entirely before model dispatch, which the admission-owner proof exercises directly.

Risks

The classification widens the benign-skip set by exactly the plugin's two intentional decline reasons; ok: false failures (native execution policy blocks, missing bindings) still throw, and manual /compact now reports the decline as a skip, matching the wording users already see. Two open PRs touch adjacent compaction surfaces (#119985 reset replay-window accounting, #136533 heartbeat byte-fuse enforcement) and neither covers this blocked-turn path; this change does not alter their non-Codex or measurement semantics.

A Codex session whose active transcript crossed the configured
maxActiveTranscriptBytes was routed into required native preflight
compaction. Host-isolated and policy-restricted bindings refuse that
operation by design, so the refusal surfaced as a generic
context-too-large reply that recommended /compact, which is skipped
for the same reason, and every later turn was rejected before model
execution even though the context reading was small.

Codex already owns the byte fuse: the startup binding caps native
rollout transcripts at the same threshold and restarts oversized
threads fresh each turn. Stop attempting the duplicate host-side
preflight for Codex runtimes on the byte trigger, matching the
documented behavior and the existing token-pressure skip. Non-Codex
runtimes keep the byte-triggered preflight, and the native-tool
restriction is untouched.
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@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. 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 Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 9:56 AM ET / 13:56 UTC.

ClawSweeper review

What this changes

This PR lets Codex-backed turns continue when a transcript-byte preflight receives one of two successful, intentional native-compaction declines, while retaining failed-compaction handling.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 1 item remains

No blocking correctness finding. The exact, success-gated classification repairs the documented restricted-binding no-op without converting known failed compactions into skips; normal exact-head CI remains the only routine gate.

Priority: P1
Reviewed head: 54c25e46407fdb46cef85a972c5628a65ff42396

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-consistent repair with meaningful owner-boundary coverage and supplied real-function proof; exact-head CI is still pending.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The supplied PR evidence links a real restricted binding, on-disk rollout rotation, and SQLite-backed admission-gate trace at commit 0cc4a18; the current head retains identical blobs for all four production owners involved. Direct gist retrieval was unavailable because network name resolution failed, but that reviewer limitation does not change the supplied after-fix trace classification.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The supplied PR evidence links a real restricted binding, on-disk rollout rotation, and SQLite-backed admission-gate trace at commit 0cc4a18; the current head retains identical blobs for all four production owners involved. Direct gist retrieval was unavailable because network name resolution failed, but that reviewer limitation does not change the supplied after-fix trace classification.
Evidence reviewed 5 items Introduced no-op classification: The PR adds two exact normalized Codex decline reasons and makes only their successful results benign skips.
Producer and preflight consumer: The Codex plugin produces the restricted-binding decline before client acquisition; required preflight admits only results accepted by the shared benign-result predicate and otherwise throws.
Restricted-thread recovery owner: Startup binding rotation clears an oversized native rollout binding, and the Codex run-attempt path invokes that rotation before prompt construction.
Findings None None.
Security None None.

How this fits together

Before a Codex-backed turn reaches model dispatch, OpenClaw checks transcript pressure and may require compaction. The Codex plugin owns restricted-thread behavior; startup binding rotation drops an oversized native binding so the subsequent turn can start fresh.

flowchart LR
  A[Incoming Codex turn] --> B[Transcript byte preflight]
  B --> C[Native compaction result]
  C --> D{Successful intentional decline?}
  D -->|Yes| E[Admit turn]
  D -->|No| F[Fail required preflight]
  G[Startup binding rotation] --> H[Fresh restricted thread]
  H --> A
Loading

Before merge

  • Resolve merge risk (P1) - The shared classifier now relies on two plugin-owned user-facing strings as stable semantics; matching is exact and success-gated, but later rewording must update the producer and classifier together.
Agent review details

Security

None.

PR surface

Source +20, Tests +224. Total +244 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 2 22 2 +20
Tests 5 230 6 +224
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 252 8 +244

Review metrics

Metric Value Why it matters
Production vs test LOC production +22/-2, tests and test routing +230/-6 Most growth is focused regression coverage; the small production increase is the exact shared classifier needed to distinguish intentional Codex no-ops from failed preflight.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #137697
Summary: This PR is a concrete candidate fix for the restricted Codex transcript-byte preflight failure reported by the linked issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Accept the bounded producer contract (recommended)
    Merge with the two exact Codex decline strings retained as coordinated producer-and-consumer behavior, backed by the focused success and failure regressions.

Technical review

Best possible solution:

Keep the exact successful-result contract and the startup-binding rotation boundary; a future API redesign can replace the string coupling with a typed native-compaction skip outcome if that contract needs to evolve.

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

Yes, from the source path: the plugin emits the successful restricted-binding decline and the required byte preflight previously throws unless that result is treated as benign. The supplied linked real-function trace exercises that path; this review did not execute untrusted contributor code.

Is this the best way to solve the issue?

Yes. The patch preserves byte-triggered native recovery for bindings that can perform it and changes only the two exact successful Codex ownership declines, leaving unsuccessful policy blocks as failures.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied PR evidence links a real restricted binding, on-disk rollout rotation, and SQLite-backed admission-gate trace at commit 0cc4a18; the current head retains identical blobs for all four production owners involved. Direct gist retrieval was unavailable because network name resolution failed, but that reviewer limitation does not change the supplied after-fix trace classification.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The supplied PR evidence links a real restricted binding, on-disk rollout rotation, and SQLite-backed admission-gate trace at commit 0cc4a18; the current head retains identical blobs for all four production owners involved. Direct gist retrieval was unavailable because network name resolution failed, but that reviewer limitation does not change the supplied after-fix trace classification.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 availability: Current PR review merge-risk labels are merge-risk: 🚨 compatibility.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The reported behavior can block all later turns in an active Codex-backed session before model dispatch.
  • merge-risk: 🚨 compatibility: Core preflight now recognizes two Codex-plugin result strings as intentional no-ops, so later producer wording changes require coordinated updates.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The supplied PR evidence links a real restricted binding, on-disk rollout rotation, and SQLite-backed admission-gate trace at commit 0cc4a18; the current head retains identical blobs for all four production owners involved. Direct gist retrieval was unavailable because network name resolution failed, but that reviewer limitation does not change the supplied after-fix trace classification.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied PR evidence links a real restricted binding, on-disk rollout rotation, and SQLite-backed admission-gate trace at commit 0cc4a18; the current head retains identical blobs for all four production owners involved. Direct gist retrieval was unavailable because network name resolution failed, but that reviewer limitation does not change the supplied after-fix trace classification.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • SunnyShu: 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 (5 earlier review cycles)
  • reviewed 2026-09-04T01:48:58.803Z sha de1b0e6 :: needs real behavior proof before merge. :: [P3] Keep the new invariant comment to three lines
  • reviewed 2026-09-04T02:09:11.924Z sha 9b09a56 :: needs real behavior proof before merge. :: [P1] Preserve the byte guard where startup rotation defers it
  • reviewed 2026-09-04T12:48:15.024Z sha cd46fd1 :: needs real behavior proof before merge. :: [P1] Keep failed native compaction out of the benign-skip path
  • reviewed 2026-09-04T13:02:31.730Z sha e68703c :: needs real behavior proof before merge. :: [P1] Require a successful result for native-compaction skips
  • reviewed 2026-09-04T13:26:11.259Z sha 0cc4a18 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Sep 4, 2026
When the Codex plugin declines native compaction for a host-isolated
or policy-restricted binding, that result is an intentional no-op, not
a compaction failure. Preflight was throwing on it, which surfaced as
the generic context-too-large reply and blocked every later turn of
the session even though the context reading was small.

Classify the plugin's decline reasons (native-tool restriction and
Codex-owned automatic compaction) as a benign skip at the shared
compaction-reason layer so preflight skips instead of throwing. The
byte-triggered attempt itself is unchanged: supervised,
context-engine, and unrestricted Codex bindings keep their configured
recovery, and restricted bindings are rotated by the startup binding
as documented.
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Sep 4, 2026

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct distinction. An intentional ok: true, compacted: false Codex policy decline should not become context exhaustion. Keeping real compaction failures hard while allowing the documented Codex-owned skip preserves recovery semantics.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 4, 2026
The decline classifier matched failure wording too broadly: sandbox and
node-host policy blocks reuse the decline phrasing with ok:false results,
and the benign-skip check ignored the ok flag, so those genuine failures
would have become successful preflight skips. Match the two documented
decline reasons exactly and gate the decline class on a successful
result; regressions now keep locked-harness and policy-block failures
failing required byte preflight.
@zhangguiping-xydt

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 4, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Sep 4, 2026
@clawsweeper clawsweeper Bot removed merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 4, 2026
@vincentkoc vincentkoc self-assigned this Sep 5, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Closing this unmerged as superseded by #136533, landed on main as 9d98269.

The final repair moved the reported failure out of string classification and into the compaction owner:

  • ordinary and heartbeat Codex admission now route an over-limit host transcript through a typed, exact-target host-compaction authority;
  • host transcript, accounting, and byte-latch state commit before optional native synchronization;
  • restricted/host-isolated proof issued zero native compact requests and the successor turn succeeded;
  • an upgraded binding with rejected native synchronization retained the host commit and its successor turn also succeeded.

That means the two Codex decline strings added here are no longer needed to admit the affected turn. Keeping them would couple shared core policy to plugin-owned wording after the owner-level path has removed that dependency.

Thanks @zhangguiping-xydt for the diagnosis and the careful success-vs-failure regressions. Your contribution is preserved in the landed squash's co-author credit.

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

Labels

agents Agent runtime and tooling extensions: codex merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

[Bug]: Medium running sessions lead to compaction issues

3 participants