Skip to content

Commit dd47e47

Browse files
authored
Fail Codex compaction at the Codex boundary (#85958)
1 parent 908b894 commit dd47e47

18 files changed

Lines changed: 672 additions & 1860 deletions

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ Docs: https://docs.openclaw.ai
247247
- Gateway/agents: preserve fresh session overrides and metadata when stale cached agent-session entries race with store updates, so subagent model/provider overrides and routing policy survive concurrent writes. (#19328) Thanks @CodeReclaimers.
248248
- Control UI/chat: keep chat session search inline with the session selector so the header no longer shows a duplicate standalone search row.
249249
- Control UI/chat: collapse focused-mode header chrome and suppress hidden-header scroll updates so focus mode no longer jumps while scrolling. Thanks @amknight.
250-
- Codex app-server: restart the native app-server and retry once when server-side compaction times out, so preflight compaction stalls recover instead of failing every dispatch. (#85500)
250+
- Codex app-server: leave automatic compaction to native Codex, drop OpenClaw preflight/CLI/context-engine forced compaction for Codex runtime sessions, and still forward explicit `/compact` or plugin compaction requests into Codex while failing native compaction honestly. (#85500)
251251
- Restore Control UI gateway token pairing [AI]. (#85459) Thanks @pgondhi987.
252252
- OpenAI video: honor configured provider request private-network opt-in for local/custom video endpoints so explicitly trusted mock and self-hosted providers are not blocked. Thanks @shakkernerd.
253253
- OpenAI video: send uploaded video edit requests to the documented `/videos/edits` endpoint with a `video` file instead of posting MP4 references to `/videos`. Thanks @shakkernerd.
@@ -332,7 +332,7 @@ Docs: https://docs.openclaw.ai
332332
- fix: constrain Windows task script names [AI]. (#85064) Thanks @pgondhi987.
333333
- Control UI: keep the chat session picker from hiding older or cross-agent configured conversations while preserving the bounded configured-agent refresh. (#85211) Thanks @amknight.
334334
- Agents/Anthropic: preserve unsafe integer tool-call input values in streamed Anthropic tool-use JSON, preventing Discord-style IDs from being rounded before dispatch. Fixes #47229. (#83063) Thanks @leno23.
335-
- Agents/Codex: estimate tool-heavy prompt pressure at the LLM boundary before provider submission, so persistent sessions compact before overflowing context windows. (#85541) Thanks @fuller-stack-dev and @joshavant.
335+
- Agents: estimate tool-heavy prompt pressure at the LLM boundary before provider submission for non-Codex embedded runtimes, so persistent PI-style sessions compact before overflowing context windows. (#85541) Thanks @fuller-stack-dev and @joshavant.
336336
- Agents/hooks: wait for local one-shot CLI and Codex `agent_end` plugin hooks before process cleanup so terminal observability flushes reliably. (#85007)
337337
- Providers/Google: preserve Gemini 3 cron `thinkingDefault: "low"` when stale catalog metadata says `reasoning:false`, so scheduled runs keep provider-supported thinking instead of downgrading to off. (#85185) Thanks @neeravmakwana.
338338
- CLI/agents: allow `openclaw agent --session-key` to target explicit session keys, including agent-scoped legacy keys. (#85121) Thanks @Kaspre.

docs/plugins/codex-harness-runtime.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ diagnostic surfaces around that boundary.
2020
OpenClaw still owns channel routing, session files, visible message delivery,
2121
OpenClaw dynamic tools, approvals, media delivery, and a transcript mirror.
2222
Codex owns the canonical native thread, native model loop, native tool
23-
continuation, and native compaction unless the active OpenClaw context engine
24-
declares that it owns compaction.
23+
continuation, and native compaction.
2524

2625
Prompt routing follows the selected runtime, not just the provider string. A
2726
native Codex turn receives Codex app-server developer instructions, while an
@@ -122,7 +121,7 @@ Supported in Codex runtime v1:
122121
| OpenClaw channel routing and delivery | Supported | Telegram, Discord, Slack, WhatsApp, iMessage, and other channels stay outside the model runtime. |
123122
| OpenClaw dynamic tools | Supported | Codex asks OpenClaw to execute these tools, so OpenClaw stays in the execution path. |
124123
| Prompt and context plugins | Supported | OpenClaw projects OpenClaw-specific prompt/context into the Codex turn while leaving Codex-owned base, model, personality, and configured project-doc prompts in the native Codex lane. Native Codex developer instructions accept only command guidance explicitly scoped to `codex_app_server`; legacy global command hints remain for non-Codex prompt surfaces. |
125-
| Context engine lifecycle | Supported | Assemble, ingest, after-turn maintenance, and context-engine compaction coordination run for Codex turns. |
124+
| Context engine lifecycle | Supported | Assemble, ingest, and after-turn maintenance run around Codex turns. Context engines do not replace native Codex compaction. |
126125
| Dynamic tool hooks | Supported | `before_tool_call`, `after_tool_call`, and tool-result middleware run around OpenClaw-owned dynamic tools. |
127126
| Lifecycle hooks | Supported as adapter observations | `llm_input`, `llm_output`, `agent_end`, `before_compaction`, and `after_compaction` fire with honest Codex-mode payloads. |
128127
| Final-answer revision gate | Supported through native hook relay | Codex `Stop` is relayed to `before_agent_finalize`; `revise` asks Codex for one more model pass before finalization. |
@@ -137,8 +136,8 @@ Not supported in Codex runtime v1:
137136
| Native tool argument mutation | Codex native pre-tool hooks can block, but OpenClaw does not rewrite Codex-native tool arguments. | Requires Codex hook/schema support for replacement tool input. |
138137
| Editable Codex-native transcript history | Codex owns canonical native thread history. OpenClaw owns a mirror and can project future context, but should not mutate unsupported internals. | Add explicit Codex app-server APIs if native thread surgery is needed. |
139138
| `tool_result_persist` for Codex-native tool records | That hook transforms OpenClaw-owned transcript writes, not Codex-native tool records. | Could mirror transformed records, but canonical rewrite needs Codex support. |
140-
| Rich native compaction metadata | OpenClaw observes compaction start and completion, but does not receive a stable kept/dropped list, token delta, or summary payload. | Needs richer Codex compaction events. |
141-
| Compaction intervention | Current OpenClaw compaction hooks are notification-level in Codex mode. | Add Codex pre/post compaction hooks if plugins need to veto or rewrite native compaction. |
139+
| Rich native compaction metadata | OpenClaw can request native compaction, but does not receive a stable kept/dropped list, token delta, completion summary, or summary payload. | Needs richer Codex compaction events. |
140+
| Compaction intervention | OpenClaw does not let plugins or context engines veto, rewrite, or replace native Codex compaction. | Add Codex pre/post compaction hooks if plugins need to veto or rewrite native compaction. |
142141
| Byte-for-byte model API request capture | OpenClaw can capture app-server requests and notifications, but Codex core builds the final OpenAI API request internally. | Needs a Codex model-request tracing event or debug API. |
143142

144143
## Native permissions and MCP elicitations
@@ -200,13 +199,18 @@ diagnostics bundle.
200199

201200
## Compaction and transcript mirror
202201

203-
When the selected model uses the Codex harness, native thread compaction is
204-
delegated to Codex app-server unless an active context engine declares
205-
`ownsCompaction: true`. Owning context engines compact first and cause OpenClaw
206-
to abandon the old Codex backend thread so the next turn can rehydrate a fresh
207-
thread from engine-managed context. OpenClaw keeps a transcript mirror for
208-
channel history, search, `/new`, `/reset`, and future model or harness
209-
switching.
202+
When the selected model uses the Codex harness, native thread compaction belongs
203+
to Codex app-server. OpenClaw does not run preflight compaction for Codex turns,
204+
does not replace Codex compaction with context-engine compaction, and does not
205+
fall back to OpenClaw or public OpenAI summarization when native Codex
206+
compaction cannot be started. OpenClaw keeps a transcript mirror for channel
207+
history, search, `/new`, `/reset`, and future model or harness switching.
208+
209+
Explicit compaction requests, such as `/compact` or a plugin-requested manual
210+
compact operation, start native Codex compaction with `thread/compact/start`.
211+
OpenClaw returns after starting that native operation. It does not wait for
212+
completion, impose a separate OpenClaw timeout, restart the shared Codex
213+
app-server, or record the operation as an OpenClaw-completed compaction.
210214

211215
When a context engine requests Codex thread-bootstrap projection, OpenClaw
212216
projects tool-call names and ids, input shapes, and redacted tool-result content
@@ -215,9 +219,9 @@ that projection.
215219

216220
The mirror includes the user prompt, final assistant text, and lightweight Codex
217221
reasoning or plan records when the app-server emits them. Today, OpenClaw only
218-
records native compaction start and completion signals. It does not yet expose a
219-
human-readable compaction summary or an auditable list of which entries Codex
220-
kept after compaction.
222+
records explicit native compaction start signals when it requests compaction. It
223+
does not expose a human-readable compaction summary or an auditable list of
224+
which entries Codex kept after compaction.
221225

222226
Because Codex owns the canonical native thread, `tool_result_persist` does not
223227
currently rewrite Codex-native tool result records. It only applies when

docs/plugins/codex-harness.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,28 +125,29 @@ Use `openai/gpt-*` model refs for Codex-backed OpenAI agent turns. Prefer
125125
`openai-codex:*` auth profiles and `auth.order.openai-codex` remain valid, but
126126
do not write new `openai-codex/gpt-*` model refs.
127127

128-
Do not set `compaction.model` or `compaction.provider` on Codex-backed agents
129-
unless a selected context engine owns compaction. Without an owning context
130-
engine, Codex compacts through its native app-server thread state, so OpenClaw
131-
ignores those local summarizer overrides at runtime and `openclaw doctor --fix`
132-
removes them when the agent uses Codex.
128+
Do not set `compaction.model` or `compaction.provider` on Codex-backed agents.
129+
Codex compacts through its native app-server thread state, so OpenClaw ignores
130+
those local summarizer overrides at runtime and `openclaw doctor --fix` removes
131+
them when the agent uses Codex.
133132

134-
Lossless remains supported as a context engine. Configure it through
133+
Lossless remains supported as a context engine for assembly, ingestion, and
134+
maintenance around Codex turns. Configure it through
135135
`plugins.slots.contextEngine: "lossless-claw"` and
136136
`plugins.entries.lossless-claw.config.summaryModel`, not through
137137
`agents.defaults.compaction.provider`. `openclaw doctor --fix` migrates the old
138138
`compaction.provider: "lossless-claw"` shape to the Lossless context-engine slot
139-
when Codex is the active runtime.
139+
when Codex is the active runtime, but native Codex still owns compaction.
140140

141141
The native Codex app-server harness supports context engines that require
142142
pre-prompt assembly. Generic CLI backends, including `codex-cli`, do not provide
143143
that host capability.
144144

145-
When the active context engine reports `ownsCompaction: true`, `/compact` runs
146-
that engine's compaction lifecycle and invalidates the bound Codex app-server
147-
thread. The next Codex turn starts a fresh backend thread and rehydrates it from
148-
the context engine instead of layering Codex native compaction on top of the
149-
engine-owned semantic summary.
145+
For Codex-backed agents, `/compact` starts native Codex app-server compaction on
146+
the bound thread. OpenClaw does not wait for completion, impose an OpenClaw
147+
timeout, restart the shared app-server, or fall back to a context-engine or
148+
public OpenAI summarizer. If the native Codex thread binding is missing or
149+
stale, the command fails closed so the operator sees the real runtime boundary
150+
instead of silently switching compaction backends.
150151

151152
```json5
152153
{
@@ -656,10 +657,10 @@ The Codex harness changes the low-level embedded agent executor only.
656657
- Codex-native shell, patch, MCP, and native app tools are owned by Codex.
657658
OpenClaw can observe or block selected native events through the supported
658659
relay, but it does not rewrite native tool arguments.
659-
- Codex owns native compaction unless the active OpenClaw context engine
660-
declares `ownsCompaction: true`. OpenClaw keeps a transcript mirror for
661-
channel history, search, `/new`, `/reset`, and future model or harness
662-
switching.
660+
- Codex owns native compaction. OpenClaw keeps a transcript mirror for channel
661+
history, search, `/new`, `/reset`, and future model or harness switching, but
662+
it does not replace Codex compaction with an OpenClaw or context-engine
663+
summarizer.
663664
- Media generation, media understanding, TTS, approvals, and messaging-tool
664665
output continue through the matching OpenClaw provider/model settings.
665666
- `tool_result_persist` applies to OpenClaw-owned transcript tool results, not

0 commit comments

Comments
 (0)