Chronos DB, self-hosted
World sets and objectives
Fork many worlds from one base, read and compare them, rank them, merge the best into the base; objectives and OPTIMIZE. Next release.
Self-hostedChronos DB is one binary you run yourself. Releases and install script. To put agents on a database you already run, with approvals: Chronos Gateway
Which release
What a world set is
A world set is a base world and worlds forked from it: many tries at one task, kept side by side, compared, ranked, and the best merged back into the base. The base can’t be main: the best world merges into the base, and the base merges into main as any world does, under its rules.
create world plan;create world set pricing from world plan with (max_live = 100);fork world set pricing count 50 run $$update prices set p = p * (0.9 + random() * 0.2) where sku % 50 = $1$$ seed 42;adopt world my_try into set pricing; -- a fork of the base, made some other wayselect _world, sum(p * sold) from prices at worlds of set pricing group by 1;compare worlds pricing_3, pricing_7; -- table, key, a_value, b_valuerank world set pricing by ($$select sum(p * sold) from prices$$ desc, $$select count(*) from stockouts$$ asc) with checks; -- world, rank, score, scores, failed, reason, keptprune world set pricing where rank > 5 or failed; -- the worlds discardedmerge best of set pricing into plan dry run; -- world, action, rowsmerge best of set pricing into plan;Make a set
CREATE WORLD SET s FROM WORLD b [WITH (max_live = n)]names the set and its base.max_livelimits the set’s worlds (53400past it).FORK WORLD SET s COUNT n RUN $$script$$ [SEED k] [THREADS t]forks n worldss_<index>and runs the script in each, asSIMULATEdoes:$1is the index,$2the seed,random()is seeded,now()is the fork’s moment. It keeps all of them, failed ones too.- The same every time. The same seed gives the same worlds on any number of threads, and
REPLAY WORLDmakes one again. ADOPT WORLD w INTO SET sadds a fork of the base made some other way: by hand, by an agent.
Read every world of a set
AT WORLDS OF SET s after a table reads it in every world of the set, one after another, each row with a last column _world naming its world.
- Same columns: the worlds must give the table the same columns.
42804names the world that does not: read it alone withAT WORLD. - An empty set gives the base’s columns and no rows.
- Read only, with the reader’s rights, tenant and masks in each world, as AT WORLD.
COMPARE WORLDS
compare worlds pricing_3, pricing_7; -- table, key, a_value, b_valuecompare worlds pricing_3, pricing_7 summary; -- table, a_changed, b_changed, differingThe rows the two worlds hold differently. Two worlds of one set are compared by what each changed since the fork, not row by row.
RANK and PRUNE
- Metrics: each is one
SELECTgiving a number, run read only in each world, as the caller. The first metric orders the worlds, the next break ties, then the index. - Last place: a world whose script failed, whose metric failed, or (with
WITH CHECKS, orWITH CHECKS (c, ...)for some) that breaks a merge check as a merge into the base would run it. - Kept: the ranking is stored in each world’s metadata (
_sonos_set_scores). PRUNE WORLD SET s WHERE rank > k OR faileddiscards by the kept ranking and returns the worlds discarded.- A world changed since it was ranked makes
PRUNEandMERGE BESTrefuse (40001): rank again. A merge into a world moves its version on as a write does, so a ranking sees it.
MERGE BEST
MERGE BEST OF SET s INTO b [DRY RUN] merges rank 1 into the base with an ordinary MERGE WORLD as the caller, under the caller’s rights, merge policy and merge checks, then discards the rest. It never merges straight into main. DRY RUN returns world, action and rows and changes nothing.
Objectives and OPTIMIZE
create objective holding_cost minimize $$select sum(qty * unit_cost) from stock$$ subject to checks (no_stockout);optimize holding_cost from world plan as set hc run $$update stock set qty = qty - $1 % 7$$ count 200 keep 5 seed 42;drop objective holding_cost;- An objective is what
OPTIMIZEranks by, and the merge checks a world must pass. Objectives are kept on main; only the database’s own users and admins make them. OPTIMIZEmakes a world set (named byAS SET, else after the objective), forks and runsCOUNTworlds, ranks them by the objective with its checks, and withKEEP kdiscards all but the best k that passed.- Without
SUBJECT TO CHECKSan objective judges no merge checks. - Then:
MERGE BEST OF SET hc INTO plan, as for any set.
Agents and limits
| What | How |
|---|---|
| Forked for an agent | Each world is forked as the agent forks any world: its own, with its tenant and its merge policy’s settings. A world with no scope of its own gets the base’s. |
| Transactions | None of these run in a transaction (25001). |
| Size | max_live per set; the agent’s max_worlds, max_children and budgets as for any fork. |
| Errors | 53400 past max_live; 40001 for a world changed since its ranking; 42804 for a set whose worlds disagree on a table’s columns; 25001 in a transaction. |