Record and evidence
How turbo-12f keeps tamper-evident hash-chained event streams, evidence blobs, documents, and leases in Postgres, typed evidence reports, read-side rollups, and the legacy v1 model.
Every state transition, test verdict, decision, and token count in a request appends to an immutable trail in Postgres: the request:<id> stream of the events table plus its evidence blobs. Read models in internal/rollup fold that log into UI pages and CLI summaries with no separate mutable status store.
Append-only event stream
Canonical JSON lines chained by SHA-256, checked inside one INSERT.
Typed immutable blobs
Sequenced RoleReport, Decision, and Session records verified by digest.
Read-only rollups
Single-pass projections for lane states, flow graphs, quality, and scorecards.
Where each kind of state lives
ADR 0005 fixes one table or document kind for every record. <home> (T12_HOME) only holds scratch.
| Table or kind | What it holds | Mutability |
|---|---|---|
events | Hash-chained logs for streams request:<id> and run:<name> | Append-only; a trigger refuses UPDATE and DELETE |
blobs, blob_chunks, files | Evidence and reports in 1 MiB chunks (gzip when it saves 10 percent), named per scope such as request:<id> | Blobs are content-addressed; a file name points at one hash, and freshly sequenced names never collide |
documents(kind, key) | Small mutable JSON with a revision: context-state, approval-mode, observer-setting, proposal, release-checks, artifact | Compare-and-swap on rev |
log_entries | Plain append logs: access, observer, release:<project>:signoffs, promotions:<project> | Append-only |
leases | Locks with a TTL on the database clock | Renewed while held, freed when the holder dies |
runs, lanes, decisions, role_reports, approvals, outbox | Structured copies and queues derived from or beside the event log | Row operations |
changes | One revision counter per scope (a conversation, convs, access, approvals, one person's own state, global) that database triggers bump on every write to the tables a page reads | Counters only go up; lease renewals do not bump them |
db_usage | Response bytes and HTTPS calls each process (ui, worker) has read, one row per day and source | Added to about once a minute |
Hash-chained event logs
internal/record (record.go) chains events into the request:<id> stream using canonical JSON from internal/store:
- Genesis & chaining: Sequence
1links toSHA256("t12-request-genesis:" + req). Each event stripshash, encodes viastore.Canonical, writes its SHA-256 intohash, and links the prior digest inprev. - Atomic appending: One statement inserts the event only if it extends the chain, records the names and hashes of the event's files, and bumps
conversations.last_seq. A lost race retries; repeated losers queue on a shortappend:<stream>lease. - Sequenced blobs & cache keys:
freshNameprefixes evidence and reports with a 4-digit sequence (0001-...);EventsStatreturns(last seq, last event time)for SSE ticks;StatusTrackerreads state in one pass. - Full verification (
Home.Verify): ReplaysSeq,Request,Prev, andHash, checks that the stored hash columns match the verbatim line, verifies every blob digest an event names, and rejects paths that leave the request. The web server, which checks on every page, verifies only what it has not checked yet (verifycache.go).
| Lease | Scope and ordering |
|---|---|
activity:<owner> (Home.WithActivity) | One per running CLI command; t12-ui --drain takes home:activity-drain and reports busy while any activity lease is live |
req:<kind>:<id> | Typed locks (LockContext, LockAsk, LockConfirm, LockRun, LockRunMerge, LockRelease), nested LockConfirm -> LockContext -> LockAsk and LockRelease -> LockRunMerge -> LockRun |
RequestLocked / IsLocked | Expose active external CLI work to t12-ui and Observer by reading live leases |
projects table | Connected GitHub repository registry managed via Home.ConnectedProjects (projects.go); no registry file or lock |
A holder that dies stops renewing, so its lease frees itself and no stale lock file needs cleaning up. A web server shows which requests are busy from one view of the live lease names that is at most 3 s old (db.Client.LiveLeaseNames); the lock itself is always taken in the database.
t12 db import --home DIR is the only code that reads the old file layout. It verifies each events.jsonl chain first, copies lines byte-exact into events.line, loads requests/<id>/ files into blobs and files with unchanged hashes, and is safe to rerun. Stop the factory before importing and do not re-import after cutover.
Design target vs. current writers
design.md restricts event appends to the orchestrator alone. Today several CLI verbs (approve, bugbash, confirm, release), internal/roles/context, the merge queue, and the cloud backend also call Home.Append directly.
Typed evidence records
| Record type | What it captures |
|---|---|
RoleReport | Step execution (Did, Done, NotDone, Next), Verdict, Findings, Checks (CheckCoverage: ran/skipped/noop-true), Cost, Context, Cage, Preferences, and Context7 Docs; also copied to role_reports |
Decision | Strategist rules (the team flow routes by rules alone; only classic adds Strategist agent decisions), "answered-for-you", Observer actions (observer-<kind>, By: "observer"), and rule proposals; Observer state lives in log_entries stream observer and the observer-inflight document |
Session (EvSession) | Harness runs with Tools calls and SessionUsage tokens; read-only sessions keep numbered transcripts (transcript-<id>[-N].jsonl) behind a TranscriptRef; approval-asked / approval-decided outcomes come from approvals.EndSession |
Read-side projections in internal/rollup
internal/rollup derives all status views, flow graphs, and scorecards directly by folding events, reports, and decisions:
- Twelve lane states:
StateWaiting,StateBuilding,StateChecking,StateFixing,StateYourOK,StateOnTest,StateHeldBack,StateStuck,StateLive,StateUndone,StateLiveFixes, andStateSplitpower UI and CLI summaries via single-pass helpers (TasksFromEvents,Summarize,NowFromEvents,PlanFromEvents,QualityFromEvents). A lane paused as a Problem reads as resumable, and a person's answer moves a stuck part on. - Waiting on a person (
wait.go):WaitsOnPersonsays a conversation is blocked, asking, or has a part that is stuck or waits for an OK;WaitPausedsays it has had no event for longer than the project'sbudgets.wait_hours, andPausedNowwords it. Nothing is written: any new event ends the pause. - Flow graph (
GraphOf&ApplyLiveJobin graph.go): Folds events intoFlowGraph, taking its steps from the conversation's flow: theflow-chosenevent written before its first part starts (teamorclassic; a log with none ranclassic). OnlyEvStepDonewithDetail["by"] == "orchestrator"advances lane steps, andEvSendBackemitsReworkEdgeonly whenfromexists instepIndex. - Acceptance & quality:
Acceptancemaps scenarios to tests and files;QualityOfcomputes catch rate from pre-merge versus escaped bugs. - Scorecards & outcomes:
Scorerecords outcomes for every conversation (RecordOutcomes, alsot12 outcomes), andt12 runandt12 release mergerecord them for their conversations (RecordOutcomesFor) asdecision-outcomeevents. Scorecards aggregateCheckCoverageand proposeguardrail-*documents afterEscapedGuardrailMin = 2escaped bugs.
Each network call costs a round trip, so the web server keeps two process-local caches in db.Client.Memo: an event cache holding the verified prefix of each log (PrimeEvents fills many logs in one query) and a blob cache keyed by SHA-256. A miss is always correct. The home page also stores derived summaries as ui-home-summary documents stamped with last_seq; T12_UI_SUMMARY_STORE=off disables them. A polled page is versioned by the changes revisions of the scopes it reads: a request that sends that version in If-None-Match gets a 304 without the page being built, and no page is older than a minute (internal/ui/conditional.go).
record.Home.observe tells the metrics recorder about events that change waits or samples. agent_spans, human_waits, and sloppiness_samples rows are keyed by stable ids, so a replayed event upserts instead of duplicating. They are derived views that can be rebuilt from the log.
Legacy v1 model contrast
Before internal/record introduced request-scoped streams, turbo-12f v1 stored per-task state in internal/model (Version = 8). That state now lives in Postgres too.
| Aspect | v2 (internal/record and internal/rollup) | Legacy v1 (internal/model) |
|---|---|---|
| Primary log layout | events stream request:<id> plus immutable blobs | runs row plus events stream run:<name> |
| Integrity hash | prev and hash chain over store.Canonical JSON | state_sha chained across snapshots and event rows |
| Concurrency safety | Chain check inside the INSERT; req: leases | run:, lane: and integration: leases, fixed order lane -> integration -> run |
| State updates | Append events and fold projections in rollup | Three-way JSON merge (ApplyChanges) with runMoved guards |
| Crash recovery | A crash leaves the whole statement or none | Explicit t12 repair CLI pass |
One hash-chained log, every view derived from it
Every t12 command and Observer decision appends to one hash-chained stream in Postgres; rollup derives snapshots for t12-ui while documents, leases, and secrets stay separate.
Click any node or press PlayKey takeaway
Because every view in t12 and t12 ui is folded from one hash-chained log in one database, there is no split-brain status store to repair. If t12 conversation verify passes, the history is intact.
Next steps
Delivery, operations, and Observer
How DevOps manages bootstraps and dry-run promotions, Release gates and bisects staging, SRE watches live URLs, and Observer resolves waiting items.
Sandbox and harnesses
How Landlock, Docker cages, Request Review command approvals through a spool bridge, read-only guards, per-person run credentials, the container database broker, and Context7 socket forwarding isolate execution.