[codex] add configurable token budget compaction reminder (#29255)

## Why

The token-budget feature reports coarse remaining-context milestones,
but it does not give the model a configurable wrap-up prompt before
automatic compaction. A strict threshold-crossing check can also miss
resumed or reconfigured windows that are already inside the threshold.

## What changed

- Add structured `[features.token_budget]` configuration for an absolute
`reminder_threshold_tokens` and bounded `reminder_message_template`;
`{n_remaining}` is expanded when the reminder is delivered.
- Compute remaining tokens against the next effective auto-compaction
boundary, including scoped `body_after_prefix` accounting and the full
context-window limit.
- Make reminder delivery level-triggered before and after sampling, with
one-shot state owned by `AutoCompactWindow` and re-armed on compaction,
`new_context`, restore, or history replacement.
- Leave the existing initial full-window token-budget context, 25/50/75%
notices, and token-budget tools unchanged.
- Persist the resolved feature configuration in the session config lock
and regenerate the config schema.

## Validation

- `just test -p codex-core token_budget`
- `just test -p codex-core
token_budget_reminder_emits_after_crossing_compaction_threshold`
- `just test -p codex-core auto_compact_window`
- `just test -p codex-core
lock_contains_prompts_and_materializes_features`
- `just test -p codex-features`
- `just test -p codex-config`
This commit is contained in:
pakrym-oai
2026-06-20 19:13:42 -07:00
committed by GitHub
parent b6d6be2a84
commit 6df037d47f
15 changed files with 418 additions and 27 deletions
+33 -2
View File
@@ -669,7 +669,7 @@
"type": "boolean"
},
"token_budget": {
"type": "boolean"
"$ref": "#/definitions/FeatureToml_for_TokenBudgetConfigToml"
},
"tool_call_mcp_elicitation": {
"type": "boolean"
@@ -967,6 +967,16 @@
}
]
},
"FeatureToml_for_TokenBudgetConfigToml": {
"anyOf": [
{
"type": "boolean"
},
{
"$ref": "#/definitions/TokenBudgetConfigToml"
}
]
},
"FeedbackConfigToml": {
"additionalProperties": false,
"properties": {
@@ -2836,6 +2846,27 @@
}
]
},
"TokenBudgetConfigToml": {
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean"
},
"reminder_message_template": {
"description": "Reminder template. `{n_remaining}` is replaced with the tokens remaining before auto-compaction.",
"maxLength": 1000,
"minLength": 1,
"type": "string"
},
"reminder_threshold_tokens": {
"description": "Number of tokens remaining before auto-compaction when the wrap-up reminder is emitted.",
"format": "int64",
"minimum": 1.0,
"type": "integer"
}
},
"type": "object"
},
"ToolSuggestConfig": {
"additionalProperties": false,
"properties": {
@@ -4932,7 +4963,7 @@
"type": "boolean"
},
"token_budget": {
"type": "boolean"
"$ref": "#/definitions/FeatureToml_for_TokenBudgetConfigToml"
},
"tool_call_mcp_elicitation": {
"type": "boolean"