[App Server / API]: No RPC to trigger compaction when auto-compact fails (context window exceeded)
Description
When running Codex through the app-server JSON-RPC API (e.g., via thread/start + turn/start), the server can hit a context window error without auto-compacting. In that state, there is no RPC endpoint to request compaction, even though core supports Op::Compact. This makes it impossible for headless clients to recover without restarting a fresh thread and losing context.
Reproduction
1) Start a thread via app-server JSON-RPC: thread/start.
2) Run enough turns via turn/start to approach/exceed the model context window.
3) Observe failures such as:
Codex ran out of room in the model's context window. Start a new conversation or clear earlier history before retrying.
4) Attempt to trigger compaction via JSON-RPC.
Observed output
There is no thread/compact / turn/compact (or similar) RPC in app-server protocol, so the client cannot request compaction. The only available fallback is starting a new thread and losing history.
Expected behavior
Either:
- Auto-compaction should reliably run before context window exceeded, OR
- Expose a JSON-RPC endpoint (e.g.,
thread/compact) that maps to coreOp::Compactso clients can recover programmatically.
Analysis
Core supports compaction via Op::Compact:
codex-rs/protocol/src/protocol.rs(Op::Compact)codex-rs/core/src/codex.rs(handlers::compact)
But the app-server protocol doesn’t expose a corresponding client request:
codex-rs/app-server-protocol/src/protocol/common.rs(no compact request)
This blocks recovery in headless clients and automated callers.
7 Comments
Are you observing that auto-compaction doesn't work? Under what circumstances? If you're not seeing it work, that's likely a bug.
We don't currently expose an API for manual compaction because we don't want users (or clients) to need to deal with that. Auto compaction should be handled for them.
The Codex VS Code Extension is built on the app server APIs, and it relies on auto compaction.
It's the first and only time I've experienced it so far. It happened in a long-running thread where about 50 compactions completed successfully, and at some point the model (or CLI) probably "bugged out" or something like that.
OK, let's focus on fixing that problem.
I think it's unlikely that we'll expose a manual compaction API through app services. That would be a backward-looking investment, not something we'd want to support long term. I'm going to close this feature request.
Yup, my issue is in the same circumstance. After successfully autocompact lots of time, it finally breaks down and /compact won't help
+1, exposing something like
turn/compactwould be invaluable for more efficient context managementThe latest version adds support for
thread/compact/start.It was added in #10445 but it's missing compaction data (mentioned regression in #10986 )