Bound rollout trace capture with configurable storage limits (#61896)

## What changed

- Add `rollout_trace.max_payload_bytes` and `rollout_trace.max_bytes`, defaulting to 64 MiB per body or separated value and 256 MiB per bundle. Root and child threads share the bundle budget.
- Record explicit truncations and omissions when limits are reached, reserve space for later events, and stop at the last complete event if the event log fills.
- Reuse identical prepared-prompt items and store inline images separately from message structure. Preserve exact JSON bytes for complete composite payloads and surviving content and links in partial captures.
- Let reducers handle partial payloads while retaining lifecycle information and reporting `closed_with_partial_payloads` for closed bundles with incomplete captures.

## Testing

Add coverage for payload reuse and byte-exact reconstruction, truncation, compressed bundle budgets, later events after omissions, readable prefixes after event-space exhaustion, and CLI capture-limit configuration and startup failures.

GitOrigin-RevId: be99a68da427414a7a12bf8209f232c1a0bbe545
This commit is contained in:
cassirer-openai
2026-11-16 22:26:31 +00:00
committed by copyberry
parent c0d47262f3
commit ef6ce8100a
23 changed files with 712 additions and 107 deletions
+32 -7
View File
@@ -34,7 +34,9 @@ async fn enabled_recording_cannot_silently_fail_to_start() -> Result<()> {
let codex = codex_utils_cargo_bin::cargo_bin("codex")?;
let home = TempDir::new()?;
let server = create_mock_responses_server_sequence(Vec::new()).await;
MockResponsesConfig::new(&server.uri()).write(home.path())?;
MockResponsesConfig::new(&server.uri())
.with_extra_config("[rollout_trace]\nmax_payload_bytes = 64")
.write(home.path())?;
let trace_root = home.path().join("traces");
std::fs::write(&trace_root, "file")?;
let mut app = TestAppServer::builder()
@@ -61,16 +63,39 @@ async fn enabled_recording_cannot_silently_fail_to_start() -> Result<()> {
std::fs::remove_file(&trace_root)?;
std::fs::create_dir(&trace_root)?;
app.start_thread(ThreadStartParams::default()).await?;
assert!(app.shutdown_gracefully().await?.success());
let mut bundles = std::fs::read_dir(trace_root)?;
let bundle = bundles.next().unwrap()?.path();
assert!(bundles.next().is_none());
assert_eq!(
reduce_with_recording_binary(&codex, home.path(), &bundle)
.await?
.recording_status,
codex_rollout_trace::RecordingStatus::Complete
// A separate root with a budget too small for its manifest must fail at startup.
let request_id = app
.send_thread_start_request_with_auto_env(ThreadStartParams {
config: Some([("rollout_trace".into(), json!({"max_bytes": 1}))].into()),
..Default::default()
})
.await?;
let error = app
.read_stream_until_error_message(RequestId::Integer(request_id))
.await?;
assert!(
error
.error
.message
.contains("manifest exceeds trace byte limit")
);
assert!(app.shutdown_gracefully().await?.success());
let trace = reduce_with_recording_binary(&codex, home.path(), &bundle).await?;
assert_eq!(
trace.recording_status,
codex_rollout_trace::RecordingStatus::ClosedWithPartialPayloads
);
assert!(trace.raw_payloads.values().any(|p| matches!(
p.capture,
codex_rollout_trace::PayloadCapture::Truncated {
retained_bytes: 64,
..
}
)));
Ok(())
}