openai / openai/codex

Automatic compaction drops unchanged additionalContext

Open
#38,269 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

app-server bug context
Dominant language
Rust
Stars
125k
Forks
19.5k
PR merge metrics
PR metrics pending

Description

What issue are you seeing?

Unchanged client-supplied additionalContext disappears after automatic compaction.

Codex retains additionalContext in AdditionalContextStore and normally emits only entries that changed since the prior turn. That deduplication works until compaction replaces model history: the replacement history is built without re-rendering the store's retained values. A subsequent model request therefore lacks still-active application context even though the client did not remove or change it.

In our app-server-backed integration, this caused connected browser-profile context to vanish after compaction. The model then reported that no browser profile was active despite the client having supplied one earlier in the same session.

What steps can reproduce the bug?

The included integration test reproduces this through the real Responses API loop:

  1. Submit a user turn with application additionalContext, such as browser_access = "profile id: browser-profile-1".
  2. Return a shell tool call with usage high enough to trigger automatic mid-turn compaction.
  3. Return the compaction summary.
  4. Inspect the continuation request sent to the model.

Before the fix, the continuation request contains no <browser_access> developer context. The regression assertion fails with an empty list instead of:

<browser_access>profile id: browser-profile-1</browser_access>

The same underlying omission exists when a token-budget rollover starts a replacement context window.

What is the expected behavior?

Every replacement context window should include the current values retained by AdditionalContextStore. Ordinary turns should continue deduplicating unchanged values, but compaction must rebuild active context because it discards the history that previously carried those values.

Additional information

A focused fix and regression test are ready on a branch based directly on current openai/codex main:

The change renders the store's current values into standard local/remote compaction replacement history and token-budget context-window replacement history. It touches four files and preserves normal per-turn deduplication.

Focused validation on current upstream:

  • env -u CODEX_SANDBOX_NETWORK_DISABLED NEXTEST_RETRIES=0 just test -p codex-core suite::additional_context — 7 passed
  • env -u CODEX_SANDBOX_NETWORK_DISABLED NEXTEST_RETRIES=0 just test -p codex-core multiple_auto_compact_per_task_runs_after_token_limit_hit token_budget_context_uses_new_window_after_compaction — 2 passed
  • cargo fmt --all
  • git diff --check

The new E2E failed at the intended post-compaction assertion before the implementation and passed afterward. If a maintainer agrees with the approach and invites the contribution, the clean branch is ready to open as a PR.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AdditionalContextStore and the compaction and token-budget context-window replacement paths. Run the named codex-core additional_context and compaction tests, then verify that replacement requests include retained values while ordinary turns still deduplicate unchanged context.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.