Concepts
Runs, worlds, merge policies, held runs, undo, keys and tokens, and the two database modes.
The idea in one paragraph
Agents are fast and sometimes wrong. A normal backend lets an agent's bad write land in production at once. Forkbase puts a fork between each agent and your data: the agent works in a private copy, Forkbase checks what it changed against a merge policy, and only then does the change reach the real data. A change the policy doesn't allow waits for a person. A change that merged can still be undone, row by row.
Your app's own code (your servers, your users' browsers) keeps writing straight to the data, as with any Postgres. Only agents go through forks.
Runs and worlds
A run is one task an agent does: "close stale tickets", "backfill country codes". Starting a run makes a world: a copy-on-write branch of the data kept by the Chronos engine. It costs nothing to make, because it shares every row with the data until the run changes one.
Inside its world a run reads the data as it was when the run started, plus its own changes, and writes freely. Nobody else sees those writes. A run has:
- an
id(run_...) and anintent(a sentence a reviewer reads), - a token (
fbr_...) that acts on this run only, - a
database_url: a plain Postgres connection to its world, forpsql, any driver or an ORM, - a time to live (
agents.run_ttl_s, one hour by default). An open run that outlives it is discarded.
A run ends one of these ways:
| Status | Meaning |
|---|---|
open | working |
merging | a merge is being applied |
merged | its changes are in the data |
held | the policy wants a person; waits up to agents.hold_ttl_s (seven days) |
rejected | a person said no; nothing changed |
discarded | the agent (or its code) threw it away |
expired | its time ran out before it merged |
undone | it merged, then a person undid it |
Propose: merged, held or conflict
When the agent is done it proposes. Forkbase hands the world's changes to the engine with the agent's merge policy, and gets one of three answers:
- merged (HTTP 200): within policy. The changes are in the data now.
- held (HTTP 202): the policy wants a person. The response has
reasons("deletes 3 rows, policy allows 0"). Nothing reached the data. A held run is a normal outcome, not an error. - conflict (HTTP 409): someone changed the same rows after the run started. Start a new run on fresh data.
Merge policies
A policy is a named set of rules, written as a file: policies/<name>.toml beside forkbase.toml.
# policies/careful.toml
max_rows = 50 # changes to more rows than this are held
max_deletes = 0 # any delete is held
review_tables = ["payments", "refunds"]
max_age = "1h" # a run older than this is heldEach key is one of the engine's merge-policy rules. Forkbase applies the files every time it starts, and a file is
the whole policy: a rule you remove from the file is removed from the policy. Every agent names a policy; an agent
that names none uses agents.default_policy (forkbase_default, which holds every delete unless you write a file for
it). See Agents for every rule.
Review
A held run shows up in the dashboard's Approvals inbox with the rows it changes, its SQL and its counts. Forkbase can also announce it to Slack and by email, each with a signed link to an approve-or-reject page. Approving merges exactly what was held, nothing that came after. Only a person decides: no agent token, run token or MCP client can approve, reject or undo.
Undo
Any merged run can be undone: Forkbase writes back the rows as they were before the merge. If someone has changed
one of those rows since, the undo stops and tells you, unless you ask it to skip rows changed since
(skip_changed). In chronos mode undo reaches back agents.undo_window (seven days by default).
Keys and tokens
Every credential has a prefix so you can tell them apart in a log.
| Credential | Prefix | Who holds it | What it can do |
|---|---|---|---|
| anon key | (a JWT) | browsers, phone apps | what RLS allows the anon and authenticated roles |
| service_role key | (a JWT) | your servers only | everything; bypasses RLS; manages agents, approves runs |
| user access token | (a JWT) | a signed-in person's app | acts as that person under RLS; lives auth.access_ttl_s |
| user refresh token | the same app | gets a new access token; rotates on every use | |
| agent token | fba_ | an agent's process | starts runs and reads its own runs |
| run token | fbr_ | one run | SQL, changes, propose and discard on that run only |
| job token | fbj_ | one running job | its own steps and sleeps (/jobs/v1/self) |
| MCP access token | fbm_ | an MCP client | the tools of the agent it was granted; one hour |
| MCP refresh token | fbmr_ | an MCP client | a new fbm_; 30 days, rotated on use |
| webhook secret | whsec_ | your webhook receiver | checks Forkbase's signature on deliveries |
Database modes
Forkbase stores your data in one of two places, set by database.mode.
postgres: your Postgres 16+ is the system of record. Your app connects to it as always. When the first agent run
starts, the engine attaches to your public tables that have a primary key: it keeps a copy-on-write copy,
refreshed from Postgres every agents.refresh_every_s. Merges are written back to Postgres in one checked
transaction. Tables made later are picked up by attaching again, once no run is open.
chronos: the bundled Chronos engine is the database. Apps connect to postgres://app:<engine_token>@127.0.0.1:54329/main?sslmode=require with any
Postgres driver (engine_token is in secrets.json). Worlds are native. Forkbase switches off the engine's protect_main, so apps write main as they
would any Postgres; agents still go through worlds. Agents see Forkbase's own tables (auth, storage, agents,
jobs, mcp) masked, and every policy holds changes to them for a person.
Differences to know:
| postgres | chronos | |
|---|---|---|
| Table triggers and realtime see rows an agent merged | yes | no (the engine applies merges without running triggers; use a run.merged event trigger) |
| Undo window | until a re-attach | agents.undo_window |
| Tables agents can touch | public tables with a primary key | all |
| Agents without the engine installed | off; the rest works | the engine is required |
What Forkbase is made of
One forkbase process serves every API on one port:
| Prefix | Part |
|---|---|
/auth/v1 | sign-in for your app's people |
/rest/v1 | your tables over HTTP |
/realtime/v1 | changes and broadcast over WebSocket |
/storage/v1 | files in buckets |
/agents/v1 | agents, runs, approvals, webhooks |
/jobs/v1 | functions, jobs, schedules, triggers |
/mcp, /oauth | the MCP server and its OAuth 2.1 |
/dashboard | the studio |
/platform/v1 | what the dashboard calls |
The Chronos engine runs as a separate program that Forkbase starts and watches; Forkbase talks to it over HTTP and
the Postgres protocol. Forkbase's own state lives in your database, in schemas of its own (forkbase, auth,
storage, agents, jobs, mcp). Several Forkbase servers can share one database: schedules fire once, jobs are
leased, and realtime travels by LISTEN/NOTIFY.
Something wrong or missing? Edit this page on GitHub or open an issue.