Skip to content

[App Server / API]: No RPC to trigger compaction when auto-compact fails (context window exceeded) #9142

Closed

Description

@Gusarich

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.
  1. 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 core Op::Compact so 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.

Activity

  1. etraut-openai commented on Jan 13, 2026

    @etraut-openai
    Contributor

    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.

  2. Gusarich commented on Jan 13, 2026

    @Gusarich
    Author

    Are you observing that auto-compaction doesn't work? Under what circumstances? If you're not seeing it work, that's likely a bug.

    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.

  3. etraut-openai commented on Jan 13, 2026

    @etraut-openai
    Contributor

    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.

  4. jiaxi98 commented on Feb 2, 2026

    @jiaxi98

    Are you observing that auto-compaction doesn't work? Under what circumstances? If you're not seeing it work, that's likely a bug.

    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.

    Yup, my issue is in the same circumstance. After successfully autocompact lots of time, it finally breaks down and /compact won't help

  5. ignatremizov commented on Feb 12, 2026

    @ignatremizov

    +1, exposing something like turn/compact would be invaluable for more efficient context management

  6. etraut-openai commented on Feb 12, 2026

    @etraut-openai
    Contributor

    The latest version adds support for thread/compact/start.

  7. ignatremizov commented on Feb 12, 2026

    @ignatremizov

    It was added in #10445 but it's missing compaction data (mentioned regression in #10986 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions