{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://coding.sh/schema.json",
"title": "coding.sh/trace v0",
"description": "The coding.sh trace format: an AgentEvent (one normalized event) or a Session (the row ingest builds from a session's events). Validate one of them with #/$defs/AgentEvent or #/$defs/Session. Generated from packages/coding.sh/src/schema/index.ts by scripts/json-schema.ts.",
"anyOf": [
{
"$ref": "#/$defs/AgentEvent"
},
{
"$ref": "#/$defs/Session"
}
],
"$defs": {
"AgentEvent": {
"type": "object",
"properties": {
"id": {
"description": "Deterministic: sha256(agent, sessionId, source line/offset). Re-ingest is idempotent.",
"type": "string"
},
"v": {
"const": 0
},
"sessionId": {
"type": "string"
},
"turnId": {
"type": "string"
},
"parentId": {
"description": "Parent event (subagent or nested tool).",
"type": "string"
},
"ts": {
"description": "Milliseconds since epoch. For spans, the start time.",
"type": "number"
},
"durationMs": {
"description": "Wall time of the thing this event describes (tool call, model call, turn), when known.",
"type": "number"
},
"traceId": {
"description": "OpenTelemetry ids when the event came from (or is exported as) a span.",
"type": "string"
},
"spanId": {
"type": "string"
},
"parentSpanId": {
"type": "string"
},
"subagentId": {
"description": "Subagent this event belongs to, when the agent runs subagents inside one session.",
"type": "string"
},
"source": {
"description": "Capture path that produced the event, for cross-path dedupe: \"hook\" | \"transcript\" | \"otel-span\" | \"otel-log\" | \"wrapper\" | â¦",
"type": "string"
},
"agent": {
"$ref": "#/$defs/AgentId"
},
"agentVersion": {
"type": "string"
},
"model": {
"type": "string"
},
"kind": {
"$ref": "#/$defs/EventKind"
},
"cwd": {
"description": "Working directory the agent ran in.",
"type": "string"
},
"repo": {
"$ref": "#/$defs/RepoState"
},
"payload": {
"description": "Kind-specific, small (< 4 KB after normalization). Conventions:\n- user.message / assistant.message: { text }\n user.message also { from?: \"agent\" }: an agent sent the prompt, not the person (T3 Code's\n provider, MCP and server prompts, notifications, delegated results, other threads' messages).\n- llm.call: { provider?, requestModel?, responseModel?, ttftMs?, stopReason?,\n tokensPerSec?, ok, error? } â one model API call; durationMs on the event.\n durationMs, ttftMs and tokensPerSec are absent when the source does not show when\n the request went out (a transcript read from the middle of a response, lines written late)\n- subagent.start: { subagentId, type?, description?, prompt? }\n- subagent.end: { subagentId, ok?, result? (truncated), childSessionId? }\n- tool.start: { tool, toolUseId, input, server? (MCP server name) }\n- tool.end: { tool, toolUseId, ok, durationMs?, output? (truncated), cut? (the agent's\n harness cut the output before the model saw it: adapters/_shared/cut.ts OutputCut) }\n (both: wrapper? â a call that runs other tool calls, e.g. a Codex code-mode\n cell; its calls point at it by parentId and only they count in session stats)\n- file.change: { path, op: \"add\"|\"modify\"|\"delete\", additions?, deletions? }\n- test.result: { runner?, passed, failed, skipped? }\n- context.compact: { trigger: \"auto\"|\"manual\", tokensBefore? }\n- error: { message, source?, statusCode?, errorType?, errorClass?, rateLimitType?, retryAfterMs?, retryAttempt? }\n- session.end: { reason?, reportedUsage? (Claude Code's cost-state: costUsd, apiDurationMs, costUsdByModel) }\n- span: { name, attributes } â an OTel span with no better mapping\n- any kind: payload.reportedUsage = totals an agent span reports (not summed, avoids double counting)\n\nPairing keys (how consumers match the two halves of a span-like pair):\n- tool.start â tool.end: same sessionId + payload.toolUseId.\n- subagent.start â subagent.end: same sessionId + payload.subagentId (also on\n event.subagentId for events the subagent itself emits). The child's own\n session, when it has one, is named by childSessionId on either event and\n carries `session.start` payload { parentSessionId, subagentId, ⦠}.\n- llm.call has no pair: one event per model call, durationMs on the event.\n\nUsage convention: `usage` holds the tokens/cost of THIS event only, so\nsumming `usage` over a session's events gives its total. An event that\nmerely repeats a running or final total (an agent span, a session summary)\nputs it in payload.reportedUsage instead, never in `usage`.\nAnything larger is moved to a blob and referenced from `blobs`.",
"type": "object"
},
"blobs": {
"description": "Blob refs: full tool output, diffs, raw source payload (\"raw\" is always blobs[0] when kept).",
"type": "array",
"items": {
"$ref": "#/$defs/BlobRef"
}
},
"usage": {
"$ref": "#/$defs/Usage"
},
"runId": {
"description": "Run id when the event came from a coding.sh eval run (CODING_SH_RUN_ID).",
"type": "string"
},
"project": {
"description": "Project the event belongs to (`coding.sh serve` sets it from the ingest\nkey). Unset means \"default\", which is all local data.",
"type": "string"
}
},
"required": [
"id",
"v",
"sessionId",
"ts",
"agent",
"kind",
"payload"
],
"additionalProperties": false
},
"AgentId": {
"type": "string",
"examples": [
"claude-code",
"codex",
"opencode",
"cursor",
"gemini-cli",
"antigravity",
"copilot-cli",
"amp",
"pi",
"droid",
"goose",
"aider",
"devin",
"t3code",
"wrapper"
]
},
"BlobRef": {
"description": "sha256 hex of the uncompressed content.",
"type": "string"
},
"CacheBreakStats": {
"description": "Session.stats.cacheBreaks: model calls whose prompt prefix was no longer cached,\nso tokens read from cache on the previous call were billed again at the write\n(or full input) rate.",
"type": "object",
"properties": {
"count": {
"type": "number"
},
"lostTokens": {
"description": "Prompt tokens that were cached before the break and paid for again.",
"type": "number"
},
"extraUsd": {
"description": "USD the re-billing cost over cache-read prices; set only when every break's model has a price.",
"type": "number"
},
"byCause": {
"type": "object",
"properties": {
"compaction": {
"type": "object",
"properties": {
"count": {
"type": "number"
},
"lostTokens": {
"type": "number"
},
"extraUsd": {
"type": "number"
}
},
"required": [
"count",
"lostTokens"
],
"additionalProperties": false
},
"idle": {
"type": "object",
"properties": {
"count": {
"type": "number"
},
"lostTokens": {
"type": "number"
},
"extraUsd": {
"type": "number"
}
},
"required": [
"count",
"lostTokens"
],
"additionalProperties": false
},
"model-switch": {
"type": "object",
"properties": {
"count": {
"type": "number"
},
"lostTokens": {
"type": "number"
},
"extraUsd": {
"type": "number"
}
},
"required": [
"count",
"lostTokens"
],
"additionalProperties": false
},
"other": {
"type": "object",
"properties": {
"count": {
"type": "number"
},
"lostTokens": {
"type": "number"
},
"extraUsd": {
"type": "number"
}
},
"required": [
"count",
"lostTokens"
],
"additionalProperties": false
}
},
"additionalProperties": false
},
"byIdle": {
"description": "The idle breaks (byCause.idle) split by where the wait was. Unset when none was idle.",
"type": "object",
"properties": {
"wait": {
"type": "object",
"properties": {
"count": {
"type": "number"
},
"lostTokens": {
"type": "number"
},
"extraUsd": {
"type": "number"
}
},
"required": [
"count",
"lostTokens"
],
"additionalProperties": false
},
"subagent": {
"type": "object",
"properties": {
"count": {
"type": "number"
},
"lostTokens": {
"type": "number"
},
"extraUsd": {
"type": "number"
}
},
"required": [
"count",
"lostTokens"
],
"additionalProperties": false
},
"away": {
"type": "object",
"properties": {
"count": {
"type": "number"
},
"lostTokens": {
"type": "number"
},
"extraUsd": {
"type": "number"
}
},
"required": [
"count",
"lostTokens"
],
"additionalProperties": false
}
},
"additionalProperties": false
},
"unpriced": {
"description": "Breaks on models with no price (extraUsd is then left out).",
"type": "number"
}
},
"required": [
"count",
"lostTokens",
"byCause"
],
"additionalProperties": false
},
"CallTally": {
"description": "Session.stats.edits and Session.stats.shells: tool calls of one kind that ended, and how many of them failed for real.",
"type": "object",
"properties": {
"calls": {
"type": "number"
},
"failed": {
"description": "Calls that failed for real (core/failures.ts): not a shell command whose exit 1 is an answer\n(no match, a probe, files that differ), not a call the person stopped. Absent when none.",
"type": "number"
}
},
"required": [
"calls"
],
"additionalProperties": false
},
"CompactionRefetchStats": {
"description": "Session.stats.compactionRefetches: read-only calls that fetched again a result a\ncompaction took out of the context, with nothing written to it in between.",
"type": "object",
"properties": {
"calls": {
"description": "Reads after a compaction that matched a read from before it; each dropped result counts once.",
"type": "number"
},
"tokens": {
"description": "Estimated tokens those reads re-sent: output characters / 4.",
"type": "number"
},
"compactions": {
"description": "Compactions that at least one of those reads followed.",
"type": "number"
}
},
"required": [
"calls",
"tokens",
"compactions"
],
"additionalProperties": false
},
"CostByTokenType": {
"description": "USD by token type: cache reads, cache writes (1-hour writes included), uncached input and output.",
"type": "object",
"properties": {
"cacheRead": {
"type": "number"
},
"cacheWrite": {
"type": "number"
},
"input": {
"type": "number"
},
"output": {
"type": "number"
}
},
"required": [
"cacheRead",
"cacheWrite",
"input",
"output"
],
"additionalProperties": false
},
"DuplicateUsage": {
"description": "Usage a session did not count because another model call already covered it (a nested span, a repeated response id).",
"type": "object",
"properties": {
"calls": {
"type": "number"
},
"tokens": {
"type": "number"
},
"costUsd": {
"type": "number"
}
},
"required": [
"calls",
"tokens"
],
"additionalProperties": false
},
"DurableAttempt": {
"description": "One attempt of a durable workflow step (DurableStats.steps[].attempts). Times are ms since epoch.",
"type": "object",
"properties": {
"n": {
"description": "Attempt number: as the engine reported it, else by start order.",
"type": "number"
},
"startedAt": {
"type": "number"
},
"endedAt": {
"type": "number"
},
"ok": {
"type": "boolean"
},
"error": {
"type": "string"
},
"replay": {
"description": "The engine re-ran recorded history here; nothing under it is counted again.",
"type": "boolean"
},
"instance": {
"description": "Process that ran it (service.instance.id, faas.instance, host:pid).",
"type": "string"
},
"version": {
"type": "string"
},
"spanId": {
"description": "Span id, for linking to the timeline.",
"type": "string"
}
},
"required": [
"n",
"startedAt",
"endedAt",
"ok"
],
"additionalProperties": false
},
"DurableResume": {
"description": "A point where the run continued after a break: a crash, a deploy, a worker restart or a durable wait.",
"type": "object",
"properties": {
"at": {
"type": "number"
},
"reason": {
"enum": [
"crash",
"deploy",
"restart",
"wait"
]
},
"step": {
"description": "Step the run resumed at, and the span of the attempt that ran first.",
"type": "string"
},
"spanId": {
"type": "string"
},
"fromInstance": {
"type": "string"
},
"toInstance": {
"type": "string"
},
"fromVersion": {
"type": "string"
},
"toVersion": {
"type": "string"
},
"afterMs": {
"description": "How long the run was stopped before it resumed.",
"type": "number"
}
},
"required": [
"at",
"reason"
],
"additionalProperties": false
},
"DurableStats": {
"description": "One durable workflow run (Session.stats.durable), folded from the\npayload.durable tags the OTLP mapper puts on its spans (src/otel/durable.ts).",
"type": "object",
"properties": {
"engine": {
"type": "string"
},
"runId": {
"description": "The engine's run id.",
"type": "string"
},
"workflow": {
"type": "string"
},
"steps": {
"type": "array",
"items": {
"$ref": "#/$defs/DurableStep"
}
},
"stepCount": {
"description": "Steps in the run when `steps` keeps only some of them (retried, failed and unreported first).",
"type": "number"
},
"retries": {
"description": "Step attempts beyond each step's first, reported or not.",
"type": "number"
},
"failedAttempts": {
"type": "number"
},
"replays": {
"description": "Replayed spans seen (history re-run; not counted as new work).",
"type": "number"
},
"replayedCalls": {
"description": "Model calls under replay spans, left out of usage.",
"type": "number"
},
"waits": {
"type": "array",
"items": {
"$ref": "#/$defs/DurableWait"
}
},
"resumes": {
"type": "array",
"items": {
"$ref": "#/$defs/DurableResume"
}
},
"instances": {
"description": "Processes that worked on the run.",
"type": "number"
},
"wallMs": {
"description": "First to last activity of the run.",
"type": "number"
},
"activeMs": {
"description": "Time something ran: the union of step attempts, invocations and model/tool calls.",
"type": "number"
},
"waitMs": {
"description": "Time inside explicit durable waits.",
"type": "number"
},
"idleMs": {
"description": "wallMs â activeMs: waits, retry backoff, queueing and downtime.",
"type": "number"
}
},
"required": [
"engine",
"runId",
"steps",
"retries",
"failedAttempts",
"replays",
"waits",
"resumes",
"instances",
"wallMs",
"activeMs",
"waitMs",
"idleMs"
],
"additionalProperties": false
},
"DurableStep": {
"description": "A durable workflow step and its attempts, in start order.",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"id": {
"description": "Stable step id (step.id, activity id) when the engine gives one.",
"type": "string"
},
"attempts": {
"type": "array",
"items": {
"$ref": "#/$defs/DurableAttempt"
}
},
"unreported": {
"description": "Attempts the run made but never reported (a gap in attempt numbers, or time before the first reported attempt).",
"type": "number"
},
"unreportedMs": {
"description": "Time between scheduling and the first reported attempt, when an earlier attempt went unreported.",
"type": "number"
},
"unreportedRanMs": {
"description": "Of unreportedMs, how long the lost attempt's process was still seen working (to its last export); the rest is lost.",
"type": "number"
},
"ok": {
"type": "boolean"
}
},
"required": [
"name",
"attempts",
"ok"
],
"additionalProperties": false
},
"DurableWait": {
"description": "A durable sleep or wait for an event (not busy time).",
"type": "object",
"properties": {
"startedAt": {
"type": "number"
},
"endedAt": {
"type": "number"
},
"name": {
"type": "string"
}
},
"required": [
"startedAt"
],
"additionalProperties": false
},
"EventKind": {
"enum": [
"session.start",
"session.end",
"user.message",
"assistant.message",
"llm.call",
"tool.start",
"tool.end",
"context.compact",
"turn.end",
"subagent.start",
"subagent.end",
"file.change",
"test.result",
"notification",
"span",
"error"
]
},
"HookContextStats": {
"description": "Session.stats.hookContext: text hooks added to the model's context\n(`notification` events with `payload.kind: \"hook.context\"`), counted and\nsized (characters / 4), in all and by source: `plugin: