From c4302c5cdf5aef909f4382ef27e6762ffa7bf4e0 Mon Sep 17 00:00:00 2001 From: Mosaic fleet seat mos Date: Fri, 6 Nov 2026 10:06:12 -0600 Subject: [PATCH] salvage 2026-11-06: uncommitted work from scratch/sage-r233/wt (disk cleanup #824) --- docs/TOOLS.md | 84 +++- packages/bus/README.md | 19 +- packages/bus/schema.sql | 31 ++ packages/bus/src/broker.mjs | 417 +++++++++++++++++- packages/bus/src/credentials.mjs | 2 +- packages/bus/src/host-run.mjs | 6 +- packages/bus/src/runtime.mjs | 17 +- packages/bus/src/server.mjs | 7 +- packages/bus/src/store.mjs | 9 +- packages/bus/tests/account-migration.test.mjs | 15 +- packages/bus/tests/chief-of-staff.test.mjs | 4 +- packages/bus/tests/comment-migration.test.mjs | 12 +- packages/bus/tests/hard-waits.test.mjs | 10 +- packages/bus/tests/host-run.test.mjs | 122 ++++- packages/bus/tests/name-migration.test.mjs | 2 +- packages/bus/tests/project-runtime.test.mjs | 3 +- packages/bus/tests/spec-fixtures.mjs | 4 +- packages/bus/tests/spec-migration.test.mjs | 2 +- packages/bus/tests/thread-migration.test.mjs | 6 +- packages/bus/tests/usage-migration.test.mjs | 4 +- packages/business/src/business.mjs | 26 +- packages/business/src/hosts.mjs | 57 +-- packages/business/tests/hosts.test.mjs | 86 ++-- packages/cli/README.md | 9 + packages/cli/src/cli.mjs | 4 + packages/cli/tests/stack-release.test.mjs | 43 ++ scripts/mosaic | 2 +- scripts/stack-release.sh | 25 +- 28 files changed, 837 insertions(+), 191 deletions(-) diff --git a/docs/TOOLS.md b/docs/TOOLS.md index eea6a923b..e4493a62c 100644 --- a/docs/TOOLS.md +++ b/docs/TOOLS.md @@ -669,7 +669,7 @@ pinned copy](../packages/cli/README.md#one-pinned-copy-row-85-1579)). #### Rehearsal on a scratch root (D2, row 163) ``` -scripts/stack-release.sh rehearse ID BUSINESS --backup ACTIVATION|PATH --port N [--timeout S] +scripts/stack-release.sh rehearse ID BUSINESS --backup ACTIVATION|PATH|last --port N [--timeout S] ``` `rehearse` starts the target copy's bus host and Console on a copy of a @@ -680,7 +680,11 @@ runs it against live data. It stops and starts no unit and writes no pointer or log line. `--backup` takes an activation id under `/backups/stack/` or an -absolute path. `--port` is the scratch Console's loopback port, 1024 to +absolute path. `--backup last` (row 233) takes the newest backup the +activation log records and prints `PASS backup-last` naming it. With none in +the log it fails `no-backup`, exits 3 and makes no directory. After the +backup's checks it prints `BACKUP_STORE schema `. +`--port` is the scratch Console's loopback port, 1024 to 65535. The run refuses `port-reserved` for 7332, 7333 and the pointer's `--port` and `--tester-port`, and `port-in-use` for a port something holds; it never picks another port. `--timeout` (default 60 seconds) bounds the @@ -779,6 +783,82 @@ instance (the business's `launch.by`), for this business, whose run started at or after the floor. `status` adds an `awaiting units:` line for an open activation. +Under `--units external`, `activate --plan` also refuses `open-activation` +while any rollback set holds `AWAITING-UNITS`, and `migrate-required` when +the target migrates the store and the run lacks `--migrate` (row 233). Under +`--units user` the plan's bytes are unchanged. + +#### Root's upgrade driver (`scripts/stack-upgrade.sh`, row 233) + +``` +scripts/stack-upgrade.sh upgrade --instance dev --bundle FILE --sha SHA [--migrate] [--no-rehearsal] + [--rehearse-port N] [--timeout S] +scripts/stack-upgrade.sh rollback --instance dev --to ID [--restore ACT [--events N]] [--timeout S] +``` + +Root runs it from a root-owned checkout of the reviewed commit, never from a +copy, because the stack's user can write the copies. Each run needs Mos's go, +and `--migrate` needs Jason present (decision 96). The host must be prepared +first (`docs/guides/host-run-sheet.md`). Only the default instance, `dev`, is +accepted; a named instance's units are a later row. + +The unit values come from `/etc/mosaic-stack/dev.args`, which I2's install +writes: one `case2-unit.sh` argument per line, the serve flags after `--`, +owned by root with no group or other write, exactly one `--copy`, and that +copy the one both installed units run. Otherwise the run refuses +`args-unreadable` or `args-differ`. The driver writes the new copy id into +that file only after `confirm` passes. + +`upgrade`, in order. Every stack user step runs as +`sudo -u USER -H env PATH=:/usr/local/bin:/usr/bin:/bin` from the +user's clone `/src/mosaic-stack`: + +1. Takes `flock -n` on `/run/mosaic-stack/upgrade-dev.lock` and holds it to + the end, rollback included. A second run refuses `upgrade-running`, and + a lock it can't open refuses `lock-failed`. +2. Fetches the bundle's `refactor` into the clone and fast-forwards it to + SHA (`fetch-failed`), then `stack-copy.sh copy --bundle FILE SHA` + (`copy-failed`). +3. A1: this checkout's HEAD is SHA (`head-mismatch`), the copy exists + (`copy-missing`), `/usr/local/lib/mosaic-stack/hostcheck.sh --check` + exits 0 (`profile-drift`, row 240), both units name one copy + (`units-unreadable`, `units-disagree`) and it is the args file's + (`args-differ`), and + `activate SHA BUSINESS --units external --plan --expect-from OLD` exits 0 + (`plan-refused`, which covers `open-activation`, `migrate-required` and + `pointer-differs`). +4. The rehearsal, `rehearse SHA BUSINESS --backup last --port 7339` + (`--rehearse-port`). Exit 0 goes on. Exit 3 means no backup in the log + and goes on only with `--no-rehearsal`, logging `rehearsal-skipped`; + without the flag it refuses `no-backup`. Exit 0 with `--no-rehearsal` + refuses `rehearsal-required`; any other exit refuses `rehearsal-failed`. +5. A2 stops the Console, then the bus, and waits for both to read inactive + or failed. A3 is `activate --units external`, A4 the render with the new + `--copy` (which also starts the bus, then the Console), A5 `confirm`. + The driver writes the new args file beside the old one before A2 + (`args-failed`, exit 3) and moves it into place after A5. A failed move + exits 1 `args-failed`: the new copy is live and confirmed, and root puts + the file in place by hand. + +A failure in A2 or a stage that exits 3 starts the old units again and gates +them (A2f). A later failure stops both units, runs `revert`, renders the old +copy and runs `confirm --rollback OLD --cause A3|A4|A5`. `rollback` is the +same from A1 on, with `rollback BUSINESS --to ID`, no fetch, no copy and no +rehearsal; `--restore` and `--events` pass through. + +Root reads no output the stack user wrote except exit codes and the +rehearsal's `BACKUP_STORE` line, which it copies into its log after a match +against a fixed pattern (`BACKUP_STORE none` otherwise). The step log +`/var/log/mosaic-stack/upgrade-dev.log`, 0640, gets one +`