aKode fase 5: rinomina interna (crate akode-*, akode-rs/, akode-cli/, binario akode, AKODE_*, ~/.akode, snapshot)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
208
akode-rs/rollout-trace/src/model/conversation.rs
Normal file
208
akode-rs/rollout-trace/src/model/conversation.rs
Normal file
@@ -0,0 +1,208 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::payload::RawPayloadId;
|
||||
use crate::raw_event::RawEventSeq;
|
||||
|
||||
use super::AgentPath;
|
||||
use super::AgentThreadId;
|
||||
use super::CodeCellId;
|
||||
use super::CodexTurnId;
|
||||
use super::CompactionId;
|
||||
use super::ConversationItemId;
|
||||
use super::EdgeId;
|
||||
use super::InferenceCallId;
|
||||
use super::ModelVisibleCallId;
|
||||
use super::ToolCallId;
|
||||
use super::session::ExecutionWindow;
|
||||
|
||||
/// One logical transcript item or transcript boundary.
|
||||
///
|
||||
/// The reducer builds conversation items primarily from inference request and
|
||||
/// response payloads. Runtime objects can be listed in `produced_by`, but they
|
||||
/// must not rewrite what the item body says the model saw. Structural items,
|
||||
/// such as compaction markers, live in the same ordered list so conversation
|
||||
/// views can show where the live history changed.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ConversationItem {
|
||||
pub item_id: ConversationItemId,
|
||||
/// Original Responses item ID, scoped to this thread. Retained for joining
|
||||
/// history acceptance and exact inference without matching rendered text.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub responses_item_id: Option<String>,
|
||||
/// Wall-clock time of the first local HistoryItemAccepted event in trace order.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub accepted_at_unix_ms: Option<i64>,
|
||||
/// Sequence of the same event for this Responses item in this thread.
|
||||
/// Seeing the item in inherited or prepared context is not an acceptance.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub accepted_seq: Option<RawEventSeq>,
|
||||
pub thread_id: AgentThreadId,
|
||||
/// Runtime activation that first introduced this item locally, when known.
|
||||
pub codex_turn_id: Option<CodexTurnId>,
|
||||
pub first_seen_at_unix_ms: i64,
|
||||
pub role: ConversationRole,
|
||||
/// Codex channel for assistant/tool content, when the item is channel-specific.
|
||||
pub channel: Option<ConversationChannel>,
|
||||
pub kind: ConversationItemKind,
|
||||
/// Routing metadata carried by a Responses `agent_message` item.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub agent_message: Option<AgentMessageMetadata>,
|
||||
pub body: ConversationBody,
|
||||
/// Protocol/model `call_id` for function/custom tool call and output items.
|
||||
pub call_id: Option<ModelVisibleCallId>,
|
||||
/// Runtime or control-plane objects that caused this conversation item to exist.
|
||||
pub produced_by: Vec<ProducerRef>,
|
||||
}
|
||||
|
||||
/// Sender and destination identities attached to a model-visible agent message.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct AgentMessageMetadata {
|
||||
/// Agent path that authored the message.
|
||||
pub author: AgentPath,
|
||||
/// Agent path that received the message.
|
||||
pub recipient: AgentPath,
|
||||
}
|
||||
|
||||
/// Model-visible role assigned to a conversation item.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ConversationRole {
|
||||
System,
|
||||
Developer,
|
||||
User,
|
||||
Assistant,
|
||||
Tool,
|
||||
}
|
||||
|
||||
/// Codex channel for model-visible content.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ConversationChannel {
|
||||
Analysis,
|
||||
Commentary,
|
||||
Final,
|
||||
/// Remote compaction summaries are reintroduced as assistant summary-channel content.
|
||||
Summary,
|
||||
}
|
||||
|
||||
/// Responses item category after normalization into the reduced transcript.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ConversationItemKind {
|
||||
Message,
|
||||
Reasoning,
|
||||
FunctionCall,
|
||||
FunctionCallOutput,
|
||||
CustomToolCall,
|
||||
CustomToolCallOutput,
|
||||
/// Structural marker inserted where live history was replaced by compaction.
|
||||
CompactionMarker,
|
||||
}
|
||||
|
||||
/// Ordered content parts for a reduced conversation item.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ConversationBody {
|
||||
/// Renderable model-visible parts. Raw payload refs are used when the bytes
|
||||
/// are too large or too structured for the normal conversation path.
|
||||
pub parts: Vec<ConversationPart>,
|
||||
}
|
||||
|
||||
/// One model-visible part inside a conversation item.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
pub enum ConversationPart {
|
||||
Text {
|
||||
text: String,
|
||||
},
|
||||
/// A model-provided summary of content whose full form may also be present.
|
||||
///
|
||||
/// Reasoning summaries are not interchangeable with raw reasoning text:
|
||||
/// both can be present in one payload, and replay/debug tooling needs to
|
||||
/// preserve which representation the model actually returned.
|
||||
Summary {
|
||||
text: String,
|
||||
},
|
||||
/// Opaque model-visible content that is intentionally not decoded here.
|
||||
///
|
||||
/// Reasoning can be carried as `encrypted_content` with no readable text.
|
||||
/// Keeping that blob inline makes it part of item identity, unlike a raw
|
||||
/// payload reference whose ID changes every time the same item is replayed
|
||||
/// in a later inference request.
|
||||
Encoded {
|
||||
label: String,
|
||||
value: String,
|
||||
},
|
||||
/// Small JSON-ish body represented by a summary plus a raw ref.
|
||||
Json {
|
||||
summary: String,
|
||||
raw_payload_id: RawPayloadId,
|
||||
},
|
||||
Code {
|
||||
language: String,
|
||||
source: String,
|
||||
},
|
||||
/// Large or uncommon payload that should be lazy-loaded from details UI.
|
||||
PayloadRef {
|
||||
label: String,
|
||||
raw_payload_id: RawPayloadId,
|
||||
/// Content identity across snapshots, independent of the containing payload file.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
content_sha256: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
/// Explanation for where a conversation item came from.
|
||||
///
|
||||
/// This is deliberately plural at the call site: a function output can be both
|
||||
/// model-visible conversation and the product of a runtime tool call.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
pub enum ProducerRef {
|
||||
UserInput,
|
||||
Inference { inference_call_id: InferenceCallId },
|
||||
Tool { tool_call_id: ToolCallId },
|
||||
CodeCell { code_cell_id: CodeCellId },
|
||||
InteractionEdge { edge_id: EdgeId },
|
||||
Compaction { compaction_id: CompactionId },
|
||||
Harness,
|
||||
}
|
||||
|
||||
/// One outbound inference request and its response metadata.
|
||||
///
|
||||
/// Full upstream request/response bodies live behind raw payload refs. The
|
||||
/// request/response item ID lists are the reduced, model-visible snapshot.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct InferenceCall {
|
||||
pub inference_call_id: InferenceCallId,
|
||||
pub thread_id: AgentThreadId,
|
||||
pub codex_turn_id: CodexTurnId,
|
||||
pub execution: ExecutionWindow,
|
||||
pub model: String,
|
||||
pub provider_name: String,
|
||||
/// Responses API response id, used by follow-up `previous_response_id` requests.
|
||||
pub response_id: Option<String>,
|
||||
/// Request id returned by HTTP/proxy/engine infrastructure.
|
||||
pub upstream_request_id: Option<String>,
|
||||
/// Complete ordered input snapshot sent with this request.
|
||||
pub request_item_ids: Vec<ConversationItemId>,
|
||||
/// Ordered output items produced by this response.
|
||||
pub response_item_ids: Vec<ConversationItemId>,
|
||||
/// Runtime tool calls whose model-visible call item came from this response.
|
||||
pub tool_call_ids_started_by_response: Vec<ToolCallId>,
|
||||
pub usage: Option<TokenUsage>,
|
||||
pub raw_request_payload_id: RawPayloadId,
|
||||
/// Full upstream response payload. `None` while running or after pre-stream failures.
|
||||
pub raw_response_payload_id: Option<RawPayloadId>,
|
||||
}
|
||||
|
||||
/// Token usage summary for one inference call.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct TokenUsage {
|
||||
pub input_tokens: u64,
|
||||
pub cached_input_tokens: u64,
|
||||
#[serde(default)]
|
||||
pub cache_write_input_tokens: u64,
|
||||
pub output_tokens: u64,
|
||||
pub reasoning_output_tokens: u64,
|
||||
}
|
||||
127
akode-rs/rollout-trace/src/model/mod.rs
Normal file
127
akode-rs/rollout-trace/src/model/mod.rs
Normal file
@@ -0,0 +1,127 @@
|
||||
//! Reduced rollout trace model.
|
||||
//!
|
||||
//! These types describe the deterministic replay output. They intentionally
|
||||
//! separate model-visible conversation from runtime/debug objects.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::payload::RawPayloadId;
|
||||
use crate::payload::RawPayloadRef;
|
||||
mod conversation;
|
||||
mod runtime;
|
||||
mod session;
|
||||
|
||||
pub use conversation::*;
|
||||
pub use runtime::*;
|
||||
pub use session::*;
|
||||
|
||||
/// Codex conversation/session UUID.
|
||||
pub type AgentThreadId = String;
|
||||
/// Stable multi-agent routing path such as `/root` or `/root/search_docs`.
|
||||
pub type AgentPath = String;
|
||||
/// Runtime submission/activation UUID. This is not a chat turn.
|
||||
pub type CodexTurnId = String;
|
||||
/// Reduced transcript item ID assigned by the trace reducer.
|
||||
pub type ConversationItemId = String;
|
||||
/// Local ID for one outbound upstream inference request.
|
||||
pub type InferenceCallId = String;
|
||||
/// Globally unique ID for one concrete MCP backend request.
|
||||
pub type McpCallId = String;
|
||||
/// Reducer-owned ID for one runtime tool-call object.
|
||||
pub type ToolCallId = String;
|
||||
/// Responses `call_id` / custom-tool call ID visible in inference payloads.
|
||||
pub type ModelVisibleCallId = String;
|
||||
/// Tool invocation ID assigned inside the code-mode JavaScript runtime.
|
||||
pub type CodeModeRuntimeToolId = String;
|
||||
/// Reducer-owned ID for one model-authored `exec` JavaScript cell.
|
||||
pub type CodeCellId = String;
|
||||
/// Process/session ID returned by Codex's terminal runtime.
|
||||
pub type TerminalId = String;
|
||||
/// Reducer-owned ID for one command/write/poll operation against a terminal.
|
||||
pub type TerminalOperationId = String;
|
||||
/// Reducer-owned ID for one installed conversation-history checkpoint.
|
||||
pub type CompactionId = String;
|
||||
/// Reducer-owned ID for one upstream request that computes a compaction.
|
||||
pub type CompactionRequestId = String;
|
||||
/// Reducer-owned ID for one information-flow edge.
|
||||
pub type EdgeId = String;
|
||||
/// Reducer-owned ID for request/log correlation metadata.
|
||||
pub type CorrelationId = String;
|
||||
|
||||
/// Canonical reduced graph for one Codex rollout.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct RolloutTrace {
|
||||
pub schema_version: u32,
|
||||
/// Unique identity for this trace capture.
|
||||
///
|
||||
/// `rollout_id` names the Codex rollout/session being observed. `trace_id`
|
||||
/// names the diagnostic artifact produced for that rollout, which keeps
|
||||
/// storage/replay identity separate from the product-level session identity.
|
||||
pub trace_id: String,
|
||||
/// CLI-visible rollout/run identity. Higher-level experiment/sample IDs wrap this object.
|
||||
pub rollout_id: String,
|
||||
pub started_at_unix_ms: i64,
|
||||
/// Wall-clock timestamp for terminal rollout status. `None` means running or partial trace.
|
||||
pub ended_at_unix_ms: Option<i64>,
|
||||
pub status: RolloutStatus,
|
||||
/// All recorder handles closed without a recorded write failure; not task success.
|
||||
#[serde(default)]
|
||||
pub recording_complete: bool,
|
||||
pub root_thread_id: AgentThreadId,
|
||||
pub threads: BTreeMap<AgentThreadId, AgentThread>,
|
||||
pub codex_turns: BTreeMap<CodexTurnId, CodexTurn>,
|
||||
pub conversation_items: BTreeMap<ConversationItemId, ConversationItem>,
|
||||
pub inference_calls: BTreeMap<InferenceCallId, InferenceCall>,
|
||||
/// Model-authored `exec` JavaScript cells keyed by reducer-owned cell ID.
|
||||
pub code_cells: BTreeMap<CodeCellId, CodeCell>,
|
||||
pub tool_calls: BTreeMap<ToolCallId, ToolCall>,
|
||||
/// Terminal runtime sessions keyed by process/session ID returned by the runtime.
|
||||
pub terminal_sessions: BTreeMap<TerminalId, TerminalSession>,
|
||||
/// Commands/writes/polls against terminals keyed by reducer-owned operation ID.
|
||||
pub terminal_operations: BTreeMap<TerminalOperationId, TerminalOperation>,
|
||||
/// Installed compaction checkpoints keyed by checkpoint ID.
|
||||
pub compactions: BTreeMap<CompactionId, Compaction>,
|
||||
/// Upstream remote compaction calls keyed by local request ID.
|
||||
pub compaction_requests: BTreeMap<CompactionRequestId, CompactionRequest>,
|
||||
/// Information-flow edges between threads, cells, tools, and runtime resources.
|
||||
pub interaction_edges: BTreeMap<EdgeId, InteractionEdge>,
|
||||
/// Raw JSON payloads keyed by raw-payload ID. Most point at files outside this object.
|
||||
pub raw_payloads: BTreeMap<RawPayloadId, RawPayloadRef>,
|
||||
}
|
||||
|
||||
impl RolloutTrace {
|
||||
/// Builds an empty reduced trace that a reducer can populate.
|
||||
pub(crate) fn new(
|
||||
schema_version: u32,
|
||||
trace_id: String,
|
||||
rollout_id: String,
|
||||
root_thread_id: AgentThreadId,
|
||||
started_at_unix_ms: i64,
|
||||
) -> Self {
|
||||
Self {
|
||||
schema_version,
|
||||
trace_id,
|
||||
rollout_id,
|
||||
started_at_unix_ms,
|
||||
ended_at_unix_ms: None,
|
||||
status: RolloutStatus::Running,
|
||||
recording_complete: false,
|
||||
root_thread_id,
|
||||
threads: BTreeMap::new(),
|
||||
codex_turns: BTreeMap::new(),
|
||||
conversation_items: BTreeMap::new(),
|
||||
inference_calls: BTreeMap::new(),
|
||||
code_cells: BTreeMap::new(),
|
||||
tool_calls: BTreeMap::new(),
|
||||
terminal_sessions: BTreeMap::new(),
|
||||
terminal_operations: BTreeMap::new(),
|
||||
compactions: BTreeMap::new(),
|
||||
compaction_requests: BTreeMap::new(),
|
||||
interaction_edges: BTreeMap::new(),
|
||||
raw_payloads: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
342
akode-rs/rollout-trace/src/model/runtime.rs
Normal file
342
akode-rs/rollout-trace/src/model/runtime.rs
Normal file
@@ -0,0 +1,342 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::payload::RawPayloadId;
|
||||
use crate::raw_event::RawEventSeq;
|
||||
|
||||
use super::AgentPath;
|
||||
use super::AgentThreadId;
|
||||
use super::CodeCellId;
|
||||
use super::CodeModeRuntimeToolId;
|
||||
use super::CodexTurnId;
|
||||
use super::CompactionId;
|
||||
use super::CompactionRequestId;
|
||||
use super::ConversationItemId;
|
||||
use super::EdgeId;
|
||||
use super::McpCallId;
|
||||
use super::ModelVisibleCallId;
|
||||
use super::TerminalId;
|
||||
use super::TerminalOperationId;
|
||||
use super::ToolCallId;
|
||||
use super::session::ExecutionWindow;
|
||||
|
||||
/// Runtime/debug object for one model-authored `exec` cell.
|
||||
///
|
||||
/// The JavaScript source and custom-tool outputs are still conversation items;
|
||||
/// this object tracks the code-mode runtime boundary and nested runtime work.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct CodeCell {
|
||||
/// Reducer-owned graph id derived from the model-visible `exec` call id.
|
||||
/// Runtime cell ids are stored separately because they are only handles for
|
||||
/// later waits and nested code-mode tools.
|
||||
pub code_cell_id: CodeCellId,
|
||||
pub model_visible_call_id: ModelVisibleCallId,
|
||||
pub thread_id: AgentThreadId,
|
||||
pub codex_turn_id: CodexTurnId,
|
||||
/// Conversation item containing the model-authored JavaScript.
|
||||
pub source_item_id: ConversationItemId,
|
||||
pub output_item_ids: Vec<ConversationItemId>,
|
||||
/// Raw code-mode runtime/session id, useful when matching runtime payloads.
|
||||
pub runtime_cell_id: Option<String>,
|
||||
/// Full JS-cell runtime window; yielded cells can outlive the initial custom call.
|
||||
pub execution: ExecutionWindow,
|
||||
pub runtime_status: CodeCellRuntimeStatus,
|
||||
pub initial_response_at_unix_ms: Option<i64>,
|
||||
pub initial_response_seq: Option<RawEventSeq>,
|
||||
pub initial_response_status: Option<CodeCellRuntimeStatus>,
|
||||
pub raw_initial_response_payload_id: Option<RawPayloadId>,
|
||||
pub raw_result_payload_id: Option<RawPayloadId>,
|
||||
pub yielded_at_unix_ms: Option<i64>,
|
||||
pub yielded_seq: Option<RawEventSeq>,
|
||||
pub source_js: String,
|
||||
pub nested_tool_call_ids: Vec<ToolCallId>,
|
||||
pub wait_tool_call_ids: Vec<ToolCallId>,
|
||||
}
|
||||
|
||||
/// Code-mode runtime lifecycle.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum CodeCellRuntimeStatus {
|
||||
/// The `exec` request has been accepted but the runtime has not yet started user code.
|
||||
Starting,
|
||||
/// Runtime is executing JavaScript and has not yet yielded or terminated.
|
||||
Running,
|
||||
/// Initial `exec` returned while JavaScript kept running in the background.
|
||||
Yielded,
|
||||
/// Runtime reached a normal terminal result.
|
||||
Completed,
|
||||
/// Runtime reached an error terminal result.
|
||||
Failed,
|
||||
/// Runtime was explicitly terminated.
|
||||
Terminated,
|
||||
}
|
||||
|
||||
/// Installed conversation-history replacement boundary.
|
||||
///
|
||||
/// Duration-bearing upstream requests live in `CompactionRequest`. This object
|
||||
/// is the checkpoint where replacement history became the live thread history.
|
||||
/// The boundary marker and the model-visible summary are separate conversation
|
||||
/// items: the marker says where history was replaced, while the summary is part
|
||||
/// of `replacement_item_ids` when the compact endpoint returned one.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Compaction {
|
||||
pub compaction_id: CompactionId,
|
||||
pub thread_id: AgentThreadId,
|
||||
pub codex_turn_id: CodexTurnId,
|
||||
pub installed_at_unix_ms: i64,
|
||||
/// Structural conversation item marking where pre-compaction history ended.
|
||||
pub marker_item_id: ConversationItemId,
|
||||
/// Upstream compaction request attempts that contributed to this checkpoint.
|
||||
pub request_ids: Vec<CompactionRequestId>,
|
||||
/// Logical conversation items present immediately before replacement.
|
||||
pub input_item_ids: Vec<ConversationItemId>,
|
||||
/// Replacement conversation items installed by the checkpoint.
|
||||
pub replacement_item_ids: Vec<ConversationItemId>,
|
||||
}
|
||||
|
||||
/// One upstream remote request made while computing a compaction checkpoint.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct CompactionRequest {
|
||||
pub compaction_request_id: CompactionRequestId,
|
||||
pub compaction_id: CompactionId,
|
||||
pub thread_id: AgentThreadId,
|
||||
pub codex_turn_id: CodexTurnId,
|
||||
pub execution: ExecutionWindow,
|
||||
pub model: String,
|
||||
pub provider_name: String,
|
||||
pub raw_request_payload_id: RawPayloadId,
|
||||
/// Full compaction response payload. `None` while running or after pre-response failures.
|
||||
pub raw_response_payload_id: Option<RawPayloadId>,
|
||||
}
|
||||
|
||||
/// Runtime operation requested by the model, a JS code cell, or Codex itself.
|
||||
///
|
||||
/// A `ToolCall` is not a chat transcript row. Model-visible call/output items
|
||||
/// link to it through `model_visible_*_item_ids`; runtime-only tools can have
|
||||
/// empty model-visible lists.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ToolCall {
|
||||
pub tool_call_id: ToolCallId,
|
||||
/// Globally unique MCP execution ID, when this tool reached an MCP backend.
|
||||
pub mcp_call_id: Option<McpCallId>,
|
||||
/// Model-visible protocol call ID, if the model directly requested this tool.
|
||||
pub model_visible_call_id: Option<ModelVisibleCallId>,
|
||||
/// Code-mode runtime's internal tool invocation ID, if this call came from JS.
|
||||
pub code_mode_runtime_tool_id: Option<CodeModeRuntimeToolId>,
|
||||
/// Cell started by this outer exec dispatch, if a matching cell was recorded.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub started_code_cell_id: Option<CodeCellId>,
|
||||
pub thread_id: AgentThreadId,
|
||||
/// Runtime activation that started the tool. Background work may outlive this turn.
|
||||
pub started_by_codex_turn_id: Option<CodexTurnId>,
|
||||
pub execution: ExecutionWindow,
|
||||
pub requester: ToolCallRequester,
|
||||
pub kind: ToolCallKind,
|
||||
pub model_visible_call_item_ids: Vec<ConversationItemId>,
|
||||
pub model_visible_output_item_ids: Vec<ConversationItemId>,
|
||||
/// Terminal operation started by this tool, when the tool touched a terminal.
|
||||
pub terminal_operation_id: Option<TerminalOperationId>,
|
||||
pub summary: ToolCallSummary,
|
||||
/// Original invocation at the Codex tool boundary.
|
||||
///
|
||||
/// Direct model tools store the model's function/custom call payload here.
|
||||
/// Code-mode nested tools store the JSON call made by model-authored JS.
|
||||
/// Runtime protocol events are deliberately kept separate below because
|
||||
/// they describe how Codex executed the request, not what the caller sent.
|
||||
pub raw_invocation_payload_id: Option<RawPayloadId>,
|
||||
/// Result returned to the immediate requester.
|
||||
///
|
||||
/// For direct tools this is the tool output item returned to the model; for
|
||||
/// code-mode nested tools this is the value returned to JavaScript.
|
||||
pub raw_result_payload_id: Option<RawPayloadId>,
|
||||
/// Runtime/protocol payloads observed while executing the tool.
|
||||
///
|
||||
/// Examples include exec begin/end, patch begin/end, and MCP begin/end
|
||||
/// events. Reducers can use these to build richer runtime objects such as
|
||||
/// terminal operations without overwriting the canonical invocation/result.
|
||||
pub raw_runtime_payload_ids: Vec<RawPayloadId>,
|
||||
}
|
||||
|
||||
/// Requester of a runtime tool.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
pub enum ToolCallRequester {
|
||||
Model,
|
||||
/// Model-authored JavaScript requested the tool through code-mode.
|
||||
CodeCell {
|
||||
code_cell_id: CodeCellId,
|
||||
},
|
||||
}
|
||||
|
||||
/// Runtime tool category.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
pub enum ToolCallKind {
|
||||
ExecCommand,
|
||||
WriteStdin,
|
||||
ApplyPatch,
|
||||
/// Resolved backend identity from an MCP runtime invocation. The callable
|
||||
/// namespace/name may differ and remain in the summary and raw invocation.
|
||||
Mcp {
|
||||
server: String,
|
||||
tool: String,
|
||||
},
|
||||
Web,
|
||||
ImageGeneration,
|
||||
SpawnAgent,
|
||||
AssignAgentTask,
|
||||
SendMessage,
|
||||
/// Multi-agent wait operation. Code-mode wait is modeled separately.
|
||||
WaitAgent,
|
||||
CloseAgent,
|
||||
Other {
|
||||
name: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// Bounded card/list summary for a tool call.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
pub enum ToolCallSummary {
|
||||
/// Tool is summarized by its terminal operation.
|
||||
Terminal { operation_id: TerminalOperationId },
|
||||
Agent {
|
||||
target_agent_path: AgentPath,
|
||||
/// Task name/path segment when the operation creates or targets a task.
|
||||
task_name: Option<String>,
|
||||
message_preview: String,
|
||||
},
|
||||
WaitAgent {
|
||||
/// Wait target, when narrower than "any child".
|
||||
target_agent_path: Option<AgentPath>,
|
||||
timeout_ms: Option<u64>,
|
||||
},
|
||||
Generic {
|
||||
label: String,
|
||||
input_preview: Option<String>,
|
||||
output_preview: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
/// One terminal process lifetime, including its command and subsequent polls.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct TerminalSession {
|
||||
pub terminal_id: TerminalId,
|
||||
pub thread_id: AgentThreadId,
|
||||
pub created_by_operation_id: TerminalOperationId,
|
||||
pub operation_ids: Vec<TerminalOperationId>,
|
||||
/// Terminal lifetime. This can outlive the operation that created it.
|
||||
pub execution: ExecutionWindow,
|
||||
}
|
||||
|
||||
/// One command/write/poll operation against a terminal session.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct TerminalOperation {
|
||||
pub operation_id: TerminalOperationId,
|
||||
/// Reduced session identity, distinct from the recyclable runtime process ID.
|
||||
pub terminal_id: Option<TerminalId>,
|
||||
pub tool_call_id: ToolCallId,
|
||||
pub kind: TerminalOperationKind,
|
||||
/// Operation execution window. This is not necessarily the terminal session lifetime.
|
||||
pub execution: ExecutionWindow,
|
||||
pub request: TerminalRequest,
|
||||
/// Runtime-observed terminal result. Model-visible output links through observations.
|
||||
pub result: Option<TerminalResult>,
|
||||
pub model_observations: Vec<TerminalModelObservation>,
|
||||
pub raw_payload_ids: Vec<RawPayloadId>,
|
||||
}
|
||||
|
||||
/// Terminal operation category.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TerminalOperationKind {
|
||||
ExecCommand,
|
||||
WriteStdin,
|
||||
}
|
||||
|
||||
/// Terminal request summary.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
pub enum TerminalRequest {
|
||||
ExecCommand {
|
||||
command: Vec<String>,
|
||||
display_command: String,
|
||||
cwd: String,
|
||||
yield_time_ms: Option<u64>,
|
||||
max_output_tokens: Option<usize>,
|
||||
},
|
||||
/// Request to interact with an existing terminal.
|
||||
WriteStdin {
|
||||
/// Bytes/text sent to stdin. Empty string means poll/read without writing bytes.
|
||||
stdin: String,
|
||||
yield_time_ms: Option<u64>,
|
||||
max_output_tokens: Option<usize>,
|
||||
},
|
||||
}
|
||||
|
||||
/// Terminal result observed by the runtime.
|
||||
///
|
||||
/// This is debugger/runtime output. It is not proof that the model saw the same
|
||||
/// bytes; link model-visible call/output items through `TerminalModelObservation`.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct TerminalResult {
|
||||
/// Process exit code. `None` if the process is still running or no exit status was produced.
|
||||
pub exit_code: Option<i32>,
|
||||
pub stdout: String,
|
||||
pub stderr: String,
|
||||
/// Tool runtime's formatted caller-facing output, when present.
|
||||
pub formatted_output: Option<String>,
|
||||
/// Token count before truncation, when the tool runtime reported it.
|
||||
pub original_token_count: Option<usize>,
|
||||
/// Streaming chunk ID, when this result was assembled from chunked terminal output.
|
||||
pub chunk_id: Option<String>,
|
||||
}
|
||||
|
||||
/// Conversation items that observed a terminal operation.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct TerminalModelObservation {
|
||||
pub call_item_ids: Vec<ConversationItemId>,
|
||||
pub output_item_ids: Vec<ConversationItemId>,
|
||||
pub source: TerminalObservationSource,
|
||||
}
|
||||
|
||||
/// Source of model-visible terminal observation.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TerminalObservationSource {
|
||||
DirectToolCall,
|
||||
CodeCellOutput,
|
||||
}
|
||||
|
||||
/// Directed information-flow relationship between trace objects.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct InteractionEdge {
|
||||
pub edge_id: EdgeId,
|
||||
pub kind: InteractionEdgeKind,
|
||||
pub source: TraceAnchor,
|
||||
pub target: TraceAnchor,
|
||||
pub started_at_unix_ms: i64,
|
||||
pub ended_at_unix_ms: Option<i64>,
|
||||
pub carried_item_ids: Vec<ConversationItemId>,
|
||||
pub carried_raw_payload_ids: Vec<RawPayloadId>,
|
||||
}
|
||||
|
||||
/// Information-flow edge category.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum InteractionEdgeKind {
|
||||
SpawnAgent,
|
||||
AssignAgentTask,
|
||||
SendMessage,
|
||||
AgentResult,
|
||||
CloseAgent,
|
||||
}
|
||||
|
||||
/// Typed pointer to one stable reduced-trace object.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
pub enum TraceAnchor {
|
||||
ConversationItem { item_id: ConversationItemId },
|
||||
ToolCall { tool_call_id: ToolCallId },
|
||||
Thread { thread_id: AgentThreadId },
|
||||
}
|
||||
111
akode-rs/rollout-trace/src/model/session.rs
Normal file
111
akode-rs/rollout-trace/src/model/session.rs
Normal file
@@ -0,0 +1,111 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::raw_event::RawEventSeq;
|
||||
|
||||
use super::AgentPath;
|
||||
use super::AgentThreadId;
|
||||
use super::CodexTurnId;
|
||||
use super::ConversationItemId;
|
||||
use super::EdgeId;
|
||||
|
||||
/// Coarse terminal status for the rollout.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum RolloutStatus {
|
||||
/// Writer has not seen a terminal rollout event.
|
||||
Running,
|
||||
/// Rollout ended normally.
|
||||
Completed,
|
||||
/// Rollout ended because an operation failed.
|
||||
Failed,
|
||||
/// Rollout was cancelled or otherwise stopped before normal completion.
|
||||
Aborted,
|
||||
}
|
||||
|
||||
/// One Codex thread/session participating in the rollout.
|
||||
///
|
||||
/// Threads are agents in the multi-agent sense, but the root interactive
|
||||
/// session is represented by the same object. Runtime objects live in top-level
|
||||
/// maps and point back to their owning thread; only transcript order is stored
|
||||
/// here because compaction/reconciliation makes it semantic.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct AgentThread {
|
||||
pub thread_id: AgentThreadId,
|
||||
/// Stable routing identity. Viewer/search should prefer this over nickname.
|
||||
pub agent_path: AgentPath,
|
||||
/// Presentation hint. It can collide and must not be used as identity.
|
||||
pub nickname: Option<String>,
|
||||
pub origin: AgentOrigin,
|
||||
/// Session lifecycle for this thread.
|
||||
///
|
||||
/// Child threads can end independently from the root rollout, for example
|
||||
/// after a parent calls `close_agent`. Keeping this on the thread prevents
|
||||
/// those shutdowns from being mistaken for whole-rollout completion.
|
||||
pub execution: ExecutionWindow,
|
||||
/// Configured model presentation hint. Individual inference calls carry the actual upstream model.
|
||||
pub default_model: Option<String>,
|
||||
/// Accepted model-visible conversation in transcript order. Unaccepted
|
||||
/// response items remain in the graph, reachable through their inference call.
|
||||
pub conversation_item_ids: Vec<ConversationItemId>,
|
||||
}
|
||||
|
||||
/// Provenance for a traced Codex thread.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
pub enum AgentOrigin {
|
||||
Root,
|
||||
Spawned {
|
||||
parent_thread_id: AgentThreadId,
|
||||
/// Interaction edge that carried the spawn task.
|
||||
spawn_edge_id: EdgeId,
|
||||
/// Stable path segment/task name selected by the parent/tool call.
|
||||
task_name: String,
|
||||
/// Selected agent role/type, for example `worker` or `explorer`.
|
||||
agent_role: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// Runtime interval for a typed trace object.
|
||||
///
|
||||
/// Wall-clock timestamps are for display and latency. Sequence numbers are the
|
||||
/// causal ordering primitive and should be used to pair observations or break
|
||||
/// same-millisecond ties.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct ExecutionWindow {
|
||||
pub started_at_unix_ms: i64,
|
||||
pub started_seq: RawEventSeq,
|
||||
pub ended_at_unix_ms: Option<i64>,
|
||||
pub ended_seq: Option<RawEventSeq>,
|
||||
pub status: ExecutionStatus,
|
||||
}
|
||||
|
||||
/// Coarse lifecycle status for a runtime object.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ExecutionStatus {
|
||||
/// Object is still live or the trace ended before its terminal event.
|
||||
Running,
|
||||
/// Object completed successfully.
|
||||
Completed,
|
||||
/// Object reached an error state.
|
||||
Failed,
|
||||
/// Object was cancelled by user/policy/runtime before completion.
|
||||
Cancelled,
|
||||
/// Object was aborted when its owner/runtime stopped.
|
||||
Aborted,
|
||||
}
|
||||
|
||||
/// One activation of the Codex runtime for one thread.
|
||||
///
|
||||
/// A Codex turn groups protocol/runtime work for one thread activation.
|
||||
/// It is not a user/assistant message pair; conversation belongs in
|
||||
/// `ConversationItem`.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct CodexTurn {
|
||||
pub codex_turn_id: CodexTurnId,
|
||||
pub thread_id: AgentThreadId,
|
||||
pub execution: ExecutionWindow,
|
||||
/// Conversation items that directly triggered this activation, when known.
|
||||
pub input_item_ids: Vec<ConversationItemId>,
|
||||
}
|
||||
Reference in New Issue
Block a user