Skip to content

Architecture decision records

View as Markdown

An architecture decision record (ADR) in docs/adr/ records one decision that shaped weft: the context, what was decided, what was rejected, and dated amendments when the decision changed. AGENTS.md makes two of them mandatory: changing model-visible behaviour needs an ADR (rule 5), and so does a third seam (rule 10). This page lists every ADR at v0.20.2 with its decision in a sentence or two and its status, checked against the code.

The records live at docs/adr/. Where an ADR’s text and the code disagree, the code is what v0.20.2 does; the open differences are listed at the end.

ADRDecision, shortStatus at v0.20.2
0001A message is a role plus typed parts; no system roleDecided, shipped; amended
0002Tool error is data, run error is a Go errorDecided, shipped; amended
0003Tools generic over input/output structs; schema from tagsDecided, shipped; amended
0004One Seq counter, assigned and emitted under one lockDecided, shipped; amended
0005Module path, option names, MIT licenceDecided; module layout superseded by 0027
0006Two middleware seams, chi-styleDecided, shipped; amended
0007Approval ends the run; a later run resumesDecided, shipped; amended
0008Structured output is a submit_output toolDecided, shipped
0009—Number never used
0010Run records in weft/storeSuperseded by 0024; weft/store deleted
0011Sessions as an append-only entry treeDecided, shipped; format not frozen
0012weft.json, generated and committedDecided, shipped; amended
0013Adapter contract and conformance suiteDecided, shipped; amended
0014A subagent is a toolDecided, shipped
0015MCP both ways, from shape-compatible toolsDecided, shipped; amended
0016The loop reports spans and log lines through the OTel APIDecided, shipped; amended
0017Model-event replay, scripting helpers, fuzz gateDecided, shipped; amended
0017 (fixture names)Replay fixture names pad to five digitsAmendment, shipped
0018Studio UI: a TanStack Start SPA, embeddedDecided, shipped; amended
0019Steering: one pull hook, two drain pointsDecided, shipped; amended
0020Compaction keeps everything, summarizes the oldDecided, shipped; amended
0021Durable, signed, granted, audited approvalsDecided, shipped; amended
0022thread/pool: bounded child runs with receiptsDecided, shipped; amended
0023thread/sandbox: a file firewallAbandoned; not shipped
0024OpenTelemetry out; obsdb; the store deletedDecided, shipped; module layout amended by 0027
0025—Reserved for a flow tier; no file
0026Postgres backend, writer rule, listing, write hookDecided; partly shipped: D4 ErrStale, D5 release on Close, D6 List in SQL on sqlite (thread 0.9.0); D1 thread/postgres, D3, D7, D8 and the D10 rename not shipped
0027One framework module, plus core for the loopAccepted, shipped
0028Record each model request as contentDecided, shipped; amended
0029A replay’s input is what the model sawDecided, shipped
0030ParkSource: a park set read once per runDecided, shipped

A message is a role plus an ordered list of typed parts, and the roles are user, assistant and tool: there is no system role, the instructions travel beside the transcript. Amendments added reasoning round-trips, FilePart with ErrUnsupported, and the transcript invariants that weft.Repair restores.

Status: decided 2026-09-09, shipped, amended four times. Read ADR 0001.

A tool error is data the model sees; a run error is a Go error the caller sees, always a *RunError carrying the partial transcript. The amendments added error codes on tool results, the truncation rule, ErrLoopDetected, RETRY and ErrModelRetriesExceeded, budgets checked at the continuation point, and the subagent codes.

Status: decided 2026-09-09, shipped, amended nine times. AGENTS.md rules 1 and 13 state it. Read ADR 0002.

Tools are generic over their input and output structs, and the schema is reflected from the input struct and its tags, the same shape as the official Go MCP SDK’s AddTool. Amendments added RawTool and ToolSource, per-tool policy, schema-shaped decode errors and the schema derivation rules.

Status: decided 2026-09-09, shipped. A 2026-09-18 amendment retracted the Replay option; it is back in the code (see the differences). Read ADR 0003.

Every tool event carries a per-run Seq from one counter, and assignment and emission happen under one lock, so the order events are observed in is the order of their Seq values. Amendments added the observation tap, the event wire format, tool_args_delta, RunFinish.Pending, run_id on every event and Nested events.

