mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add configurable hook context spill limits (#34393)
## What changed - Add `additionalContextLimit` to command hook configuration for events that can emit `additionalContext`. - Apply the limit independently to each hook's context before it is sent to the model. Unset values retain the 2,500-token default, while `0` disables spilling for that hook. - Expose configured limits through app-server hook and requirements responses, and show them in the TUI hooks browser. ## Testing - Cover JSON and TOML parsing, discovery and hashing, per-hook spilling behavior, app-server responses, and TUI rendering. GitOrigin-RevId: 55ddc2dbbdf9067dceee3e1968c03617bbf6bcea
This commit is contained in:
1 parent
bd92b056dd
commit
e4836f998d
37 files changed
+679
-85
No files matched your search
@@ -40,3 +40,39 @@ async fn large_hook_output_spills_to_file() -> Result<()> {
|
||||
assert_eq!(fs::read_to_string(path).await?, text);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn additional_contexts_apply_limits_individually() -> Result<()> {
|
||||
let dir = tempdir()?;
|
||||
let limited_text = "limited hook output ".repeat(1_000);
|
||||
let unlimited_text = "unlimited hook output ".repeat(5_000);
|
||||
assert!(approx_token_count(&unlimited_text) > 10_000);
|
||||
let output_dir = AbsolutePathBuf::from_absolute_path(dir.path())?.join(HOOK_OUTPUTS_DIR);
|
||||
let spiller = HookOutputSpiller { output_dir };
|
||||
let output = spiller
|
||||
.maybe_spill_additional_contexts(
|
||||
ThreadId::new(),
|
||||
vec![
|
||||
AdditionalContext {
|
||||
text: limited_text.clone(),
|
||||
limit: AdditionalContextLimit::from_config(Some(1)),
|
||||
},
|
||||
AdditionalContext {
|
||||
text: unlimited_text.clone(),
|
||||
limit: AdditionalContextLimit::from_config(Some(0)),
|
||||
},
|
||||
AdditionalContext {
|
||||
text: unlimited_text.clone(),
|
||||
limit: AdditionalContextLimit::from_config(Some(usize::MAX)),
|
||||
},
|
||||
],
|
||||
)
|
||||
.await;
|
||||
let [limited_output, zero_limit_output, high_limit_output] = output.as_slice() else {
|
||||
panic!("expected one output for each additional context");
|
||||
};
|
||||
assert!(limited_output.contains("Full hook output saved to:"));
|
||||
assert_eq!(zero_limit_output, &unlimited_text);
|
||||
assert_eq!(high_limit_output, &unlimited_text);
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user