Local compaction request omits tool specs, so it never hits the prompt cache (full window re-billed uncached on every compaction)
已打开 05:27PM - 06 Aug 26 UTC
bug
rate-limits
CLI
context
### Version / context
codex-cli 0.146.1 (code references pinned to tag `rust-v0….146.1`). Affects every provider that takes the local compaction path (all non-OpenAI/Azure providers today; and OpenAI users too if #34428 is fixed by routing custom compact prompts locally).
### What happens
`run_compact_task_inner_impl` builds the summarization request as
https://github.com/openai/codex/blob/rust-v0.146.1/codex-rs/core/src/compact.rs#L277-L281
```rust
let prompt = Prompt {
input: turn_input,
base_instructions: sess.get_base_instructions().await,
..Default::default()
};
```
i.e. **without `tools` / `parallel_tool_calls`**, while every regular turn in the same session serializes the tool specs into the request (see the remote analogue, which does include them: https://github.com/openai/codex/blob/rust-v0.146.1/codex-rs/core/src/compact_remote_request.rs#L63-L70).
Prompt caching is prefix-based over the serialized request *including tools*, so the compaction request's prefix never matches the session's cached prefix. Result: the entire conversation history is re-billed **uncached** on every compaction.
### Measured impact
On a long-running session: compaction triggers at ~235k input tokens and normal turns run 96–99% cached. A prefix-mismatched compaction re-bills the full ~235k uncached each time; across a thread with frequent compactions this added roughly +70% to total uncached input on our workload.
### Suggested fix (validated locally)
Mirror the remote request builder: include `tools: step_context.tool_router.model_visible_specs()` and `parallel_tool_calls: turn_context.model_info.supports_parallel_tool_calls` in the local compaction `Prompt`. We applied exactly this on top of `rust-v0.146.1`: compaction requests then hit the prompt cache (65–88% cached even on a small verification session whose uncached tail was dominated by freshly read files), summaries are unaffected, and `cargo test -p codex-core --lib compact` / `--test all compact` match pristine (54 / 115 passing).
### Interaction
This compounds with #34428: any fix that makes `compact_prompt` effective by routing to local compaction will surface this cost bug for the default provider as well.