Status: decided 2026-09-09, shipped. AGENTS.md rule 3 states it. Read ADR 0004.

The module path is github.com/weftgo/weft, the option vocabulary is the code’s (Parallelism(n), Sequential(), StopWhen), and the licence is MIT. Its layout of one module per adapter, tagged independently, is replaced by ADR 0027.

Status: decided 2026-09-09; path, names and licence stand; module layout superseded by 0027. Read ADR 0005.

Everything that changes a run attaches at two composable seams, func(next Model) Model and func(next ToolCaller) ToolCaller, first listed outermost; observation is a tap, not a seam, and a third seam needs an ADR. Later notes place PrepareStep (the one loop knob, not a seam), OnRunEnd and OnMessages (observers).

Status: decided 2026-09-14, shipped. AGENTS.md rule 10 states it. Read ADR 0006.

Pending approvals end the run successfully with the calls on RunResult.Pending, and a later run resumes with the transcript plus Approve or Deny per call; an undecided call is DENIED: no decision. It is a policy seam, not a security boundary; the 2026-09-22 amendment added Resolve for results computed outside the process.

Status: decided 2026-09-14, shipped, amended once. AGENTS.md rule 12 states it. Read ADR 0007.

Structured output is a tool: weft.Output registers submit_output with a schema reflected from the type, and the run ends after the step in which that call produced a non-error result. It works on every adapter with no provider-specific mode.

Status: decided 2026-09-12, shipped. Read ADR 0008.

weft.Manifest renders version 1 of weft.json, a description of every agent and tool generated from the code, committed and diffed; nothing is ever configured from it. Amendments added the subagent field and ruled out an MCP field; a 2026-10-26 amendment lists each agent’s model and tool middleware and its hooks (The onion in the record).

Status: decided 2026-09-10, shipped; amended 2026-10-26 (0.20.0). Read ADR 0012.

Every provider adapter passes one executable contract, wefttest/conformance, with wire-level fixtures and live runs behind -tags live, plus cross-cutting rules every adapter keeps. Amendments added thinking pass-through, argument-delta progress, enforced cancellation, tool choice, request params, ExtraBody/ExtraHeaders, prompt-cache markers and, on 2026-10-17, the optional ThinkingWire method.

Status: decided 2026-09-10, shipped, amended six times. Read ADR 0013.

One agent delegates to another through a tool whose handler runs it: weft.Subagent. The child’s events arrive as Nested, its usage rolls into the parent’s, and its failure is data the parent’s model reads.

Status: decided 2026-09-19, shipped; a 2026-09-22 note keeps handoff isolation. Read ADR 0014.

Because the tool contract mirrors the Go MCP SDK’s, the bridge is a conversion: mcp.Tools consumes a server’s tools as weft tools, and mcp.AddTools and mcp.Serve expose weft tools and agents as an MCP server. A 2026-09-27 amendment makes a tool that cannot be imported fail that tool, not the listing.

A 2026-10-26 amendment records each import’s server: mcp.Server(name) makes the tools’ origin mcp:<name>, the tools record carries source_detail and the skipped tools, and a JSON-RPC error answer reads mcp_rpc_error (MCP identity).

Status: decided 2026-09-19, shipped; amended 2026-09-27 and 2026-10-26 (0.20.0). Read ADR 0015.

Spans and log lines are the loop’s own reporting at its phases (run, model call, tool call), through the OpenTelemetry API, the core’s one dependency, a no-op until an SDK registers. Its amendments added OnRunEnd, the observation accessors, the Logs API (from ADR 0024), the reporting hook for attempts, and the stop, cancel, failure-kind and approval-link attributes.

Status: decided 2026-09-19, shipped, amended eleven times, the last on 2026-10-26 (0.20.0): the middleware onion recorded, at three levels and reporting only. AGENTS.md rule 6 states its dependency rule. Read ADR 0016.

Application tests replay model events at the weft.Model seam with wefttest.Record and wefttest.Replay, with no HTTP cassettes; adapters keep their wire fixtures. It also fixes the scripting helpers and the fuzz gate; a 2026-09-22 amendment adds ToolChoice to the replay key, not Params.

Status: decided 2026-09-19, shipped. Read ADR 0017.

