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 an intent (a sentence a reviewer reads),
  • a token (fbr_...) that acts on this run only,
  • a database_url: a plain Postgres connection to its world, for psql, 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:

StatusMeaning
openworking
merginga merge is being applied
mergedits changes are in the data
heldthe policy wants a person; waits up to agents.hold_ttl_s (seven days)
rejecteda person said no; nothing changed
discardedthe agent (or its code) threw it away
expiredits time ran out before it merged
undoneit 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.

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 held

Each 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.

CredentialPrefixWho holds itWhat it can do
anon key(a JWT)browsers, phone appswhat RLS allows the anon and authenticated roles
service_role key(a JWT)your servers onlyeverything; bypasses RLS; manages agents, approves runs
user access token(a JWT)a signed-in person's appacts as that person under RLS; lives auth.access_ttl_s
user refresh tokenthe same appgets a new access token; rotates on every use
agent tokenfba_an agent's processstarts runs and reads its own runs
run tokenfbr_one runSQL, changes, propose and discard on that run only
job tokenfbj_one running jobits own steps and sleeps (/jobs/v1/self)
MCP access tokenfbm_an MCP clientthe tools of the agent it was granted; one hour
MCP refresh tokenfbmr_an MCP clienta new fbm_; 30 days, rotated on use
webhook secretwhsec_your webhook receiverchecks 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:

postgreschronos
Table triggers and realtime see rows an agent mergedyesno (the engine applies merges without running triggers; use a run.merged event trigger)
Undo windowuntil a re-attachagents.undo_window
Tables agents can touchpublic tables with a primary keyall
Agents without the engine installedoff; the rest worksthe engine is required

What Forkbase is made of

One forkbase process serves every API on one port:

PrefixPart
/auth/v1sign-in for your app's people
/rest/v1your tables over HTTP
/realtime/v1changes and broadcast over WebSocket
/storage/v1files in buckets
/agents/v1agents, runs, approvals, webhooks
/jobs/v1functions, jobs, schedules, triggers
/mcp, /oauththe MCP server and its OAuth 2.1
/dashboardthe studio
/platform/v1what 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.

Concepts · Forkbase