codex_rollout_trace/model/session.rs
1use serde::Deserialize;
2use serde::Serialize;
3
4use crate::raw_event::RawEventSeq;
5
6use super::AgentPath;
7use super::AgentThreadId;
8use super::CodexTurnId;
9use super::ConversationItemId;
10use super::EdgeId;
11
12/// Coarse terminal status for the rollout.
13#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
14#[serde(rename_all = "snake_case")]
15pub enum RolloutStatus {
16 /// Writer has not seen a terminal rollout event.
17 Running,
18 /// Rollout ended normally.
19 Completed,
20 /// Rollout ended because an operation failed.
21 Failed,
22 /// Rollout was cancelled or otherwise stopped before normal completion.
23 Aborted,
24}
25
26/// One Codex thread/session participating in the rollout.
27///
28/// Threads are agents in the multi-agent sense, but the root interactive
29/// session is represented by the same object. Runtime objects live in top-level
30/// maps and point back to their owning thread; only transcript order is stored
31/// here because compaction/reconciliation makes it semantic.
32#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
33pub struct AgentThread {
34 pub thread_id: AgentThreadId,
35 /// Stable routing identity. Viewer/search should prefer this over nickname.
36 pub agent_path: AgentPath,
37 /// Presentation hint. It can collide and must not be used as identity.
38 pub nickname: Option<String>,
39 pub origin: AgentOrigin,
40 /// Session lifecycle for this thread.
41 ///
42 /// Child threads can end independently from the root rollout, for example
43 /// after a parent calls `close_agent`. Keeping this on the thread prevents
44 /// those shutdowns from being mistaken for whole-rollout completion.
45 pub execution: ExecutionWindow,
46 /// Configured model presentation hint. Individual inference calls carry the actual upstream model.
47 pub default_model: Option<String>,
48 /// Logical conversation items first observed for this thread, in transcript order.
49 pub conversation_item_ids: Vec<ConversationItemId>,
50}
51
52/// Provenance for a traced Codex thread.
53#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
54#[serde(rename_all = "snake_case", tag = "type")]
55pub enum AgentOrigin {
56 Root,
57 Spawned {
58 parent_thread_id: AgentThreadId,
59 /// Interaction edge that carried the spawn task.
60 spawn_edge_id: EdgeId,
61 /// Stable path segment/task name selected by the parent/tool call.
62 task_name: String,
63 /// Selected agent role/type, for example `worker` or `explorer`.
64 agent_role: String,
65 },
66}
67
68/// Runtime interval for a typed trace object.
69///
70/// Wall-clock timestamps are for display and latency. Sequence numbers are the
71/// causal ordering primitive and should be used to pair observations or break
72/// same-millisecond ties.
73#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
74pub struct ExecutionWindow {
75 pub started_at_unix_ms: i64,
76 pub started_seq: RawEventSeq,
77 pub ended_at_unix_ms: Option<i64>,
78 pub ended_seq: Option<RawEventSeq>,
79 pub status: ExecutionStatus,
80}
81
82/// Coarse lifecycle status for a runtime object.
83#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
84#[serde(rename_all = "snake_case")]
85pub enum ExecutionStatus {
86 /// Object is still live or the trace ended before its terminal event.
87 Running,
88 /// Object completed successfully.
89 Completed,
90 /// Object reached an error state.
91 Failed,
92 /// Object was cancelled by user/policy/runtime before completion.
93 Cancelled,
94 /// Object was aborted when its owner/runtime stopped.
95 Aborted,
96}
97
98/// One activation of the Codex runtime for one thread.
99///
100/// A Codex turn groups protocol/runtime work for one thread activation.
101/// It is not a user/assistant message pair; conversation belongs in
102/// `ConversationItem`.
103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
104pub struct CodexTurn {
105 pub codex_turn_id: CodexTurnId,
106 pub thread_id: AgentThreadId,
107 pub execution: ExecutionWindow,
108 /// Conversation items that directly triggered this activation, when known.
109 pub input_item_ids: Vec<ConversationItemId>,
110}