Repository navigation
fix(agents): allow required-preflight native Codex compaction - #120197
fuller-stack-dev merged 46 commits into
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 16, 2026, 9:56 AM ET / 13:56 UTC. ClawSweeper reviewWhat this changesThe PR makes mandatory Codex preflight compaction use a registry-owned native capability and allows context-engine recovery only after a typed missing or stale Codex thread-binding failure. Regression provenancePossible regression — probable (reproduction; failure trace; reviewed change). No predecessor PR is attributed. Merge readinessKeep this PR open for final maintainer review: current main does not contain the repair, the patch has no discrete source-level defect found, and the new exact-head production-boundary evidence is substantive; however, the required direct Codex dependency-source check cannot be completed because the sibling checkout is unavailable in this read-only environment. Priority: P1 Review scores
Verification
How this fits togetherReply preflight compacts an oversized agent session before the next model turn. For Codex-backed sessions, it dispatches Codex app-server compaction and either continues with the compacted thread or uses the existing context engine for a narrowly authorized binding-recovery path. flowchart LR
A[Incoming reply turn] --> B[Required preflight]
B --> C[Selected Codex harness]
C --> D[Registry-held native capability]
D --> E[Codex app-server thread]
E -->|Compacted| F[Continue model turn]
E -->|Missing or stale binding| G[Context engine recovery]
G --> F
Decision needed
Why: The applicable repository policy requires an acting reviewer to inspect the sibling Codex source directly; this environment has no ../codex checkout and cannot create one. Before merge
Agent review detailsSecurityNone. PR surfaceSource +116, Tests +693, Other 0. Total +809 across 26 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the registry-held Codex-only capability design, then complete direct inspection of the pinned Codex protocol source before landing. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main's required-preflight caller reaches ordinary Codex compaction, whose non-manual ownership skip does not satisfy the preflight success condition; the PR supplies exact-head boundary proof for the repaired path. Is this the best way to solve the issue? Yes, provisionally: moving authority from a public harness property to registry-held Codex capability state is the narrowest repair that preserves locked-runtime ownership, provided the pinned Codex contract is directly verified. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 51964c1eee30. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (29 earlier review cycles; latest 8 shown)
|
9f5b9b2 to
fc3607f
Compare
|
🦞👀 Command router queued. I will update this comment with the next step. |
fc3607f to
dae1779
Compare
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
dae1779 to
4592ff6
Compare
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review Updated evidence: the full-path proof now explicitly pins and logs the managed Codex binary identity — |
|
🦞👀 Command router queued. I will update this comment with the next step. |
# Conflicts: # scripts/plugin-sdk-surface-report.mts
# Conflicts: # scripts/plugin-sdk-surface-report.mts
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Exact-head proof and maintainer decision for Maintainer decision: accept the registry-held, Codex-only native-compaction capability as the permanent owner boundary. The public Plugin SDK registration shape may expose the typed option, but runtime authorization requires bundled provenance or a verified official Fresh exact-head Blacksmith Testbox behavior proof passed 329 tests across five Vitest shards:
This exact-head run proves both sides of the final authorization design:
Direct Codex
The reported “persistent data-model change” is a false path classification of Rank-up moves: both requested exact-head behavior branches are now proven, and the restricted SDK/security contract is explicitly accepted above. No agent transcript was inserted. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Exact-head production-boundary proof is now complete for This is a standalone non-Vitest fault-injection run through the production plugin loader, bundled Codex plugin, registry-held capability, Codex app-server binding store, SQLite session target, prepared runtime generation, queued compaction entrypoint, and a temporary context-engine plugin. It made no provider request and used no live credential.
Observed authorized path:
Observed forged-owner path in the same process:
Raw redacted receipt: {
"proof": "pr-120197-production-boundary",
"head": "8dbc38443c4de21f64edc949a00fcbc4351a3ade",
"authorized": {
"pluginOrigin": "bundled",
"pluginSource": "extensions/codex/index.ts",
"registryOwner": "codex",
"nativeCapability": true,
"injectedFault": "missing_thread_binding",
"fallbackCalls": [{
"sessionId": "pr120197-missing-binding",
"sessionKey": "agent:main:pr120197-missing-binding",
"tokenBudget": 1000000,
"currentTokenCount": 800000
}],
"result": {
"ok": true,
"compacted": true,
"compactionKind": "context-engine",
"result": {
"summary": "production-boundary recovery completed",
"tokensBefore": 800000,
"tokensAfter": 120000
}
}
},
"forgedOwner": {
"origin": "global",
"source": "/plugins/impostor/index.js",
"registeredHarnesses": 0,
"diagnostic": {
"level": "error",
"pluginId": "codex",
"message": "native compaction requires the registry-owned \"codex\" harness"
}
}
}The repository-required direct sibling Codex inspection was performed by the acting maintainer at pinned
Both requested rank-up branches are now demonstrated at the real production boundary on the exact final head. The proof harness was temporary, removed after the run, and is not part of the PR tree. No agent transcript was inserted. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
What Problem This Solves
In Codex app-server sessions, when a message crosses the context budget, the required preflight compaction used to be silently skipped and then misclassified as a fatal failure, so the user's turn was dropped with a "Context is too large" error and no model call ever ran. Required-preflight compaction now explicitly asks Codex to compact natively, and falls back to the context engine when the thread binding is missing or stale.
ok:true, compacted:false, reason:"codex app-server owns automatic compaction"no-op,isBenignCompactionSkipResultrejected it, and the preflight gate threw — dropping the user's turn and leaving the oversized session unrecoverable. Production logs in [Bug]: Preflight (budget) compaction treats Codex "owns automatic compaction" no-op as fatal and drops the user's turn #119971 show this firing 41 times.compactAfterContextEnginecapability (which passesallowNonManualNativeRequest: true) so Codex actually starts native compaction. A missing/stale thread binding surfaces as the canonical recoverablestale_thread_binding/missing_thread_bindingfailure that the existing context-engine fallback handles.src/agents/harness/compaction.ts(new"required_preflight"native request type + routing),src/agents/embedded-agent-runner/compact.queued.ts(passrequired_preflightwhenpreflightRequired; locked-harness branch now lets required-preflight recoverable binding failures reach the context-engine fallback),extensions/codex/src/app-server/compact.ts(required-preflight binding change returns canonical recoverable failure, not anok:trueskip),extensions/codex/harness.ts(propagatenativeCompactionRequest), plus regression tests inselection.test.ts,compact.test.ts,compact.hooks.test.ts.compacthook unchanged), and the benign-skip classifier incompact-reasons.ts.Why This Change Was Made
The same Codex ownership skip was already handled in the CLI compaction path (#88207 for #91793), but the reply preflight caller was never updated. ClawSweeper's review confirms current main still turns the successful automatic-compaction skip into the preflight failure reply. The fix follows the issue's recommended option 2 (re-request with
allowNonManualNativeRequest: true, fall back to the context engine on a recoverable binding failure) rather than merely labeling the skip benign — labeling it benign would let mandatory compaction silently not happen.Two P1 follow-ups emerged during review and are addressed here:
ok:true, compacted:falseskip that bypassed the shared fallback guard, so required preflight still threw and dropped the turn. The Codex compaction producer now returns the canonical recoverablestale_thread_bindingfailure for required-preflight (only a genuine post-context-engine request may skip).modelSelectionLocked: true, the shape persisted for durable Codex sessions) previously returned the recoverable missing/stale-binding failure as terminal: the locked-harness branch incompact.queued.tsshort-circuited before the shared fallback. Required preflight is now the one scoped exception — a missing or stale binding falls through to the context-engine fallback while the persisted Codex runtime lock is retained. Non-preflight locked sessions and non-recoverable locked failures are unchanged.Risk: the fix deliberately changes opted-in Codex preflight behavior from "drop the turn on ownership skip" to "compact natively, fall back to context engine". The fallback path is the existing, already-shipped context-engine compaction; no new compaction code is introduced. Non-Codex harnesses and non-preflight paths are untouched.
User Impact
With a Codex app-server–bound session that crosses the preflight context budget, the user's turn is no longer silently dropped. Codex is asked to compact natively; if its thread binding is missing or stale, the context engine compacts instead and the same turn completes with a model reply. No configuration change; default installs are unaffected (the failure only affected Codex app-server sessions, and the ownership skip itself is intentional Codex behavior — only its misclassification as fatal was the bug).
Evidence
All live evidence captured on PR head
492c4810e45(Linux x86_64, Node v22.22.3), production modules driven directly vianode --import tsxwith the plugin-pinned@openai/[email protected]managed package (codex-cli 0.147.0). The two live proof scripts are committed inevidence/119971/so they are inspectable on the exact head; their redacted terminal output is inlined below.1. Real Codex app-server, required-preflight recoverable binding fallback (core proof)
evidence/119971/codex-live-binding-race-proof.mtsdrives the real codex app-server binary (real thread created via stdio transport) through the realmaybeCompactCodexAppServerSessionwithnativeCompactionRequest: "required_preflight". Output:This is the exact gate ClawSweeper asked for: a real after-fix trace showing the required-preflight path reaching the recoverable binding fallback (not the pre-fix
ok:trueskip that dropped the turn).2. Model-locked required-preflight session (real codex, locked branch)
evidence/119971/codex-live-locked-preflight-proof.mtsdrives the real codex app-server withmodelSelectionLocked=true, preflightRequired=true, trigger=budget. Output:3. Full-path gateway proof (real gateway + real codex binary + local mock model endpoint)
A full-path driver (available on request — it spawns the real OpenClaw gateway and real codex binary, so it is not committed to the repo) starts the real OpenClaw gateway with the real
@openai/[email protected]managed binary pointed at a loopback OpenAI-compatible mock, inflates the transcript past the 128kb byte fuse, and confirms the same user turn still completes a model reply. Output:What was not tested: a live credentialed Codex app-server session crossing the preflight budget on a real OpenAI-subscription conversation (requires external Codex subscription/auth). Everything up to the model endpoint is proven on the exact head: real production modules, real codex binary, real binding-change/locked-session races, and a real-gateway oversized-reply completion trace (local mock model endpoint). The preflight compaction log line itself was not captured in the gateway stdout excerpt (the gateway writes compaction logs to its rotating log file, not stdout); the recoverable-binding evidence in items 1–2 is the direct proof that required-preflight reaches the fallback instead of the fatal skip.
4. Regression coverage (exact head
492c481)selection.test.ts: required-preflight routes throughcompactAfterContextEnginewithnativeCompactionRequest: "required_preflight"; absent-capability fallback to plaincompacthook.compact.test.ts: required-preflight origin recorded on nativethread/compact/start; binding change reports canonical recoverablestale_thread_bindingfailure.compact.hooks.test.ts: model-locked required-preflight recovers via context-engine fallback on missing/stale binding; non-preflight locked and non-recoverable locked failures unchanged.AI Assistance
Fixes #119971