/** * Where the wall time of one finished logical turn went, rebuilt from the * session event log. Pure: the store loads the turn, its attempts and a * content-free projection of its events, and this module turns them into * exclusive segments that add up to the turn's wall time, plus an ordered list * of steps (model requests, tool calls, sandbox operations, waits) with their * own start, end and duration. * * Bump the version whenever the attribution rules change; stored profiles keep * the version that computed them. */ export declare const TURN_TIMING_PROFILE_VERSION = 2; /** * Exclusive wall-time categories. Every millisecond between the turn's * creation and its finish lands in exactly one of them. * * - queue: accepted, not yet started by a worker. * - turn_start: the first attempt started, before its first model request, * tool or sandbox operation. * - dispatch: Opengeni work right before a model request reaches the provider. * - model_inference / model_provider_other / model_network: a model request * split by the provider's own server timing (engine time, the rest of the * provider's handling, and what remains of the request: transport and * network). * - model_unsplit: a successful model request whose provider reports no * server timing. * - model_stalled: a model request that failed, timed out or never finished. * - compaction: compacting the conversation's context inside the turn, from * its start until it was compacted or skipped, including its own model call. * - web_search: hosted web search inside a model request, and web tools. * - mcp_tool: tools served by a remote MCP server (custom or integration). * - sandbox_tool: shell, patch and code-mode tools that run in the sandbox. * - own_tool: every other first-party tool. * - sandbox_setup: sandbox lifecycle operations (provision, resume, ...). * - human_wait: waiting for an approval or an answer from a person. * - capacity_wait: waiting for provider capacity. * - after_model / after_tool: Opengeni time between steps, named by what came * before. * - recovery: between attempts, and before the first step of a later attempt. * - turn_end: after the last step until the turn was settled. */ export declare const TURN_TIMING_CATEGORIES: readonly ["queue", "turn_start", "dispatch", "model_inference", "model_provider_other", "model_network", "model_unsplit", "model_stalled", "compaction", "web_search", "mcp_tool", "sandbox_tool", "own_tool", "sandbox_setup", "human_wait", "capacity_wait", "after_model", "after_tool", "recovery", "turn_end"]; export type TurnTimingCategory = (typeof TURN_TIMING_CATEGORIES)[number]; export type TurnTimingSegments = Record; export type TurnTimingTurn = { createdAt: Date; startedAt: Date | null; finishedAt: Date; }; export type TurnTimingAttempt = { id: string; startedAt: Date; closedAt: Date | null; outcome: string | null; }; /** One session event with the content-free payload projection the store reads. */ export type TurnTimingEvent = { type: string; sequence: number; occurredAt: Date; attemptId: string | null; payload: Record; }; export type TurnTimingStepKind = "attempt" | "startup" | "model" | "tool" | "web_search" | "sandbox" | "compaction" | "human_wait" | "capacity_wait"; /** * One step of the turn. `ms` is its own duration; `exclusiveMs` is the part * of the turn's wall time attributed to it after overlaps (parallel tools * share time, a model request outranks the sandbox and tools, and so on). * Timestamps are ISO strings so products can join their own logs. */ export type TurnTimingStep = { kind: TurnTimingStepKind; start: string; end: string; ms: number; exclusiveMs?: number; category?: TurnTimingCategory; attemptId?: string; name?: string; callId?: string; family?: string; outcome?: string; requestId?: string; provider?: string; model?: string; purpose?: string; dispatchMs?: number; preDispatchMs?: number; inferenceMs?: number; providerOtherMs?: number; networkMs?: number; timeToFirstTokenMs?: number; }; export type TurnTimingProfile = { version: number; wallMs: number; segments: TurnTimingSegments; provider: string | null; attempts: number; modelRequests: number; toolCalls: number; steps: TurnTimingStep[]; }; /** Event types the store loads for a profile; everything else is ignored. */ export declare const TURN_TIMING_EVENT_TYPES: readonly ["turn.started", "turn.recovery.requested", "turn.capacity_waiting", "turn.startup.phase.completed", "agent.model.request", "agent.model.usage", "agent.toolCall.created", "agent.toolCall.output", "sandbox.operation.started", "sandbox.operation.completed", "sandbox.operation.failed", "session.context.compaction.started", "session.context.compacted", "session.context.compaction.skipped", "session.requiresAction", "user.approvalDecision", "session.humanInput.requested", "user.humanInputResponse", "codex.capacity.waiting", "codex.capacity.resumed", "codex.capacity.superseded"]; /** Closed tool family, recognising remote MCP tools whose family was not stamped. */ export declare function turnTimingToolFamily(toolFamily: string | null, name: string): string; export declare function turnTimingToolCategory(family: string, name: string): TurnTimingCategory; /** * Compute a turn's profile. Event timestamps are clamped into the turn's * lifetime (worker and database clocks may differ slightly), so the segments * always add up to the wall time. */ export declare function computeTurnTimingProfile(input: { turn: TurnTimingTurn; attempts: readonly TurnTimingAttempt[]; events: readonly TurnTimingEvent[]; }): TurnTimingProfile;