mirror of
https://github.com/openai/codex.git
synced 2026-10-24 18:18:41 +00:00
[codex] simplify token budget context (#29295)
## Why The token-budget feature currently adds remaining-token messages whenever usage crosses the 25%, 50%, and 75% thresholds. Those periodic inserts create prompt churn without requiring action, while the near-compaction reminder and explicit `get_context_remaining` tool already cover actionable and on-demand budget information. The context-window lineage block is also easier to scan as plain labeled text than as a `<token_budget>`-wrapped fragment. ## What changed - Stop recording automatic remaining-token messages at percentage thresholds. - Render context-window lineage in `First`, `Current`, `Previous` order with colon-separated labels. - Omit the `Previous` line for the first context window. - Remove `<token_budget>` wrappers from newly rendered lineage, near-compaction reminders, and `get_context_remaining` output. - Keep recognizing legacy wrapped fragments so existing rollouts remain compatible. - Remove the post-sampling token snapshot that was only needed by the periodic threshold path. ## Testing - `just test -p codex-core token_budget` (11 tests passed)
This commit is contained in:
@@ -39,24 +39,25 @@ impl ContextualUserFragment for TokenBudgetContext {
|
||||
}
|
||||
|
||||
fn type_markers() -> (&'static str, &'static str) {
|
||||
("<token_budget>\n", "\n</token_budget>")
|
||||
("", "")
|
||||
}
|
||||
|
||||
fn body(&self) -> String {
|
||||
let thread_id = self.thread_id;
|
||||
let first_window_id = self.first_window_id;
|
||||
let previous_window_id = self
|
||||
.previous_window_id
|
||||
.map_or_else(|| "none".to_string(), |window_id| window_id.to_string());
|
||||
let window_id = self.window_id;
|
||||
let mcp_result = self
|
||||
.mcp_result
|
||||
.as_deref()
|
||||
.map(|result| format!("\n{result}"))
|
||||
.unwrap_or_default();
|
||||
format!(
|
||||
"Thread id {thread_id}.\nFirst context window id {first_window_id}.\nPrevious context window id {previous_window_id}.\nCurrent context window id {window_id}.{mcp_result}"
|
||||
)
|
||||
let mut lines = vec![
|
||||
format!("Thread id {thread_id}."),
|
||||
format!("First context window id: {first_window_id}"),
|
||||
format!("Current context window id: {window_id}"),
|
||||
];
|
||||
if let Some(previous_window_id) = self.previous_window_id {
|
||||
lines.push(format!("Previous context window id: {previous_window_id}"));
|
||||
}
|
||||
if let Some(mcp_result) = &self.mcp_result {
|
||||
lines.push(mcp_result.clone());
|
||||
}
|
||||
lines.join("\n")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +88,7 @@ impl ContextualUserFragment for TokenBudgetRemainingContext {
|
||||
}
|
||||
|
||||
fn type_markers() -> (&'static str, &'static str) {
|
||||
("<token_budget>\n", "\n</token_budget>")
|
||||
("", "")
|
||||
}
|
||||
|
||||
fn body(&self) -> String {
|
||||
@@ -123,7 +124,7 @@ impl ContextualUserFragment for TokenBudgetReminder {
|
||||
}
|
||||
|
||||
fn type_markers() -> (&'static str, &'static str) {
|
||||
("<token_budget>\n", "\n</token_budget>")
|
||||
("", "")
|
||||
}
|
||||
|
||||
fn body(&self) -> String {
|
||||
|
||||
Reference in New Issue
Block a user