mirror of
https://github.com/openai/codex.git
synced 2026-11-22 15:15:18 +00:00
Add auto-compaction fallback token-budget settings (#33243)
## What changed - Add `auto_compact_fallback_prompt` and `auto_compact_fallback_buffer_tokens` to `features.token_budget` and the generated configuration schema. - Trim empty fallback prompts, limit prompts to 2,000 bytes, require a buffer when a prompt is configured, and reject non-positive buffer values. - Preserve the new settings when locking resolved session configuration. ## Testing - Cover config resolution and validation for overlong prompts, missing buffers, and non-positive buffers. - Extend the configuration-lock test to cover both settings. GitOrigin-RevId: 6463f963ba1dbd633d76601b8344360a8c85cf8b
This commit is contained in:
1 parent
fca51f6daf
commit
8aae858958
5 files changed
+135
No files matched your search
@@ -572,11 +572,15 @@ enabled = true
|
||||
reminder_threshold_tokens = 16000
|
||||
reminder_message_template = "Custom reminder: {n_remaining} tokens."
|
||||
guidance_message = "Preserve important state before compaction."
|
||||
auto_compact_fallback_prompt = " Write notes immediately. "
|
||||
auto_compact_fallback_buffer_tokens = 8000
|
||||
"#,
|
||||
TokenBudgetConfig {
|
||||
reminder_threshold_tokens: Some(16_000),
|
||||
reminder_message_template: "Custom reminder: {n_remaining} tokens.".to_string(),
|
||||
guidance_message: Some("Preserve important state before compaction.".to_string()),
|
||||
auto_compact_fallback_prompt: Some("Write notes immediately.".to_string()),
|
||||
auto_compact_fallback_buffer_tokens: Some(8_000),
|
||||
},
|
||||
),
|
||||
] {
|
||||
@@ -595,6 +599,26 @@ guidance_message = "Preserve important state before compaction."
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn load_config_rejects_overlong_auto_compact_fallback_prompt() -> std::io::Result<()> {
|
||||
let codex_home = tempdir()?;
|
||||
let prompt = "x".repeat(AUTO_COMPACT_FALLBACK_PROMPT_MAX_BYTES + 1);
|
||||
let config_toml = toml::from_str(&format!(
|
||||
"[features.token_budget]\nenabled = true\nauto_compact_fallback_prompt = {prompt:?}\n"
|
||||
))
|
||||
.expect("TOML should deserialize");
|
||||
let error = Config::load_from_base_config_with_overrides(
|
||||
config_toml,
|
||||
ConfigOverrides::default(),
|
||||
codex_home.abs(),
|
||||
)
|
||||
.await
|
||||
.expect_err("overlong fallback prompt should be rejected");
|
||||
|
||||
assert_eq!(error.kind(), std::io::ErrorKind::InvalidInput);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn load_config_rejects_invalid_token_budget_reminder_template() -> std::io::Result<()> {
|
||||
for reminder_message_template in [
|
||||
@@ -644,6 +668,55 @@ async fn load_config_rejects_non_positive_token_budget_reminder_threshold() -> s
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn load_config_rejects_non_positive_auto_compact_fallback_buffer() -> std::io::Result<()> {
|
||||
for auto_compact_fallback_buffer_tokens in [-1, 0] {
|
||||
let codex_home = tempdir()?;
|
||||
let config_toml = toml::from_str(&format!(
|
||||
"[features.token_budget]\nenabled = true\nauto_compact_fallback_prompt = \"Write notes.\"\nauto_compact_fallback_buffer_tokens = {auto_compact_fallback_buffer_tokens}\n"
|
||||
))
|
||||
.expect("TOML should deserialize");
|
||||
let error = Config::load_from_base_config_with_overrides(
|
||||
config_toml,
|
||||
ConfigOverrides::default(),
|
||||
codex_home.abs(),
|
||||
)
|
||||
.await
|
||||
.expect_err("non-positive fallback buffer should be rejected");
|
||||
|
||||
assert_eq!(error.kind(), std::io::ErrorKind::InvalidInput);
|
||||
assert_eq!(
|
||||
error.to_string(),
|
||||
"features.token_budget.auto_compact_fallback_buffer_tokens must be positive"
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn load_config_rejects_missing_auto_compact_fallback_buffer() -> std::io::Result<()> {
|
||||
let codex_home = tempdir()?;
|
||||
let config_toml = toml::from_str(
|
||||
"[features.token_budget]\nenabled = true\nauto_compact_fallback_prompt = \"Write notes.\"\n",
|
||||
)
|
||||
.expect("TOML should deserialize");
|
||||
|
||||
let error = Config::load_from_base_config_with_overrides(
|
||||
config_toml,
|
||||
ConfigOverrides::default(),
|
||||
codex_home.abs(),
|
||||
)
|
||||
.await
|
||||
.expect_err("missing fallback buffer should be rejected");
|
||||
assert_eq!(error.kind(), std::io::ErrorKind::InvalidInput);
|
||||
assert_eq!(
|
||||
error.to_string(),
|
||||
"features.token_budget.auto_compact_fallback_buffer_tokens is required when auto_compact_fallback_prompt is set"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn load_config_resolves_rollout_budget() -> std::io::Result<()> {
|
||||
let codex_home = tempdir()?;
|
||||
|
||||
Reference in new issue
Block a user