---
title: obsdb record and span types
description: The types an obsdb database stores or returns besides runs and sessions. Spans, records, the hub, transcript and request records, stock derivation, experiments, manifests and the command store, field by field.
url: https://weftgo.dev/docs/reference/obsdb-records/
type: reference
sources:
  - 'v0.20.2: weft/core/request.go:152-194 (wireFacts: the WireFacts() convention along the Unwrap chain; behind mw.Fallback the primary''s)'
  - 'weft/obsdb/request.go:378-390 (RequestWire.Dropped counts the names left out); weft/core/request.go:145-149 (maxWireNames 32, maxWireName 128); weft/obsdb/compaction.go:56-60 (RecordThread = thread, the tenth kind); weft/obsdb/stock.go:109-116 (IsStockRoot; a top-level invoke_agent without a conversation id opens a run DeriveStockRuns decides), 181-186 (DeriveStockRuns: one per stock root or top-level invoke_agent) — v0.20.2'
  - weft/obsdb/request.go:355-387 (RequestBody.Parallelism, Wire; RequestWire), 465-520 (ToolsRecord.Skipped, SkippedMore; SkippedTool; SourceDetail; ToolEntry.SourceDetail); weft/obsdb/model.go:70-82, 151-160 (CallerRunID, CallerCallID; a remote link read as empty); weft/obsdb/db.go:360-368 (PassPredicate), 400-412 (ExperimentInput.FromStep); weft/obsdb/commands.go:70-77 (DeleteRuntime), 105-135 (BreakpointProvenanceStore, BreakpointSet) — v0.20.2
  - '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)'
  - every path and line below is in the weft v0.17.0 tag (53bab77f), read from the weft-v0.17.0 worktree
  - obsdb/doc.go:1-35 (the model, the hub, optional capabilities, deltas and heartbeats)
  - obsdb/model.go:11-52 (Span, SpanEvent, Record, Batch), 54-88 (Weft), 91-128 (the identity and record attribute names)
  - obsdb/otlp.go:18-23 (FromOTLPTraces), 67-72 (FromOTLPLogs)
  - 'obsdb/hub.go:10-31 (Frame, the frame kinds), 36-74 (Selector, matches), 76-82 (Hub), 104-118 (NewHub, default queue 1000), 120-134 (HubOption, QueueSize), 136-155 (Publish drops a full subscriber), 157-189 (Subscribe: a cursor ahead of the hub reads as none), 191-215 (RecordFrame, RunFrame, AttemptFrame)'
  - obsdb/db.go:176-203 (TranscriptBatch, TranscriptBodies, DedupBatches), 355-416 (Experiment, ExperimentCommand, ExperimentVariant, ExperimentInput), 643-654 (PosEvent), 960-963 (SessionTitleKey)
  - obsdb/compaction.go:14-76 (Compaction, CompactionRun, CompactionSession, ReasonCompacted, RecordCompaction)
  - obsdb/asof.go:14-56 (StepMessages, ErrStepMessages, StepMessagesError), 113-160 (Assembler, NewAssembler, Step)
  - obsdb/search.go:174-200 (MessageText, MessagesText)
  - obsdb/request.go:305-521 (RequestRecord, RequestBody and its parts, PromptRecord, PromptSegment, ToolsRecord, ToolEntry), 723-751 (StoredRecord)
  - obsdb/raw.go:9-62 (RecordRaw, RawRecord, RawSide)
  - obsdb/logs.go:42-64 (OtherLog)
  - obsdb/manifests.go:1-90 (ManifestStore, StoredManifest, ManifestSourceFile, ManifestSourceRuntime, ErrInvalidManifest, ManifestHash)
  - obsdb/commands.go:1-252 (CommandStore, the Command* states, ErrInvalidCommand, StoredCommand, CommandQuery, RunRoute, StoredRuntime)
  - 'core/request.go:472 (prompt segment sources), 565-614 (tools record entries: source local, subagent or the tool''s origin; approval includes the run''s park rule)'
  - studio/studio.go:66-71, 279-283 (the DB's own hub, else obsdb.NewHub fed by ingest)
  - core/tool.go:732-735 (ReplayNever never, ReplaySafe safe)
  - docs/record-contract.md:486-537 (§4 log records, the record kinds), 607-730 (request, prompt and tools bodies), 731-850 (raw, compaction marker)
  - 'obsdb/sqlite/write.go:93-100 (a zero Time stored at Observed; hub frames keep the record as ingested), 420-454 (publish: only the SQLite backend''s Write feeds its hub)'
  - 'obsdb/clickhouse/write.go:420-428 (recordTime: a zero Time stored at Observed)'
  - 'obsdb/model.go:170-239 (DeriveRecord: the record kinds event, delta, messages, heartbeat, request, prompt, tools, raw, compaction)'
  - studio/ingesthealth.go:135-139 (Studio publishes ingested frames into its hub)
  - 'runtime/registry.go:184-194 (registration: Host from os.Hostname, Pid from os.Getpid)'
  - studio/runtime/runtime.go:1026 (the <id>-<pid> runtime id when another process holds the id)
  - obsdb/commands.go:60-67 (PutRuntime, Runtimes most recently seen first), 75-135 (PruneCommands' rules, its count on ClickHouse)
  - obsdb/stock.go:58-65 (StockRunID, ParseStockRunID), 76 (StockTraces), 117-129 (IsStockRoot, StockCandidate), 192 (DeriveStockRuns), 224 (StockRunSpans)
  - obsdb/delete.go:83 (StockRunsOf)
  - obsdb/stock_test.go:20 (ExampleDeriveStockRuns)
  - 'obsdb/db.go:60-66 (Prompt and Tools: ErrNotFound, a HoleError when the reason is known)'
  - 'CHANGELOG.md:607 (CommandStore, obsdbtest command cases), 1053-1056 (DeriveRecord reads a non-string weft.messages.reason), 3258-3260 (structured log bodies render as JSON), 2947-2948 (TranscriptBatch, TranscriptBodies, DedupBatches in 0.10.0), 4296-4327 (obsdb''s first release: the model, the hub, FromOTLPTraces and FromOTLPLogs)'
---

# obsdb record and span types

Package [`obsdb`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb) stores what weft and stock OpenTelemetry send as OTLP-shaped spans and log records, and reads them back as typed records: events, transcript batches, compaction views, request, prompt, tools and raw records, and app log lines. This page lists those types, the live-lane hub, and the three small stores a database keeps beside its runs: experiments, manifests and the playground's commands. The database interface, the queries and the run, session and trace rows are on [obsdb: reading the observability database from Go](https://weftgo.dev/docs/reference/obsdb/); the holes a record can carry are on [Badges and holes](https://weftgo.dev/docs/reference/badges/).

The shapes on this page are what a backend returns from [`DB`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#DB)'s methods and from the optional [`ManifestStore`](#manifeststore) and [`CommandStore`](#commandstore). The functions that build them from stored rows are shared plumbing, exported so the backends, Studio and `otel` parse alike. This page names them only:

| Builds | Shared functions |
|---|---|
| Request, prompt, tools and raw records | `RequestRecordOf`, `PromptRecordOf`, `ToolsRecordOf`, `RawRecordOf`, `AttachRaw` |
| Compactions and step messages | `CompactionOf`, `ViewOf`, `ApplyView`, `AssembleStep`, `MessagesAsOf` |
| Identity and the transcript | `DeriveRecord`, `DeriveSpan`, `DedupBatches`, `TranscriptBodies` |
| Command store and manifests | `CommandByRun`, `CommandTerminal`, `CheckStoredCommand`, `CheckStoredManifest` |

## What a Write takes

A backend's `Write` takes one [`Batch`](#batch): spans and log records exactly as ingested, OTLP-shaped, resource included. Weft identity is never parsed out of ids; it is derived from attributes into a [`Weft`](#weft) and stored as indexed columns. These types arrived with obsdb's first release in 0.7.0.

### Batch

[`obsdb.Batch`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Batch) is one write, in arrival order. `Write` is idempotent on (run, record kind, position) and (trace, span), so a retried transport's duplicate is a no-op.

| Field | Meaning |
|---|---|
| `Spans` | The finished spans of the write, as [`Span`](#span) values |
| `Records` | The log records of the write, as [`Record`](#record) values: weft records and non-weft lines alike |

### Span

[`obsdb.Span`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Span) is one finished span, OTLP-shaped. Non-weft spans pass through unchanged, so a polyglot trace is stored whole.

| Field | Meaning |
|---|---|
| `TraceID` | The trace id, lowercase hex |
| `SpanID` | The span id, lowercase hex |
| `ParentSpanID` | The parent span's id, lowercase hex; `""` for a root |
| `Name` | The span name (`invoke_agent …`, `chat …`, `execute_tool …`, `attempt`, or any other producer's) |
| `Kind` | The OTLP `SpanKind` number |
| `Start` | When the span started |
| `End` | When the span ended |
| `StatusCode` | 0 unset, 1 ok, 2 error |
| `StatusMessage` | The status description |
| `Service` | The resource's `service.name` |
| `Attrs` | The span attributes: `string`, `bool`, `int64`, `float64` or `[]any` values |
| `Resource` | The resource attributes |
| `Events` | The span's events (exceptions and markers), as [`SpanEvent`](#spanevent) values |

### SpanEvent

[`obsdb.SpanEvent`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#SpanEvent) is one event recorded on a span.

| Field | Meaning |
|---|---|
| `Time` | When the event happened |
| `Name` | The event name (`exception`, a marker's name) |
| `Attrs` | The event's attributes |

### Record

[`obsdb.Record`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Record) is one log record, OTLP-shaped. A record with `weft.run.id` is a weft record, routed by its `weft.record` kind; one without is an app log line and lands in the app-log table (`other_logs` on SQLite, `otel_logs` on ClickHouse). Since 0.14.0 a non-string `weft.messages.reason` reads as its text, so such a record is a compaction view, not growth, and no longer counts in a SQLite run's message count.

| Field | Meaning |
|---|---|
| `Time` | The record's time. `FromOTLPLogs` leaves a zero time zero, and so do hub frames; a backend stores a zero-time record at its `Observed` time |
| `Observed` | When the SDK observed the record |
| `TraceID` | The trace of the span the record was emitted under, lowercase hex; `""` without one |
| `SpanID` | That span's id; app log lines are attributed to a run through it |
| `Severity` | The OTLP severity number, 0 unspecified or 1–24 |
| `EventName` | The OTLP event name (`weft.event`, `weft.messages`, `weft.request`, …) |
| `Body` | The body as text: a weft record's JSON, an app line's message |
| `Service` | The resource's `service.name` |
| `Attrs` | The record's attributes |
| `Resource` | The resource attributes |

### Weft

[`obsdb.Weft`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Weft) is the identity obsdb derives from a span's or record's attributes and stores as indexed columns. Zero values mean absent; a span or record with no `weft.run.id` is non-weft and every field reads absent.

| Field | Attribute | Meaning |
|---|---|---|
| `RunID` | `weft.run.id` | The run the span or record belongs to |
| `ParentRunID` | `weft.parent.run.id` | The parent run, for a subagent child |
| `ParentCallID` | `weft.parent.call.id` | The parent's tool call that started this run |
| `SessionID` | `weft.session.id` | The thread session of the run |
| `PublicID` | `weft.public_id` | The session's public id |
| `Turn` | `weft.turn` | The session turn number |
| `Agent` | `gen_ai.agent.name` | The agent's name |
| `Record` | `weft.record` | The record kind, one of ten: `event`, `delta`, `messages`, `heartbeat`, `request`, `prompt`, `tools`, `raw`, `compaction`, `thread` (a thread session's records, since 0.18.0); `""` for a span or a non-weft record |
| `EventType` | `weft.event.type` | The event's type (`run_start`, `tool_start`, …) |
| `Pos` | `weft.event.pos`, `weft.messages.index`, `weft.delta.pos`, `weft.request.index`, `weft.prompt.index`, `weft.tools.index`, `weft.raw.index` | The record's position in its kind: the value of the (run, kind, pos) key and the live lane's dedup |
| `Step` | `weft.step.index` | The step; -1 when absent |
| `ToolSeq` | `weft.tool.seq` | The tool call's sequence number; -1 when absent |
| `Playground` | `weft.playground` | The run was started by the playground |
| `ExperimentID` | `weft.experiment.id` | The saved experiment the run belongs to |
| `ForkedFrom` | `weft.forked_from` | The run this one was forked from |
| `ResumedFrom` | `weft.resumed_from` | The parked run this one resumes; on the `invoke_agent` span and the `run_start` record only |
| `CallerRunID`, `CallerCallID` | `weft.caller.run.id`, `weft.caller.call.id` | The tool call that started this run when it is no Subagent child, such as a `thread/pool` child session's turn or a `Generate` inside a handler. A link, never parenthood. On the `invoke_agent` span and the `run_start` record only. Empty when the link is remote (`weft.caller.remote`, `weft.WithCaller`), since readers place a run by its local link alone |
| `Reason` | `weft.messages.reason` | `""` for transcript growth, `compacted` for a compaction view, which is never counted or concatenated as transcript; a non-string value reads as its text |
| `Input` | `weft.messages.input` | The messages record is the run's input record: what search reads the turn's prompt from |

### Decoding OTLP

Both decoders arrived in 0.7.0, with golden protobuf and JSON fixtures under `obsdb/testdata` that Studio's ingest and the SDK path pin against. Scalars are kept verbatim, arrays become `[]any`, key-value lists become maps and bytes become base64; a nil element at any layer is skipped.

| Function | Meaning |
|---|---|
| <span id="fromotlptraces"></span>[`FromOTLPTraces`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#FromOTLPTraces) | Decodes an OTLP/HTTP trace export request into `[]Span`. Studio's receiver and a stock collector's dump produce the same rows the local sink does |
| <span id="fromotlplogs"></span>[`FromOTLPLogs`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#FromOTLPLogs) | Decodes an OTLP/HTTP log export request into `[]Record`. Weft and non-weft records both pass through; the kind they carry decides where `Write` puts them |

## The live lane

The SQLite backend's `Write` publishes its frames to its hub before it returns, so an in-process subscriber (Studio's `/api/live` handler in setup A) sees a record with no network hop; the handle exposes the hub through `Hub()`. ClickHouse's `Write` publishes nothing: for a backend without a hub, Studio publishes what it ingests into its own [`NewHub`](#newhub).

### Hub

[`obsdb.Hub`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Hub) is the live lane's interface. It promises only that `Publish` never blocks the caller beyond a bounded per-subscriber queue, and that a slow subscriber is dropped. The rest of the behaviour below is the in-process hub's, from `NewHub`.

| Method | Meaning |
|---|---|
| [`Publish(ctx, f)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Hub) | Sends the frame to every matching subscriber without blocking. `NewHub`'s hub stamps `f.Seq` from its hub-wide counter, and drops a subscriber whose queue is full: its channel closes |
| [`Subscribe(ctx, sel, after)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Hub) | Returns a channel of the frames `sel` matches with `Seq` above `after`. The channel closes when the hub drops it or `ctx` ends; tell the two apart by `ctx.Err()`. A cursor ahead of this hub's counter (one minted by a previous process) reads as 0 |

A [`Selector`](https://weftgo.dev/docs/reference/obsdb/#selector) scopes a subscription to one run, session, public id or agent, or to every run with `All`; an empty or over-set selector matches nothing.

| Name | Meaning |
|---|---|
| <span id="newhub"></span>[`NewHub(opts...)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#NewHub) | Returns the in-process hub: one `Seq` counter for every frame, one bounded queue per subscriber. A hosted Studio may swap in another implementation of `Hub` |
| <span id="huboption"></span>[`HubOption`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#HubOption) | Configures `NewHub` |
| <span id="queuesize"></span>[`QueueSize(n)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#QueueSize) | Sets the per-subscriber queue depth; default 1000, and 0 or less keeps it. Publishing to a full queue drops the subscriber rather than blocking the writer: a live tail resumes from the database |

### Frame

[`obsdb.Frame`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Frame) is one live-lane message.

| Field | Meaning |
|---|---|
| `Kind` | `record`, `run` or `attempt` (the constants below) |
| `Record` | The record as ingested, deltas included; set when `Kind` is `record` |
| `Weft` | The frame's derived identity, what a `Selector` matches on |
| `Run` | The run row that changed; set when `Kind` is `run` |
| `Span` | The `attempt` span as it landed; set when `Kind` is `attempt` |
| `Seq` | Hub-wide and monotonic: the SSE id and the resume cursor |

| Constant or function | Value | Meaning |
|---|---|---|
| <span id="framerecord"></span>[`FrameRecord`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#FrameRecord) | `record` | A record as ingested, deltas included |
| <span id="framerun"></span>[`FrameRun`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#FrameRun) | `run` | A run row that changed |
| <span id="frameattempt"></span>[`FrameAttempt`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#FrameAttempt) | `attempt` | An `attempt` span (one try inside a model call) published as it lands: a step is retrying or falling back before its `chat` span ends. Live only: the span is stored as any span is, and the frame is never backfilled |
| <span id="recordframe"></span>[`RecordFrame(r)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RecordFrame) | | The frame a `Write` publishes for one record, with its derived identity |
| <span id="runframe"></span>[`RunFrame(r)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RunFrame) | | The frame a `Write` publishes for a run row that changed |
| <span id="attemptframe"></span>[`AttemptFrame(s)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#AttemptFrame) | | The frame for an `attempt` span; `ok` is false for any other span and for an attempt span that names no run |

## Events and the transcript

Deltas travel on the live lane but are counted, never stored; heartbeats are never stored and only move a run's last-seen. What a backend keeps of a run's stream is its positioned events and its messages records.

### PosEvent

[`obsdb.PosEvent`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#PosEvent) is one positioned event of a run, as `DB.Events` pages them in an [`EventPage`](https://weftgo.dev/docs/reference/obsdb/#eventpage).

| Field | Meaning |
|---|---|
| `Pos` | The durable position, `weft.event.pos` |
| `Time` | The record's time |
| `Event` | The event body, verbatim JSON (`weft.UnmarshalEvent` restores it) |
| `Content` | `weft.content`: `stripped` from a content-off chain, `""` as emitted |
| `TruncatedBytes` | `weft.content.truncated_bytes`: what a content-on chain's cap cut, 0 for none. A ClickHouse row written before migration 0004 carries neither attribute |

### TranscriptBatch

[`obsdb.TranscriptBatch`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#TranscriptBatch) is one growth messages record as `DB.TranscriptBatches` returns it. Readers place a batch by its `Step`, never by its neighbours. `TranscriptBatch`, with the internal `TranscriptBodies` and `DedupBatches`, arrived in 0.10.0 (ADR 0028 §8).

| Field | Meaning |
|---|---|
| `Index` | `weft.messages.index`: the record's place in the run's transcript |
| `Step` | `weft.step.index`, the step the batch joined; -1 when the record carried none (a ClickHouse row before migration 0004, or a producer that never stamped it), and a reader that places it anyway shows the `derived` badge |
| `Input` | `weft.messages.input`: the run's input record. On a partial resume it ends at the last assistant message with tool calls; the rebuilt tool message is the next batch, at step 0 |
| `InputDerived` | `Input` was inferred by the backend for a row that did not store the flag (ClickHouse rows before `weft_records.Input`): true on index 0 unless the body is a lone assistant message. Readers badge it `derived` |
| `Messages` | The body: a JSON array of messages, through the backends' dedup of the old partial-resume shape |

### Compaction

[`obsdb.Compaction`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Compaction) is one compaction a run's records name, as `DB.Compactions` returns it: the run-scope views by index, then the session markers in emission order. A view is never part of the plain transcript and applies only to the request whose `messages_ref` names its index.

| Field | Meaning |
|---|---|
| `Scope` | `run` for a compaction view, `session` for thread's marker (the constants below) |
| `Hash` | `weft.compaction.hash` |
| `Index` | The view's messages index; -1 for a session marker |
| `Step` | The step the view was recorded at; -1 for a session marker |
| `FromSeq` | Start of the replaced transcript range, inclusive; 0 for a marker |
| `ToSeq` | End of the replaced range, exclusive; 0 for a marker |
| `Messages` | The view's messages, which replace `[FromSeq, ToSeq)`; a marker carries none and is never applied |
| `Reason` | Thread's compaction reason: `manual`, `threshold`, `overflow`, `from_hook` or `trim`; `""` for a view |
| `Replaced` | Messages replaced: `ToSeq-FromSeq` for a view, thread's count for a marker |
| `Entries` | Messages put in their place: the length of `Messages` for a view, thread's count for a marker |
| `TokensBefore` | Thread's estimate before compacting; 0 for a view |
| `TokensAfter` | Thread's estimate after compacting; 0 for a view |

| Constant | Value | Meaning |
|---|---|---|
| <span id="compactionrun"></span>[`CompactionRun`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CompactionRun) | `run` | The `weft.compaction.scope` of a view the core emits when a `PrepareStep` sent messages that are not the run's transcript |
| <span id="compactionsession"></span>[`CompactionSession`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CompactionSession) | `session` | The scope of thread's informational marker, filed under the last run that produced the compacted context |
| <span id="reasoncompacted"></span>[`ReasonCompacted`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ReasonCompacted) | `compacted` | The one `weft.messages.reason` ADR 0028 §8 defines. A messages record with any other reason fails `DB.Compactions` loudly |
| <span id="recordcompaction"></span>[`RecordCompaction`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RecordCompaction) | `compaction` | The `weft.record` kind of thread's session marker |

### StepMessages

[`obsdb.StepMessages`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#StepMessages) is the messages one step's model call carried: the replay prefix for `from_step` and what a replay fixture keys on. Studio's `transcript?step=N`, `weft/runtime`'s replay and the `wefttest` fixtures all assemble it the same way.

| Field | Meaning |
|---|---|
| `Step` | The step asked for |
| `Messages` | The growth records up to the request's own index, or, under a view, up to the view's index with its range replaced |
| `View` | The run-scope compaction view the step's request named; nil when it carried the plain transcript |
| `Derived` | No request record placed the messages (a run written before ADR 0028, or a `messages_ref` a content-off chain stripped): the transcript before step `Step`'s assistant message was used instead |

### StepMessagesError

[`obsdb.StepMessagesError`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#StepMessagesError) is the refusal when the stored records do not rebuild the messages a request names. `errors.Is(err, obsdb.ErrStepMessages)` holds; its text is `obsdb: step <n>: <msg>`. [Badges and holes](https://weftgo.dev/docs/reference/badges/#stepmessageserror) has its two holes in full.

| Field | Meaning |
|---|---|
| `Step` | The step that could not be rebuilt |
| `Hole` | `gap` when a record the request names is missing or does not fit; `stripped` when the run stored no messages at all |
| `Msg` | What did not fit, in words |

### Assembler

[`obsdb.Assembler`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Assembler) assembles several steps of one run from batches decoded once, for a reader that walks every step (the `wefttest` fixture export). It is not safe for concurrent use, and the messages it returns share their parts with its decoded batches: read them, or copy before changing them.

| Name | Meaning |
|---|---|
| <span id="newassembler"></span>[`NewAssembler(batches)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#NewAssembler) | Decodes the run's growth batches once |
| [`(*Assembler).Step(requests, compactions, step)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Assembler.Step) | Answers one step's `StepMessages` from the decoded batches, the run's request records (the answering, last, attempt of the step is used) and its compactions |

### MessageText

[`obsdb.MessageText`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#MessageText) is one message reduced to what search reads.

| Field or function | Meaning |
|---|---|
| `Role` | The message's role: `user`, `assistant` or `tool` |
| `Text` | The text of its `text` parts, joined by `\n`, empty parts included |
| `ToolCall` | The message carries a `tool_call` part |
| <span id="messagestext"></span>[`MessagesText(body)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#MessagesText) | Reads a messages record body into its messages' text, in order. A body that does not parse reads as no messages: search never fails a write over it |

### Session title

| Constant | Value | Meaning |
|---|---|---|
| <span id="sessiontitlekey"></span>[`SessionTitleKey`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#SessionTitleKey) | `weft.session.title` | The run metadata a thread session stamps with its current title: it lands in `RunRow.Meta` and is read back as [`SessionRow.Title`](https://weftgo.dev/docs/reference/obsdb/#sessionrow). It survives content-off |

## Request, prompt, tools and raw records

Each model-call attempt writes a `request` record; a system text new to the run writes a `prompt` record and a tool catalog new to the run a `tools` record, each keyed by its hash. Under `otel.RawBodies(true)` behind the development gate (`WEFT_ENV=dev`, or `otel.DevMode()`), a `raw` record holds the provider wire exchange. A content-off chain strips the request record and drops the prompt and tools records it names.

### RequestRecord

[`obsdb.RequestRecord`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RequestRecord) is one stored request record: one model-call attempt, as `DB.Requests` pages them.

| Field | Meaning |
|---|---|
| `Index` | `weft.request.index`, the record's per-run position |
| `Step` | The stored `weft.step.index`; -1 when absent |
| `Attempt` | The body's attempt: 1 for the loop's call, 2, 3, … per further reported attempt |
| `Time` | The record's time |
| `SystemHash` | `weft.system.hash` when set (it wins over the body when they disagree), else the body's `system_hash` |
| `CatalogHash` | `weft.catalog.hash` when set, else the body's `tools.catalog_hash`; `""` when no tools were offered |
| `Content` | The record's hole: `""` as emitted, `stripped` from a content-off chain, `derived` when an unstripped body did not parse (then `Body` is zero and `Attempt` 0) |
| `TruncatedBytes` | Informational only: weft never caps a request record |
| `Body` | The parsed body, a [`RequestBody`](#requestbody) |
| `Raw` | The body verbatim |
| `Wire` | The attempt's [`RawRecord`](#rawrecord); nil when the run holds none for it (raw bodies off, an adapter that does not report, a run written before the raw record) |

### RequestBody

[`obsdb.RequestBody`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RequestBody) is the request record's body, keys as the core writes them; an absent field is unset.

| Field | JSON | Meaning |
|---|---|---|
| `Step` | `step` | The step of the call |
| `Attempt` | `attempt` | The attempt number |
| `SystemHash` | `system_hash` | The composed system text's hash: the [`PromptRecord`](#promptrecord) it names |
| `MessagesRef` | `messages_ref` | Which messages the request carried, a [`RequestMessagesRef`](#requestmessagesref) |
| `Tools` | `tools` | The catalog offered, a [`RequestTools`](#requesttools) |
| `ToolChoice` | `tool_choice` | The tool choice in force; nil when unset |
| `Thinking` | `thinking` | The thinking configuration in force; nil when unset |
| `SequentialTools` | `sequential_tools` | The step's tool calls run one at a time |
| `Parallelism` | `parallelism` | The step's `Parallelism` dial: how many of its tool calls may run at once; 0 on a record written before 0.20.0 |
| `Params` | `params` | The sampling parameters, a [`RequestParams`](#requestparams) |
| `Model` | `model` | The model requested, a [`RequestModel`](#requestmodel) |
| `Stream` | `stream` | The call streamed |
| `Prepared` | `prepared` | The parts the run's `PrepareStep` chain changed, in the order `system`, `messages`, `tools`, `tool_choice`, `params`, `thinking`, `sequential_tools`; absent when none did |
| `Wire` | `wire` | Since 0.20.0, how the adapter's escape hatches shape the request, names only, a [`RequestWire`](#requestwire); nil when no model along the `Unwrap` chain declares the optional `WireFacts()` method ([what the run record names](https://weftgo.dev/docs/guides/providers/#what-the-run-record-names)) |

### The request body's parts

| Type and field | JSON | Meaning |
|---|---|---|
| <span id="requestmessagesref"></span>[`RequestMessagesRef`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RequestMessagesRef) `.Index` | `index` | The messages record the request's messages are the run's view as of; nil where no messages record exists (capture off, or stripped by a content-off chain) |
| `RequestMessagesRef.Count` | `count` | How many messages the request carried |
| <span id="requesttools"></span>[`RequestTools`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RequestTools) `.CatalogHash` | `catalog_hash` | The offered catalog's hash: the [`ToolsRecord`](#toolsrecord) it names; `""` for no tools |
| `RequestTools.Names` | `names` | The tool names, in the order offered |
| <span id="requesttoolchoice"></span>[`RequestToolChoice`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RequestToolChoice) `.Mode` | `mode` | The tool-choice mode in force |
| `RequestToolChoice.Name` | `name` | The tool a named choice forces |
| <span id="requestthinking"></span>[`RequestThinking`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RequestThinking) `.Level` | `level` | The thinking level in force |
| `RequestThinking.Budget` | `budget` | The token budget, when one was set |
| `RequestThinking.Wire` | `wire` | How the adapter sends the level: the provider field it writes (`reasoning_effort`, `thinking.budget_tokens`, `thinking_level`, …) or `none`; absent when the model declares none |
| <span id="requestparams"></span>[`RequestParams`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RequestParams) `.Temperature` | `temperature` | The temperature; nil is the adapter's default (as for every parameter below) |
| `RequestParams.TopP` | `top_p` | The nucleus-sampling bound |
| `RequestParams.MaxTokens` | `max_tokens` | The output token limit |
| `RequestParams.Stop` | `stop` | The stop sequences; removed by a content-off chain |
| `RequestParams.Seed` | `seed` | The sampling seed |
| <span id="requestmodel"></span>[`RequestModel`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RequestModel) `.Provider` | `provider` | The provider of the model the attempt requested |
| `RequestModel.Name` | `name` | The model name the attempt requested |
| <span id="requestwire"></span>[`RequestWire`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RequestWire) `.ServerAddress` | `server_address` | The endpoint's `host[:port]`, never its credentials, path or query. The model reports all four facts through the optional `WireFacts()` method, found along the `Unwrap` chain; behind `mw.Fallback` they are the primary's ([what the run record names](https://weftgo.dev/docs/guides/providers/#what-the-run-record-names)) |
| `RequestWire.ExtraBodyKeys` | `extra_body_keys` | The top-level keys of the adapter's `ExtraBody`, never their values |
| `RequestWire.ExtraHeaders` | `extra_headers` | The names of the adapter's `ExtraHeaders`, lowercase, never their values |
| `RequestWire.Dropped` | `dropped` | How many names were left out. Each list is sorted and keeps at most 32 names, each at most 128 bytes |

### PromptRecord

[`obsdb.PromptRecord`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#PromptRecord) is one stored prompt record: the composed system text of one distinct system hash, as `DB.Prompt` returns it. A missing one is `ErrNotFound`, a [`*HoleError`](https://weftgo.dev/docs/reference/badges/#holeerror) when the reader knows why.

| Field | Meaning |
|---|---|
| `Index` | `weft.prompt.index` |
| `Time` | The record's time |
| `Hash` | The hash, over the text before any cut; from the `weft.system.hash` attribute when the body did not parse |
| `Text` | The composed system text: the instructions after `PrepareStep`, with the tools' prompt snippets appended |
| `Segments` | The text attributed to its sources, as [`PromptSegment`](#promptsegment) values; nil when no tool contributed a snippet, a cap cut the text, or the writer predates the field |
| `Content` | `truncated` when a destination's cap cut `Text`, `derived` when the body did not parse, else `""` |
| `TruncatedBytes` | What the cap cut, 0 for none |

### PromptSegment

[`obsdb.PromptSegment`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#PromptSegment) is one source's share of a composed system text. Joined by blank lines, the segments are `Text` exactly.

| Field | JSON | Meaning |
|---|---|---|
| `Source` | `source` | `instructions`, or `tool:<name>` for a tool's `PromptSnippet` |
| `Text` | `text` | That source's text |

### ToolsRecord

[`obsdb.ToolsRecord`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ToolsRecord) is one stored tools record: the catalog of one distinct catalog hash, tools in name order, as `DB.Tools` and `DB.Catalogs` return it. A missing one is `ErrNotFound`, a `*HoleError` when the reason is known.

| Field | Meaning |
|---|---|
| `Index` | `weft.tools.index` |
| `Time` | The record's time |
| `Hash` | The hash over the whole catalog; from the `weft.catalog.hash` attribute when the body did not parse |
| `Tools` | The catalog, as [`ToolEntry`](#toolentry) values in name order |
| `Content` | `truncated` when a destination's cap dropped entries from the end, `derived` when the body did not parse, else `""` |
| `TruncatedBytes` | What the cap removed, 0 for none |
| `Skipped` | Since 0.20.0, the tools an importer left out of the offered sources (`weft/mcp`'s `ImportError`), each a `SkippedTool` `{name, reason, source}`, its `source` the origin it would have come from (`mcp:billing`); at most 64, nil when none was skipped |
| `SkippedMore` | How many skipped tools past those 64 |

### ToolEntry

[`obsdb.ToolEntry`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ToolEntry) is one tool of a catalog: the model-visible triple and the policy this run applied to it. Playground `tool_args` edits are checked against its `Schema`.

| Field | JSON | Meaning |
|---|---|---|
| `Name` | `name` | The tool's name |
| `Description` | `description` | The description the model saw |
| `Schema` | `schema` | The input JSON schema the model saw |
| `TimeoutMS` | `timeout_ms` | The call deadline in milliseconds: the tool's own, else the agent's; 0 for none |
| `Approval` | `approval` | The call parks: the tool requires approval, or the run's park rule parks it |
| `Replay` | `replay` | The side-effect class for re-runs: `safe` or `never` |
| `MaxResultBytes` | `max_result_bytes` | The result cap: the tool's own, else the agent's; 0 is no cap |
| `Sequential` | `sequential` | The tool is a barrier: it runs alone |
| `Source` | `source` | Where the tool comes from: `local`, `subagent`, or the tool's origin (`mcp:<server>` from `weft/mcp` under `mcp.Server`, else `mcp`) |
| `Output` | `output` | The tool is the run's `submit_output` (`weft.Output`): its typed answer |
| `SourceDetail` | `source_detail` | Since 0.20.0, the tool's origin in parts, a `SourceDetail` `{server, transport, prefix, remote_name}`; nil when the producer set none ([MCP identity](https://weftgo.dev/docs/guides/mcp/#mcp-identity)) |

### StoredRecord

[`obsdb.StoredRecord`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#StoredRecord) is a request, prompt, tools or raw record as a backend stored it. A backend fills it from its columns and builds the read types above through the shared parsers, so every backend parses alike. You meet it when you write a backend.

| Field | Meaning |
|---|---|
| `Index` | The record's per-kind index |
| `Step` | The stored `weft.step.index`; -1 when absent |
| `Time` | The record's time |
| `Body` | The body bytes |
| `Content` | `weft.content`, the content mark (`stripped` or `""`) |
| `TruncatedBytes` | `weft.content.truncated_bytes` |
| `SystemHash` | `weft.system.hash` |
| `CatalogHash` | `weft.catalog.hash` |

### RawRecord

[`obsdb.RawRecord`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RawRecord) is one stored raw record: an attempt's wire exchange as the core shaped it, attached to its attempt's `RequestRecord.Wire`. Raw records reach only the Local and Studio destinations, and only under `otel.RawBodies(true)` behind the development gate (`WEFT_ENV=dev`, or `otel.DevMode()`).

| Field | JSON | Meaning |
|---|---|---|
| `Index` | `index` | `weft.raw.index` |
| `Step` | `step` | The stored `weft.step.index` |
| `Attempt` | `attempt` | The attempt in flight when the adapter reported; where an SDK's own retries put several exchanges on one attempt, the highest index is the attempt's |
| `Time` | `time` | The record's time |
| `Request` | `request` | The request side, a [`RawSide`](#rawside) |
| `Response` | `response` | The response side; nil when the exchange got no response (a transport error) |
| `RedactedHeaders` | `redacted_headers` | The credential headers stripped from both sides |
| `RedactedQuery` | `redacted_query` | The credential query parameters whose values were replaced |
| `Content` | `content` | `truncated` when a body was cut, `derived` when the record's body did not parse (both sides zero), else `""` |
| `TruncatedBytes` | `truncated_bytes` | `weft.content.truncated_bytes`: what the cap cut over both bodies |

### RawSide

[`obsdb.RawSide`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RawSide) is one side of the exchange. Each body is capped at 256 KiB, with the cut counted.

| Field | JSON | Meaning |
|---|---|---|
| `Method` | `method` | The HTTP method; request side only |
| `URL` | `url` | The request URL, credential query values replaced; request side only |
| `Status` | `status` | The HTTP status; response side only |
| `Headers` | `headers` | The headers, credentials stripped |
| `MediaType` | `media_type` | The body's media type |
| `Body` | `body` | The body as text, or base64 when `Encoding` is `base64` |
| `Encoding` | `encoding` | `base64` when the bytes were not UTF-8, else empty |
| `Bytes` | `bytes` | The whole body's size before the cap |
| `TruncatedBytes` | `truncated_bytes` | What the cap removed |
| `Complete` | `complete` | Response side: false when the body was not read to its end (a transport retry closed it, a timeout, a reader that stopped); nil on the request side and on records that do not say |

| Constant | Value | Meaning |
|---|---|---|
| <span id="recordraw"></span>[`RecordRaw`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RecordRaw) | `raw` | The `weft.record` kind of a raw record, positioned by `weft.raw.index` and stored beside the request records |

## Stock derivation

Studio derives a run from stock OTel GenAI spans that carry no `weft.run.id` ([How Studio derives a run](https://weftgo.dev/docs/observe/other-languages/#how-studio-derives-a-run)); the derived run is a [`StockRun`](https://weftgo.dev/docs/reference/obsdb/#stockrun). These functions are the derivation's rules, shared by the backends:

| Function | Meaning |
|---|---|
| [`StockRunID(traceID, spanID)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#StockRunID) | The derived run's id, `otel-<trace id>-<root span id>`, lowercase hex: deterministic, never contains `/`, cannot collide with a core id |
| [`ParseStockRunID(id)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ParseStockRunID) | Splits a derived run id into its trace and root span ids; `ok` false for any other id |
| [`StockTraces(ids)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#StockTraces) | The trace ids the derived run ids among `ids` name, in order, once each |
| [`IsStockRoot(s)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#IsStockRoot) | Reports whether a span opens a derived run on its own: an `invoke_agent` span with no `weft.run.id` and a `gen_ai.conversation.id`. A top-level one without a conversation id opens one too, but only `DeriveStockRuns` can tell, from the trace |
| [`StockCandidate(s)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#StockCandidate) | Reports whether a span may take part in a derived run: no `weft.run.id`, and one of `invoke_agent`, `chat`, `execute_tool` |
| [`DeriveStockRuns(spans)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#DeriveStockRuns) | Every run the spans hold, ordered by start then id; converges whatever order the spans arrived in. One run per stock root, and one per top-level `invoke_agent` span without a conversation id: that run has no session |
| [`StockRunSpans(spans, id)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#StockRunSpans) | The spans of derived run `id` among one trace's spans; nil when no root of that id is there |
| [`StockRunsOf(all, keys, deleted)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#StockRunsOf) | The derived runs whose root a deletion takes, so their rows do not outlive their spans |

[`ExampleDeriveStockRuns`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#example-DeriveStockRuns) derives a run from a stock trace.

## App log lines

### OtherLog

[`obsdb.OtherLog`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#OtherLog) is one app log record of a run: a non-weft line (the app's slog lines, OTel Logs API records) attributed to the run through the span it was emitted under, as `DB.OtherLogs` pages them in a [`LogPage`](https://weftgo.dev/docs/reference/obsdb/#logpage).

| Field | Meaning |
|---|---|
| `Index` | The line's place among the run's app logs, in time order; stable once the run has ended |
| `Time` | The record's time |
| `Severity` | The OTLP severity number, 0 unspecified or 1–24 (`SeverityText` names it: 13 is `WARN`) |
| `EventName` | The OTLP event name, when the producer set one |
| `Body` | The line's body; a structured body renders as JSON |
| `Attrs` | The record's attributes: typed on SQLite, strings on ClickHouse, whose `otel_logs` keeps the collector's string map |
| `TraceID` | The trace the line was emitted under |
| `SpanID` | The span the line was emitted under: the run's attribution key |
| `Service` | The resource's `service.name` |

## Saved experiments

`DB.SaveExperiment`, `DB.Experiments` and `DB.Experiment` keep the playground's saved groups in one small table beside the runs. The definition is keyed by the `weft.experiment.id` its runs carry; the runs stay in the runs table.

### Experiment

[`obsdb.Experiment`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Experiment) is one saved playground group.

| Field | Meaning |
|---|---|
| `ID` | The experiment id, the `weft.experiment.id` its runs carry; `SaveExperiment` upserts by it |
| `Name` | The name it was saved under |
| `Agent` | The agent its runs ran |
| `Created` | When it was first saved |
| `Updated` | When it was last saved; `Experiments` lists newest update first |
| `Variants` | The matrix's columns, as [`ExperimentVariant`](#experimentvariant) values, wire shapes verbatim |
| `Inputs` | The matrix's rows, as [`ExperimentInput`](#experimentinput) values |
| `PassPredicate` | The experiment's pass predicate, as the playground sent it: stored and returned verbatim; `""` when none, or on an experiment saved before 0.19.0 |
| `ExperimentCommand` | The embedded rest of the run command the matrix sent, so the experiment reopens as the form that ran it; zero on one saved before obsdb kept it |

### ExperimentCommand

[`obsdb.ExperimentCommand`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ExperimentCommand) is the experiment-wide part of the run command, kept as sent and stored as one JSON document. obsdb does not validate it (Studio does, on the way in). Every field is optional; zero is "not recorded" or the command's default, and a reader cannot tell the two apart.

| Field | JSON | Meaning |
|---|---|---|
| `Engine` | `engine` | `live` or `scripted` |
| `SideEffects` | `side_effects` | `substitute`, `park` or `allow` |
| `Thread` | `thread` | `ephemeral` or `fork` |
| `FromStep` | `from_step` | The step every cell continues from |
| `SourceRunID` | `source_run_id` | The run the cells replay from |
| `TranscriptEdits` | `transcript_edits` | The transcript edits, the list as sent |

### ExperimentVariant

[`obsdb.ExperimentVariant`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ExperimentVariant) is one column of the matrix.

| Field | JSON | Meaning |
|---|---|---|
| `Key` | `key` | The column's key |
| `Overrides` | `overrides` | The overrides object it applies, verbatim: `instructions`, `tools_enabled`, `model`, `thinking`, `options`, `params`, `tool_choice`, `park_on`, `only_tools`, and any key a later command adds |
| `Engine` | `engine` | The engine when it differs from the experiment's; empty is the experiment's own |
| `SideEffects` | `side_effects` | The side-effect mode when it differs; empty is the experiment's own |
| `Thread` | `thread` | The thread mode when it differs; empty is the experiment's own |

### ExperimentInput

[`obsdb.ExperimentInput`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ExperimentInput) is one row of the matrix: a source run to take the turn from, or a literal text.

| Field | JSON | Meaning |
|---|---|---|
| `Key` | `key` | The row's key |
| `SourceRunID` | `source_run_id` | The run whose turn the row replays |
| `Text` | `text` | A literal prompt |
| `FromStep` | `from_step` | The row's own step, so each source run continues from its own failing step; nil is the experiment's `FromStep` |

## Stored manifests

### ManifestStore

[`obsdb.ManifestStore`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ManifestStore) is a database's optional manifest capability: each agent's configuration by its hash, so a run's `RunRow.ManifestHash` resolves to the configuration it ran with, even after it stopped being current.

- Both first-party backends implement it: SQLite migration 0014, ClickHouse migration 0016. The conformance table holds them to the same answers.
- Studio writes it from the `weft.json` it serves and from runtime registrations; `/api/manifests/{hash}` reads it.

| Method | Meaning |
|---|---|
| [`PutManifest(ctx, m)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ManifestStore) | Stores `m` unless its hash is stored already (then a no-op returning nil). A zero `FirstSeen` is stamped with the current time. `ErrInvalidManifest` when the body is not a JSON object or the hash is not its sha256 |
| [`Manifest(ctx, hash)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ManifestStore) | The manifest stored under `hash`; false when none is |

The store is content-addressed and immutable: a second `PutManifest` of a stored hash changes nothing, so `FirstSeen` and `Source` are the first write's. Manifests are kept forever; `DeleteRun`, `DeleteSession`, `Sweep` and `Vacuum` never touch them.

### StoredManifest

[`obsdb.StoredManifest`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#StoredManifest) is one stored agent configuration.

| Field | Meaning |
|---|---|
| `Hash` | sha256 of `Body`, lowercase hex |
| `Body` | The one-agent `weft.Manifest` document, byte for byte: the bytes whose sha256 the agent's runs carry |
| `Source` | Where Studio first saw it: `file` or `runtime`; `""` when the writer did not say |
| `FirstSeen` | When it was first stored |

| Name | Value | Meaning |
|---|---|---|
| <span id="manifestsourcefile"></span>[`ManifestSourceFile`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ManifestSourceFile) | `file` | Written from the `weft.json` Studio serves |
| <span id="manifestsourceruntime"></span>[`ManifestSourceRuntime`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ManifestSourceRuntime) | `runtime` | Written from a runtime registration |
| <span id="manifesthash"></span>[`ManifestHash(body)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ManifestHash) | | The hash a manifest body is stored under: sha256 of its bytes, lowercase hex, the core's `weft.manifest.hash` of the same bytes |

## The playground's command store

### CommandStore

[`obsdb.CommandStore`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandStore) is a database's optional playground-link capability: what Studio's runtime server asked its runtimes to do, so a restarted Studio still knows.

- It holds four sets of rows: commands, run routes (what cancel, steer and the debugger's verbs are routed by), each runtime's breakpoint set, and runtime registrations.
- Both first-party backends implement it: SQLite migration 0007, ClickHouse migration 0008. It arrived in 0.15.0. A backend without it keeps the runtime server in memory only.
- The rows are Studio's bookkeeping, not run data: `DeleteRun`, `DeleteSession`, `Sweep` and `Vacuum` never touch them, and `PruneCommands` is their only retention.

| Method | Meaning |
|---|---|
| [`PutCommand(ctx, c)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandStore) | Upserts `c` whole under `c.ID`. A zero `Created` or `Updated` is stamped with the current time on every write, so carry the `Created` you read back. `ErrInvalidCommand` for an empty ID or a state outside the five |
| [`Commands(ctx, q)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandStore) | The rows `q` selects, newest `Created` first (ties by ID, descending); an empty query returns every row |
| [`PutRoute(ctx, r)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandStore) | Replaces the route of `r.RunID`. A zero `Seen` is stamped. `ErrInvalidCommand` for an empty `RunID` or `RuntimeID` |
| [`Route(ctx, runID)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandStore) | The route of `runID`; false when none is stored |
| [`PutBreakpoints(ctx, runtimeID, tools)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandStore) | Replaces the runtime's breakpoint set whole; empty `tools` stores the empty set (a clear). `ErrInvalidCommand` for an empty runtime id |
| [`Breakpoints(ctx, runtimeID)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandStore) | The stored set, never nil when stored; false when none was ever stored, which is distinct from a stored empty set |
| [`PutRuntime(ctx, r)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandStore) | Upserts `r` whole under `r.ID`; zero `Registered` or `LastSeen` is stamped. `ErrInvalidCommand` for an empty ID |
| [`Runtimes(ctx)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandStore) | Every stored runtime, most recently seen first (ties by ID) |
| [`DeleteRuntime(ctx, runtimeID)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandStore) | Removes the runtime's row and its breakpoint set: Studio's "forget" of a runtime that is gone. Its commands and routes stay as history. An id with nothing stored is no error; `ErrInvalidCommand` for an empty id |
| [`PruneCommands(ctx, before, keep)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandStore) | Bounds the store by the rules below. Returns how many commands it deleted; on ClickHouse, how many it selected, which can count a command a racing put kept |

A backend may also implement `BreakpointProvenanceStore`, which keeps a breakpoint set with when and through which surface Studio delivered it, so a restarted Studio still says `set by <surface> at <time>`. `PutBreakpointSet(ctx, runtimeID, set)` and `BreakpointSet(ctx, runtimeID)` take and return a `BreakpointSet` `{Tools, SetAt, SetBy}`: `SetBy` is the Studio page that sent it (`runtimes`), else `api`. A clear keeps neither field. Both first-party backends implement it.

`PruneCommands(ctx, before, keep)` applies these rules:

- A terminal command whose `Updated` is before `before` is deleted.
- Then, while more than `keep` commands remain, the oldest terminal ones by `Created` go (`keep` ≤ 0: no count bound). A queued or accepted command is never deleted.
- A route goes when it names a command no longer stored, or when its `Seen` is before `before` and no live command names its run.
- A runtime goes when its `LastSeen` is before `before`, no live command is addressed to it and its breakpoint set is absent or empty.
- An empty breakpoint set no runtime names goes when last written before `before`.
- On SQLite the terminal commands go in passes of `SweepBatch`, each its own transaction. On ClickHouse the prune is not atomic with concurrent puts, so serialize it with your writes.

### Command states

| Constant | Value | Meaning |
|---|---|---|
| <span id="commandqueued"></span>[`CommandQueued`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandQueued) | `queued` | Enqueued to a runtime, not yet acknowledged. Live |
| <span id="commandaccepted"></span>[`CommandAccepted`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandAccepted) | `accepted` | The runtime acknowledged it and is running it. Live |
| <span id="commandrejected"></span>[`CommandRejected`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandRejected) | `rejected` | The runtime refused it. Terminal |
| <span id="commandfinished"></span>[`CommandFinished`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandFinished) | `finished` | It ran to an outcome. Terminal |
| <span id="commandlost"></span>[`CommandLost`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandLost) | `lost` | Studio decided it lost (no ack in time, or an accepted command fell silent); never re-issued. Terminal |

### StoredCommand

[`obsdb.StoredCommand`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#StoredCommand) is one command row. The indexed columns are what queries select by and what a restart decides from.

| Field | Meaning |
|---|---|
| `ID` | The command id |
| `RuntimeID` | The runtime the command was enqueued to |
| `Kind` | The frame kind the caller names: `""`, `run`, `cancel`, `approve`, `breakpoints` or `steer`; stored verbatim, never interpreted |
| `State` | One of the five states above |
| `RunID` | The run an ack named; `""` until one did |
| `PublicID` | The public id the command is scoped to |
| `Fork` | A `thread=fork` command: its runs are sessions the runtime owns |
| `Agent` | The command's agent, copied out of `Body` |
| `SourceRunID` | The command's source run, copied out of `Body` |
| `ExperimentID` | The command's experiment, copied out of `Body` |
| `Status` | A finished command's run outcome: `succeeded` or `failed` |
| `Error` | Why, when there is a why: a rejection's reason, a failed run's error, what made it lost |
| `Created` | When the row was first written |
| `Updated` | When it was last written |
| `AcceptedAt` | When the accepted ack arrived; zero when none did |
| `LastBeat` | The last heartbeat (a repeated accepted ack); zero when none did. A restarted Studio decides a silent accepted command lost from these two |
| `Body` | The whole wire command, verbatim |
| `Ack` | The last ack the runtime posted, verbatim; nil reads back nil |

### CommandQuery

[`obsdb.CommandQuery`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandQuery) selects commands. Every set field must match; an empty query matches every row.

| Field | Meaning |
|---|---|
| `ID` | One command by id |
| `RuntimeID` | The commands enqueued to one runtime |
| `RunID` | The commands whose ack named one run |
| `States` | Any of these states; nil and empty both mean no filter |
| `Limit` | At most this many rows; ≤ 0 returns every match |

### RunRoute

[`obsdb.RunRoute`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RunRoute) is one run → runtime route.

| Field | Meaning |
|---|---|
| `RunID` | The run |
| `RuntimeID` | The runtime an ack said started the run |
| `CommandID` | The command whose ack named it last |
| `PublicID` | The public id the command carried |
| `Fork` | The command's fork mark |
| `Seen` | When an ack last named the run |

### StoredRuntime

[`obsdb.StoredRuntime`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#StoredRuntime) is one runtime's latest registration, so a restarted Studio can list what was registered before it.

| Field | Meaning |
|---|---|
| `ID` | The runtime id (`rt_…`) |
| `Service` | The app's service name |
| `Host` | The hostname the runtime reported: the app's `os.Hostname()` |
| `Cwd` | The app's working directory when the registration carries one, else `""` |
| `Pid` | The app's process id (`os.Getpid()`); Studio uses `<id>-<pid>` as the runtime id when another process holds the id |
| `Agents` | The names of its registered agents |
| `Registered` | When it registered |
| `LastSeen` | When it was last heard from |
| `Body` | The whole registration as the runtime posted it |

## Best practices & gotchas

- **Never treat the live lane as durable.** A slow subscriber's channel closes when its queue fills; resume from the database, then subscribe with the last `Seq`. (Source: `obsdb/hub.go:120-155`)
- **Do not expect deltas or heartbeats back.** `Write` counts deltas and drops them, and heartbeats only move last-seen; the hub still carries deltas live. (Source: `obsdb/doc.go:32-34`)
- **Read a record's `Content` before its body.** A `stripped` or `derived` request record has no usable body, and a `truncated` prompt or catalog is a prefix; show the badge, not a blank. (Source: `obsdb/request.go:305-351`)
- **Carry `Created` into every `PutCommand`.** A zero `Created` is stamped with now on each write and moves the command to the front of the newest-first order. (Source: `CommandStore.PutCommand` godoc, `obsdb/commands.go:34-44`)
- **Carry `Registered` into every `PutRuntime`.** A zero `Registered` is overwritten with now, so the registration time is lost; the order is unaffected, since `Runtimes` sorts by `LastSeen`. (Source: `CommandStore.PutRuntime`, `Runtimes` godoc, `obsdb/commands.go:60-67`)
- **Serialize `PruneCommands` with your own puts on ClickHouse.** Each rule decides from what it read; a racing put keeps its own row but may still be counted. (Source: `obsdb/commands.go:34-137`; `obsdbtest.CommandsPruneRace`)

## See also

- [obsdb: reading the observability database from Go](https://weftgo.dev/docs/reference/obsdb/)
- [Badges and holes](https://weftgo.dev/docs/reference/badges/)
- [The record contract](https://weftgo.dev/docs/reference/record-contract/)
- [Choose the observability database: SQLite or ClickHouse](https://weftgo.dev/docs/production/storage-backends/)

Symbols used: [`obsdb.Batch`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Batch) · [`obsdb.Span`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Span) · [`obsdb.Record`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Record) · [`obsdb.Weft`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Weft) · [`obsdb.Hub`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Hub) · [`obsdb.Frame`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Frame) · [`obsdb.PosEvent`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#PosEvent) · [`obsdb.TranscriptBatch`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#TranscriptBatch) · [`obsdb.Compaction`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Compaction) · [`obsdb.StepMessages`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#StepMessages) · [`obsdb.RequestRecord`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RequestRecord) · [`obsdb.PromptRecord`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#PromptRecord) · [`obsdb.ToolsRecord`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ToolsRecord) · [`obsdb.RawRecord`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#RawRecord) · [`obsdb.OtherLog`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#OtherLog) · [`obsdb.Experiment`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#Experiment) · [`obsdb.ManifestStore`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ManifestStore) · [`obsdb.CommandStore`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CommandStore) · [`obsdb.ErrStepMessages`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ErrStepMessages) · [`obsdb.ErrInvalidCommand`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ErrInvalidCommand) · [`obsdb.ErrInvalidManifest`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#ErrInvalidManifest) · [`obsdb.SweepBatch`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#SweepBatch) · [`obsdbtest.CommandsPruneRace`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb/obsdbtest#CommandsPruneRace)
