Skip to content

fix: scope context remaining to body window - #29665

Merged
bolinfest merged 1 commit into
mainfrom
pr29665
Jun 23, 2026
Merged

fix: scope context remaining to body window#29665
bolinfest merged 1 commit into
mainfrom
pr29665

Conversation

@bolinfest

@bolinfest bolinfest commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Why

With model_auto_compact_token_limit_scope = "body_after_prefix", the persistent prefix should not count against the active body window. get_context_remaining and the token-budget reminder should report the same usable body-after-prefix window that auto-compaction uses, rather than the total token count since the session began.

This is stacked on #29664 so the mechanical move from turn.rs is isolated from the behavior fix.

What

  • Extends ContextWindowTokenStatus with context_remaining_tokens.
  • Updates get_context_remaining to use the shared context-window accounting.
  • Adds integration coverage for body-after-prefix reminder timing and get_context_remaining output.

Testing

  • just test -p codex-core body_after_prefix_window
  • just test -p codex-core auto_compact_body_after_prefix
  • just fix -p codex-core

@pakrym-oai pakrym-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stamping to unlbock but I think token_budget::maybe_record should also be using tokens before compaction.

@bolinfest
bolinfest force-pushed the pr29665 branch 3 times, most recently from fdd29fc to f2d56c6 Compare June 23, 2026 22:44
(Some(scope_remaining), None) => Some(scope_remaining),
(None, Some(full_remaining)) => Some(full_remaining),
(None, None) => None,
};

@pakrym-oai pakrym-oai Jun 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let tokens_until_compaction = match (auto_compact_scope_remaining, full_context_remaining) {

    (Some(a), Some(b)) => Some(a.min(b)),

    (a, b) => a.or(b),

};

bolinfest added a commit that referenced this pull request Jun 23, 2026
## Why

This PR keeps the mechanical helper extraction separate from the
behavior change in #29665. The follow-up needs the token-window
accounting from `turn.rs` in another call path, but reviewing that is
much easier when the helper extraction is separate from the semantic
change.

## What

- Adds `session/context_window.rs` with `ContextWindowTokenStatus`.
- Moves the existing auto-compaction token-status calculation out of
`session/turn.rs`.
- Replaces the duplicated inline remaining-token calculation in
`turn.rs` with `tokens_until_compaction()`.

This PR is intended to be behavior-preserving. The
`get_context_remaining` behavior change is stacked separately in #29665.

## Testing

- `just test -p codex-core auto_compact_body_after_prefix`













---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/29664).
* #29665
* __->__ #29664
Base automatically changed from pr29664 to main June 23, 2026 22:49
@bolinfest
bolinfest force-pushed the pr29665 branch 2 times, most recently from 7c14c89 to 4ba46e7 Compare June 23, 2026 22:51
@bolinfest
bolinfest enabled auto-merge (squash) June 23, 2026 23:05
@bolinfest
bolinfest merged commit 77e7ce1 into main Jun 23, 2026
46 checks passed
@bolinfest
bolinfest deleted the pr29665 branch June 23, 2026 23:08
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants