---
title: The record contract
description: 'What weft''s observability pipeline emits and what obsdb reads back: the four span kinds and their attributes, every weft.record log record kind with its fields and position, app log records, the identity chain, content values, the GenAI semantic conventions, the run row a reader derives, derived runs from stock spans, the run-level badges and the conformance fixtures.'
url: https://weftgo.dev/docs/reference/record-contract/
type: reference
sources:
  - 'W11-tag3, v0.20.2: weft/docs/record-contract.md:382-388 (weft.attempt.layer: a backup that reports its own attempts marks every request fallback, its retries included, U23.1-fix); weft/core/mw/model.go:27-30 (Fallback godoc, 0.20.2)'
  - 'W11-auditB1-fix, v0.20.2: weft/docs/record-contract.md:315-328 (event weft.repair); weft/core/layers.go:413-449 (RepairInfo.Kind words; the event''s keys; repairOriginalCap 4 KiB), 457-501 (Reporter.Repair: the event on the chat span, original only under the detail level with content on, original_cut only when cut); weft/otel/devdetail.go:10-26 (the original for Local and Studio with content on alone); weft/core/mw/repairjson.go:50-58 (mw.RepairJSON reports each repair)'
  - 'weft/docs/record-contract.md:88-90, 177 (weft.caller.remote, weft.flow), 260, 283 (invoke_agent: weft.caller.remote, weft.output.type), 395-412 (attempt: classified error.type, giveup_reason), 445-451 (execute_tool: the weft.panic event, args_repaired, origin, denied_by, error_masked, mcp_rpc_error), 462-485 (the layer span), 1728-1730 (the derived row''s session_id and turn)'
  - 'weft/CHANGELOG.md:35, 36, 38, 39, 40, 46 (0.20.0: the onion, MCP identity, the caller link, give-up, output type, flow), 74 (attempt error.type classified)'
  - 'weft/otel/options.go:104-123 (DevMode), 169-198 (DevDetail, dev-gated); weft/otel/pipeline.go:241-311, 931-960 (the gate, its WARNs and the DevMode INFO lines); weft/obsdb/request.go:93, 149, 167-168 (the gap and raw_off fixes name otel.DevMode()); weft/CHANGELOG.md:124 (0.19.0: DevMode), 35 (0.20.0: DevDetail)'
  - 'weft/docs/record-contract.md:85-89 (the identity links: parent, caller), 113-149 (caller links since 0.18.0)'
  - every path and line below is in the weft v0.17.0 tag (53bab77f), read from the weft-v0.17.0 worktree
  - docs/record-contract.md:1-44 (the authority, the pins, the contents)
  - 'studio/playground.go:367, 841-850 (actorOf: server, panel:<public id>, local), runtime/executor.go:1454-1456 (weft.playground.actor from the command''s actor)'
  - docs/record-contract.md:46-76 (§1 the transport)
  - docs/record-contract.md:78-180 (§2 the identity chain, Subagent children, lineage marks)
  - docs/record-contract.md:181-233 (empty = none, what lands in meta, the ClickHouse meta limit)
  - docs/record-contract.md:237-458 (§3 spans)
  - docs/record-contract.md:486-536 (§4 log records, the kinds table)
  - docs/record-contract.md:538-729 (event, delta, messages, request, prompt, tools, hashes)
  - docs/record-contract.md:731-885 (raw, compaction, heartbeat, weft.records.dropped, weft.logs.bridged)
  - docs/record-contract.md:887-934 (app log records, the slog bridge)
  - docs/record-contract.md:936-962 (§5 content policy)
  - docs/record-contract.md:971-1512 (§6 the run row, steps, run trees, sessions, manifests, user code)
  - docs/record-contract.md:1554-1617 (§7 badges and status words)
  - docs/record-contract.md:1629-1650 (§8 the GenAI semantic conventions)
  - docs/record-contract.md:1652-1886 (§9 deriving a run from stock spans)
  - docs/record-contract.md:1888-2008 (§10 the conformance fixtures, normalisation)
  - core/observe.go:44 (instrumentationName github.com/weftgo/weft/core)
  - core/agent.go:714-715 (the tracer and the records' logger under that name)
  - core/observe.go:53-105 (the weft.* span attribute keys)
  - core/observe.go:110-135 (the record attribute keys, event names, content values)
  - 'core/observe.go:218-223 (span names: <operation> <name>)'
  - core/observe.go:331 (run start line on the run's context)
  - core/observe.go:409-436 (run error and run finish lines)
  - core/observe.go:499-554 (chat span end attributes; model call line on the chat context)
  - core/observe.go:619-737 (execute_tool span attributes; tool call line on the tool context)
  - 'core/observe.go:917-949 (toolErrorType: code, timeout, panic, context error, ErrorType(), tool_error)'
  - core/observe.go:1197-1199 (severity INFO, WARN for an error tool_finish)
  - core/observe.go:1230-1252 (event record attributes; tool_finish carries its own event's seq)
  - core/report.go:364-481 (the attempt span and its attributes)
  - core/report.go:500 (model attempt line on the chat context)
  - core/request.go:33-51 (request, prompt, tools, compaction view keys and event names)
  - core/request.go:104-131 (the request body, prepared, messages_ref)
  - core/run.go:865-875 (the weft.override.* keys)
  - core/subagent.go:305 (Subagent)
  - core/run.go:223-232 (ResumeOf, RunID)
  - otel/pipeline.go:36 (the pipeline's logger name, github.com/weftgo/weft/core)
  - otel/pipeline.go:392 (defaultHeartbeat 10 s)
  - 'otel/tracker.go:185-217 (heartbeats: weft.record heartbeat, run_start''s string attributes, weft.logs.bridged)'
  - otel/proc.go:29-30 (weft.records.dropped, stripped)
  - otel/proc.go:120-229 (per-kind content policy, app logs, the priority tier and weft.records.dropped)
  - otel/proc.go:344-434 (shapeAppLog, stripEvent)
  - otel/slog.go:32-57 (bridge scope, weft.logs.bridged, weft.log.attrs_dropped, 120 attributes, ContentLog)
  - otel/slog.go:376-381 (severity = level + 9, held to 1-24)
  - thread/compactmarker.go:25-41 (the compaction marker, its event name and scope github.com/weftgo/weft/thread)
  - 'thread/compactmarker.go:288-334 (the marker''s attributes: scope, hash, weft.content none, metadata)'
  - 'obsdb/model.go:338-452 (nonMetaAttr: the keys meta never holds)'
  - 'obsdb/model.go:486-500 (MetaOf: string values outside the list, empty dropped)'
  - 'obsdb/model.go:502-517 (markerPos: a marker''s position from its hash)'
  - obsdb/db.go:440-459 (StatusWords, ParseStatus)
  - obsdb/db.go:480-606 (RunRow)
  - obsdb/db.go:523-527 (RunRow.PromptPreview)
  - 'obsdb/db.go:950-957 (SessionContentOff: not derived, not running, not settling)'
  - core/loop.go:139-139 (parent attributes from CallFromContext)
  - core/observe.go:1258-1259 (run_start's parent attributes)
  - core/observe.go:515-525 (ttft only when set; chat span status)
  - core/report.go:252-266 (ttft counts from the first TextDelta or ToolArgsDelta)
  - core/observe.go:760-775 (a denied call's span)
  - core/content.go:62-79 (StripContent empties reasoning_delta.text and tool_args_delta.args)
  - core/request.go:883-892 (a request record stripped by the core with capture off)
  - core/raw.go:111-122 (raw body fields, omitempty)
  - otel/pipeline.go:893 (the heartbeat logger carries no version)
  - thread/compactmarker.go:227-242 (the marker on the run's span context when the Session saw it)
  - obsdb/sqlite/write.go:831-836 (provider and model from the span, first non-empty)
  - obsdb/clickhouse/query.go:43 (max(Provider))
  - obsdb/stock.go:152-170 (what a derived run does not derive; a tool's step absent when no chat span preceded it)
  - obsdb/contract_test.go:83-254 (expect.json's keys)
  - studio/api.go:1756-1758 (derived for a replay view derived or unknown)
  - runtime/executor.go:1451-1452 (weft.public_id on playground runs)
  - 'CHANGELOG.md:295 (0.17.0: the run cards'' facts)'
  - 'CHANGELOG.md:323 (0.17.0 breaking: weft.override.params shape)'
  - obsdb/db.go:998-1049 (InterruptedAfter 30 s, DeriveStatus, DeriveSettling)
  - obsdb/tree.go:108-136 (TreeSpanCap, TreeTraceCap, TreeMissingCap, TreeRowCap, ChildRunsCap)
  - obsdb/problems.go:17-198 (Problems, RunErrorType, SpanProblems, CountProblems)
  - obsdb/request.go:570-591 (RequestsHole, RequestsHoleCause)
  - obsdb/stock.go:25-65 (StockErrNoDescription, the otel- prefix, StockRunID, ParseStockRunID)
  - obsdb/stock.go:94-138 (stockOp, IsStockRoot, StockCandidate)
  - 'obsdb/stock.go:406-491 (deriveRun: the derived row, step and seq stamps, usage)'
  - studio/ingest/ingest.go:40 (MaxBody 16 MiB)
  - studio/export.go:765-851 (the export's run holes, which §7's table matches)
  - studio/api.go:1718-1795 (the run document's holes)
  - 'studio/requests.go:192-202 (hidden: a read-scoped token''s request records)'
  - 'studio/api.go:2088-2166 (hidden: a run tree''s descendants outside a panel token''s public id)'
  - studio/auth.go:386-428 (hidden child holes)
  - 'obsdb/request.go:58-154 (CauseDevTokenOnly: hidden on routes that answer the dev token only)'
  - 'CHANGELOG.md:594 (0.15.0: docs/record-contract.md, pinned by obsdb/model.go and the fixtures)'
  - 'CHANGELOG.md:547-553 (0.15.0: derived runs, DeriveStockRuns)'
  - 'CHANGELOG.md:2904 (0.10.0: the compaction view in the record)'
  - 'CHANGELOG.md:2957 (0.10.0: the request, prompt and tools records)'
  - 'CHANGELOG.md:3256 (0.8.0: weft.playground read in its string spelling)'
  - 'CHANGELOG.md:338 (0.16.0: weft.resumed_from, weft.resume.calls, denied execute_tool spans)'
  - 'CHANGELOG.md:344 (0.16.0: weft.run.events, weft.run.messages, drop accounting)'
  - 'CHANGELOG.md:283 (0.17.0: the slog bridge)'
  - 'observed: a scratch program recorded a scripted thread turn with two tools, a tool error and a Subagent through otel.Start(ctx, otel.Local(path), otel.NoGlobal()) and read the spans, records, other_logs and runs tables back from SQLite; the attribute names, span ids and severities on this page match it'
  - 'weft v0.20.2: docs/record-contract.md:163-164 (weft.turn.parent, weft.session.branch), 434 (weft.tool.approved_by, weft.grant.id), 775-849 (thread: the scope, attributes, filing, held at Close and the 256 cap, one emitter per Session, an index not evidence; the body and content; the kinds table; stored as plain records, indexed by session), 1007 (caller_run_id: fill-if-empty, empty for a remote caller, RunQuery.CallerRunID, no backfill); weft/CHANGELOG.md:224 (0.18.0: the state log as OTel records, otel.ContentThread, obsdb.RecordThread), 227 (0.18.0: the session timeline index)'
---

# The record contract

weft's observability pipeline sends every run as OpenTelemetry **spans** and **log records**, and [`obsdb`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb) reads them back into a run. This page lists every span kind and attribute, every `weft.record` kind with its fields and position, the identity chain that joins them, the content values, the GenAI conventions weft writes, the run row a reader derives, and how Studio builds a run from stock GenAI spans. Use it to query weft data in your own backend, or to make a non-Go agent emit records Studio reads as its own.

The authority is weft's [`docs/record-contract.md`](https://github.com/weftgo/weft/blob/v0.20.2/docs/record-contract.md) at v0.20.2. This page restates it and checks it against the code. Where they disagree, this page follows the code and says so in a note. `obsdb/model.go` and `TestRecordContractDocNames` pin the names: the test fails when the contract names a `weft.*` or `gen_ai.*` key no emitter or reader spells. A change to a name, a kind or a rule is a schema change that needs an ADR amendment and regenerated fixtures. How to send the records somewhere is in [Use your own OpenTelemetry SDK](https://weftgo.dev/docs/observe/opentelemetry/) and [Record every run](https://weftgo.dev/docs/observe/recording/).

<span id="overview"></span>
## What the contract covers

| Section of `docs/record-contract.md` | On this page |
|---|---|
| The record contract (intro) | This page's opening and [Conformance fixtures](#conformance-fixtures) |
| 1. The transport | [Transport](#transport) |
| 2. The identity chain | [Identity chain](#identity-chain) |
| 3. Spans: `invoke_agent`, `chat`, `attempt`, `execute_tool` | [Spans](#spans) |
| 4. Log records: `event` and `delta`, `messages`, `request`/`prompt`/`tools`, `raw`, `compaction`, `heartbeat` | [Log records](#log-records) |
| App log records, the slog bridge | [App log records](#app-log-records) |
| 5. Content policy | [Content policy](#content-policy) |
| 6. The run row: what a reader derives | [The run row](#the-run-row) |
| 7. Badges | [Badges](#badges), and [Badges and holes](https://weftgo.dev/docs/reference/badges/) |
| 8. The GenAI semantic conventions | [GenAI semantic conventions](#genai-conventions) |
| 9. Deriving a run from stock spans | [Deriving a run from stock spans](#deriving-a-run-from-stock-spans) |
| 10. The conformance fixtures | [Conformance fixtures](#conformance-fixtures) |

The contract document arrived in 0.15.0 as one spec. Before that, ADR 0016 (spans), ADR 0024 (records, identity) and ADR 0028 (the request record, the compaction view, the badges) held it; they keep the reasons.

<span id="transport"></span>
## The transport

| Item | Rule |
|---|---|
| Signals | Spans through the trace API, log records through the Logs API, exported as OTLP |
| Studio's receiver | `POST /v1/traces` and `POST /v1/logs`, OTLP/HTTP protobuf or JSON, optionally gzip, at most 16 MiB decompressed per request |
| Ids on OTLP/JSON | Lowercase hex: `traceId` 32 digits, `spanId` 16 |
| What is weft's | A span or record that carries `weft.run.id`. Anything else is stored as it came: other spans appear in the trace view, other log records become the run's app logs when they share its spans. They never become a run, except by [derivation](#deriving-a-run-from-stock-spans) |
| Integer values | A reader accepts an int, a double or a decimal string. Run metadata is stamped as strings, so `weft.turn` arrives as `"3"` |
| Boolean flags | `true` or the string `"true"`. `weft.playground` arrives as `"true"`; readers take that spelling since 0.8.0 |
| Resource | `service.name` (the run row's `service`) and `weft.version` (the framework release that built the pipeline) |
| Instrumentation scope | `github.com/weftgo/weft/core` for spans, weft records and heartbeats, with the core's version for spans and weft records; heartbeats, the thread marker and bridged lines carry no scope version. A `thread` compaction marker comes from `github.com/weftgo/weft/thread`; a bridged slog line from `github.com/weftgo/weft/otel/slog` |
| Trace and span ids | Correlation, not identity: zero without an SDK, missing when sampled out. Every join is on a weft id |

**Contract and code.** The contract document names the records' logger `github.com/weftgo/weft` (record-contract.md:358-359); the code names it `github.com/weftgo/weft/core` (core/observe.go:44, core/agent.go:715), as the contract's own §1 says (record-contract.md:69). The same §1 gives one scope for everything; the compaction marker's is `github.com/weftgo/weft/thread` (thread/compactmarker.go:41).

## Identity chain

Every span and record of a run carries these attributes. The run's [metadata](https://weftgo.dev/docs/guides/metadata/) rides every span and record verbatim.

| Link | Attribute | Type | Minted by | Notes |
|---|---|---|---|---|
| run | `weft.run.id` | string | the core | 32 lowercase hex digits for a plain run; `<session>-t<n>` for a `thread` turn; `<parent>/<step>/<call id>` for a Subagent child; or your own through [`weft.RunID`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#RunID). Do not start your own with `otel-`, the derived-run prefix: nothing enforces it, and an id of the exact shape `otel-<32 hex>-<16 hex>` would be read as a derived run's |
| parent run | `weft.parent.run.id` | string | the core | On the `invoke_agent` span and `run_start` record of a `core.Subagent` child only |
| parent call | `weft.parent.call.id` | string | the core | The parent's tool call the child ran under (its `gen_ai.tool.call.id`) |
| caller run | `weft.caller.run.id`, `weft.caller.call.id` | string | the core | Since 0.20.0 also on a run started on a context [`weft.WithCaller`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#WithCaller) named, with `weft.caller.remote` `"true"`. That caller is in another process, such as an MCP client under `mcp.CallerMeta` ([Link a served run to its caller](https://weftgo.dev/docs/guides/mcp/#link-a-served-run-to-its-caller)). Readers never place a run by a remote link: the run stays top-level, and obsdb leaves its `caller_run_id` empty. Since 0.18.0, on any other run started on a tool call's context: a `thread/pool` child session's turn, another agent's `Generate` in a handler (whose id stays random), a run under a Subagent child's own tool call. A link, not parenthood. A run started inside a run's machinery (its model chain, `PrepareStep`, a tap, `OnRunEnd`) carries neither. Before 0.18.0 these runs carried `weft.parent.*` |
| session | `weft.session.id` | string | `thread`, or the app through metadata | Mirrored as `gen_ai.conversation.id` and `session.id` on every span and record the core emits, and on heartbeats; not on the compaction marker |
| turn | `weft.turn` | int, as a string | `thread` | The turn number the run id was minted from |
| public id | `weft.public_id` | string | [`thread.PublicID`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/thread#PublicID), `weft/runtime` (playground runs), or the app | The browser-facing id a panel token is scoped to |
| agent | `gen_ai.agent.name` | string | the core | Absent for an unnamed agent |
| agent config | `weft.manifest.hash`, `weft.version` | string | the core | On the `invoke_agent` span and the `run_start` record |
| step | `weft.step.index` | int | the core | 0-based model-call ordinal within the run |
| tool call | `weft.tool.seq`, `gen_ai.tool.call.id` | int, string | the core | On the span and the `tool_start` record, `weft.tool.seq` is the `tool_start` event's `seq` |
| event, delta | `weft.event.pos`, `weft.delta.pos` | int | the core | Two separate counters |
| end user | `enduser.id`, mirrored as `user.id` | string | the app through metadata | Attribution, not part of the chain |
| flow | `weft.flow` | string | [`scope.Header`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/scope#Header) (the scope's flow, else the request's own `Weft-Scope`), `scope.WithFlow`, or the app through metadata | Since 0.20.0. Studio's `flow=` filters on it (runs, sessions, search, traces, live), and the devtools panel narrows its list by it. A flow narrows a view, never grants one. A scope's `tag.<k>=<v>` pairs are read the same way, as metadata the caller wrote; a tag scope, such as a panel token minted with tags, is only as tight as the app's own tagging |

**Contract and code.** The contract puts the parent attributes on a Subagent child's span and `run_start` only (record-contract.md:86, 88). The code stamps both whenever the run's context holds a tool call (core/loop.go:139-139, core/observe.go:1258-1259), so a plain `Generate` started inside a tool handler carries them too, under its own random 32-hex id.

**Contract and code.** The contract says `weft.tool.seq` is the `tool_start` event's `seq` everywhere (record-contract.md:95, 435). The code stamps a `tool_finish` record with the `tool_finish` event's own `seq` (core/observe.go:1250): in one scratch run, for illustration, a call's span and `tool_start` carried 1 and its `tool_finish` 3; the numbers depend on the run. Pair a finish with its start on `gen_ai.tool.call.id`, not on `weft.tool.seq`.

**Subagent children.** A [`weft.Subagent`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#Subagent) tool runs a child with the id `<parent run id>/<step>/<call id>`, or `<parent run id>/resume/<call id>` when the call ran under `Approve`. Studio's cost split subtracts exactly those children's usage from the parent's, because the parent's own usage includes every child's. The link is still explicit (`weft.parent.run.id`, `weft.parent.call.id`), and a reader never parses an id to find a parent. The child's `invoke_agent` span is a child of the parent's `execute_tool` span. A `thread/pool` child is a separate session: no `/` in its id, no parent attributes, linked by session metadata.

### Session lineage and playground marks

These are run metadata, so they are strings on every span and record of the run. The last column says where a reader puts each: a run-row column, or the row's `meta` map.

| Attribute | Set by | Meaning | Run row |
|---|---|---|---|
| `weft.session.title` | `thread` (`SetInfo`'s title) | The session's title as the turn started; absent before one is set. A label, not content: it survives a content-off destination. A fork carries the newest title on the copied path | `meta`; the session row's `title` |
| `weft.session.forked_from` | `thread` (`Fork`) | `<origin session>#<entry id>` | `meta` |
| `weft.session.parent` | `thread/pool` | The parent session of a pool child | `meta` |
| `weft.session.parent_call` | `thread/pool` | The parent's tool call that spawned it, when known | `meta` |
| <span id="weft-turn-parent"></span>`weft.turn.parent` | `thread` | Since 0.18.0, the turn whose line this turn continues (its `weft.turn`), set only when that is not the session's newest turn: the first turn after a navigation (`Branch`, `Uncompact`, a rollback, an overflow re-run's branch-back) took the leaf off the newest line. `"0"` when the line it continues holds no turn; absent for a linear turn | `meta` |
| <span id="weft-session-branch"></span>`weft.session.branch` | `thread` | Since 0.18.0, the branch the turn's line descends from: the label (`Label`) on the entry the newest navigation on its path went to, else that navigation's leaf entry id. On every turn of that line; absent on a line no navigation made. A failed send's leaf move back (`LeafEntry.Abandoned`) is no navigation | `meta` |
| `weft.playground` | `weft/runtime` | `"true"` on a run Studio's playground started; never part of a session | column `playground` |
| `weft.playground.command` | `weft/runtime` | The playground command id | `meta` |
| `weft.playground.actor` | `weft/runtime` | Who issued the command, from the caller's identity at `POST /api/playground/runs`: `server` (the server token), `panel:<public id>` (a panel token) or `local` (setup A's open API) | `meta` |
| `weft.playground.breakpoints` | `weft/runtime` | The tool names a playground run parks at, comma-joined and sorted: a `park_on` park named there reads as a breakpoint, not an approval gate | `meta` |
| `weft.experiment.id` | `weft/runtime` | The saved experiment the run belongs to | column `experiment_id` |
| `weft.forked_from` | `weft/runtime` | `<source run>#<from step>`: the run this replay continues | column `forked_from` |
| `weft.replay.view` | `weft/runtime` | A replay from step N > 0: `transcript`, `compacted:<index>`, `derived` or `unknown` | `meta` |
| `weft.edits` | `weft/runtime` | The transcript edits a replay applied | `meta` |
| `weft.page_url` | `weft/scope` | The app page the run started from, sanitised | `meta` |
| `weft.approval.actor` | `thread` (each decision's key id, else its `Who`), `weft/runtime` (`panel:<public id>`, `server`, `local`), or the app | Who decided the calls this run resumes, distinct actors in call order, comma-joined. Metadata survives content-off and goes to every destination, so put an opaque id here, not an email. `thread` sets it on every resume turn and `""` on every other | `meta` |
| `enduser.id` | the app through metadata | The end user | `meta` (its mirror `user.id` is not) |

**Empty means none.** Metadata rides the context into every run started under it, so a session turn started inside another run's tool handler would inherit that run's pairs. `thread` therefore sets every key a session owns (`weft.public_id`, `weft.session.title`, `weft.session.forked_from`, `weft.session.parent`, `weft.session.parent_call`) on each of its runs, `""` when it has none. The core reads `""` as none: it removes the inherited pair, which then appears on no span or record. Readers hold the same rule: [`obsdb.MetaOf`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#MetaOf) drops an empty string, and a `public_id` of `""` matches no scope.

### What lands in `meta`

`obsdb.MetaOf` keeps every **string** attribute of any span or record of the run, merged, whose key is not on one closed list, [`obsdb.NonMetaKeys`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#NonMetaKeys). Your own metadata keys, `enduser.id`, the `meta` rows above and any other `weft.` key (a module's own) land there. A non-string attribute off the list is dropped on SQLite and stringified on ClickHouse.

| Never in `meta` | Keys |
|---|---|
| Identity | `weft.run.id`, `weft.parent.run.id`, `weft.parent.call.id`, `weft.session.id`, `weft.public_id`, `weft.turn`, `gen_ai.agent.name` |
| Run-row columns | `weft.playground`, `weft.experiment.id`, `weft.forked_from`, `weft.resumed_from`, `weft.version`, `weft.manifest.hash`, `weft.instructions.hash`, `weft.run.stopped_by`, `weft.cancel.cause` |
| Record keys | `weft.record`, `weft.event.type`, `weft.event.pos`, `weft.delta.pos`, `weft.messages.index`, `weft.messages.count`, `weft.messages.input`, `weft.messages.reason`, `weft.messages.from_seq`, `weft.messages.to_seq`, `weft.request.index`, `weft.prompt.index`, `weft.tools.index`, `weft.raw.index`, `weft.system.hash`, `weft.catalog.hash`, `weft.compaction.hash`, `weft.compaction.scope`, `weft.content`, `weft.content.truncated_bytes`, `weft.step.index`, `weft.tool.seq`, `weft.attempt.index`, `weft.latency_ms`, `weft.records.dropped`, `weft.logs.bridged` |
| Span keys | `weft.run.steps`, `weft.run.pending`, `weft.run.denied`, `weft.run.stop_reason`, `weft.run.events`, `weft.run.messages`, `weft.stop.raw`, `weft.model.tool_calls`, `weft.stream`, `weft.ttft_ms`, `weft.attempt.retry_after_ms`, `weft.attempt.layer`, `weft.attempt.wait_ms`, `http.response.status_code`, `weft.tool.approved`, `weft.tool.pending`, `weft.tool.pending.source`, `weft.tool.timeout_ms`, `weft.tool.queue_ms`, `weft.subagent.pending`, `weft.tool.result_bytes`, `weft.tool.truncated_bytes`, `weft.tool.input_error`, `weft.tool.retry`, `weft.tool.retry_budget`, `weft.panic.layer`, `weft.output.submitted`, `weft.metadata.dropped`, `weft.tap.panics`, `weft.resume.calls`, `weft.tool.denied`, `weft.tool.denied_kind`, `weft.override.hash` and every `weft.override.*` key |
| GenAI keys | `gen_ai.operation.name`, `gen_ai.provider.name`, `gen_ai.request.model`, `gen_ai.response.model`, `gen_ai.response.finish_reasons`, the five `gen_ai.usage.*` keys, `gen_ai.tool.name`, `gen_ai.tool.call.id`, `error.type` |
| Mirrors | `gen_ai.conversation.id`, `session.id`, `user.id` |

**Contract and code.** The contract calls its list exact (record-contract.md:175-185) but leaves out keys the code excludes too: `weft.run.events`, `weft.run.messages`, `weft.attempt.layer`, `weft.attempt.wait_ms`, `http.response.status_code`, `weft.tool.pending.source`, `weft.tool.timeout_ms`, `weft.tool.queue_ms`, `weft.subagent.pending` and `weft.output.submitted`, beside the ones its prose names elsewhere (obsdb/model.go:338-452). The table above is the code's list.

On ClickHouse a run's `meta` is the greatest of its rows' JSON maps compared as strings, not a merge. The core's spans and records carry the same map, so this only shows when a reopened `thread` session emits a compaction marker for a run it did not see: that marker's map can win and drop your pairs from the run's ClickHouse `meta`.

## Spans

Four span kinds, named `<operation> <name>` by the GenAI conventions, and a fifth, `layer`, only under the development detail level. Spans carry ids, names, counts, durations, reasons and error types, never content (ADR 0016). Every weft span carries `weft.run.id` and the run's metadata.

| Span | Name | Kind | Parent | One per |
|---|---|---|---|---|
| `invoke_agent` | `invoke_agent <agent>`, or `invoke_agent` | Internal | none; a Subagent child's is the parent's `execute_tool` | run |
| `chat` | `chat <model>` | Client | `invoke_agent` | model call (a step) |
| `attempt` | `attempt` | Client | `chat` | try inside a model call, when the model chain reports attempts |
| `execute_tool` | `execute_tool <tool>` | Internal | `invoke_agent` | tool call, and a zero-length one per call a resume denied |
| `layer` | `layer <name>` | Internal | the layer outside it, else the `chat` or `execute_tool` span | middleware layer per call, under `otel.DevDetail` only (since 0.20.0; [`layer`](#layer)) |

<span id="invoke-agent"></span>
### `invoke_agent`

The root of the run's tree. It ends when the run does, however the run ends. Status `Ok` on success (a run parked at an approval succeeded); `Error` with the error text as the description and a recorded exception on failure.

| Attribute | Type | When |
|---|---|---|
| `gen_ai.operation.name` | string `invoke_agent` | Always |
| `weft.run.id` | string | Always |
| `gen_ai.agent.name` | string | Named agents |
| `gen_ai.provider.name` | string | The model reports a provider: `openai`, `anthropic`, `gcp.gemini`, else verbatim |
| `gen_ai.request.model` | string | The model reports a name |
| `weft.instructions.hash` | string, sha256 hex | Always since 0.10.0; the empty string's hash when there are no instructions |
| `weft.parent.run.id`, `weft.parent.call.id` | string | Subagent children |
| `weft.caller.run.id`, `weft.caller.call.id` | string | Other runs started on a tool call's context (pool child turns, nested `Generate`s), and runs started on a `weft.WithCaller` context |
| `weft.caller.remote` | string `"true"` | A `weft.WithCaller` link: a caller in another process, which readers never place a run by. The span also carries an OpenTelemetry link to the caller's span when one was given |
| `weft.manifest.hash` | string | Named agents |
| `weft.version` | string | Always |
| `weft.logs.bridged` | int | At start, while the pipeline has a live slog bridge, on the copy a destination that takes app logs exports: the lines bridged so far. Its presence means "this store holds the run's bridged lines". Set by `weft/otel`, not the core |
| `weft.metadata.dropped` | int | The metadata limits dropped pairs: the run's `truncated` hole, cause `metadata_cap` |
| `weft.resumed_from` | string | The run this one resumes, as [`weft.ResumeOf`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#ResumeOf) named it. `thread` and `weft/runtime` always pass it; an app resuming a plain `Generate` passes the parked `RunResult.ID` |
| `weft.resume.calls` | string | A run fed decisions: each parked call in call order as `<call id>=<kind>`, comma-joined, kind `approved`, `denied`, `resolved` or `no_decision`. The decision, not the outcome. Capped at 32 calls, then `,…+k`. `thread` writes an undecided call as an explicit deny, so only a plain core resume reads `no_decision` |
| `weft.override.hash` | string, sha256 hex | A run option changed the agent's configuration: the experiment fingerprint |
| `weft.override.instructions` | bool `true` | The instructions were replaced; the text is never on a span |
| `weft.override.tools` | string, sorted names, comma-joined | `OnlyTools` |
| `weft.override.model` | string `<provider>/<name>`, or the bare name | `UseModel` |
| `weft.override.park_on`, `weft.override.park_all_except` | string | `ParkOn`, `ParkAllExcept` |
| `weft.override.thinking` | string | A per-run thinking level |
| `weft.override.tool_choice` | string | A per-run tool choice: `auto`, `any`, `none`, `tool:<name>` (a named choice with no name reads `tool`) |
| `weft.override.params` | string, JSON | Per-run sampling params: the replacement's set knobs, plus `null` for each knob the agent's default set that the replacement leaves unset, such as `{"temperature":0.4,"top_p":null}`. The hash takes the set knobs alone |
| `weft.override.max_steps`, `weft.override.parallelism` | int | Lowered per run |
| `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens` | int | At end: run totals, Subagent children included |
| `gen_ai.usage.cache_read.input_tokens`, `gen_ai.usage.cache_creation.input_tokens`, `gen_ai.usage.reasoning.output_tokens` | int | At end, each only when non-zero |
| `weft.run.steps` | int | At end |
| `weft.run.events` | int | At end, always: the durable `event` records the run handed to its LoggerProvider, 0 with no logger. A reader compares it with what it stored |
| `weft.run.messages` | int | At end, always: growth `messages` records emitted (views excluded), 0 with content capture off or no logger |
| `weft.run.pending` | int | At end, when calls are parked for approval |
| `weft.output.type` | string | At start, an agent built with `Output` only: the type its typed answer decodes into, package-qualified (`main.Invoice`; a pointer's element; `struct` for an anonymous struct), at most 128 bytes cut at a rune boundary. The manifest's `submit_output` tool carries it as `output_type` |
| `weft.output.submitted` | bool | At end, an agent built with `Output` only: `true` when the run ended with a valid `submit_output` call, `false` when it did not (the case `GenerateAs` answers `ErrNoOutput`) |
| `weft.run.denied` | int | At end, on a resuming run that denied parked calls: explicit denies and calls left undecided. Not a `Resolve`, not an `mw.Allow` refusal (that has its own span) |
| `weft.tap.panics` | int | At end, when observers panicked and were contained: taps, `OnMessages` observers, a record or report that failed to build. `OnRunEnd` panics are not counted here |
| `weft.run.stop_reason` | string | At end: the last step's `stop`, `tool_calls` or `max_tokens` |
| `weft.run.stopped_by` | string | At end, what ended the run: a fired `StopWhen` condition's name (`has_tool_call:<tools>`, `step_count_is:N`, `output_submitted`, a custom condition's `String()`, else `custom`), `final_answer`, `parked`, `max_steps`, `usage_limit`, `loop_detected`, `model_retries_exceeded`, `canceled`. Absent on a failure no control decided. On a failed run this span is its only carrier |
| `weft.cancel.cause` | string | At end, a `canceled` run whose cause names itself: `thread.interrupted`, `thread.closed`, `studio.cancel`, `app.shutdown`, any [`weft.CancelCause`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#CancelCause) kind, or `deadline`. Absent for a plain cancel |
| `error.type` | string | On failure, a closed table: `max_steps`, `usage_limit`, `loop_detected`, `model_retries_exceeded`, `model_contract`, `duplicate_tool`, `nil_tool`, `no_output`, `stream_idle`, `unsupported`, `model_requests_denied`, `run_panicked`, `model_error` (a provider failure, the default), `context.Canceled`, `context.DeadlineExceeded`. A run row reads the last two as `cancelled` |

### `chat`

Started after `PrepareStep` built the request, ended when the stream is consumed. Model middleware such as retry and fallback runs inside it. Status `Ok` on success; `Error` with the error text, a recorded exception and `error.type` on failure.

| Attribute | Type | When |
|---|---|---|
| `gen_ai.operation.name` | string `chat` | Always |
| `weft.run.id`, `weft.step.index` | string, int | Always |
| `weft.stream` | bool `true` | Always |
| `gen_ai.provider.name`, `gen_ai.request.model` | string | The model the call asked |
| `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, the three splits | int | At end: this call's usage, splits only when non-zero |
| `gen_ai.response.finish_reasons` | string array, one element | At end: `stop`, `tool_calls` or `max_tokens` |
| `weft.stop.raw` | string | At end, the vendor's raw reason when set |
| `weft.model.tool_calls` | int | At end: tool calls requested |
| `gen_ai.response.model` | string | At end, a call that finished: the model that answered |
| `weft.ttft_ms` | int | At end, when a `TextDelta` or `ToolArgsDelta` arrived: ms to the first one (reasoning deltas don't count); absent otherwise |
| `error.type` | string | On failure |
| event `weft.repair` | `gen_ai.tool.call.id`, `weft.repair.kind`, `weft.repair.bytes_before`, `weft.repair.bytes_after` | Since 0.20.0, one per tool call whose arguments a model middleware repaired (`Reporter.Repair`, `mw.RepairJSON`), at the moment it did. `weft.repair.kind` is `fence` (a Markdown fence stripped), `unterminated` (open strings, objects or arrays closed), `fence+unterminated`, or `trim` (whitespace or an empty argument made `{}`). The two byte counts are ints. The call's `execute_tool` span carries `weft.tool.args_repaired` |
| event `weft.repair`, under `otel.DevDetail` | `weft.repair.original`, `weft.repair.original_cut` | With the run's content on: the arguments as the model sent them, capped at 4 KiB on a rune boundary. `weft.repair.original_cut` (int) counts the rest, only when cut. Content: only Local and Studio destinations with content on receive them; an OTLP preset gets the event without them |

### `attempt`

Present only when the model chain reports attempts through [`weft.ReportFromContext`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#ReportFromContext): [`mw.Retry`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/mw#Retry), [`mw.Fallback`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/mw#Fallback), or an adapter reporting its SDK's retries. It carries no `gen_ai.operation.name`.

| Attribute | Type | When |
|---|---|---|
| `weft.run.id`, `weft.step.index` | string, int | Always |
| `weft.attempt.index` | int | Always: 1-based, numbered per model call |
| `gen_ai.provider.name`, `gen_ai.request.model` | string | The attempt names them |
| `weft.attempt.retry_after_ms` | int | The provider asked to wait |
| `weft.attempt.layer` | string | `fallback` on a request `mw.Fallback` sent to a backup: the marker the `fallbacks` counter keys on; `retry` on one `mw.Retry` sent again after a failure (since 0.20.0). A backup that reports its own attempts (a `mw.Retry` around it) marks every request it sends `fallback`, its retries included. Absent on a first try |
| `weft.attempt.giveup_reason` | string | On the attempt after which a retrying layer stopped: `budget`, `not_retryable` or `retry_after_too_long` |
| `weft.attempt.wait_ms` | int | The backoff the reporting layer slept **before sending this attempt** (`mw.Retry`'s delay, a retry-after it honoured), rounded up, never 0. Absent on an attempt sent at once: a first try, a fallback's backup |
| `http.response.status_code` | int | The provider's HTTP status, when the reporter found one (`mw.HTTPStatus` reads it off the error) |
| `gen_ai.response.model` | string | On success |
| `error.type` | string | On failure, with status `Error`. Since 0.20.0 classified: `rate_limit` (429), `overloaded` (503, 529), `timeout` (408, 504, a transport timeout), `auth` (401, 403), `server_error` (any other 5xx), `context_overflow`, the run's own failure types as it reads them, else `model_error` |

Studio's live stream also sends each attempt span as an `attempt` frame the moment it lands (`/api/live?kinds=attempt`). That is a reading of this span, not a record: nothing new is emitted or stored, and the frame is never backfilled.

<span id="execute-tool"></span>
### `execute_tool`

Status `Ok` for a result; `Error` with an empty description for an error result (the result text is content); unset for a call parked for approval. A `Resolve`d call has no span: nothing executed.

| Attribute | Type | When |
|---|---|---|
| `gen_ai.operation.name` | string `execute_tool` | Always |
| `gen_ai.tool.name`, `gen_ai.tool.call.id` | string | Always |
| `weft.run.id`, `weft.step.index`, `weft.tool.seq` | string, int, int | Always; a denied call's span has no `weft.tool.seq` and carries `weft.step.index` 0 |
| `weft.tool.approved` | bool `true` | A call resumed by `Approve` |
| `weft.tool.approved_by`, `weft.grant.id` | string, string | Since 0.18.0, an approved call's provenance as [`weft.ApproveBy`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#ApproveBy) named it; absent for a plain `Approve`. `thread` passes `user` (`Decide`, `DecideSigned`), `grant` (a standing grant matched, `weft.grant.id` its entry id), `approver`, `quorum` or `policy` on every resume it runs; `weft/runtime` passes `runtime` on a playground approval. Ids and enums, never who by name (that is the `thread` record's `content.who`); span attributes, never `meta` |
| `weft.tool.denied`, `weft.tool.denied_kind` | bool `true`, string | A parked call the resume denied: `denied` (`Deny`) or `no_decision` (left undecided). The span is zero-length at the moment the resume decided, carries `weft.step.index` 0 and no `weft.tool.seq`, `error.type` `DENIED`, status `Error`, never the reason. Since 0.16.0 |
| `weft.tool.result_bytes` | int | At end, a successful result only: the length the model sees, after the result cap |
| `weft.tool.pending` | bool `true` | At end: the call was parked for approval |
| `weft.tool.pending.source` | string | Beside `weft.tool.pending`, why it parked: `approval` (`RequireApproval`), `park_on` (the run's `ParkOn`, which is how playground breakpoints park), `park_source` (an agent `ParkSource`), `park_all_except`, `middleware` (an error wrapping `ErrApprovalRequired`) |
| `weft.tool.timeout_ms` | int | At start, when a deadline is in force: the call's `Timeout`, rounded up (a sub-millisecond deadline reads 1) |
| `weft.tool.queue_ms` | int | At start, a call that waited behind a `Sequential` barrier or for a `Parallelism` slot: the wait, rounded up, never 0 |
| `weft.subagent.pending` | string | `error.type` `SUBAGENT_PENDING`: the parked child's pending calls by tool name, comma-joined |
| `weft.tool.truncated_bytes` | int | At end, a result or error result the result cap (`MaxResultBytes`) cut: the bytes removed, the number in the model's `…[truncated N bytes]` marker |
| `error.type` | string | An error result, in this order: the `ToolError` code (`INVALID_INPUT`, `NO_SUCH_TOOL`, `DENIED` from a policy middleware, `RETRY`, your own); `timeout`; `panic`; `context.Canceled` or `context.DeadlineExceeded`. Then the error's own `ErrorType()` string when one in its chain declares it, else `tool_error`. `weft/mcp` declares `mcp_transport` (no answer), `mcp_rpc_error` (a JSON-RPC error answer, since 0.20.0) and `mcp_tool_error` (an `isError` result) |
| `weft.tool.retry`, `weft.tool.retry_budget` | int, int | `error.type` `RETRY` ([`weft.ModelRetry`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#ModelRetry)) counted by the loop: the tool's consecutive RETRY count (a success resets it) and the run's `MaxModelRetries`. On the span only, not on `tool_finish`. Absent on a resumed approved call's RETRY |
| `weft.panic.layer` | string | `error.type` `panic`: `handler` or `middleware` |
| `weft.tool.input_error` | string | `error.type` `INVALID_INPUT` from the loop's own decode: `strict` (an undeclared field under `StrictInput`), `schema` (wrong type or shape), `syntax` (not one JSON value) |
| event `weft.panic` | `weft.panic.stack`, `weft.panic.stack_cut` | `error.type` `panic`, under `otel.DevDetail` with content on: the panicking goroutine's stack, capped at 16 KiB, the rest counted. Only Local and Studio destinations with content on receive it |
| `weft.tool.args_repaired` | bool `true` | At start: a model middleware repaired the call's arguments (`Reporter.Repair`, `mw.RepairJSON`); the `chat` span's `weft.repair` event says how |
| `weft.tool.origin` | string | At start, a tool that is not local: `subagent`, `mcp:<server>` (an import under `mcp.Server(name)`; `mcp` without it), or your own `Origin` word. Never an address |
| `weft.tool.denied_by` | string | An error result a tool layer reported refusing (`ToolReporter.Denied`): `allow` for `mw.Allow`. On a resume's denied span: `approval`, or `grant` with `weft.grant.id` (`weft.DenyBy`) |
| `weft.tool.error_masked` | string | An error result a tool layer replaced (`ToolReporter.Masked`, `mw.MapErrors`): the hidden error's kind, never its text: its `ErrorKind()`, a context error's name, its `ErrorType()`, a `ToolError` code, a standard sentinel such as `io.EOF` or `fs.ErrNotExist`, else its Go type (Studio and the devtools panel draw `*errors.errorString` as "plain error" and `*errors.joinError` or `*fmt.wrapErrors` as "joined errors"; the value recorded is the type) |

### `layer`

One span per `WrapModel` or `WrapTools` layer per call, named `layer <name>`, kind Internal, under [`otel.DevDetail()`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#DevDetail) alone: the development gate (`WEFT_ENV=dev`, or `otel.DevMode()`), and only the Local and Studio destinations with content on receive it. Never by default. A layer span's parent is the layer outside it, the outermost's the `chat` or `execute_tool` span ([The onion in the record](https://weftgo.dev/docs/guides/middleware/#the-onion-in-the-record)). Spans your code starts inside a layer, such as a handler's or an `attempt`, keep the call's span as their parent, so a destination that drops layer spans orphans nothing. A layer that returned an error has status `Error`, except a parked call's `ErrApprovalRequired`.

| Attribute | Type | When |
|---|---|---|
| `weft.layer.name` | string | Always: the layer's name as the manifest names it (`mw.Retry`, a type, a function) |
| `weft.layer.kind` | string | Always: `model` or `tool` |
| `weft.layer.index` | int | Always: its place outer to inner, 0 the outermost (a tool's own `WrapTools` numbered after the agent's) |
| `weft.run.id`, `weft.step.index` | string, int | Always |
| `gen_ai.tool.name`, `gen_ai.tool.call.id` | string | A tool layer |
| `error.type` | string | The layer returned an error: a model layer the `chat` span's classification; a tool layer the `ToolError`'s code, a context error's name, else `tool_error`. `panic` when a panic went through the layer. Status `Error` |

## Log records

Every weft record is one OTel log record: logger `github.com/weftgo/weft/core`, an `EventName`, a JSON string body, the emission time, severity INFO (WARN for a `tool_finish` with `is_error`) and attributes. Every record but the heartbeat carries `weft.record` (its kind, mirroring the EventName for backends that drop it), `weft.run.id`, `gen_ai.agent.name` when named, `weft.content`, and the run's metadata.

| `weft.record` | EventName | Position attribute | Count per run | Body | Trace context |
|---|---|---|---|---|---|
| `event` | `weft.event` | `weft.event.pos` | one per durable event | the event's wire JSON | `invoke_agent` |
| `delta` | `weft.delta` | `weft.delta.pos` | one per streamed delta | the delta's wire JSON; counted, never stored | `invoke_agent` |
| `messages` | `weft.messages` | `weft.messages.index` | one per transcript batch, plus compaction views | a JSON array of messages | `invoke_agent` for growth; `chat` for a view |
| `request` | `weft.request` | `weft.request.index` | one per model-call attempt | the request object | `chat` |
| `prompt` | `weft.prompt` | `weft.prompt.index` | one per distinct system hash | `{"hash", "text"}` | `chat` |
| `tools` | `weft.tools` | `weft.tools.index` | one per distinct catalog hash | `{"hash", "tools": [...]}` | `chat` |
| `raw` | `weft.raw` | `weft.raw.index` | one per HTTP exchange, development only | the wire request and response | `chat` |
| `compaction` | `weft.compaction` | none: the store keys it on `weft.compaction.hash` | one per `thread` compaction | the session marker | the run it is filed under, when the Session saw that run; none after a reopen. It describes no span |
| `thread` | `weft.thread.<kind>` | none: a store derives it from the body | one per fact of a session's state log (since 0.18.0) | `{kind, session, at, …, content?}` | the run it is filed under; none when held to `Close` |
| `heartbeat` | `weft.heartbeat` | none | every 10 s per open run | none; never stored | none |

The app log record (slog bridge) is a log record too, but no `weft.record` kind: it carries neither `weft.record` nor `weft.run.id`. See [App log records](#app-log-records).

**Which span a record names.** A record carries the trace and span id of the context it was emitted on, not of the span it describes: a `tool_start` does not carry its `execute_tool` span's ids, nor a `step_finish` its `chat` span's. Join records to spans, and records to each other, on `weft.run.id`, `weft.step.index` and `gen_ai.tool.call.id`, never on span ids.

**The storage key.** A store is idempotent on (run id, kind, position), so a retried export is a no-op. Each positioned kind has its own per-run counter from 0 without gaps: a hole below the high-water mark is a lost record (`gap`). A positioned record without its position attribute comes only from a malformed producer; it is stored at position -1 and readers skip it. A `delta` without one counts as position 0. The `compaction` and `heartbeat` kinds have no position attribute: a store derives a marker's position from its hash, and never stores a heartbeat.

### `event` and `delta`

The body is the core's [event wire](https://weftgo.dev/docs/reference/events/), discriminated by `type`; `weft.event.type` repeats it. Durable events, on `weft.event.pos`:

| `weft.event.type` | Body fields | Extra attributes |
|---|---|---|
| `run_start` | `id`, `model {provider, name}`, `agent`, `instructions_hash` (informational: readers take the attribute) | `weft.parent.run.id` and `weft.parent.call.id` (Subagent children), `weft.caller.run.id` and `weft.caller.call.id` (other runs started on a tool call's context), `weft.manifest.hash` (named agents), `weft.instructions.hash`, `weft.version`, `weft.resumed_from` and `weft.resume.calls` (a resume) |
| `step_start` | `run_id`, `index` | `weft.step.index` |
| `tool_start` | `run_id`, `seq`, `call_id`, `name`, `args` | `weft.tool.seq`, `gen_ai.tool.call.id`, `gen_ai.tool.name` |
| `tool_finish` | `run_id`, `seq`, `call_id`, `name`, `content`, `is_error` | the same three keys (`weft.tool.seq` is this event's own `seq`); `weft.tool.truncated_bytes` when the result cap cut the content |
| `step_finish` | `run_id`, `index`, `reason`, `usage`, `raw`, `latency_ms`, `ttft_ms` | `weft.step.index`, `weft.latency_ms`, `weft.ttft_ms` when known, `gen_ai.response.model` |
| `steered` | `run_id`, `seq`, `step`, `messages` | `weft.step.index` |
| `run_finish` | `run_id`, `usage`, `steps`, `pending` (parked calls), `stopped_by` | none from the core |

`usage` is `{input_tokens, output_tokens, cached_input_tokens?, cache_write_tokens?, reasoning_tokens?}`. Deltas (`text_delta`, `reasoning_delta`, `tool_args_delta`) are on `weft.delta.pos`, a counter of their own, so a dropped delta never opens a gap in the event counter. A Subagent child's events are its own records under its own run id; the parent's `nested` wrapper is never recorded. A run that ended has a `run_finish` (success, or parked) or a stored `invoke_agent` span (status `Error`: failed; any other status: succeeded); with neither it is running or interrupted.

### `messages`

Attributes `weft.messages.index`, `weft.messages.count` (messages in the body), `weft.step.index` (the step the batch joined, 0 for the input) and `weft.messages.input = true` on index 0. The body is a JSON array of `{"role": "user" | "assistant" | "tool", "content": [parts]}`. There is no system role: the system text is the `prompt` record.

| Form | How to tell | What it is |
|---|---|---|
| Growth | no `weft.messages.reason` | Emitted at the run's input (index 0), the tool message a resume creates or rebuilds, each assistant message, each tool message and each steered batch. Concatenated in index order, the growth records are the run's transcript, byte for byte |
| View | `weft.messages.reason = compacted` | What one request saw instead of the transcript, when a `PrepareStep` trimmed or summarised it (since 0.10.0). Never part of the transcript, never counted. Extra attributes: `weft.messages.from_seq` and `weft.messages.to_seq` (the half-open range of transcript ordinals it replaced; equal for a pure insertion), `weft.compaction.scope = run`, `weft.compaction.hash`. It takes the next index, right before the request record that names it |

The view's hash is lowercase hex sha256 over the canonical JSON of `{"entries": <the view's body>, "from_seq": n, "to_seq": m}`, keys sorted. The messages the model saw are the growth records below the view's index, concatenated, with `[from_seq, to_seq)` replaced by the view's body. A transcript builder skips every record with a non-empty `weft.messages.reason`; only a reader applying views fails on a reason it does not know.

### `request`, `prompt`, `tools`

Since 0.10.0. Emitted in the model-call phase after `PrepareStep`, immediately before the model is called, in this order: `prompt` (when its hash is new to the run), `tools` (when its hash is new), the view (when the messages were rewritten), `request`. A request that was never sent is never recorded.

| Record | Attributes | Body |
|---|---|---|
| `request` | `weft.request.index`, `weft.step.index`, `weft.attempt.index` (1 for the loop's call, then 2, 3 per further reported attempt), `weft.system.hash` (when there was system text), `weft.catalog.hash` (when tools were offered) | `step`, `attempt`, `system_hash`, `messages_ref {index?, count}`, `tools {catalog_hash, names}` (offered order), `tool_choice?`, `thinking? {level, budget?, wire?}`, `sequential_tools`, `params {temperature?, top_p?, max_tokens?, stop?, seed?}`, `model {provider, name}`, `stream`, `prepared?` |
| `prompt` | `weft.prompt.index`, `weft.system.hash` | `{"hash", "text"}`: the composed system text (instructions after `PrepareStep`, the tools' prompt snippets appended); `segments?: [{source, text}]` attributes it to `instructions` and `tool:<name>`, absent when no tool contributed a snippet |
| `tools` | `weft.tools.index`, `weft.catalog.hash` | `{"hash", "tools": [{name, description, schema, timeout_ms, approval, replay, max_result_bytes, sequential, source, output?}]}` in name order; `output: true` marks `submit_output` |

| Body field | Meaning |
|---|---|
| `messages_ref` | The messages record the request's messages are the view as of; `index` absent when capture was off or a content-off destination removed it |
| `thinking.wire` | How the adapter sends the level, the provider field it writes, never a value: `openai` `reasoning_effort`, `thinking` or `none`; `anthropic` `thinking.adaptive`, `thinking.budget_tokens` or `thinking.disabled`; `google` `thinking_level` or `thinking_budget`; `none` when the level maps to nothing. Declared by a model's optional `ThinkingWire` method; absent when none does |
| `prepared` | The parts the agent's `PrepareStep` chain changed, in the order `system`, `messages`, `tools`, `tool_choice`, `params`, `thinking`, `sequential_tools`. Names only, so it survives content off; absent when nothing changed |
| `segments` | Content like the text: a content-off chain drops the record; a content-on chain redacts each segment and drops `segments` when its cap cut the text |

<span id="hashes"></span>
**Hashes.** Every text hash is lowercase hex sha256 of the UTF-8 bytes, taken before any destination redacts or caps the text: `weft.system.hash` over the composed system text, `weft.instructions.hash` over the raw configured instructions (fixed for the run; `e3b0c442…b855`, the empty string's, when there are none). The catalog hash is sha256 over canonical JSON built in four steps:

| Step | Rule |
|---|---|
| 1 | Decode each tool's JSON schema keeping every number's source lexeme |
| 2 | Build one map per tool with the keys `description`, `name` and `schema`, and sort the maps by `name`. Every object at every level is written with its keys sorted |
| 3 | Encode with no insignificant whitespace, no HTML escaping and no trailing newline |
| 4 | sha256 the bytes |

Go's encoder output is the definition. An emitter starting from RFC 8785 (JCS) must keep three differences: numbers keep their source lexeme (`1.0` stays `1.0`), U+2028 and U+2029 are written escaped, and invalid UTF-8 becomes U+FFFD. No tools offered is `catalog_hash ""` and no `tools` record. A stored record's step is -1 when `weft.step.index` was absent.

### `raw`

Only under [`otel.RawBodies(true)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#RawBodies) behind the development gate (`WEFT_ENV=dev`, or [`otel.DevMode()`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#DevMode)), and only to `Local` and `Studio` destinations with content on. Attributes `weft.raw.index`, `weft.step.index`, `weft.attempt.index`, `weft.content = full`, and `weft.content.truncated_bytes` when a body was cut. The body is `{step, attempt, request {method?, url?, headers, media_type?, body, encoding?, bytes, truncated_bytes?}, response {status?, headers, media_type?, body, encoding?, bytes, truncated_bytes?, complete?} or null, redacted_headers, redacted_query?}`. Credentials are stripped before emission, and each body is capped at 256 KiB (ADR 0028 §12).

### `compaction`

Emitted by `thread` when a session compaction lands, under the id of the last run of the session that produced the compacted context; with no such run it waits for the next run the Session drives. Informational: it carries no messages and a reader never applies it, because the next run's input record already holds the compacted context. See [Compaction](https://weftgo.dev/docs/sessions/compaction/).

| Field | Value |
|---|---|
| Attributes | `weft.compaction.scope = session`, `weft.compaction.hash` (sha256 of the compaction entry's JSON as `thread` wrote it, entry id included), `weft.content = none`, `gen_ai.agent.name`, and the session's metadata verbatim (`weft.session.id`, `weft.turn`, `weft.public_id`, …), but not the `gen_ai.conversation.id` and `session.id` mirrors |
| Position | No attribute: a store derives it from the hash |
| Body | `{scope, hash, entry, reason, replaced, entries, messages_before, messages_after, tokens_before, tokens_after}` |

### `thread`

Since 0.18.0 `weft/thread` reports its state log, every decision, grant, receipt and tree move it writes, as one record per fact. It emits through the agent's `LoggerProvider` under the instrumentation scope `github.com/weftgo/weft/thread`. Each record has `weft.record = thread`, EventName `weft.thread.<kind>`, severity INFO (WARN for `approval.refused`), `weft.run.id` and `gen_ai.agent.name`. Its `weft.content` is `full` when the body carries a `content` object, else `none`, or `stripped` on a content-off chain. It carries the session's metadata with `weft.session.id`, but not the `gen_ai.conversation.id` and `session.id` mirrors, and no position attribute. The exported trail is an index, not evidence: the session file is the record ([ADR 0021](https://github.com/weftgo/weft/blob/v0.20.2/docs/adr/0021-thread-approvals.md)).

**The run it is filed under.** A record is filed under the run its entry names: a request's, a decision's or a delivered receipt's parking or draining run. Else it is filed under the turn in flight: a receipt's busy turn, the turn whose chain saw a grant lapse, a pool receipt's delegating turn. Else it goes under the last run of the session on the leaf's line, as the compaction marker does. With no run yet (grants minted before the first turn), or when that run has not reported yet, the record is held and emitted when the run reports. What is still held at `Close` is emitted then with `held: true` in its body, on a context with no span: under the run it waited for, or, with no run at all, with no `weft.run.id`, keyed by `weft.session.id`. Past 256 held records the oldest are dropped, counted in a Debug line. `thread` decides each record under its session lock and hands it to one emitter goroutine per Session, in order, so no provider call runs while the session is locked; `Close` waits for it. A logger that panics or refuses changes nothing the session does.

**The body** is one JSON object: `kind`, `session`, `at` (the fact's time, RFC 3339), the kind's fields below (ids, enums and counts, absent when empty), and `content`, an object of strings that rides only when capture is on (the agent's `Content` option, else the destination's `Enabled` for `weft.messages`). Under `weft/otel` a content-off destination strips `content`, and a content-on one passes it through `Redact` as [`otel.ContentThread`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#ContentThread) and caps it at `MaxBytes`. App-chosen names, such as a label's `name`, are metadata, never content.

| Kind | When | Fields | `content` |
|---|---|---|---|
| <span id="weft-thread-approval-request"></span>`weft.thread.approval.request` | a call parks | `entry`, `call_id`, `tool`, `args_sha256`, `expiry`, `quorum` (above 1), `child_session` / `wrapper_call` (a mirrored pool child's) | — |
| <span id="weft-thread-approval-decision"></span>`weft.thread.approval.decision` | any decision: `Decide`, `DecideSigned`, a grant or approver step, an expiry, an interrupt, a pool resolution | `entry`, `call_id`, `outcome` (`approve`, `deny`, `resolve`, `resolve_error`), `via` (`user`, `signed`, `grant`, `approver`, `expiry`, `interrupt`, `child`, `parent`, `quorum`), `key_id`, `request_entry`, `always`, `grant_id` and `grant_scope` (`shared`) for a grant step | `who`, `reason`, `content` (a resolve's result) |
| <span id="weft-thread-approval-refused"></span>`weft.thread.approval.refused` | a signed decision refused, at most 16 audited per request | `entry`, `call_id`, `reason` (`bad_signature`, `replayed`, `expired`, `args_changed`, `not_pending`), `key_id` (when the ring holds it) | — |
| <span id="weft-thread-grant-mint"></span>`weft.thread.grant.mint` | `Grant`, or an approve-always verdict | `entry`, `grant_id`, `tool`, `scope` `session`, `args` (the predicate count, never their values), `deny`, `max_uses`, `expiry`; `via` `always` and `call_id` when a decision minted it | `reason` (a deny grant's model-visible text) |
| <span id="weft-thread-grant-use"></span>`weft.thread.grant.use` | the chain matched a grant | `entry`, `call_id`, `grant_id`, `outcome` (`approved`, `denied`), `scope` (`session`, `shared`), `uses` (this one included), `max_uses` | — |
| <span id="weft-thread-grant-revoke"></span>`weft.thread.grant.revoke` | `Revoke` | `entry`, `grant_id`, `tool`, `uses` | — |
| <span id="weft-thread-grant-expire"></span>`weft.thread.grant.expire` | a grant's lapse, once per grant per Session: its last use under `MaxUses`, or its `Expiry` passed | `grant_id`, `tool`, `reason` (`max_uses`, `expiry`), `uses`, `max_uses`, `expiry` | — |
| <span id="weft-thread-receipt"></span>`weft.thread.receipt` | a busy-policy receipt ([Busy sessions and steering](https://weftgo.dev/docs/sessions/busy-and-steering/)) | `entry`, `receipt_id` (the acceptance entry), `state` (`queued`, `accepted`, `delivered`, `deferred`, `dropped`), `input` (`steer`, `send`), `minted_run` and `turn` (an accepted send's, and a queued steer's). A steer takes a turn number as it is accepted; one delivered into the busy turn names no run, which explains the gaps in a session's run ids. Then `follow_up_entry` (a deferred steer's), `unanswered` | `text` |
| <span id="weft-thread-interrupt"></span>`weft.thread.interrupt` | an `Interrupt` or `Rollback` send felled a running turn (`target` `run`) or an open approval boundary (`target` `boundary`) | `policy` (`interrupt`, `rollback`), `target`, `by_run`, `by_turn`, `denied_calls` | — |
| <span id="weft-thread-rewind"></span>`weft.thread.rewind` | the leaf moved back so a run's entries left the path: a rollback, or an overflow re-run's branch-back | `entry`, `from_entry`, `to_entry`, `reason` (`rollback`, `overflow`) | — |
| <span id="weft-thread-branch"></span>`weft.thread.branch` | `Branch` | `entry`, `from_entry`, `to_entry`, `summarized`; with `SummarizeLeft` also `summary_entry`, `branch_from`, `summarizer_usage`, `summarizer_model` | `summary` |
| <span id="weft-thread-uncompact"></span>`weft.thread.uncompact` | `Uncompact` | `entry`, `from_entry`, `to_entry`, `compaction` (the entry undone) | — |
| <span id="weft-thread-label"></span>`weft.thread.label` | `Label` | `entry`, `target`, `name` | — |
| <span id="weft-thread-pin"></span>`weft.thread.pin` | `Pin` | `entry`, `target` | — |
| <span id="weft-thread-fork"></span>`weft.thread.fork` | `Fork`, on the origin, under the run that produced the forked entry's line | `entry` (the fork point on the origin; a fork writes no entry there) and `new_session` | — |
| <span id="weft-thread-pool-delegate"></span>`weft.thread.pool.delegate` | a `thread/pool` delegation accepted | `entry`, `receipt_id`, `child_session`, `call_id`, `state` `accepted` | `prompt` |
| <span id="weft-thread-pool-retire"></span>`weft.thread.pool.retire` | its settlement | `entry`, `receipt_id`, `child_session`, `call_id`, `state` (`done`, `failed`, `canceled`, `capped`), `usage` (the child session's whole cost) | `stop` |

A store keeps each as a plain record under the run it is filed under ([`obsdb.RecordThread`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RecordThread)), never as an app log line, a record filed under no run included. No reader applies one to the run row, though it moves the run's last-seen like any record, and its attributes add nothing to `meta` but the run's own metadata. Each `thread` record and `compaction` marker with a `weft.session.id` is also indexed by its session, which is what Studio's session timeline reads ([`GET /api/sessions/{id}/timeline`](https://weftgo.dev/docs/reference/studio-api/#get-api-sessions-id-timeline)).

### `heartbeat`

`weft/otel`'s pipeline emits one per open run every 10 s ([`otel.Heartbeat`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#Heartbeat) changes the interval): `weft.record = heartbeat`, `weft.run.id`, and a copy of the string attributes of the run's `run_start` record (metadata with its mirrors, `gen_ai.agent.name`, the hashes, `weft.version`). No body, no position. It is never stored; it moves the run's last-seen so a quiet run reads running instead of interrupted. A plain SDK without the pipeline emits none.

Two counters ride on it, both kept out of `meta`:

| Attribute | On | Value |
|---|---|---|
| `weft.records.dropped` | the heartbeat, `run_start` and `run_finish` records, on each destination's own copy once it has lost a record | Cumulative records that destination lost since the pipeline started: its queue full (deltas shed at half full, ordinary records at seven eighths, `run_start`, `run_finish` and heartbeats only when full), a failed export or write, a redaction failure. Policy filters are not losses. Studio keeps the largest per `service.name` as its ingest health (`/api/meta`'s `ingest.dropped`, `weft doctor`). Since 0.16.0 |
| `weft.logs.bridged` | the heartbeat, while a slog bridge is live, on copies to destinations that take app logs | The lines the bridge emitted since the pipeline started. Informational: the logs route reads the root span's mark instead |

## App log records

Not weft records: they carry no `weft.record` and no `weft.run.id`. A store keeps them with the app's other log records (`other_logs` on SQLite, `otel_logs` on ClickHouse), and a reader attributes them to a run through the span they were logged under: the run's own spans and non-weft spans below them, never a child run's. `weft/otel`'s bridge ([`otel.Slog()`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#Slog), [`otel.SlogHandler`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#SlogHandler), `Pipeline.SlogHandler`) emits one per slog line logged under a valid span context; a line with no span is not bridged. Since 0.17.0. [Bridge your app's slog lines into runs](https://weftgo.dev/docs/observe/app-logs/) shows the setup.

| Field | Value |
|---|---|
| Instrumentation scope | `github.com/weftgo/weft/otel/slog`, which is how the destination chains recognise a bridged line |
| Trace id, span id | The context's: the `chat` span for `mw.Log`'s lines and the model chain's, the `execute_tool` span for a tool handler's and `mw.Audit`'s, and for [`weft.Logger`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#Logger)'s lines the span of the phase: run start, finish and error on `invoke_agent`, model call and model attempt on `chat`, tool call on `execute_tool` |
| Timestamp | The slog record's time (its emission when zero); observed timestamp the bridge's clock |
| Severity number | The slog level + 9, held to 1–24: DEBUG 5, INFO 9, WARN 13, ERROR 17 |
| Severity text | The level's name: `DEBUG`, `INFO`, `WARN`, `ERROR`, `INFO+2` |
| Body | The slog message |
| Attributes | The handler's and the record's attributes, flattened: group keys joined with `.` (`db.table`). Strings, ints, floats and bools as themselves; durations and times as strings; anything else its `fmt` text. Every key starting `weft.` is renamed `slog.weft.…`. The first 120 are kept and the rest counted in `weft.log.attrs_dropped` |
| `weft.content`, `weft.content.truncated_bytes` | The destination's content policy: `stripped` on a content-off destination's copy; the bytes Redact-then-MaxBytes cut on a content-on one. Absent on a content-on copy with nothing cut |

**Contract and code.** The contract puts all of `core.Logger`'s run lines on the `invoke_agent` span (record-contract.md:720). The code logs each line on its phase's context: `run start`, `run finish` and `run error` on the run's (core/observe.go:331, 409-436), `model call` and `model attempt` on the `chat` span's (core/observe.go:554, core/report.go:500), `tool call` on the `execute_tool` span's (core/observe.go:737). The scratch run's stored lines carry those span ids.

Which destinations take the lines is [`otel.AppLogs`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#AppLogs): Local and Studio with content on by default; Datadog, Langfuse, OTLP and Exporters only with `otel.AppLogs(true)`. The opt-in never bypasses content policy. Every slog level goes to the pipeline: the bridge has no level of its own, and `weft.Logger`'s and `mw.Log`'s lines are DEBUG. An agent's [`weft.Content(false)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#Content) reaches its own lines first: the `tool call` line names an error result's size (`err_bytes`) instead of its text. Under a full queue, bridged lines are shed at the delta threshold. The pipeline's own WARNs about its destinations are never bridged.

## Content policy

Content means message text, tool arguments and results, the system prompt and the catalog. It is off in the core by default and decided per destination: on for [`otel.Local`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#Local) and [`otel.Studio`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#Studio), off for [`otel.OTLP`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#OTLP), [`otel.Exporters`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#Exporters) and the vendor presets. `weft.content` says what a record holds. [Control what content leaves the process](https://weftgo.dev/docs/production/content-and-privacy/) is the how-to.

| `weft.content` | Meaning |
|---|---|
| `full` | As emitted. A content-on chain may still have redacted or capped it |
| `stripped` | A content-off destination's chain stripped it, or a `request` record the core emitted with capture off |
| `none` | The core captured none (no destination wanted content, or `weft.Content(false)`); also every compaction marker, which carries none by nature |

| Kind | On a content-off destination |
|---|---|
| `event`, `delta` | Kept, the shape intact and the content fields emptied: `tool_start.args` null, `tool_finish.content` `""`, `text_delta.text` `""`, `reasoning_delta.text` `""`, `tool_args_delta.args` `""`, `steered.messages` `[]`, parked calls' `args` null. Marked `stripped` |
| `messages`, `prompt`, `tools`, `raw` | Dropped |
| `request` | Kept with `params.stop` emptied and `messages_ref.index` removed (`count` stays), marked `stripped`: hashes, names and numbers survive |
| App log line | Kept only with `otel.AppLogs(true)`: body and string values `""`, `weft.content = stripped`, time, severity, span and other attributes kept |

A content-on chain may cap content (`MaxBytes`, default 32 KiB) and then sets `weft.content.truncated_bytes` (int, the bytes cut). The transcript (`messages`) is never capped.

## The run row

A conforming store keeps one row per `weft.run.id` and fills it from spans and records as they arrive, in any order. Every rule holds on both shipped backends, `obsdb/sqlite` and `obsdb/clickhouse`. The Go type is [`obsdb.RunRow`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RunRow); Studio serves most fields on [`GET /api/runs`](https://weftgo.dev/docs/reference/studio-api/#get-api-runs). Where two carriers disagree, "the larger" means the larger string, on both backends.

| Field | Derived from |
|---|---|
| `id` | `weft.run.id` |
| `parent_run_id`, `parent_call_id` | `weft.parent.run.id`, `weft.parent.call.id` |
| `caller_run_id`, `caller_call_id` | `weft.caller.run.id`, `weft.caller.call.id`, fill-if-empty like every identity column; empty when the run carries `weft.caller.remote` `"true"`, so a remote link places nothing. `RunQuery.CallerRunID` lists the runs started from one run's calls. `""` on a run recorded before 0.18.0 |
| `trace_id` | The `invoke_agent` span's trace id, else any record's |
| `service` | The resource's `service.name` |
| `agent` | `gen_ai.agent.name` |
| `provider`, `model` | `run_start`'s `model.provider` and `model.name`, or the span's `gen_ai.provider.name` and `gen_ai.request.model`, from either carrier: SQLite keeps the first to arrive, ClickHouse the larger string, so a Google run may read `gcp.gemini` (the span's spelling of `google`) |
| `session_id`, `public_id`, `turn` | `weft.session.id`, `weft.public_id`, `weft.turn` |
| `playground`, `experiment_id`, `forked_from` | `weft.playground`, `weft.experiment.id`, `weft.forked_from` |
| `resumed_from` | `weft.resumed_from` on the span or `run_start`; the larger when they differ |
| `resumed_by` | On a parked run, at read time, never stored: the latest run by start time whose `resumed_from` names it (a tie goes to the larger id). Deleting the resumer unlinks it |
| `manifest_hash`, `weft_version` | `weft.manifest.hash`, `weft.version` from any record or span that carries them, so a run whose records were lost still names both. For the version, `run_start` and the root span rank together; the root's resource `weft.version` only when the root has no attribute |
| `meta` | Every string attribute outside the contract (`obsdb.MetaOf`, [above](#what-lands-in-meta)) |
| `started` | The earliest time of anything of the run |
| `last_seen` | The latest time of anything of the run, heartbeats included |
| `finished` | The later of the `invoke_agent` span's end and `run_finish`'s time; absent until either arrives |
| `root_ended` | The `invoke_agent` span is stored, any status. Kept by both backends, not served by Studio |
| `finish_recorded`, `settling` | `finish_recorded`: `run_finish` is stored (not served). `settling`, at read time ([`obsdb.DeriveSettling`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#DeriveSettling)): root stored, not derived, not failed, no `run_finish`, last-seen at most 30 s old. While settling, no reader calls records lost |
| `status` | At read time, never stored: `failed` if the root's status is `Error`; else `succeeded` if `run_finish` exists or the root is stored; else `running` if last-seen is at most 30 s old; else `interrupted`. No parked status: a parked run is `succeeded` with `pending` > 0. As a filter, two more read-time words: `parked` (succeeded, pending, no resumer stored) and `cancelled` (failed with `error_type` `cancelled`); [`obsdb.ParseStatus`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ParseStatus) refuses any other word |
| `error` | The `invoke_agent` span's status description |
| `steps`, `pending` | `run_finish`'s `steps` and the length of its `pending`, else the span's `weft.run.steps` and `weft.run.pending` |
| `stop_reason` | `weft.run.stop_reason`: the last model call's finish, not what ended the run |
| `stopped_by` | The span's `weft.run.stopped_by` or `run_finish`'s `stopped_by`, the larger when they differ; `""` when neither carried one. Filterable exactly, or by prefix ending in `:` (`has_tool_call:`) |
| `cancel_cause` | The span's `weft.cancel.cause`; `""` on a plain cancel and every other run |
| `usage` | `run_finish`'s `usage`, else the span's `gen_ai.usage.*`; the cache and reasoning splits from the span |
| `event_count` | Stored `event` records |
| `message_count` | Stored growth `messages` records, views excluded |
| `delta_count` | The delta counter's high-water mark; deltas are not stored |
| `instructions_hash` | `weft.instructions.hash` from `run_start` or the span, the larger when they differ |
| `events_emitted`, `messages_emitted` | The span's `weft.run.events` and `weft.run.messages`, the larger across roots; 0 when the root carried neither. Fewer events stored is `gap`, `events_lost`; fewer messages stored, with at least one stored, is `gap`, `messages_lost`. None stored is never called lost: a content-off destination stores none by design |
| `error_type` | A failed run's kind: the span's `error.type`, with `context.Canceled` and `context.DeadlineExceeded` read as `cancelled` ([`obsdb.RunErrorType`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RunErrorType)); `""` otherwise. The status stays `failed` |
| `problems` | Counters derived at ingest from the spans, one token per span id, so a span stored twice counts once. `attempts_retried` (failed `attempt` spans a later attempt of the same call followed), `fallbacks` (successful `attempt` spans with `weft.attempt.layer` `fallback`). `tool_errors` (`execute_tool` spans with status `Error`, except `DENIED`, `RETRY` and the context errors). `denied` (`DENIED` spans plus each root's `weft.run.denied`), `truncated` (`weft.tool.truncated_bytes` > 0), `repaired` (0 for now), `tap_panics` (each root's `weft.tap.panics`). `metadata_dropped` rides the same fold as the `truncated` hole. `log_warn` and `log_error` are read time, on the run document only |
| `children_count`, `children_failed` | Studio's run row only, read time, never stored: the rows whose `parent_run_id` is this run, one level deep, and how many of them failed |
| `prompt_preview` | The run's prompt (the turn's own; a resume's new prompt when it carries one), cut to 200 runes; `""` when the records carried no content or no user text |
| `catalog_hash` | `weft.catalog.hash` of request index 0; `""` when it offered no tools |
| `request_count` | The highest `weft.request.index` + 1 |

| Read | Rule |
|---|---|
| Steps | The run's `chat` spans ordered by `weft.step.index`, equally its `step_start` and `step_finish` events |
| Tool calls | The run's `execute_tool` spans ordered by `weft.tool.seq`, equally its `tool_start` and `tool_finish` events |
| Transcript | The growth `messages` records concatenated in index order |
| Session | The runs sharing `weft.session.id` that are top-level and not playground runs, ordered by `weft.turn`, then `started`. Its `title` is the newest turn's non-empty `weft.session.title`; `first_prompt` the first turn's prompt preview; `content_off` true when the first turn stored events and no `messages` record, and is not derived, not running and not settling |
| Run tree | A run's spans plus every descendant run's, found through `parent_run_id` and, for a run no row names a parent of, core's child id shape. Capped at 10,000 spans ([`obsdb.TreeSpanCap`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#TreeSpanCap)) and 10,000 rows; a derived run's trace is read up to its first 50,000 spans. Served as [`GET /api/runs/{id}/spans?tree=1`](https://weftgo.dev/docs/reference/studio-api/#get-api-runs-id-spans-tree-1) |
| Manifest | Not derived from records: `manifest_hash` names a one-agent manifest an `obsdb.ManifestStore` keeps, written by Studio from `weft.json` and runtime registrations, kept forever |

**What the record says about your own code.** `PrepareStep`, `WrapModel`, `WrapTools`, `Tap`, `OnMessages` and `OnRunEnd` are not recorded as hooks; only their effects are. A step whose `weft.system.hash` or catalog differs from the run's instructions or the step before reads as rewritten, and the request's `prepared` names what changed. `WrapModel` shows through the `attempt` spans its middleware reports. `WrapTools` shows through the `execute_tool` outcome (`weft.panic.layer` `middleware`, `DENIED`). Observer panics are counted in `weft.tap.panics`; `OnRunEnd` leaves nothing.

## Badges

Every place a record is missing, cut or derived is shown with a badge from one closed table, [`obsdb.Hole`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Hole). [Badges and holes](https://weftgo.dev/docs/reference/badges/) lists every hole, cause, reason and fix. The run-level rules, in short:

| Badge | On a run when |
|---|---|
| `not_recorded` | `instructions_hash` is `""` and `request_count` is 0: written before 0.10.0, no request, prompt or tools records |
| `not_recorded`, cause `no_logger` | A weft run, not derived, not running, whose spans are stored and no record, and whose root says none were emitted: the app exported spans only |
| `interrupted` | The status is `interrupted` |
| `max_tokens` | `stop_reason` is `max_tokens` |
| `stripped` | An event record is marked `stripped` or `none` |
| `truncated` | An event record carries `weft.content.truncated_bytes` > 0 |
| `truncated`, cause `metadata_cap` | The root carries `weft.metadata.dropped` > 0 |
| `gap` | The event counter has a hole below its high-water mark |
| `gap`, cause `events_lost`, `messages_lost` or `tail_lost` | Fewer records stored than the root says were emitted, or (a root without the counts) a stored root with events and no `run_finish`. Raised only once the run stopped settling |
| `compacted` | The run holds a run-scope view |
| `derived` | The run was built from stock spans |
| `derived` (replay view) | On the run document, a top-level playground replay (one with no parent run) whose `weft.replay.view` is `derived` or `unknown` |

These rules are the ones the export's and the fixtures' `holes` follow (studio/export.go:765-851); the export also adds per-record notes (holes from the prompt and catalog refs, `not_recorded` for a batch at step < 0, `derived` for a derived input batch, a hidden-children hole). `GET /api/runs/{id}` raises a subset and leaves `max_tokens`, a cut event and `compacted` to the step or event they belong to, as [Run-level badges](https://weftgo.dev/docs/reference/badges/#record-badges) explains. `redacted` is reserved. `hidden` comes from the reader's token scope, not the data. It is used more widely than the contract's "a read-scoped token's view of a system prompt". Request records, the tool catalog, a run tree's descendants outside a panel token's public id, and routes that answer the dev token only all answer it.

Status words beyond the four stored ones are read time: **cancelled** is `failed` with `error_type` `cancelled`; **parked** is `succeeded` with `pending` > 0 while nothing is known to have resumed it, and **parked → tN** once `resumed_by` or a later turn of its session says so.

<span id="genai-conventions"></span>
## GenAI semantic conventions

weft writes the OTel GenAI conventions (semconv v1.41.0) beside its own keys, so any GenAI-aware backend renders its traces:

| Key | Where weft writes it |
|---|---|
| `gen_ai.operation.name` | Every span but `attempt`: `invoke_agent`, `chat`, `execute_tool` |
| `gen_ai.agent.name` | `invoke_agent`; every record |
| `gen_ai.provider.name` | `invoke_agent`, `chat`, `attempt` |
| `gen_ai.request.model` | `invoke_agent`, `chat`, `attempt` |
| `gen_ai.response.model` | `chat`, `attempt` on success; the `step_finish` record |
| `gen_ai.response.finish_reasons` | `chat` |
| `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens` | `invoke_agent` (run totals), `chat` (the call's) |
| `gen_ai.usage.cache_read.input_tokens`, `gen_ai.usage.cache_creation.input_tokens`, `gen_ai.usage.reasoning.output_tokens` | The same spans, when non-zero |
| `gen_ai.tool.name`, `gen_ai.tool.call.id` | `execute_tool`; the `tool_start` and `tool_finish` records |
| `gen_ai.conversation.id` | Every span and record the core emits for a run with a `weft.session.id`, and its heartbeats, beside `session.id`; not the compaction marker |
| `error.type` | Failed spans |

weft never writes the conventions' opt-in content attributes (input and output messages on spans): content travels in log records under each destination's content policy.

## Deriving a run from stock spans

An app that exports **stock** GenAI spans, such as a Python or TypeScript agent instrumented by the OTel GenAI conventions with no `weft.*` attribute anywhere, gets runs too. [`obsdb.DeriveStockRuns`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#DeriveStockRuns) is the one derivation both backends write through (since 0.15.0). [Inspect agents written in other languages](https://weftgo.dev/docs/observe/other-languages/) shows how to send such spans.

| Rule | Detail |
|---|---|
| A span's operation | Its `gen_ai.operation.name` (an empty value is unset); without it, its name: starting with `invoke_agent` or `execute_tool`, or `chat` alone or followed by a space (so a `chatbot` span is not a model call) |
| A root | An `invoke_agent` span with no `weft.run.id` and a `gen_ai.conversation.id`. Each root is one derived run |
| A subtree | The spans under the root by parent span id, down to, not into, any nested root or any span with `weft.run.id` |
| No conversation id | An `invoke_agent` span without one opens no run; its `chat` and `execute_tool` spans count toward the enclosing root. A tree with no conversation id anywhere stays a trace only |
| weft spans | Never derived: a weft run's spans carry the GenAI mirrors, `gen_ai.conversation.id` among them, and still make no derived twin |
| Partial exports | A span counts only through a complete chain of stored parents, so a run whose spans arrive over several exports converges: steps, usage and last-seen only grow |
| When it runs | The writers re-derive a trace from all its stored spans whenever an export brings a span without `weft.run.id` whose operation is one of the three |

| Field | Derived as |
|---|---|
| `id` | `otel-<trace id>-<root span id>`, lowercase hex; deterministic, so a retried export lands on the same row ([`obsdb.ParseStockRunID`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ParseStockRunID) splits it) |
| `derived` | `true`: the row says the reader built it |
| `trace_id`, `service` | The root's trace id and resource `service.name` |
| `agent` | The root's `gen_ai.agent.name` |
| `provider`, `model` | The root's `gen_ai.provider.name` and `gen_ai.request.model`, else the first `chat` span's |
| `session_id` | The root's `gen_ai.conversation.id`: the conversation is the session, its derived runs its turns; `""` (no session) for a root without one, since 0.20.0 a run in its own right rather than skipped |
| `turn` | `0` on the row. Studio's session document numbers a session's derived top-level runs 1..n by start order (after the highest numbered `thread` turn, when the session holds both) for display, never stored; a session whose every run is derived is badged "derived (stock OTel)" |
| `parent_run_id`, `parent_call_id` | For a root nested in another root's subtree: that root's derived id and the `gen_ai.tool.call.id` of the nearest `execute_tool` span above. A stock root under a weft run's tool is top-level |
| `started`, `finished` | The root's start and end |
| `last_seen` | The latest time in the subtree |
| `status`, `error` | `failed` with the status description when the root's status is `Error` (with no description: "the root span's status is Error (no description)"), else `succeeded`. Never running or interrupted |
| `usage` | The run's own: the root's `gen_ai.usage.*` when present, as given; else the sum over the subtree's `chat` spans. No correction either way. With no usage key anywhere the row reads zero and Studio prices it unknown |
| `steps` | The number of `chat` spans in the subtree |
| `chat` | The subtree's `chat` spans in start order, each span's step its 0-based ordinal |
| `tools` | The subtree's `execute_tool` spans in start order: `gen_ai.tool.name`, `gen_ai.tool.call.id`, `seq` the 1-based ordinal, `step` the latest `chat` span that started before it, absent when none did |
| `holes` | `derived` |

A derived run's spans are read from its trace at read time with the reader's numbers stamped on the copy: `weft.step.index` on `chat` and `execute_tool` spans, `weft.tool.seq` on `execute_tool` spans, and `gen_ai.operation.name` as resolved. Not derivable, and badged `derived` (cause `stock_spans`) rather than shown empty: events, the transcript, message bodies, the request, prompt and catalog, `turn`, `public_id`, `stop_reason`, `pending`, `meta`, the record counts and the hashes. Studio refuses a derived run as a replay or fixture source, and a panel token never reaches one, since it has no public id.

## Conformance fixtures

`obsdb/testdata/contract/` holds one directory per case: an OTLP/JSON export (`traces.json`, `logs.json`) and `expect.json`, the run rows any conforming store derives from it. `TestContract` checks every case on SQLite, `TestContractClickHouse` on ClickHouse with `WEFT_CLICKHOUSE_DSN`. The inputs are real pipeline output, except `stock_genai`, which is hand-written. `go test ./obsdb -run 'TestContract$' -update-contract` regenerates them, normalised so a regeneration with no code change leaves `git diff` empty.

| Case | What it pins |
|---|---|
| `plain` | One model call, no tools: the minimal succeeded run |
| `tool_calls` | Two steps, one tool call, `catalog_hash`; metadata in `meta` (`enduser.id` yes, `user.id` no); the playground marks as columns and `meta` |
| `subagent` | A parent and its `<id>/0/call_1` child, linked; the parent's usage includes the child's; the parent's run tree |
| `session_turns` | Two `thread` turns: run ids, session id, public id, turn |
| `compacted` | A run-scope view, excluded from `message_count`; the `compacted` badge |
| `content_off` | Stripped events, no messages, request records kept; the `stripped` badge |
| `max_tokens` | `stop_reason` `max_tokens`; the `max_tokens` badge |
| `interrupted` | No `invoke_agent`, no `run_finish`: status `interrupted` |
| `pre_upgrade` | No request, prompt or tools records, no `weft.instructions.hash`: `not_recorded` |
| `failed` | `MaxSteps(1)` exceeded: `failed`, the error text, steps, usage and stop reason from the span; `error_type` `max_steps` |
| `parked` | A `RequireApproval` call parked: `succeeded`, `pending` 1, `stopped_by` `parked` |
| `session_title` | A content-off session titled after its first turn: `weft.session.title` in `meta`, the session row's `title`, `content_off` |
| `stopped_by` | `StopWhen(HasToolCall("submit_ticket"))`: `stop_reason` `tool_calls`, `stopped_by` `has_tool_call:submit_ticket` |
| `canceled` | A cancel with cause `studio.cancel`: `failed`, `error_type` `cancelled`, `stopped_by` `canceled`, `cancel_cause` from the span alone |
| `tool_problems` | A handler panic, a `StrictInput` refusal, a cut result, an `mw.Allow` refusal: `tool_errors` 2, `truncated` 1, `denied` 1 |
| `retry_fallback` | `mw.Retry` and `mw.Fallback` cases: `attempts_retried`, `fallbacks` keyed on `weft.attempt.layer` |
| `approval_denied` | Two parked calls, one denied, one undecided: zero-length denied spans, `weft.resume.calls`, `weft.run.denied` 2, `resumed_from`, `resumed_by` |
| `retries_taps` | `weft.tool.retry` 1 and 2 under `MaxModelRetries(1)`, `model_retries_exceeded`; a panicking `Tap`; 65 metadata pairs (`metadata_cap`); prompt `segments` |
| `resumed` | `Approve` and `Resolve` with `weft.ResumeOf` and `weft.approval.actor`: `weft.tool.approved`, `weft.resume.calls`, the actor in `meta` |
| `stock_genai` | Stock spans only: two derived runs in one conversation, one with a tool call, one failed |
| `tracer_only` | Spans only: `succeeded` from the root, `events_emitted` 0, `not_recorded` cause `no_logger` |
| `tracer_only_failed` | The `failed` run, spans only: `failed` from the root, `no_logger` |
| `tail_lost` | Every record after a `tool_finish` dropped: `succeeded`, `gap` with `events_lost` and `messages_lost` |
| `slog_bridged` | `mw.Log` lines under `chat` (DEBUG 5) and a tool's WARN 13 under `execute_tool`, attributed to the run; the root's `weft.logs.bridged` 0, not in `meta` |
| `records_dropped` | `weft.records.dropped` 3 on `run_start` and `run_finish`; no row field |
| `run_cards` | `Output` runs (`weft.output.submitted`), `park_on` and `park_source` parks, a `Timeout` (`timeout_ms`), a parked Subagent child (`SUBAGENT_PENDING`), `prepared` and `thinking.wire`, a 503 then an answer (`http.response.status_code`, `weft.attempt.wait_ms`) |
| `queue_breakpoints` | `weft.tool.queue_ms` under `Parallelism(1)`; a playground breakpoint park (`weft.playground.breakpoints`) |
| `bridge_overrides` | `weft.override.params` with a `null`, `weft.override.tool_choice` `any`; a redacted bridged WARN with 125 attributes (`weft.log.attrs_dropped` 5) |
| `bridge_stripped` | A bridged WARN on a content-off destination that opted in: stored stripped |
| `messages_lost` | One growth `messages` record dropped: `message_count` 3 of 4, `gap` with `messages_lost` |

`expect.json` is `{case, description, pending?, derived?, runs: [...], sessions?}`; each run lists the run-row fields, `derived` when true, its `chat` and `tools` lists, its `tree` and its `holes`, and may carry `logs`, `hole_causes` and `problems`. Empty fields are omitted. Runs are ordered by `started`, then id; times are RFC 3339 UTC.

| Normalisation | Rule |
|---|---|
| Export | Folded to one resource and scope block |
| Times | Each signal keeps its own order on a 1 ms grid from the case's epoch (2026-10-01T09:00Z plus one minute per case). Span and record times are not comparable with each other |
| Durations | `weft.ttft_ms`, `weft.latency_ms`, `weft.attempt.wait_ms`, `weft.tool.queue_ms` and `step_finish`'s `latency_ms` and `ttft_ms` read 1 where set |
| Version | `weft.version` and the scope's version read `v0.0.0-contract` |
| Ids | Renumbered in first-seen order with their shapes kept: trace ids `7ace…`, span ids `5ba0…`, run ids `a110…`, session ids `01K…`, manifest hashes `3a21f…` |
| Batches | Each step holds at most one tool call, so no parallel race churns a fixture |

## Versions

| Since | What arrived |
|---|---|
| 0.8.0 | `weft.playground` read in its string spelling, `"true"` |
| 0.10.0 | The `request`, `prompt` and `tools` records, `weft.instructions.hash`; the compaction view (`weft.messages.reason = compacted`) |
| 0.15.0 | `docs/record-contract.md` and the conformance fixtures; derived runs from stock spans |
| 0.16.0 | `weft.resumed_from`, `weft.resume.calls`, denied calls' `execute_tool` spans; `weft.run.stopped_by`, `weft.cancel.cause`; `weft.run.events`, `weft.run.messages`, `weft.records.dropped` |
| 0.17.0 | The slog bridge: app log records, `weft.logs.bridged`. The run cards' facts: `weft.attempt.wait_ms`, `http.response.status_code`, `weft.tool.timeout_ms`, `weft.tool.queue_ms`, `weft.tool.pending.source`, `weft.subagent.pending`, `weft.output.submitted`, the tools record's `output`, the request's `prepared` and `thinking.wire`, `weft.playground.breakpoints`. Breaking: `weft.override.params` changed shape from the Go struct's JSON to the request record's lower-case names with `null`s, which changes a params override's `weft.override.hash` |

## See also

- [Use your own OpenTelemetry SDK](https://weftgo.dev/docs/observe/opentelemetry/)
- [Badges and holes](https://weftgo.dev/docs/reference/badges/)
- [Inspect agents written in other languages](https://weftgo.dev/docs/observe/other-languages/)
- [Event types](https://weftgo.dev/docs/reference/events/)
- [`docs/record-contract.md` at v0.20.2](https://github.com/weftgo/weft/blob/v0.20.2/docs/record-contract.md)