A second file numbered 0017 holds one amendment with no ADR around it: replay fixture names pad their sequence to five digits (<seq:05d>), so recordings of 1,000 requests or more sort in order; replay matches on the key inside the file, so old names still replay.

Status: amendment of 2026-09-26, shipped (core/wefttest/replay.go writes %05d). Read the file.

Steering is one pull source the loop drains at two fixed points, after a step’s tool batch and at what would be the final step, set per run with weft.Steering; delivered messages are ordinary transcript and the Steered event reports them. Policy (queue, reject, interrupt) lives above it, in weft/thread.

Status: decided 2026-09-28, shipped; amended 2026-10-01 (a steer’s receipt) and 2026-10-11 (a steer from a caller that does not own the turn). Read ADR 0019.

weft.ParkSource is an agent option holding a function the loop reads once per run, at its start, and merges into the run’s park set as ParkOn would. It lets debugger breakpoints park the app’s own runs while the agent stays immutable; it is neither a seam nor a hook.

Status: decided 2026-10-11, shipped. Read ADR 0030.

github.com/weftgo/weft is the framework, one module with every layer as a package, one version and one tag; github.com/weftgo/weft/core is the loop alone, whose only dependency is the OpenTelemetry API. The root package is a generated facade over core, and the layers import core.

Status: accepted 2026-10-07, shipped; it supersedes ADR 0005’s module layout. Read ADR 0027.

weft/thread stores a session as an append-only tree of entries, with branching, turns and a pluggable Storage; one Session writes a session at a time. The 2026-10-01 amendment, which wins where it disagrees with the text, adds the session core rules, the writer lease and its release on Close, the turn’s durable shapes, and defers the format freeze.

Status: decided 2026-09-28, shipped; the format and API are not frozen (pre-1.0). Read ADR 0011.

Compaction summarizes the older part of a session and keeps every entry: the model sees the summary plus the recent part, and the defaults work with no configuration. Five configuration layers sit over it, thread.ContextWindow arms it, an overflow re-runs once, and provider-native compaction has a seam.

Status: decided 2026-09-28, shipped; amended 2026-09-29 and 2026-10-01 (the context shape, the trim record, the hook rules, what is not built). Read ADR 0020.

The core’s approval boundary becomes durable in a session: pending calls survive a restart, decisions go through a chain, can be signed (thread.NewKeyring), granted ahead of time, and audited. It is still a policy seam, not a security boundary.

Status: decided 2026-09-28, shipped; amended three times. Read ADR 0021.

thread/pool bounds child runs with one FIFO semaphore per Pool value (pool.New(max)), runs each child as its own session with a receipt, and carries nested approvals up to the parent. The 2026-10-01 amendment replaces the slot rule (slots bound work, not waiting), the depth guard, the nested-approval bridge and Decide’s shape.

Status: decided 2026-09-29, shipped. Read ADR 0022.

A proposal for thread/sandbox, a file firewall every file tool would go through. It was abandoned on 2026-09-29 before any decision or code; approvals remain a policy seam, not a security boundary.

Status: abandoned, never decided, not shipped. v0.20.2 has no thread/sandbox package. Read ADR 0023.

D1 decides a thread/postgres backend on pgx; the rest fixes the writer rule with a fence, Session.Close releasing the writer’s hold, List answered by the database, a write hook joining the app’s writes to the transaction, opt-in search, and a weft_thread_ table prefix for thread/sqlite.

Status: decided 2026-10-02, partly shipped. Three decisions shipped in thread 0.9.0, recorded there under ADR 0011’s amendment B: D4, the fence, is thread.ErrStale; D5, Session.Close releasing the writer’s hold, is thread.Releaser and thread.Leaser; D6, List answered by the database, is thread/sqlite’s SQL listing (migration 0003_leases_keyset.sql). Not shipped: D1 (no thread/postgres), D3’s lease modes, D7’s write hook, D8’s search helper, and D10’s weft_thread_ table rename. Read ADR 0026.

Run records as events plus a result, versioned and append-safe, in a weft/store module.

Status: superseded by ADR 0024 on 2026-09-30; weft/store was deleted with no migration. Its survey stays the reference for obsdb’s versioning and loud-on-unknown rules. Read ADR 0010.

