Run Tracesdoc/{zh,en}/design/traces/run-traces.md

Run Traces: One Base, Many Surfaces

简体中文 · Status: proposed, 2026-11-21, and checked against a real run (section 15). S1, S2, S2b, S3, S4a, S4b and S7 are built (section 17): the base with its rules, orquelo run trac

简体中文 · Status: proposed, 2026-11-21, and checked against a real run (section 15). S1, S2, S2b, S3, S4a, S4b and S7 are built (section 17): the base with its rules, orquelo run trace, the HTML page, /trace with its report for cards, trace_get, the times and outcomes recorded where they happen, what the model was given on each call, the steps around the calls, and the steps plugins run themselves and report. Since 2026-11-27 each model call records its context window, and the CLI finds what /trace finds. A traces.limits setting and naming an extension kind by the plugin's message key wait. It turns the research and the owner's decisions of 2026-11-21 into a design for slices S1–S4 and S7; ADR 0017 records its decisions. Aggregates and the daily report (S5, built) and scores and the judge (S6) are in run quality; the page aligned with dsh-context, with what is still to be recorded for it (S8, designed 2026-11-29; S8a to S8e built: the page in parts, its cards, context timeline and waterfall, clock times in the Host's zone on every surface, each request's sizes by text and kind with each tool's size and provider, the run's input and reply, its children, deliveries and budgets, and each model call's stream by kind), is in run insights.

1. Outcomes

  • ◆In a direct chat, /trace shows a summary of the person's last run in that chat, with the full trace attached as one HTML file. /trace <run> shows a given run. The summary names the slowest steps and the findings (research T1, T2).
  • ◆A trace covers the request from its birth (the Transport hands in the event) to its end (the final reply is sent), and the background work that follows.
  • ◆For every model call the trace shows what the model was given, zone by zone, and how it was built: which sources were asked and what each returned, what was cut and why, and what came from the cache (run context). Every tool call shows its arguments and its result.
  • ◆In a group, /trace is refused with trace.direct_only. A group run carries other people's messages, so only admins see it, and only in a direct chat (decision 1).
  • ◆On the Host, orquelo run trace -c CONFIG ID prints the same trace as text, JSON or the HTML file. An admin can also ask the agent, whose trace_get tool returns the trace.
  • ◆Every surface shows the same trace to the same viewer, because they all read it from one base (section 2), and new plugins, runtimes and channels appear in it without changes to the base (section 8).

2. One Base, Many Surfaces

text
 writers: engine, broker, interaction, delivery, the runtime's zone map, plugin span reports  →  records (section 10)
                                        │
                     trace base: internal/host/trace (the only reader of those records)
                     assembles the tree · authorizes the viewer · resolves content · applies the rules
                                        │
                  one exit: TraceReader.Build(run, viewer) → trace.v1
      ┌──────────────┬───────────┬──────────────┬────────────┬───────────────┬───────────────┐
  chat /trace     HTML file      CLI         agent tool    HTTP JSON      OTel exporter    daily report
  card or text    waterfall    text, JSON   budgeted JSON    (later)        (later)        (aggregates)
      │
  each channel's Presentation → Delivery (Feishu card, console text, HTTP notice)
  • ◆One exit. Every surface gets its data from TraceReader. No surface reads the trace's tables, so they cannot drift apart.
  • ◆The base owns data, the surfaces own display. The base assembles, authorizes and judges; it formats nothing, and its output holds codes and machine names, not sentences. Each surface turns trace.v1 into its own form and language.
  • ◆Channels are consumers. Feishu, the console and HTTP receive the chat surface's output through their Presentation like any notice. They add no trace logic, and a new channel needs nothing here.
  • ◆Authorization lives in the base, so every surface gives a viewer the same answer.
  • ◆A new surface needs no change to the base, only a consumer of trace.v1.

3. Call Chains

3.1 /trace in chat

text
Transport.Submit(event "/trace run_8f2c")
→ Host inbox (durable) → chat Trigger: directive /trace (P84 table) → Decision{Action: trace, Text: "run_8f2c"}
→ engine.traceView(connection, entry, conversation)                       the chat surface
   1. group conversation → notice trace.direct_only; log trace.refused{reason: direct_only}; stop
   2. run = the id given, else the newest run of this conversation
   3. t = TraceReader.Build(run, viewer{entry.Principal})                 the base: one read transaction
      not found or not allowed → the same notice trace.not_found; log trace.refused{reason}
   4. text = summary of t.View in message keys; file = the HTML surface's page of t → artifact
   5. Output{Kind: notice, Text: text, Artifacts: [file], Report: the same as data}
      → Presentation → items → Delivery.Enqueue and inbox.Mark(routed) in one transaction
→ Delivery sends, retrying the items only                                 log trace.viewed{run_id, viewer, surface, spans, findings, dur_ms}

3.2 The CLI

orquelo run trace -c CONFIG ID [-format text|json|html] [-o FILE] opens the store as run show does, calls Build with the operator as admin (the CLI runs on the Host, with its files), and prints the text tree, the JSON or the HTML surface's file. It finds what /trace finds (2026-11-27): it judges each model call by the context window the call recorded (section 9), and its baselines fold what is new first, as /trace's do (run quality, section 3). The fold's cursor makes that safe beside a running Host, so it needs no Host lock.

3.3 The agent

The admin plugin gains a read tool, trace_get {run, back, detail}. It calls a new Manager.Trace(ctx, cc, run, back); the Host takes the viewer from the call context it issued, and Build applies the usual rules. The result is trace.v1 JSON cut to a budget (findings and the slowest spans first), marked untrusted, because it holds people's text and tool output. Without run it reads the run before the calling one in the direct chat (trace.no_run when there is none), as /trace without an id reads the newest: nothing the agent sees names earlier runs, so it would have to guess an id (2026-11-30). When the request replies to one of the agent's messages, trace_get without run reads the run that sent it (the delivery whose receipt is the event's parent_id; Feishu passes a thread reply's parent too, though it quotes only another message, #79), so "this run" on a reply means that one (Feishu #295). back counts runs back in the same chat, 1 the previous: "the last two runs" are 1 and 2, never another chat's (Feishu #294). By default it returns a summary (totals, findings, scores, the start of the input and reply, one line per step, at most 150), as the whole trace passed 1 MB; detail: "full" returns the whole trace (Feishu #410).

3.4 HTTP

HTTP clients send /trace through POST /v1/messages and read the reply and its file like any notice. A JSON surface (GET /v1/runs/{id}/trace) waits until a client needs it.

4. Contract trace.v1

The types live in pkg/plugin/trace.go: the base produces them, and the surfaces, the Presentation plugins (Output.Report) and the admin tool consume them. The protocol schemas are regenerated from them.

json
{"version": "trace.v1", "run_id": "run_8f2c", "content": "full",
 "summary": {"state": "succeeded", "err_code": "", "born_at": "2026-11-21T01:30:00.000Z",
   "wall_ms": 48200, "active_ms": 11200, "ask_ms": 20300, "steps": 3,
   "tokens_in": 41200, "tokens_cached": 28000, "tokens_out": 1900, "cost_usd": 0.031, "priced": true},
 "spans": [
   {"id": "run", "kind": "run", "name": "run_8f2c", "start_ms": -6, "end_ms": 48200, "status": "ok",
    "events": [{"name": "steer", "at_ms": 20100}]},
   {"id": "s:2", "parent": "p:1", "kind": "step", "name": "2", "start_ms": 9300, "end_ms": 46900, "status": "ok"},
   {"id": "b:412", "parent": "s:2", "kind": "assemble", "name": "request", "start_ms": 9300, "end_ms": 9310,
    "status": "ok", "attrs": {"input_tokens": 14000, "first_changed_zone": "steps"}},
   {"id": "t:call_7", "parent": "s:2", "kind": "tool", "name": "fetch", "start_ms": 15400, "end_ms": 30300,
    "status": "ok", "attrs": {"provider": "fetch", "result_bytes": 18321}, "refs": {"result": "res:run_8f2c/call_7"}}],
 "findings": [{"code": "trace.slow_step", "severity": "warn", "spans": ["t:call_7"],
   "params": {"name": "fetch", "ms": 14900, "limit_ms": 10000}}],
 "truncated": false}

4.1 Span kinds

The root run span starts when the Transport hands in the event and ends when the final output's last delivery settles; its attempt children cover execution.

KindCoversFromRecorded today
eventan inbound event from submit to routed, with its attachment fetches as item childreneventsreceived and routed (S3); attachment fetches are item spans under the attempt that fetched them (S3)
routethe Trigger's decision: action, directive, skillroute.decideda fact, with the run it made (S4b)
queuewaiting for the conversation's active run or a workerruns, created to startedyes
run, attemptthe request, and one execution per start after a restart or requeuerunsyes; one attempt per run.started fact (S3)
setupthe session view, workspace resolution (P83), tool binding with MCP waits, the skillthe engineits time as setup_ms in run.started (S4b)
contextone context source call: instructions, recall, step context (P19), with items and outcomethe Host's provider callscontext.provided per source, with the items it could not give (S4b)
assemblebuilding one model request: zones, budgets, cuts, cache hints (section 5)the runtime's zone map, measured by the Hostyes for the built-in agent (S4a); budgets are not recorded yet, and cache hints were dropped for the cache key (run insights)
stepone loop iterationsession_entries.stepstep numbers; bounds derived
modelone model call; a fallback is its own spanmodel_callsyes; its step, its caller and the time to its first streamed output (S3); a call that returns only tool calls streams nothing, so it has no such time
toolone tool call, tool_search and load_skill includedtool_calls, tool.finishedstart in the table, end and outcome in the fact; a call refused before it runs has only its fact (S3)
hookone guard, hook or policy check at any stage (input, tool, step, completion, stop) and its decision: allow, deny, ask, withhold, rewriteguard.denied, hook.decideddeny and withhold as guard.denied, ask and rewrite as hook.decided; a check that lets a call through unchanged is not recorded (S4b)
reviewan approval decided by a reviewer pluginreview.decideda fact (S4b)
aska question, approval or sign-in waiting for a personinteractions, question.settledyes
compactionat run start (T2), within the run (P5) or /compact, with its model callcompaction.doneyes
subagenta child agent with its own steps; a merge child when its workspace is merged; a runtime run as a child (ADR 0013)subagent.finished; run_childrenend; its model calls name it as their caller (S3); runtime children (S7)
externalsteps a runtime ran itself and reported, such as Claude Code's model turns and tool uses (section 8)reported_spansreported, with the instance (S7)
x-<plugin>.<name>a plugin's own phase inside its call, such as a download (section 8)reported_spansreported, with the instance (S7)
presentrendering one output for a targetthe engine's presentoutput.presented (S3)
deliveryone target, with an attempt child per send and an item child per card or filedeliveries, delivery.senteach send as delivery.attempted; progress sends are instants on the run (S3)
backgroundwork that follows the run, outside its time: observers (memory learning) and evaluators (the judge), with their model callstheir dispatchbackground.done for observers handling run.finished; their model calls are audited with the run as bg:<instance>, outside its times and totals (S4b)

The enum is these kinds plus the child kinds item and merge, and x-<plugin>.<name> for spans a plugin reports (section 8).

4.2 Span events

Instants are events on a span (name, at_ms, attrs), not spans:

EventOnFrom
steerrunrun_steering.taken_at, with the event's id (built 2026-11-28, Feishu #262, as are reminder, retry, limit and recovered)
cancel_requestedrunruns.cancel_requested_at, the first request (S3)
progressrunprogress.sent (S3)
checkpointstepcheckpoint.saved, in the checkpoint's transaction (S3)
first_tokenmodelmodel_calls.ttft_ms (S3)
reminderstepreminder entries (P45), with the reminder's kind
cache_missmodelgiven as the finding trace.cache_miss instead (S4a)
retrymodelthe provider's retries in place, which it reports in ChatResponse.retries and the Host records as model.retried facts, also before an error
limitrunthe step limit (kind: steps, from its reminder) or the time limit (kind: time, a run.timeout end) was reached
recoveredattempta resume after a restart (run.recovered), with the call keys of the tool results the attempt replayed from the ledger (tool.replayed)

4.3 Rules of the contract

  • ◆Ids are stable: a kind prefix plus the key of the fact the span comes from, such as m:<model call id>, t:<call key>, b:<model call id> for its request, or d:<delivery id>/2 for a second attempt. Findings and scores cite them, and building again gives the same ids.
  • ◆Names are machine names: a tool's or model's name, a step number, a delivery's purpose. Surfaces put them into words through message keys.
  • ◆Times are milliseconds from the run's creation, so the event's birth is slightly negative; born_at is UTC. estimated: true marks bounds the base inferred rather than read: a step grouped from calls recorded before S3, or a refused call placed at its approval before S3. A model call's start is its recorded end minus its measured duration, which is read, not inferred.
  • ◆Active time is the attempts' time minus ask spans. runs.active_ms is not used: it counts only attempts left for a later goal round.
  • ◆Status: ok, error, denied, withheld, cancelled, unknown, or open for a run still running.
  • ◆Content is never in a span. refs point to it, and content says what the viewer may see: full or metadata. With full, surfaces resolve references through the base: the HTML file and the CLI show every tool call's arguments and result in full, re-indented and folded (a result over 64 KiB is cut, with its reference for the rest), and the agent tool gets previews of at most 2 KiB each. With metadata, surfaces show sizes only.
  • ◆Limits: at most 2,000 spans per trace. A cut keeps, in this order, the run, its attempts, every model span and its assemble span, then the steps, then the slowest of the rest, and sets truncated: true with the counts; a run whose steps alone pass the limit loses steps, not the request builds its findings cite (Feishu #274). The view for a model keeps 300 spans by the same order.
  • ◆Compatibility: new optional fields and new kinds keep trace.v1, because surfaces show a kind they do not know in a neutral style; a changed meaning becomes trace.v2.
  • ◆Output.Report: the summary as data: a title, numbers with their labels, and sections of lines, every string already in the output's locale. The chat surface builds it from trace.v1 with the same message keys as its text, so the base still emits no words; the TraceView once planned for the base was dropped. Presentations that lay out cards use it; one that ignores it shows Text, so every channel works without change. Feishu lays it out with the elements its other cards use: the title as the header, the numbers in bold, and each section under its title. A column layout waits until it can be tested against Feishu.

5. Context and Its Construction

What the model was given on each call, and how it was built, is designed in run context (ADR 0017, decision 3). The runtime declares a zone map with its decisions, and the Host measures each zone from the request it actually sends. model_inputs and context_texts keep it for every run, and surfaces show each zone formatted, with what changed since the previous call. In the trace each request is an assemble span, and each context source call a context span.

6. The Trace Base

internal/host/trace. Its exit is TraceReader.Build(ctx, runID, Viewer) (Trace, error): read only, one read transaction. It reads the run, its facts and the detail rows, assembles the tree, and applies the rules. Its providers sit behind narrow ports:

PortProviderReads or does
factsstore readerruns, events, observed_events, model_calls, model_inputs, tool_calls, interactions, deliveries, reported_spans, step numbers from session_entries
contentresolversession_entries, tool_calls results, prompt_texts, context_texts, only for full
rulesrule set (section 9)the assembled trace and its limits

The base owns no table, and every fact keeps its own writer. Facts and runs share the retention cutoff (retention, 30 days by default), so a trace lives as long as its run.

7. Surfaces

SurfaceConsumesShowsLives in
chat /tracetrace.v1, the HTML filea summary in message keys, the same as Output.Report for cards, and the filethe engine's directive handler, then each channel's Presentation
HTML filetrace.v1the waterfall, span details with each tool call's arguments and result, the context of each call formatted, the findingsinternal/host/trace/tracehtml: one self-contained page, inline styles and script, no network; the trace travels as JSON in a data block whose <, > and & are escaped, so no text can end it, and the page escapes every text it inserts
CLItrace.v1a text tree, JSON, the HTML fileinternal/cli
agent tooltrace.v1JSON cut to a budget, marked untrustedthe admin plugin, through Manager.Trace
HTTP JSON (later)trace.v1JSONhttpapi, through a TransportHost call
OTel exporter (later)trace.v1 spansspans with the GenAI namesan observer plugin
daily reportaggregates and top findingsmetadata onlyrun quality

The same run rendered by the HTML surface, from the real run of section 15: run-trace-example.html (generated; it opens offline in a browser).

8. How Extensions Join

Most of the trace needs nothing from a new plugin, because the Host mediates every call a plugin makes or receives:

AddedHow it reaches the traceWork for the extension
a model pluginevery call goes through the Host's caller: model spans with usage, and cost at its declared pricenone
a tool plugin, an MCP server, a skill's toolsthe broker runs every call: tool spans with outcome, duration and result references, and the hook and ask spans around themnone
a context sourcethe Host calls it: context spans with items, which the runtime's zone map citesnone
a guard, hook or reviewerthe Host runs it: hook and review spansnone
a channel (Transport, Presentation, Delivery)events, presentations and deliveries are Host records: event, present and delivery spans; /trace works through its Presentation, with Text as the fallbacknone; optionally a card layout for Output.Report
an observer or evaluatorthe Host dispatches it: background spans, with its model calls audited (S4)none
a runtime adapter (Claude Code, Codex, a workflow)its calls through RuntimeHost are recorded as above; the steps it runs itself it reportsmap its own events once to ReportSpans (built for Claude Code)
a plugin's own phasesit may report spans inside its call, such as an MCP tool's download and parseoptional ReportSpans
a surfaceit consumes trace.v1 from TraceReadernone in the base
a rulein the base today; later a rule role (input trace.v1, output findings with codes in the plugin's namespace, a timeout, skipped on failure)the rule plugin

Reported spans (S7, built), through ReportSpans of the optional host interface SpanReporter, which the hosts of runtimes and tool calls offer, and host/report_spans for process plugins:

  • ◆Parent: the Host attaches them under the call they were reported from: the attempt for the run's runtime, the tool call for a tool, the child's span for a runtime child. A plugin cannot reach another run or call.
  • ◆Shape: {kind, name, start, end, status, attrs}. kind is external for a runtime's steps, else x-<plugin>.<name>; a name is one line. Attribute keys are prefixed with the plugin's name and hold scalars of at most 200 characters; nothing carries content. References to artifacts wait for a plugin that needs them.
  • ◆Limits: at most 200 spans per call (plugin.MaxReportedSpans) and 2 KiB of attributes per span (plugin.MaxReportedAttrs). The trace clamps their times into the parent's interval, so a claim cannot stretch a span the Host measured. The spans that break a rule are refused and logged (trace.span_refused, a line per report) and the rest kept; the call goes on, and the plugin gets the refusal as an error.
  • ◆Trust: a reported span is marked reported_by its instance: it is the plugin's claim, not the Host's measurement, and surfaces show it as such: the page outlines it dotted and says so, the CLI adds reported by.
  • ◆Display: a surface shows external by its label and an extension kind by its raw name, in a neutral style; naming it by the plugin's message key <plugin>.span.<name> is not built. The built-in rules apply to built-in kinds only, and reported spans add nothing to the chat text, the totals or the slowest steps.
  • ◆Storage: reported_spans, written when the plugin reports, one transaction per report, and removed with the run and by sessions forget.
  • ◆Claude Code reports each model turn, from when its input was ready to its message's last line, and each tool use, with its name, times and whether it failed; also the steps before a cut-off, never content.
  • ◆Runtime children: a runtime the run ran as its child (ADR 0013) gets a subagent span from run_children, whose started_at is new, under the step that asked for it. Its calls, its reported usage and its reported steps nest inside it.

9. Findings

The rules start in the base (research, proposal 6), behind Rule{Code() string; Check(Trace, Limits) []Finding}, so a contract can move them to plugins later (section 8). A finding has a stable code, a severity (info, warn, error), the spans it cites and parameters; surfaces word it with the message key trace.finding.<code>.

CodeWhen
trace.slow_stepa tool or model span over its limit (defaults: tool 10 s, model 30 s); a tool call is also held to its tool's p95 (same tool and provider) over its tenant's last 7 days once the tool has 20 timed calls there, and the lower limit applies: the finding's basis is fixed or usual
trace.queue_waitthe queue span over 5 s
trace.human_waitan ask span over 10 min (info: not the system's time)
trace.model_retry, trace.fallbacka call was retried, or a fallback model answered
trace.tool_errora tool span ended error, denied or unknown
trace.repeat_callthe same tool with the same arguments three times or more
trace.step_limitthe run ended at its step limit
trace.output_cutoffa model call stopped at its output limit
trace.context_pressurethe last input used 80% or more of the declared window, or a compaction ran
trace.context_omitteda context source timed out or failed, or an item it could not give (such as an unreadable instruction file), with the reason
trace.context_slowa context source took over 2 s (S4b)
trace.context_cutitems were cut for a budget or a cap (not built: the zones show each cut item)
trace.cache_missa call after the run's first read less than half its input from the cache: names the first zone before the run's own steps that changed, or says the provider dropped its cache; none when the provider reports no cache reads (S4a)
trace.cache_below_usualthe run read under half as much of its input from the cache as its model usually does in its tenant (20 runs with input in the last 7 days)
trace.cost_outlierthe run cost over three times its runtime's p95 run cost in its tenant (20 priced runs in the last 7 days)
trace.delivery_retrya delivery took more than one attempt, or failed
trace.scores_unreadthe run's scores could not be read; the trace shows none of them, and the Host logs trace.scores_failed

The limits are these defaults, constants in the base; a traces.limits setting waits for an operator who needs other values. As built, trace.step_limit comes from the step-limit reminder in the transcript, and trace.context_pressure judges a call by the context window it recorded when it was made, so a later configuration change does not change an old run's findings; a call recorded before calls did (2026-11-27) is judged by its model's declared window now, which the chat surface and the agent tool know and the CLI does not, so the CLI skips the rule for it. A compaction shows as its own span. trace.cache_miss came with S4a, and trace.context_omitted and trace.context_slow with S4b. The rules that compare a run with its usual numbers came with the aggregates (run quality, section 3), on every surface, the CLI included.

10. Facts Completed at Their Writers

Appended migrations and facts. Each is written in the transaction that already commits its fact; a render, a progress send and an attachment fetch have no other record, so their fact is written on its own:

SliceTable or factNewWriter
S3tool.finishedan outcome (ok, error, denied), also for a call refused before it runs; a result a guard withheld is guard.denied with stage result and the call's keythe broker; the engine for refusals and guards
S3model_callsstep, caller (empty at the top level, else the sub-agent's key; a runtime names its own sub-agent on the request, ChatRequest.Caller, since 2026-11-29), ttft_ms (when the provider streams)the caller's audit
S3facts delivery.attempted, output.presented, progress.senteach send with its time and result; each render; each progress sendthe delivery service; the engine
S3events, runs, facts attachment.fetched, checkpoint.savedevents.routed_at, runs.cancel_requested_at; each fetch; each checkpoint (attempt starts were already run.started)the inbox, the run store, the engine
S4amodel_inputs, context_textseach call's measured zones, and each message and tool list once per person (section 5; built)the caller's audit, through internal/host/requests
S4bfacts route.decided, context.provided, hook.decided, review.decided, background.done; setup_ms in run.startedthe spans of section 4.1 that only logs had (built)their writers
S4bmodel_callsrows for background calls (BackgroundHost.Chat) with the run they followed and caller bg:<instance> (built)the background host
S7reported_spans; run_children.started_atspans plugins report (section 8); a runtime child's start (built)the Host, when the plugin reports; when the child starts
2026-11-27model_callscontext_window: the model's declared context window when the call was made, on the model span as context_window (built)the caller's audit

Tool ends, settlements and sends are already in the facts (tool.finished, question.settled, delivery.sent), so they need no new columns. Older rows stay as they are, and their spans keep estimated: true. A child run's parent waits for RunChild (external runtimes); today sub-agents run inside their parent's run.

11. Who Sees What

From decision 1 of 2026-11-21:

Run inThe person who askedAn adminAnyone else
a direct chateverything, in a direct chateverythingnothing
a groupnothing, since the run carries other people's messageseverything, in a direct chatnothing
  • ◆The viewer is the principal the Host verified. An admin is an admin of the run's tenant (identity.IsAdmin).
  • ◆"Not found" and "not allowed" give the same answer, so a run's existence does not leak.
  • ◆Zone texts follow the same rule: full viewers read them, metadata viewers see tokens and digests only.
  • ◆Secrets never appear: secret_env values are redacted where they are produced.
  • ◆A trace exists as long as its run: run retention (P49) and sessions forget (P105) remove it. The HTML file is stored with the traced run and goes with it.

12. Localization and Time

  • ◆Surfaces use message keys in zh-CN and en-US: summary lines, kinds, statuses, zone names, findings, and plugins' own keys for their spans. Durations, numbers and money are formatted for the locale.
  • ◆A new top-level timezone setting, one per Host (the owner's decision; an IANA name, by default the Host machine's zone), gives the zone for times on every surface. A name that is no zone is refused when the configuration loads, so a misspelled zone does not quietly show the machine's times. JSON stays in UTC. Nothing infers a time zone from a language.

13. Logging

EventFields
trace.viewedrun_id, viewer, surface (chat, tool; the CLI writes no Host log), spans, findings, dur_ms
trace.refusedrun_id, viewer, reason: direct_only, not_found
trace.no_previous_runviewer, surface (tool): trace_get without a run, in a chat with no run before the calling one
trace.build_failedrun_id, err
trace.scores_failedrun_id, err (WARN)
trace.render_failedrun_id, err; the summary is sent without the file
trace.zones_mismatchrun_id, model call id; the map is dropped, the call goes on
trace.span_refusedrun_id, instance, reason; the report is dropped, the call goes on

14. Failure and Recovery

CaseWhat happens
The store cannot be readnotice trace.unavailable and trace.build_failed; the inbox entry is marked routed and nothing else changes
The scores cannot be readthe trace is built without them, with the finding trace.scores_unread, and trace.scores_failed is logged
The HTML file fails to render or storethe summary goes alone, with a line saying the file is missing; trace.render_failed
The notice fails to sendthe delivery retries its items; the trace is not built again
The Host stops before the routing transaction commitsthe entry is still new; after the restart it is handled again, and building again is harmless (read only)
The Host stops after the committhe delivery is pending and is sent after the restart, once per item key
The run is still runningthe trace shows what is committed, with open spans
A zone map does not match its requesttrace.zones_mismatch; that call has no zone map; the call itself is unaffected
A zone text cannot be storedthe audit logs it and keeps the call's row; surfaces show the zone's size without its text
A plugin reports a span that breaks the rulestrace.span_refused; that span is dropped; the plugin's call is unaffected

15. Verification Against a Real Run (2026-11-21)

The design was checked against a real run: code c98f3bc, a scratch Host with the HTTP channel, kimi-for-coding, memory on GLM, localenv with shell_approval: true and a project AGENTS.md, and webfetch. Two requests went into one conversation. A throwaway script assembled the second into trace.v1 from a copy of the store and the debug log, and a second script rendered that one output as a zh-CN and an en-US page: the base and one surface of section 2. The page is run-trace-example.html.

PartWhat the run gaveSource
birth → route → queue → attempt → final reply sent−6 ms → 0 → 6 ms → 54,478 ms → 54,499 msthe store and facts
model calls4,867, 5,202 and 7,177 ms; 21,759 tokens in, 94% from the cache; first response after 1.4–2.0 sthe store; first response only in a debug log
toolstwo reads (16 and 31 ms); fetch refused (host not allowed); bash not approvedthe store and facts; the refused bash call only in the log
approval37.0 s waiting for a person, not active time (active: 17.5 s)the store and facts
contextmemory recalled one item; AGENTS.md applied (the answer cited its sources); within the run only steps changed, and tools and system matched the previous runlogs; instructions not recorded
backgroundmemory learning ended 10.2 s after the run, with a 5.9 s GLM callthe log only

What it changed in this design:

  1. Tool ends, settlements and sends are already in the facts, so S3 adds fewer columns.
  2. A tool call refused before it runs is not in tool_calls; S3 records its outcome.
  3. runs.active_ms counts only goal rounds; active time comes from the spans.
  4. Background model calls are not audited; S4 adds them, and the judge's cost depends on it (run quality).
  5. Progress messages are not delivery records; S3 adds progress events.
  6. The run-start context was gone after the run (its checkpoint cleared), which confirms S4's context_texts.
  7. The prototype base first wrote display names into its output; moving them to the surface let one output render in both languages, which is now a rule of the contract (section 4.3).

16. Acceptance (Proposed)

SliceCase
S1A recorded run (two model calls; three tool calls, one failing; one question; two deliveries, one failing) gives the expected trace JSON: ids, parents, times inside their parents, statuses, totals equal to model_calls. Every surface (CLI text, JSON, HTML) shows the same spans for the same viewer. -format html writes one file that opens with no network. A secret_env value appears nowhere.
S2In a direct chat, /trace shows the last run's summary and file in zh-CN and en-US; the slow tool and the failed delivery are found, each citing its span. In a group it is refused for everyone. Another person's run gives trace.not_found. An admin sees a group run's trace in a direct chat. The admin tool's result is marked untrusted. End to end: the console with a real model, and Feishu once its runner exists.
S3New runs have no estimated spans, deliveries show each attempt, and a refused tool call appears with its outcome. Each new value is written in its fact's transaction, so a failure rolls both back.
S4A run with a recalled item cut for budget, a context source that times out, deferred tools and a cleared tool result shows each in its zone with its state and reason. Zone tokens add up to the request's estimate. An instruction file changed between two runs makes instructions the first changed zone, with trace.cache_miss. A metadata viewer sees sizes but no text. The run-start text is readable after the run finished, and each zone shows formatted: messages by role, every tool call with its arguments and result. A background call appears with its model and duration.
S7A test plugin that reports spans inside its tool call sees them under that call, marked as reported; a span outside the call's interval is clamped; a span with an attribute outside its namespace, in another plugin's namespace or over the limits is refused with trace.span_refused while the call succeeds; a surface shows an unknown kind in the neutral style with its raw name; a Claude Code run shows its model turns and tool uses, and a failed one gives no finding.

17. Slices and Size

SliceContentLines (estimate, or built)
S1trace.v1 types, the base, the CLI surface, the HTML surface (built)1,103
S2/trace, the rules, trace_get (built)383
S2bOutput.Report and the Feishu report card (built)82
S3the new times and outcomes at their writers (built)339
S4athe zone map in the agent, model_inputs and context_texts, the context view (built)530
S4bthe new facts, the background audit, the context, route, setup, hook, review and background spans (built)244
S7ReportSpans, reported_spans, the Claude Code adapter's steps, runtime children's spans (built)398

S1 came to 1,103 lines against an estimate of 600, S2 to 383, S2b to 82, S3 to 339, S4a to 530, S4b to 244 and S7 to 398; the page itself is HTML and not counted. With S7 and main merged on 2026-11-26, production code is 81,763 lines. The owner raised the cap from 69k to 71k on 2026-11-21 for S2b–S4 and S7; with main's raises to 75k for the deep-review fixes and by 7k for the app-client protocol, the cap is 84k, which the owner confirmed on 2026-11-26. Run quality's S5 came to 1,263 lines; the 1.3k the owner allowed for run quality on 2026-11-26 was kept when it merged (cap 88.3k), and S6 needs a further raise.

18. Decisions

The owner decided on 2026-11-21:

  1. ADR 0017 records the base, the context record and reported spans (S7).
  2. Zone texts are kept for every run, and every surface shows them formatted, with each tool call's arguments and result.
  3. One timezone per Host.

On 2026-11-27:

  1. Each model call records its model's declared context window, and every surface judges context pressure by it. A call recorded before is judged by the declared window now where the surface knows it; the CLI skips the rule for it silently, and its other findings and exit status are unchanged.

Nothing is open here.