- 88tables in the AgentOS schema, from 79 forward-only migrations
- 13,000lines of SQL in that schema
- 178tables in Helix's collaboration control store
- 29columns in one presence-aware upsert
I use SQL to design state, contracts and correctness under concurrency, from a governance state machine to an agent runtime's event writer. The databases are PostgreSQL. Helix keeps the durable state of its collaboration shell in its own PostgreSQL control store, grown alongside the shell's features through numbered migrations.
A state machine kept as data
AgentOS runs a multi-agent state machine, and I chose to model it relationally, in forward-only migrations. A generic registry sits underneath and the domain sits on top.
work orders · criteria · tasks · contracts · evidence · cost
The registry underneathA reported number computed next to its data
Logic that defines a reported number lives with the data. Validated human-equivalent hours, the labour measure AgentOS reports, is computed by PL/pgSQL functions in the database, with the old and new formulas side by side so a recalibration can be compared. See Why long agent runs fail.
One statement per concurrent write
Agent Swarm writes agent state under heavy concurrency, and I wanted each write to be one exact statement. The schema uses partitioned tables and paired up and down migrations.
INSERT … ON CONFLICT: one wins, the other inserts nothing
Each square is one of its columns; only the ones an event carries change (which ones is illustrative). A materialized common table expression makes a terminal transition one statement as well.
A view as a function's contract
FAFO Core and Function Forge starts every function from a PostgreSQL work view, and I made that view the function's data contract, so schema design stays a human step.
- The view's SQL, checkedrequired
- DDL run by the generatornever
196 deadlocks to zero came from the same habit.
In a performance diagnosis, the database's tuple statistics are the ground truth.