Commit Graph

2 Commits

  • fix: scope context remaining to body window (#29665)
    ## 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`
  • refactor: extract context window token status (#29664)
    ## 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