codex_rollout_trace/model/mod.rs
1//! Reduced rollout trace model.
2//!
3//! These types describe the deterministic replay output. They intentionally
4//! separate model-visible conversation from runtime/debug objects.
5
6use std::collections::BTreeMap;
7
8use serde::Deserialize;
9use serde::Serialize;
10
11use crate::payload::RawPayloadId;
12use crate::payload::RawPayloadRef;
13mod conversation;
14mod runtime;
15mod session;
16
17pub use conversation::*;
18pub use runtime::*;
19pub use session::*;
20
21/// Codex conversation/session UUID.
22pub type AgentThreadId = String;
23/// Stable multi-agent routing path such as `/root` or `/root/search_docs`.
24pub type AgentPath = String;
25/// Runtime submission/activation UUID. This is not a chat turn.
26pub type CodexTurnId = String;
27/// Reduced transcript item ID assigned by the trace reducer.
28pub type ConversationItemId = String;
29/// Local ID for one outbound upstream inference request.
30pub type InferenceCallId = String;
31/// Globally unique ID for one concrete MCP backend request.
32pub type McpCallId = String;
33/// Reducer-owned ID for one runtime tool-call object.
34pub type ToolCallId = String;
35/// Responses `call_id` / custom-tool call ID visible in inference payloads.
36pub type ModelVisibleCallId = String;
37/// Tool invocation ID assigned inside the code-mode JavaScript runtime.
38pub type CodeModeRuntimeToolId = String;
39/// Reducer-owned ID for one model-authored `exec` JavaScript cell.
40pub type CodeCellId = String;
41/// Process/session ID returned by Codex's terminal runtime.
42pub type TerminalId = String;
43/// Reducer-owned ID for one command/write/poll operation against a terminal.
44pub type TerminalOperationId = String;
45/// Reducer-owned ID for one installed conversation-history checkpoint.
46pub type CompactionId = String;
47/// Reducer-owned ID for one upstream request that computes a compaction.
48pub type CompactionRequestId = String;
49/// Reducer-owned ID for one information-flow edge.
50pub type EdgeId = String;
51/// Reducer-owned ID for request/log correlation metadata.
52pub type CorrelationId = String;
53
54/// Canonical reduced graph for one Codex rollout.
55#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
56pub struct RolloutTrace {
57 pub schema_version: u32,
58 /// Unique identity for this trace capture.
59 ///
60 /// `rollout_id` names the Codex rollout/session being observed. `trace_id`
61 /// names the diagnostic artifact produced for that rollout, which keeps
62 /// storage/replay identity separate from the product-level session identity.
63 pub trace_id: String,
64 /// CLI-visible rollout/run identity. Higher-level experiment/sample IDs wrap this object.
65 pub rollout_id: String,
66 pub started_at_unix_ms: i64,
67 /// Wall-clock timestamp for terminal rollout status. `None` means running or partial trace.
68 pub ended_at_unix_ms: Option<i64>,
69 pub status: RolloutStatus,
70 pub root_thread_id: AgentThreadId,
71 pub threads: BTreeMap<AgentThreadId, AgentThread>,
72 pub codex_turns: BTreeMap<CodexTurnId, CodexTurn>,
73 pub conversation_items: BTreeMap<ConversationItemId, ConversationItem>,
74 pub inference_calls: BTreeMap<InferenceCallId, InferenceCall>,
75 /// Model-authored `exec` JavaScript cells keyed by reducer-owned cell ID.
76 pub code_cells: BTreeMap<CodeCellId, CodeCell>,
77 pub tool_calls: BTreeMap<ToolCallId, ToolCall>,
78 /// Terminal runtime sessions keyed by process/session ID returned by the runtime.
79 pub terminal_sessions: BTreeMap<TerminalId, TerminalSession>,
80 /// Commands/writes/polls against terminals keyed by reducer-owned operation ID.
81 pub terminal_operations: BTreeMap<TerminalOperationId, TerminalOperation>,
82 /// Installed compaction checkpoints keyed by checkpoint ID.
83 pub compactions: BTreeMap<CompactionId, Compaction>,
84 /// Upstream remote compaction calls keyed by local request ID.
85 pub compaction_requests: BTreeMap<CompactionRequestId, CompactionRequest>,
86 /// Information-flow edges between threads, cells, tools, and runtime resources.
87 pub interaction_edges: BTreeMap<EdgeId, InteractionEdge>,
88 /// Raw JSON payloads keyed by raw-payload ID. Most point at files outside this object.
89 pub raw_payloads: BTreeMap<RawPayloadId, RawPayloadRef>,
90}
91
92impl RolloutTrace {
93 /// Builds an empty reduced trace that a reducer can populate.
94 pub(crate) fn new(
95 schema_version: u32,
96 trace_id: String,
97 rollout_id: String,
98 root_thread_id: AgentThreadId,
99 started_at_unix_ms: i64,
100 ) -> Self {
101 Self {
102 schema_version,
103 trace_id,
104 rollout_id,
105 started_at_unix_ms,
106 ended_at_unix_ms: None,
107 status: RolloutStatus::Running,
108 root_thread_id,
109 threads: BTreeMap::new(),
110 codex_turns: BTreeMap::new(),
111 conversation_items: BTreeMap::new(),
112 inference_calls: BTreeMap::new(),
113 code_cells: BTreeMap::new(),
114 tool_calls: BTreeMap::new(),
115 terminal_sessions: BTreeMap::new(),
116 terminal_operations: BTreeMap::new(),
117 compactions: BTreeMap::new(),
118 compaction_requests: BTreeMap::new(),
119 interaction_edges: BTreeMap::new(),
120 raw_payloads: BTreeMap::new(),
121 }
122 }
123}