stolon

Guide

Review an agent's changes as a pull request

Give the agent a branch, preview the merge, read it row by row, then land exactly what you reviewed.

1. Give the agent its own branch

psql "postgresql://app:<password>@db.stolondb.com/acme.main" -c 'CREATE DATABASE "agent-7"'

The agent writes on agent-7 while main keeps taking writes:

psql "postgresql://app:<password>@db.stolondb.com/acme.agent-7" \ -c "UPDATE accounts SET balance = 175.00 WHERE id = 1" \ -c "DELETE FROM accounts WHERE id = 3" \ -c "INSERT INTO accounts VALUES (5, 'noor', 42.00)" psql "postgresql://app:<password>@db.stolondb.com/acme.main" -c "UPDATE accounts SET balance = 130.00 WHERE id = 1"

2. Preview the merge

psql "postgresql://app:<password>@db.stolondb.com/acme.main" -c 'MERGE DATABASE "agent-7" INTO main DRY RUN'
kind | detail ------------------+------------------------------------------------------------------ conflict | accounts[1].balance: changed here and on agent-7 review | b7a889ecaec843516fb0a1d811e19813bf68076e60c6efbd8a4efcf3eae507f8 rows to apply | 1 deletes to apply | 1 (4 rows)

3. Read it row by row

psql "postgresql://app:<password>@db.stolondb.com/acme.main" -c 'MERGE DATABASE "agent-7" INTO main DRY RUN ROWS 10'
row | {"after":null,"before":[3,"sam","75.50",null],"change":"removed","changed":[],"key":"3","table":"accounts"} row | {"after":[5,"noor","42.00",null],"before":null,"change":"added","changed":[],"key":"5","table":"accounts"}

The console shows the same pull request, with both sides of each conflict.

4. Settle conflicts

psql "postgresql://app:<password>@db.stolondb.com/acme.main" -c 'MERGE DATABASE "agent-7" INTO main'
ERROR: merge of "agent-7" has 1 conflict(s), nothing applied: accounts[1].balance: changed here and on agent-7

Choose a side with RESOLVE OURS (keep main's) or RESOLVE THEIRS (take the branch's).

5. Merge exactly what you reviewed

Pass the preview's digest; if either branch moved since, nothing lands.

MAIN="postgresql://app:<password>@db.stolondb.com/acme.main" DIGEST=$(psql "$MAIN" -tA -c 'MERGE DATABASE "agent-7" INTO main RESOLVE THEIRS DRY RUN' | awk -F'|' '$1=="review"{print $2}') psql "$MAIN" -c "MERGE DATABASE \"agent-7\" INTO main RESOLVE THEIRS REVIEWED '$DIGEST'"
action | count ---------------------+------- rows applied | 2 deletes applied | 1 tables created | 0 tables dropped | 0 conflicts resolved | 1 keys renumbered | 0 tables full-scanned | 0 (7 rows)

Then DROP DATABASE "agent-7". More in the docs.