Add opt-in overhead timing to code-mode responses (#46288)

## Why

Code-mode responses show host duration without exposing time spent outside the host, including app-server waiting.

## What changed

- Add `features.code_mode.experimental_show_cell_overhead`, disabled by default, to show handler duration, host duration, and their difference in `exec` and `wait` response headers.
- Reuse the completed handler measurement from tool-call logging, excluding dispatch waiting, and capture it even when logging is disabled.
- Preserve the existing timing format when the option is disabled or host timing is unavailable, and preserve boolean feature toggles when merging nested code-mode configuration.

## Testing

Add coverage for timing headers, zero and missing host measurements, negative rounding differences, content preservation, and configuration merging. Extend app-server tests across gRPC and stdio to verify timing includes post-host elicitation waiting, and add a response snapshot for successful execution and a failed wait.

GitOrigin-RevId: 929b84784d9c6077cf2b5927a90bd2d5f3870078
This commit is contained in:
cassirer-openai authored and copyberry committed 2026-09-17 19:34:45 +00:00
1 parent 0a5b999169
commit 0fd1cd8d99
19 files changed
+619 -116

No files matched your search

@@ -76,6 +76,25 @@ fn lite_tool_catalog_and_code_calls_are_visible() {
assert!(rendered.contains("04:function_call_output:Wall time: <DURATION> seconds"));
}
#[test]
fn code_mode_timing_normalization_preserves_status_and_user_output() {
for status in ["Script completed", "Script failed", "Script terminated"] {
let text = format!(
"{status}\nWall time 1.000 seconds (code-mode 1.001 seconds; overhead -0.001 seconds)\nOutput:\nWall time 2.0 seconds"
);
assert_eq!(
Normalizer::default().text(
&text,
TextSource::Other,
&ContextSnapshotOptions::default(),
),
format!(
"{status}\nWall time <DURATION> seconds (code-mode <DURATION> seconds; overhead <DURATION> seconds)\nOutput:\nWall time 2.0 seconds"
),
);
}
}
#[test]
fn tool_outputs_show_only_their_own_names_and_namespaces() {
let items = [
@@ -109,17 +109,22 @@ impl Normalizer {
}
fn normalize_values(&mut self, text: &str) -> String {
// Tool calls report elapsed wall time in an otherwise stable output header.
let text = if text.starts_with("Script completed\nWall time ")
|| text.starts_with("Wall time: ")
{
// Tool calls report elapsed times in an otherwise stable output header.
let text = if text.starts_with("Script ") || text.starts_with("Wall time: ") {
static WALL_TIME: OnceLock<Regex> = OnceLock::new();
WALL_TIME
.get_or_init(|| {
Regex::new(r"(?m)^(Wall time:?) [0-9]+(?:\.[0-9]+)? seconds$")
Regex::new(r"(?m)^(Wall time:?) [0-9]+(?:\.[0-9]+)? seconds( \(code-mode [0-9]+(?:\.[0-9]+)? seconds; overhead -?[0-9]+(?:\.[0-9]+)? seconds\))?$")
.expect("tool wall time regex")
})
.replace(text, "${1} <DURATION> seconds")
.replace(text, |captures: &regex_lite::Captures<'_>| {
let prefix = &captures[1];
if captures.get(2).is_some() {
format!("{prefix} <DURATION> seconds (code-mode <DURATION> seconds; overhead <DURATION> seconds)")
} else {
format!("{prefix} <DURATION> seconds")
}
})
.into_owned()
} else {
text.to_string()