[codex] Instrument rollout persistence bytes (#29498)

- Add 1%-sampled rollout persistence metrics that report per-item and
per-thread JSON byte totals before and after filtering when metrics
export is enabled.
- Tag each item with its exact response or event variant, including
nested turn-item kinds for conditionally persisted completion events, so
aggregate cloud-storage impact can be estimated by policy choice.
This commit is contained in:
Tom
2026-06-23 09:26:30 -07:00
committed by GitHub
Unverified
parent c553cea9ea
commit 02c326f646
7 changed files with 696 additions and 1 deletions
@@ -17,6 +17,8 @@ use crate::ResumeThreadParams;
use crate::ThreadStoreError;
use crate::ThreadStoreResult;
const ROLLOUT_SIZE_BYTES_METRIC: &str = "codex.rollout.size_bytes";
pub(super) async fn create_thread(
store: &LocalThreadStore,
params: CreateThreadParams,
@@ -128,8 +130,15 @@ pub(super) async fn shutdown_thread(
thread_id: ThreadId,
) -> ThreadStoreResult<()> {
let recorder = store.live_recorder(thread_id).await?;
let rollout_path = recorder.rollout_path().to_path_buf();
recorder.shutdown().await.map_err(thread_store_io_error)?;
sync_materialized_rollout_path(store, thread_id).await?;
if let Some(metrics) = codex_otel::global()
&& let Ok(metadata) = tokio::fs::metadata(rollout_path).await
{
let size_bytes = i64::try_from(metadata.len()).unwrap_or(i64::MAX);
let _ = metrics.histogram(ROLLOUT_SIZE_BYTES_METRIC, size_bytes, &[]);
}
store.live_recorders.lock().await.remove(&thread_id);
Ok(())
}