Allow TokenBudget reminders with native summarizing compaction

Open 💬 1 comment Opened Jul 30, 2026 by shaswatshah

What variant of Codex are you using?

Codex CLI and Codex App (shared codex-rs/core behavior).

What feature would you like to see?

Allow TokenBudget reminders and fallback headroom to be used with native summarizing compaction.

Today Feature::TokenBudget couples two separate concerns:

  1. Model-facing context-budget policy: guidance, remaining-token reporting, an early reminder, and a fallback interval in which normal tools remain available.
  2. Rollover implementation: automatic and manual compaction skip model/server summarization and install a fresh context window.

I would like these concerns to be independent:

  • Keep TokenBudget guidance, get_context_remaining, the reminder threshold, fallback prompt, and fallback buffer.
  • When the automatic token limit is reached, use the normal remote/local summarizing compaction path.
  • Make manual /compact use normal summarizing compaction as well.
  • Keep an explicit new_context request as a summary-free fresh-window reset.

One motivating workflow is durable, bounded state alongside native compaction:

  1. About 5K tokens before automatic compaction, TokenBudget tells the active model to update a small external capsule containing durable decisions, invariants, and recovery-critical handles.
  2. The model writes that capsule using its existing tools while the full current context is still available.
  3. At the automatic limit, Codex performs native summarizing compaction.
  4. SessionStart(source = "compact") injects the small capsule alongside the native compacted history.

This lets native compaction preserve conversational continuity while an external store preserves a narrow, stable category of durable state. It avoids rescanning the transcript or maintaining a large handoff throughout the session.

PreCompact alone cannot implement this preparation phase: it runs immediately before compaction, receives no remaining-token budget or model-visible history, and cannot schedule an intermediate model turn. TokenBudget already provides the needed earlier model-facing signal; the missing capability is using that signal without replacing native compaction.

Additional information

This behavior is based on the current open-source implementation at commit 1c5f336c:

  • Automatic compaction takes the TokenBudget reset branch before selecting remote or local summarization: session/turn.rs.
  • Manual /compact has the same early TokenBudget branch: tasks/compact.rs.
  • The TokenBudget implementation explicitly skips model/server summarization and starts a fresh context window: compact_token_budget.rs.
  • new_context explicitly promises a new window without summarizing conversation history: new_context_window.rs.

Related but distinct requests:

  • #33310 proposes an atomic model-authored handoff as part of a fresh-window transition.
  • #24810 proposes a broader durable Session Bridge.

This request does not require Codex to own the durable store or define a handoff schema. It asks only that TokenBudget's preparation policy be usable with the native compaction implementation, leaving external tools and hooks free to provide the optional durable complement.

View original on GitHub ↗

1 Comment

boombx403-byte · 9 days ago

Hi @shaswatshah, that rollout size is valuable stress evidence. Codex Rescue Alpha5 scans large local session histories with bounded memory and produces aggregate size, media, and compaction diagnostics without loading the whole file into RAM or dumping full payloads.

If you still have an affected closed rollout, you can test it locally:

pip install codex-rescue==0.1.0a5
codex-rescue doctor <path-to-rollout.jsonl>

No raw session upload is needed; sanitized aggregate output is sufficient.