Studio’s UI is React and TypeScript on TanStack Start in SPA mode, built ahead of time and embedded, with Go as the only server: every piece of data comes from the Go handler’s JSON API.

Status: decided 2026-09-28, shipped (studio/web); §7’s gzip budget amended to 800 KiB on 2026-10-26 (0.19.0). Read ADR 0018.

OpenTelemetry is the only way observability data leaves the process: the core emits spans and, through the Logs API, the run’s events and transcript, and weft/otel sends them to several destinations at once, each with its own content policy. weft/obsdb is the observability database Studio reads; weft/store is deleted.

Status: decided 2026-09-30, shipped. Its separate obsdb/clickhouse module and studio/cmd binary are, at v0.20.2, packages of the framework module (ADR 0027) and cmd/weft. Read ADR 0024.

What each model call was sent is recorded, under the same content policy as messages: three record kinds (request, prompt, tools), attempts and timing, the step index on transcript batches with the compaction view, the badge table for holes, and the dev-only raw record of provider wire bodies. It reverses the earlier rule that no record carries the instructions text.

Status: decided 2026-10-07, shipped; amended 2026-10-17 (prepared[], thinking.wire, the tools record’s output) and 2026-10-26 (the tools record’s source_detail and skipped, 0.20.0). Read ADR 0028.

A playground replay from step N is fed step N’s recorded request messages, the compaction view applied only to the request that names it, so a replay across a compaction reproduces the model’s exact input. Decision 8 adds the edited request.

Status: decided 2026-10-09, shipped. Read ADR 0029.

ADRs change by dated amendment at the end of the record, never by rewriting the decision; where an amendment disagrees with the text above it, the amendment is the decision. The CHANGELOG names the amendments a release carried:

  • 0.2.0 (CHANGELOG.md:6746-6748): ADR 0013 amended with per-run thinking mappings, argument-delta progress, enforced cancellation, and empty-content and refusal handling; the adapter package docs were updated to match.
  • 0.3.0 (CHANGELOG.md:6085-6089): ADR 0013 amended (tool choice, request params and the escape hatch, cache markers, the provider-executed-tools stance), ADR 0007 amended (Resolve), ADR 0014 noted (handoff isolation stands), ADR 0016 noted (usage split attributes), and ADR 0017 amended (the replay key gains ToolChoice, not Params).
  • 0.3.0, review round (CHANGELOG.md:6094-6099): ADR 0013’s capability matrix gained the tool choice column, with all three adapters supporting it and each provider’s wire tokens listed.
  • 0.13.0 (CHANGELOG.md:1450-1453): ADR 0029 added: the prefix rule, the transcript route’s step, the refusal of an edit inside a compacted range, the child-as-source rule and weft.forked_from as the link back.

v0.20.2’s code is the authority. These ADR passages describe something else:

  • Replay is back. ADR 0003 (lines 199-205) and ADR 0006 (lines 139-149) delete the Replay(ReplaySafe|ReplayNever) option until a checkpoint store ships, to return “in one change” with its ADR. weft.Replay and weft.ReplayPolicy exist since 0.7.0 as the playground’s side-effect class (core/tool.go:720-756, CHANGELOG.md:4276), and the manifest records replay_policy (core/manifest.go:120); no ADR records its return (ADR 0024 uses ReplaySafe in passing).
  • Compaction’s input. ADR 0020 (lines 70-73) says the range is serialized “as a plain transcript”. The code sends the summarizer role-bearing messages (thread/compaction.go:1165-1200), with tool results capped at 2,000 characters (thread/compaction.go:31).
  • A failed turn’s leaf entry. ADR 0011 §7 (lines 232-236) says a failed turn rewrites its tail on a fresh line with a leaf entry. The code attaches the batch after the last matching entry and writes a leaf entry only for an overflow re-run (thread/turn.go:1592-1619, thread/perstep.go:283-302).
  • What Audit returns. ADR 0021 §5 (lines 168-170) includes “the turn entry of each resume”. Session.Audit returns no turn entries (thread/approval.go:1104-1125).

Symbols used: weft.Output · weft.Manifest · weft.Subagent · weft.Steering · weft.ParkSource · weft.Replay · mcp.Tools · wefttest.Record · wefttest.Replay