Expand description
RunTraceStore — the persisted per-Run trace rail (TraceEvent
stream) plus the normalized worker-stats types (TokenUsage /
WorkerStats) shared by the trace rail and the
crate::store::run::StepEntry step-stats extension.
Two rails observe the same dispatch (issue: per-step run stats):
crate::store::run::StepEntry— the terminal summary of one dispatched step (write-once, appended by the dispatcher after the outcome is known; carries duration / usage / model / verdict).TraceEvent(this module) — the in-flight stream of what is happening (core.step_dispatched,mw.long_hold_warn, …), append-only, per-Run, ordered byseq.
Everything here is purely observational: a failed append must never
fail the dispatch it observes (callers warn-and-swallow — the same
fail-open convention as EngineDispatcher::dispatch’s
append_step_entry). The naming is deliberately Trace, not Log:
in the Rust ecosystem “log” collides with the log/tracing
facade crates, and this rail is domain data, not process logging.
Kinds are an open set of namespaced strings — writers may insert new kinds without a schema migration. Current namespaces:
core.*— engine/dispatcher (run_started/step_dispatched/step_completed/cancel_requested/run_finished)mw.*— middleware (long_hold_warn, …)worker.*— adapter / worker self-reportsext.*— future external writers (Lua flow, enhance flow, tools)
Layering invariant (future mlua-swarm-trace crate split): this
module must not depend on engine types — only crate::types ids and
serde values.
Re-exports§
pub use sqlite::SqliteRunTraceStore;
Modules§
- kind
- Well-known
TraceEvent.kindvalues written by the engine itself. The kind axis is an open set — these constants exist so in-tree writers and tests agree on spelling, not to constrain writers. - sqlite
SqliteRunTraceStore— SQLite-backedRunTraceStoreusing [rusqlite-isle], sharing the same database FILE ascrate::store::run::SqliteRunStore(~/.mse/store/run.sqliteby default) in its ownrun_tracetable. Sharing the file keeps “one Run’s persistence” a single artifact on disk; each store still owns its own confinedConnection(its ownAsyncIslethread), so both connections setbusy_timeoutto ride out each other’s short write transactions.
Structs§
- InMemory
RunTrace Store - Process-volatile
RunTraceStore— the default when no persistent backend is wired. - Token
Usage - Aggregated token usage for one worker attempt, normalized across
worker kinds (agent-block
agent.runreturn / subprocess declared mapping / operator self-report). Field names follow the Anthropic wire convention (input_tokens/output_tokens) that agent-block already normalizes OpenAI-style responses into. - Trace
Event - One persisted trace event — a member of a Run’s append-only stream.
- Trace
Event Draft - The caller-supplied half of a
TraceEvent— the store assignsseqandts_msat append time. - Trace
Handle - A cheap, cloneable write handle binding one
run_idto aRunTraceStore— the single port through which the dispatcher, middlewares (viaEngine::trace_handle), server handlers, and any future writer append trace events. Appends are best-effort: a store failure is logged atwarnand swallowed, never propagated (fail-open, matching theappend_step_entryconvention). - Trace
Query - Filter/paging parameters for
RunTraceStore::list. All filters AND together;latestandafterare mutually exclusive withlatestwinning (it answers “show me the tail” regardless of any cursor the caller also carried). - Worker
Stats - Normalized per-attempt worker statistics, reported by a worker
boundary (spawner fold site / result captor /
POST /v1/worker/submit) into the engine and folded into the terminalcrate::store::run::StepEntryby the dispatcher.
Enums§
- Trace
Store Error - Errors surfaced by a
RunTraceStoreimplementation.
Constants§
- DEFAULT_
TRACE_ LIST_ LIMIT - Default
listpage size when a query sets neitherlimitnorlatest. - DEFAULT_
TRACE_ MAX_ EVENTS_ PER_ RUN - Default per-Run retention ceiling — appends beyond this many events prune the oldest rows first.
- TRACE_
PAYLOAD_ CAP_ BYTES - Byte cap applied to
TraceEvent::payloadandWorkerStats::adapter_databefore persisting. Oversized values are replaced by a truncation marker object (seecap_payload) — the trace rail is an observability artifact, not a blob store.
Traits§
- RunTrace
Store - Persistence interface for the per-Run trace stream.
Functions§
- cap_
payload - Replace an oversized payload with a truncation marker carrying the
original size and a head excerpt, so a runaway writer cannot bloat
the trace store. Values at or under
TRACE_PAYLOAD_CAP_BYTESpass through unchanged.