Skip to Content
turbo-12f
Architecture

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.

Explanation

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.

Write

Append-only event stream

Canonical JSON lines chained by SHA-256, checked inside one INSERT.

Store

Typed immutable blobs

Sequenced RoleReport, Decision, and Session records verified by digest.

Project

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 kindWhat it holdsMutability
eventsHash-chained logs for streams request:<id> and run:<name>Append-only; a trigger refuses UPDATE and DELETE
blobs, blob_chunks, filesEvidence 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, artifactCompare-and-swap on rev
log_entriesPlain append logs: access, observer, release:<project>:signoffs, promotions:<project>Append-only
leasesLocks with a TTL on the database clockRenewed while held, freed when the holder dies
runs, lanes, decisions, role_reports, approvals, outboxStructured copies and queues derived from or beside the event logRow operations
changesOne 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 readsCounters only go up; lease renewals do not bump them
db_usageResponse bytes and HTTPS calls each process (ui, worker) has read, one row per day and sourceAdded 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 1 links to SHA256("t12-request-genesis:" + req). Each event strips hash, encodes via store.Canonical, writes its SHA-256 into hash, and links the prior digest in prev.
  • 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 short append:<stream> lease.
  • Sequenced blobs & cache keys: freshName prefixes evidence and reports with a 4-digit sequence (0001-...); EventsStat returns (last seq, last event time) for SSE ticks; StatusTracker reads state in one pass.
  • Full verification (Home.Verify): Replays Seq, Request, Prev, and Hash, 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).

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 typeWhat it captures
RoleReportStep 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
DecisionStrategist 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, and StateSplit power 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): WaitsOnPerson says a conversation is blocked, asking, or has a part that is stuck or waits for an OK; WaitPaused says it has had no event for longer than the project's budgets.wait_hours, and PausedNow words it. Nothing is written: any new event ends the pause.
  • Flow graph (GraphOf & ApplyLiveJob in graph.go): Folds events into FlowGraph, taking its steps from the conversation's flow: the flow-chosen event written before its first part starts (team or classic; a log with none ran classic). Only EvStepDone with Detail["by"] == "orchestrator" advances lane steps, and EvSendBack emits ReworkEdge only when from exists in stepIndex.
  • Acceptance & quality: Acceptance maps scenarios to tests and files; QualityOf computes catch rate from pre-merge versus escaped bugs.
  • Scorecards & outcomes: Score records outcomes for every conversation (RecordOutcomes, also t12 outcomes), and t12 run and t12 release merge record them for their conversations (RecordOutcomesFor) as decision-outcome events. Scorecards aggregate CheckCoverage and propose guardrail-* documents after EscapedGuardrailMin = 2 escaped bugs.

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.

Aspectv2 (internal/record and internal/rollup)Legacy v1 (internal/model)
Primary log layoutevents stream request:<id> plus immutable blobsruns row plus events stream run:<name>
Integrity hashprev and hash chain over store.Canonical JSONstate_sha chained across snapshots and event rows
Concurrency safetyChain check inside the INSERT; req: leasesrun:, lane: and integration: leases, fixed order lane -> integration -> run
State updatesAppend events and fold projections in rollupThree-way JSON merge (ApplyChanges) with runMoved guards
Crash recoveryA crash leaves the whole statement or noneExplicit t12 repair CLI pass

One hash-chained log, every view derived from it

Flow
100%
eventchainblob hashderiveviewsre-hashSHA-256Producerst12 · roles · ObserverAppend engineone INSERT per eventevents streamChainseq · prev · SHA-256Rollup viewsstatus · graph · scoreBlobs & filesreports · evidencet12 ui serverJSON · SSE · ObserverChain verifyre-hash + zero linksDocuments & logsdocuments · log_entriesHost secretsenv · DATABASE_URLLocal trust modelno external anchor

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 Play

Key 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

On this page