Tracker sync on Postgres

How each cycle's Core Council Tracker sync (new Queue Requests imported as spell items, changed cycles moved) runs against production now that it stores on Postgres: the backup, the local rehearsal on a copy, and the production run with its read-backs. The tools are in applications/main/scripts/backfill/ (README); the record package of each sync (the Notion pull, records/<cycle>.json, moves.json, the read-back scripts) lives outside the repository, in ~/Documents/processos-review/backfill/sync-<date>/.

Adam is the accountable owner. Every production write below (the import, the stamp, the moves, a sharing reconcile) needs his go for that sync, given after he has seen the plan and the rehearsal's results. --as names the person the writes are recorded under; it is attribution, not approval.

What every sync does by default

These are standing decisions. A sync applies them; it does not put them back to Adam as choices. Only a question none of them (or another recorded decision) answers goes to Adam, labelled as a first-impression question with the precedents that were checked and a recommended default.

  1. Notion is the source of truth (Adam, 2026-10-13). Source = Queue Requests only. Every Submitted request missing from the app is imported, even an apparent duplicate (listed for the EPL).
  2. One Queue Request is one app item. A request that already backs an item is never imported again (--allow-duplicate-source stays off unless the plan names that one record and why).
  3. A re-dated request is moved in the same sync (Adam, 2026-10-13: "move every item whose cycle Notion changed"). When the move reopens a decided strategic review (v19, see below), that is intended (Adam, 2026-11-11: there is always at least some new decision about whether an item should be included). Its moves.json entry says "reopensStrategicReview": true, and the EPL is told the same day (rule 6). It is not deferred or left for later.
  4. Changed text on an existing request is updated in the same sync (Adam, 2026-11-25): the title, summary, objective, what it does, components, priority rationale and both exposure answers are set to the Notion text, plain text as the importer writes it, with a field update through the application service (the item page's edit path), so the old values stay in the field audit. Not with --allow-update, which replaces the item's state. (No general script yet: the 2026-11-25 BUIDL-I package's fix-buidl-i-text.ts is the pattern.)
  5. Changed exposure answers on an item BA Labs has already reviewed need BA's re-review. A move sends the item back to Prepare strategic review, not to the financial pre-risk review, so the sync's follow-ups ask BA for it.
  6. Follow-ups leave the sync the same day. Anything for the EPL or BA goes out as a Slack draft to Adam the day of the run and is tracked until answered. A follow-up that is only written in the package's README has not been sent.

Every sync's PLAN.md has a Precedents checked section: for each item that is not routine, the rule above (or the dated decision) that settles it. An item with no precedent is marked "first impression" with a recommended default; only those go to Adam as questions.

Why this section exists: the 2026-11-24 sync put a re-dated request (Grove BUIDL-I, 9c63519a) to Adam as "move it, or leave it to the EPL" because its move would reopen a decision. Rules 1, 3 and v19's rationale already answered it. It was left on Dec 3, missed the Dec 17 cycle and BA's review until the EPL noticed, and was fixed on 2026-11-25.

What changed with Postgres

  • The importer, the mover and the export act on the store the app is configured with (STORAGE_DRIVER=postgres and DATABASE_URL in the process-platform container), through the app's repositories. Every write is sealed into the item's audit chain by the store, so audit:verify checks it. With no store configured they refuse to run.
  • The read-only export is scripts/backfill/export-readonly.ts (it replaces the Mongo-only export_prod_readonly.mjs of the earlier packages). Its processes keep the shape read_back.py, verify_text.py and diff_notion_prod.py read; on Postgres every session it opens is read-only.
  • The backup is a pg_dump taken inside the Postgres service's container (Postgres 18), and the rehearsal restores it into a local postgres:18. Railway's point-in-time recovery on the Postgres service is a second way back.
  • A cycle move reopens the strategic review of an item that has reached it (spell-request v19): the item goes back to Prepare strategic review with its hold-back, strategic decision and communication cleared. The mover's dry run says so per item and refuses such a move unless its moves.json entry says "reopensStrategicReview": true. Such a move is the default for a re-dated request (rule 3 above): mark it in moves.json and tell the EPL the same day; a move of a decided item is a new review, not a date change.

Backup

From a laptop with the Railway CLI linked to project soter-os, environment production. The dump is the whole database in custom format with its owners and grants (a faithful rollback copy; the rehearsal drops them at restore), written inside the container, sent back base64-encoded (so no terminal translation can change a byte) and checked by its sha256 at both ends. The first command also reads the database's collation, which the rehearsal copies.

BACKUPS=<a 0700 directory outside any repository>; TS=$(date -u +%Y%m%dT%H%MZ); OUT=$BACKUPS/prod-pg-$TS-pre-tracker-sync.pgdump; umask 077
railway ssh --service Postgres -- sh -c 'pg_dump --version; echo db=$PGDATABASE user=$PGUSER; psql -h 127.0.0.1 -Atc "SELECT datcollate, datctype FROM pg_database WHERE datname = current_database()"'   # 18.x; no secret printed
railway ssh --service Postgres -- sh -c 'umask 077; pg_dump -h 127.0.0.1 --format=custom --file=/tmp/pp-sync.pgdump && sha256sum /tmp/pp-sync.pgdump && pg_restore --list /tmp/pp-sync.pgdump | grep -c "TABLE DATA"'
railway ssh --service Postgres -- sh -c 'base64 /tmp/pp-sync.pgdump' | tr -d '\r' | base64 -d > "$OUT"
shasum -a 256 "$OUT"                                                                                    # must equal the in-container sha256
railway ssh --service Postgres -- rm -f /tmp/pp-sync.pgdump

pg_dump reads the user, password and database from the container's own PGUSER, PGPASSWORD and PGDATABASE; if a future image does not set them, use --dbname="$DATABASE_URL" instead of -h 127.0.0.1. Never print or copy the connection string. If any step after the dump fails, still remove the dump file from the container (the last command above): it is a full copy of production. Write down the dump's time. Railway's point-in-time recovery is a second way back only if the service's backup settings show it enabled and its restorable window covers that time; check both on the day.

Rehearsal on a local copy

Restore the backup into a throwaway local Postgres 18 and run the whole sequence there first, against a checkout of the commit the production web service runs.

docker run -d --name pp-sync-rehearsal -e POSTGRES_PASSWORD=postgres -p 127.0.0.1:55432:5432 --tmpfs /var/lib/postgresql postgres:18
docker exec pp-sync-rehearsal createdb -U postgres --template=template0 --encoding=UTF8 --locale=<production's datcollate> processos
docker exec -i pp-sync-rehearsal pg_restore -U postgres -d processos --no-owner --no-privileges --exit-on-error < "$OUT"
export STORAGE_DRIVER=postgres DATABASE_URL=postgres://postgres:postgres@127.0.0.1:55432/processos MONGO_URL=
export PROCESS_ACCESS_CONFIG=<0600 copy of the production access policy>   # its deployment and owner must match the copy
# plus the read-only Auth0 management variables, for the operator check and the Prime groups' members

Then, from applications/main, run the production sequence with npx tsx in place of the container's tsx and a local records directory: audit:verify first (the baseline), then dry, write, stamp, moves, reconcile dry, export, read-back and audit:verify again. Every count the rehearsal prints is the expected value for the production run; write them into the sync's plan. Remove the container (docker rm -f -v pp-sync-rehearsal) and the restored data afterwards.

Production run

Scripts run inside the process-platform container (railway ssh --service process-platform), from the main application's directory in the image, with the container's own storage, access policy and Auth0 variables; nothing is passed from the laptop and no connection string is printed. The tooling must be in the deployed image: check the commit first.

umask 077; AS='<operator user id>'; CT=/tmp/pp-sync      # Adam's verified user id; one working directory per sync
rs()  { railway ssh --service process-platform -- sh -c "$1"; }
up()  { railway ssh --service process-platform -- sh -c "mkdir -p $CT/records && cat > $CT/$2" < "$1"; }
run() { rs "cd /app/applications/main && /app/node_modules/.bin/tsx $*"; }

rs 'echo commit=$RAILWAY_GIT_COMMIT_SHA storage=$STORAGE_DRIVER'                           # storage=postgres
up records/<cycle>.json records/<cycle>.json; up moves.json moves.json
rs "sha256sum $CT/records/*.json $CT/moves.json"                                             # = the package's
rs "cd /app && node scripts/run-main.mjs audit:verify"                                       # baseline: 0 FAILED
run "scripts/backfill/export-readonly.ts --out $CT/pre.json" && rs "cat $CT/pre.json" > pre.json
rs "sha256sum $CT/pre.json"; shasum -a 256 pre.json                                          # equal
run "scripts/backfill/upsert-db.ts --as '$AS' --records $CT/records"                        # dry: n/n ok · would insert=n update=0
run "scripts/backfill/upsert-db.ts --as '$AS' --records $CT/records --write"                # WRITE
rs "cat $CT/records/upsert-log.json" > upsert-log.json
run "scripts/migrations.ts backfill --template spell-request --as '$AS'"                    # dry: n to stamp, 0 unknown
run "scripts/migrations.ts backfill --template spell-request --yes --as '$AS'"              # WRITE: n stamped, 0 refused
run "scripts/backfill/move-cycles.ts --as '$AS' --moves $CT/moves.json"                     # dry: per item, reopens or not
run "scripts/backfill/move-cycles.ts --as '$AS' --moves $CT/moves.json --write"             # WRITE (skip when moves.json is [])
run "scripts/backfill/move-cycles.ts --as '$AS' --reconcile-sharing"                        # dry; --write only if it plans writes
run "scripts/backfill/export-readonly.ts --out $CT/post.json" && rs "cat $CT/post.json" > post.json
rs "sha256sum $CT/post.json"; shasum -a 256 post.json                                        # equal
python3 -I read_back.py pre.json post.json; python3 -I verify_text.py post.json            # the package's read-backs
rs "cd /app && node scripts/run-main.mjs audit:verify"                                       # 0 FAILED
rs "rm -rf $CT"

Each write step runs only after its dry run printed exactly what the rehearsal did. Stop at the first difference, and at any [share] dry-run: could not load line (the dry run carries on without a Prime's members; the write would fail). The importer refuses a record whose Queue page already backs an item (an update would replace that item's state; --allow-update exists, a sync does not use it), a new record whose Queue Request already backs an item (--allow-duplicate-source, which applies to the whole run: import such a record alone, only when the plan says so), and an import that would not land on the published spell-request version. The exports hold the items' full text: keep them 0600 (the umask above).

Undoing a sync

  • Imported items: abandon them as the operator (scripts/processes.ts abandon <ids…> --as …, plan first, --yes to apply). The abandon is recorded in each item's audit chain.
  • A move: move the item back with another moves.json entry. A reopened strategic review is not restored by moving back; its cleared values are in the field audit and are entered again by the EPL.
  • The whole database: restore the backup, or recover to the dump's time with Railway's point-in-time recovery. Either loses every write since, so it is Adam's decision.