diff --git a/agents/sage/work/window-plan/repin-rows-177-185.md b/agents/sage/work/window-plan/repin-rows-177-185.md new file mode 100644 index 000000000..66d028b40 --- /dev/null +++ b/agents/sage/work/window-plan/repin-rows-177-185.md @@ -0,0 +1,303 @@ +# Re-pin 89af38a83 to the refactor head (rows 177, 180-185), and the row 178 activation + +Sage, 2026-10-20 (draft 1), for mos-0928 under DECISIONS Q173, with Q174 (mos-0882) while Jason is away. + +Two parts. Part A is a re-pin Q173 covers, run by Darkwing, Mos and Sage the way the merged B+C window ran +(`repin-merged-bc.md`, draft 9). Part B turns on row 178's proxy proof. It changes who can reach the Console from +outside, so it waits for Jason. Part B is drafted here and goes on Jason's morning list; nobody runs any of it. + +Status: Part A goes to Mos before W0, as draft 9 did. It needs one tool row to land first, the backup row below, +and NEW becomes that row's landing commit. Mos's formal check runs on this file at that NEW. Any change to this +file or to the tool blob after the check means Mos checks again (mos-0849/0850). + +# Part A: the re-pin + +## Who, and what nobody does + +- Darkwing operates, as the tester. Mos verifies each step's output before the next step starts. Sage owns the + plan and files the STATE report in Vikunja (P19 386) and on Gitea. +- Jason has no step. Q173 lets agents re-pin, roll back and restore this test system without him, with a backup + first and a STATE report after. Decision 96 condition 4 stands: nothing is pruned. +- Nobody runs anything as Jason: no `--by jason`, no human shell, no typing into a tmux pane or a human Console + session. Every bus read and write in this plan carries `--tester`. No request in the 7332 matrix carries + Jason's user id. +- `bus.tester` stays as it is. It's Jason's switch. If it reads anything but `true`, the window stops before W0. +- No pi (mos-0865 D2, P19 #383). Nobody presses Save in the human Console, and `mosaic name` stays out (mos-0641). +- Who can reach the Console from outside doesn't change. Row 178's code goes live with `--proof-header` and + `--proof-file` unset, the tunnel still forwards 7332 only, and P4, P6 and W10 check both. + +## Names + +- OLD, live: `89af38a83afa22a8a4f0d368a0a4030ad15a0efa`, pointer `pm: true`, schema 3i, Console flags + `--port 7332 --public-host mosaic.woltje.com --auth-header X-authentik-username --allow-user jason.woltje + --send --tester-port 7333` (read from the unit at 06:15Z, mos-0928). +- NEW: the origin `refactor` commit that lands the backup row. Until it lands, the candidate is + `9f5153deb23bcc4c7c1eaa60244a70ea75b2d770`, read at 06:23Z, 46 commits past OLD. `console-check.sh` takes the + bare sha (mos-0866 F3). Commits after NEW are records only and don't move NEW. +- REPO: the canonical checkout, held at NEW for the window (P5). The tool blob at 9f5153deb is + `a51b2bb68754955762cc553e8538db7ab9522fd8` (OLD's was `adcb68477c25`). The backup row changes it again, and the + blob at NEW goes in this file before the check. `stack-release.sh:N` references are at 9f5153deb. +- `COPIES`, `C_OLD`, `C_NEW` as in draft 9. `C_NEW` is `node $COPIES/$NEW/packages/cli/src/cli.mjs`. +- `DATA`: the config's data root, absolute. The store is `$DATA/bus/bus.sqlite`. +- `P=/mnt/storage/scratch/sage-pin-de352dfaf`, with `business-check.mjs` and `console-check.sh` checked against + `agents/sage/work/window-plan/repin-de352dfaf/SCRIPTS.sha256`, unchanged. +- `T=7333`, the tester port. `WIN`: `agents/darkwing/work/window-rows-177-185/`, where every transcript goes. +- `SNAP`: `$WIN/snapshot.mjs`, a copy of draft 9's whole-store snapshot, sha256 + `639fd28a2674aaa03ce824e3394b4052f21cdef7d6fa49bae61a9927ed341e67` (mos-0899). Darkwing checks the sha before + each of S1, S2 and D3 and refuses to run anything else. + +## What NEW carries over OLD + +The path-limited log over `packages`, `scripts`, `roles`, `contracts` and `adapters` from OLD to 9f5153deb lists +these code commits. The rest of the 46 are queue, sessions and brief records. + +| Row | Commit | Live effect | +|---|---|---| +| 177 | 1f994257a, 9d9d95485 | Tester threads. The tester can create a project and a thread and talk in it. The 7333 Console lets the four chat write routes through (`TESTER_CHAT_WRITE`, `serve.mjs`). A thread's assistant run is the `assistant` instance: holder `mos`, harness `claude-code`, model `opus`, thinking `high`, launched by the chief. | +| 180 | 1905e385c | `activate` adds the activation id suffix and refuses `tester-port-invalid` and `tester-port-target` earlier. The inherited `--tester-port 7333` passes both. | +| 181 | ef48597d0 | The `--restore` guard counts the 11 `COUNTED` tables (`stack-release.sh:296`), not just `events`, and the refusal prints the count per table. | +| 183 | d1272e714 | Console chat strings (`chat.mjs`). | +| 178 | b2b33aee5 | Proxy proof code, off unless both flags are set. Without them `proofOptions` returns null, serve skips the check, and the startup journal says `Proxy: proxy proof off`. `webui-service.sh` renders the pair only when given. | +| 182 | 33ab5eeb9 | A tester message reaches only a tester-owned thread; `thread-not-owned` both ways. | +| 184 | 87aca4cb8 | The CLI forms: `project create --tester`, `thread create\|open\|read --tester`, `threads --tester`, `talk --thread --tester`, `follow --thread --tester`. | +| 185 | (pending, #1683) | Tool only: every `activate` backs up the stopped store (brief `docs/plans/2026-10-20_activate-always-backs-up.md`). | + +Unchanged from OLD to 9f5153deb: `roles/`, `skills/`, `contracts/`, `adapters/`, the plug-in kinds, every +migration, `stack-copy.sh` and `bus-service.sh`. So there's no harness set, no skill carry and no `pm-on` phase: +one `activate --pm`, like the 5fa9cc8f2 window. + +## No schema step + +`SCHEMA_VERSION` (`packages/bus/src/store.mjs:17`) is 3i at OLD and at 9f5153deb, and no migration file was +added. The activate runs without `--migrate`, and `--plan` must print `migration: none; the store is at the +target's version` (`stack-release.sh:801`). If the backup row or anything else lands a schema change before NEW, +this plan is void and gets redrafted. + +## Why the backup row comes first + +Q173 wants a backup before every change. `backup_store` (:349) runs only when the store's schema differs from the +target's (:839-842), so a same-schema activate today takes no store backup. The two backups in the live root are +3f (the 8e7ea89a1 window) and 3h (the merged window), and `rollback --restore` refuses both `restore-mismatch` +because their SCHEMA isn't 3i (:904-905). A backup made by hand would sit outside the tool's layout, and restoring +it by hand would skip the row 181 guard, which mos-0928 asks for in the rollback path. + +So the backup row makes every `activate` back up the stopped store under its own activation id, before any +migration. The in-run restore stays migration-only. Darkwing builds it, Filbert reviews, Sage gates. Its tests +include the exact rollback this plan uses: a same-schema `rollback --restore` that refuses `post-backup-events` +with one `instance_names` row after the stamp and passes with `--events 1`. + +If Mos rejects the row, the only other backup is a hand copy of a stopped store, which needs a second stop of +the bus outside the tool, and its restore would skip the guard. I don't recommend it, and this plan doesn't +describe it. + +## Backups (Q173: a backup before every change) + +| Before | Backup | Taken by | +|---|---|---| +| W5 activate | the stopped store, `$DATA/backups/stack//` with SHA256SUMS, DATA_ROOT, SCHEMA 3i and STAMP | `stack-release.sh`, from the backup row. W5 records the path and stamp | +| W5 activate | the rollback set the activation captures (units, wrapper, pointer) | `stack-release.sh` (`capture`, `run_steps`) | +| W9 tester thread | the business file, `cp -p` to `~/.config/mosaic-dev/businesses/mosaic-stack.json.pre-window-` with its sha256. Nothing in the window writes it; the copy is evidence that nothing did | Darkwing, in W0b | + +Nothing else changes: no plug-in set, no role change, no skill change. + +## Before the window (nothing stopped) + +| # | Who | Step | +|---|-----|------| +| P0 | Mos | `cd $P && grep -E ' (business-check.mjs\|console-check.sh)$' $REPO/agents/sage/work/window-plan/repin-de352dfaf/SCRIPTS.sha256 \| sha256sum -c`: two OK lines. | +| P1 | Darkwing | The live business file, read only, printing these values and nothing else: `vars["bus.tester"]` is `true`; `plugins` is usage-source `["transcript"]`, channel `["cli","webui"]`, harness `["claude-code"]`; `launch.by` is `chief`; `launch.instances` includes `assistant`; no role's `vars.harness` or `vars["fallback.harness"]` is `pi`. sha256 is `1e49bdf05e62607972958f5b7298cfd600c7825812370e26d7c2a842f2af9b93` unless something wrote it since 06:15Z, in which case Darkwing reports the new value and why. Then `node $P/business-check.mjs` for OLD and, after W0, for NEW. Both LOAD_OK. | +| P2 | Sage | `console-check.sh $NEW` against a stub Console of NEW on a scratch port, once without and once with `--tester-port` on a second scratch port. CONSOLE_PASS both times. | +| P3 | Darkwing | The rehearsal on a scratch root seeded at OLD and 3i, on NEW's tool blob, with the example file plus the plug-in keys (mos-0847), `bus.tester` true and a scratch tester port. Run W3 and W5 on it, then the W9 tester thread flow (below), then three rollbacks. (1) A plain `rollback` back to OLD: passes, store untouched, Console flags keep `--tester-port`. (2) Activate NEW again, make one tester `project create` after the stamp, then `rollback --restore --plan`, the real run without `--events` (must refuse `post-backup-events` and print the per-table counts), and the rerun with `--events N` (must pass). (3) After (1), OLD's Console and `$C_OLD threads --tester --json` read the store that NEW's tester thread wrote without an error. The chief launch is emulated as in queue-169. Output in `$WIN/p3/` with sha256 values Sage checks. | +| P4 | Darkwing | The tunnel, read only: `systemctl --user show mosaic-preview-tunnel.service -p ExecStart -p DropInPaths`. Exactly one `R:` spec, `R:0.0.0.0:7332:127.0.0.1:7332`, and DropInPaths empty. Anything else stops the window. | +| P5 | Darkwing | `git -C $REPO rev-parse HEAD` is NEW and `git -C $REPO status --porcelain -- scripts/stack-release.sh scripts/webui-service.sh scripts/bus-service.sh scripts/stack-copy.sh` is empty. `activate` runs REPO's `webui-service.sh` (`stack-release.sh:439`), so REPO must not move during the window. | +| P6 | Darkwing | The 7332 matrix on OLD (below), saved as `$WIN/matrix-old.txt`. | + +## The window + +| # | Who | Step | +|---|-----|------| +| W0 | Darkwing | `cd $REPO && scripts/stack-copy.sh copy $NEW`. Note the full id. Then P1's `business-check` for NEW. | +| W0b | Darkwing | The business file copy in the table above, with its sha256 in `$WIN/backups.txt`. | +| W1 | Darkwing | The idle check: `mosaic agents --business mosaic-stack --tester` (the chief must not be `working`) and `mosaic launches list`. Record the start stamp with `date -u +%FT%TZ`. Then S1, `node $SNAP --store "$DATA/bus/bus.sqlite" --held`. Nobody talks to the chief until W9. | +| W2 | Darkwing | `scripts/stack-release.sh status mosaic-stack`: pointer on OLD, `pm: true`, schema 3i, no pending line, last line ok, unit flags match the pointer. | +| W3 | Darkwing | `scripts/stack-release.sh activate $NEW mosaic-stack --pm --plan`. It must match P3 on: from OLD, to NEW, `migration: none`, the backup line the backup row adds, the commit count, and the Console line with the flags identical to OLD's, `--tester-port 7333` included and no `--proof-header` or `--proof-file`. No `tester-port-invalid` or `tester-port-target` refusal. Any other difference stops the window here. | +| W4 | Darkwing | The units, read only: `systemctl --user show mosaic-bus@mosaic-stack.service -p ExecStart -p WorkingDirectory -p DropInPaths -p Environment` and `systemctl --user show mosaic-webui.service -p ExecStart -p WorkingDirectory -p DropInPaths`. DropInPaths empty on both. Bus ExecStart has `--pm`. Both name the OLD copy. No `"`, `'` or `\` in the bus `Environment=` or either ExecStart. | +| W5 | Darkwing, on Mos's go | `scripts/stack-release.sh activate $NEW mosaic-stack --pm`. Exit 0, final `result ok`, every gate check including `pm_launched`. Record the activation id and the backup path and STAMP, and `sha256sum` the backup's SHA256SUMS file into `$WIN/backups.txt`. Then `status`: pointer on NEW, `pm: true`, schema 3i, Console flags as in W3. | +| W9 | Darkwing, after Mos verifies W5 | The checks and the turns below. | +| W10 | Darkwing | The browser check and the 7332 matrix below, then P4's tunnel read again. | +| W11 | Darkwing, then Sage | The STATE report (below). Sage files it on P19 386 and on the backup row's issue. | + +W6 to W8 are left out on purpose: no harness set, no `pm-on`, no skill carry. The step numbers match draft 9 so +the STATE reports line up. + +### W9 checks and the turns + +``` +scripts/stack-release.sh status mosaic-stack # pointer on NEW, pm true, schema 3i, last line ok +bash $P/console-check.sh $NEW # CONSOLE_PASS +journalctl --user -u mosaic-webui.service --since "" --no-pager | grep -c 'Proxy: proxy proof off' # 1 +mosaic launches list # one running chief from this start +mosaic agents --business mosaic-stack --tester # chief idle +mosaic talk chief "[mos test] re-pin $NEW: reply with one line, no staffing request" --tester +mosaic project create window- --tester +mosaic thread create window- w9 --tester # note the thread id +mosaic talk --thread "[mos test] reply with one line, then stop" --wait 180 --tester +mosaic thread read --json --tester # the tester message and one assistant reply +mosaic threads --tester # lists the thread +$C_NEW names --business mosaic-stack --tester --json +mosaic usage --business mosaic-stack --tester --json # new byRun entries for the chief and assistant turns +node $SNAP --store "$DATA/bus/bus.sqlite" --held # S2, after the assistant run ends +``` + +`journalctl --since` takes the stamp with an explicit `UTC` suffix; this host reads a bare time as CDT. + +Nobody can stop the assistant run as the tester: the CLI has no `--tester` stop, and the 7333 Console has no +assistant stop (its listener is built with `assistantStop` null, `cli.mjs:92`, and `serve.mjs` refuses one). +Darkwing records how it ends, with the stamp. P3 shows whether it exits by itself at idle. If it is still running +10 minutes after the reply, Darkwing reports to Mos, and a stop is Mos's call. S2 runs after it ends. + +What passes: + +- S2 has S1's rows unchanged, plus the PM launch, the chief turn, the tester project, thread and messages, and + the assistant run. `instance_names` is unchanged. +- The tester thread round trip works: one reply arrives through `talk --wait`, and `thread read` shows it. +- A human thread read as the tester refuses `thread-not-owned` (one `thread read --tester`, + if S1 shows any human thread; skipped and noted if none exists). +- The journal line says the proof is off. + +### W10 browser check and the 7332 matrix + +On http://127.0.0.1:7333/ with the webui browser harness, from Darkwing's run: + +1. The page shows the tester banner. The tester's chat lists the W9 thread. +2. The Board and Settings read as in draft 9 W10, amended (the tester Settings has no Token limits panel). +3. No write through the listener except what W9 already did. + +The matrix, run in P6 on OLD and here on NEW, each request a `curl -s -o /dev/null -w '%{http_code} '` plus the +JSON `error` field, from Darkwing's shell: + +| # | Request | Expected on both | +|---|---|---| +| a | `GET http://127.0.0.1:7332/healthz` | 200 `{ok:true}` | +| b | `GET /` on 7332 with `Host: mosaic.woltje.com`, no auth header | 401 `sign-in required` | +| c | as (b) plus `X-Mosaic-Proof: <32 letters>` | 401 `sign-in required`. With the proof on it would be 401 `proxy proof required`; the same code is the "same behavior" check | +| d | `GET /` on 7332, loopback Host, `X-authentik-username: tester-probe` | 403 `proxy Host refused` | +| e | `GET /` on 7332 with `x-mosaic-tester: 1` | 403 `tester listener required` | +| f | `GET /` on 7333 with `X-authentik-username: tester-probe` | 403 `proxy header refused` | +| g | `GET /` on 7333 with `X-Mosaic-Proof: <32 letters>` | 200, since no proof header is configured | + +`matrix-old.txt` and `matrix-new.txt` must be identical. No request carries `jason.woltje` or any credential. +The `<32 letters>` value is a fixed dummy written in the plan run, not a secret. + +### W11 STATE report + +Darkwing writes `$WIN/STATE.md`: the stamps, the W5 activation id, the backup path and sha256 values, the +pointer before and after, the unit ExecStart lines (no Environment values), S1 and S2, the W9 and W10 outputs, +both matrices and any stop. Sage checks it against the transcripts, then posts a summary on P19 386 and the +backup row's Gitea issue, #1683. + +## Stop conditions + +Before W5, any refusal or mismatch ends the window with nothing stopped. + +- W5 exit 1: the run rolled back inside itself and started OLD. With no migration it doesn't restore the store. + Report the log line and the failing check to Mos. +- W5 exit 2, `rollback-failed`: both units stay stopped. Mos settles it from the rollback set the message names. +- A W9 or W10 failure after W5 passed: Mos decides between a fix forward and the rollback. +- Two failures in one window: stop and report (mos-0823). + +### The rollback + +Default: `scripts/stack-release.sh rollback mosaic-stack --plan`, then the real run. Both copies are at 3i, so it +needs no `--restore` and loses no data: the store stays as it is, with the W9 thread rows. P3 (3) shows OLD reads +them. The Console flags stay as they are, since OLD takes `--tester-port`. + +If Mos wants the store back as it was before W5 too: + +1. D3: `node $SNAP --store "$DATA/bus/bus.sqlite" --held --after "$(cat /STAMP)" --backup + /bus/bus.sqlite`, `` being `$DATA/backups/stack/`. With `--stopped` in place + of `--held` if the bus is down. Darkwing reports every table's rows after the stamp, the count difference + for `message_threads`, `meta` and `task_comment_cursors`, which the tool doesn't count (row 181 BUILD.md, + finding F1), and `stopTables`. +2. `rollback mosaic-stack --restore --plan`, then the real run without `--events`. Past W5 it + always refuses `post-backup-events`: the PM launch writes `role_claims`, and W9 writes `projects`, `threads`, + `messages` and `usage_records`. The refusal prints the count for each table. Its text says "Jason decides"; + under Q173 Mos decides. +3. Mos's go names the rows the restore drops, table by table, including any D3 finds in the three uncounted + tables. Then the rerun with `--events N`, N the total the refusal printed. If N moves between the refusal + and the rerun, the tool refuses again before anything stops, and Mos's go is taken again. +4. Nobody opens or changes the post-attempt store the restore keeps. + +## Rollback copies + +Keep 5fa9cc8f2, 8e7ea89a1, 52f35e7a0, 3190ad762 and 89af38a83. Don't touch 66ea40580. Prune nothing: the rollback +sets, the backups and any post-attempt store stay. `/home` has 38G free; each store backup is about 2.2 MB. + +## Questions for the plan check + +- Q1, the backup row: a tool change before the window, which moves NEW to its landing. I recommend it over a hand + backup, for the reason in "Why the backup row comes first". +- Q2, matrix items (d) and (f) send a non-Jason value in the auth header to loopback listeners. Both only test a + refusal, and neither reaches a sign-in path. OK to keep? +- Q3, the W9 assistant run uses opus at high thinking through the `assistant` instance. It's one short turn. OK + under Q173, or should W9 stop at the thread create and skip the turn? + +## What Sage ran for this plan + +Read only, 2026-10-20 between 06:15Z and 06:40Z. Nothing live was changed. + +- `git fetch`, `git rev-parse origin/refactor` (9f5153deb), `git rev-list --count 89af38a83..origin/refactor` + (46), the path-limited log and `git diff --stat` over the unchanged paths above, and the `webui-service.sh` + and `serve.mjs` diffs. +- `SCHEMA_VERSION` at both ends and the migrations directory. +- `scripts/stack-release.sh` at 9f5153deb: `backup_store`, `rollback_in_run`, `flags_drift`, + `console_for_target`, `plan`, `run_steps`, `do_rollback`. +- `serve.mjs` request checks (:480-520) and `cli.mjs:101`, for the matrix. +- `agents/darkwing/work/queue-181/BUILD.md`, the row 178 brief, `packages/cli/README.md` tester sections. +- The live backups' SCHEMA files, the business file's sha256 and the listed values only, and the pointer. + +# Part B: the row 178 activation (drafted, not run) + +Part B turns the proxy proof on for the 7332 Console. Then a request through the public name must carry a secret +header that only the cluster's proxy adds, so a process on dragon-lin that reaches 127.0.0.1:7332 with the right +Host and a forged sign-in header gets 401 instead of the Console. That changes who can reach the Console from +outside, so under Q173 it waits for Jason. It also depends on two things only Jason can do. Nobody runs any step +below until Jason says so. + +## What the brief said, and what overrides it + +The row 178 brief (`docs/plans/2026-10-19_console-proxy-proof.md`, Vikunja #385, Gitea #1676) says four things +mos-0928 changes. It says the turn-on doesn't wait for Jason (mos-0881, brief :89); mos-0928 says it does. It +puts the middleware under ops-01's R27 standing authority (brief :92); mos-0928 makes it Jason's. It says uid +separation doesn't hold up the window (brief :61); mos-0928 makes it a precondition. And its step 3 puts the flags +on with `webui-service.sh install`, which doesn't work on the pinned stack: the Console flags live in the pointer, `flags_drift` (:625-636) refuses +`unit-flags-drift` when the unit differs, and `console_for_target` (:643) carries the pointer's flags unchanged, +so a hand install would make every later `activate`, `pm-on` and `rollback` refuse. `activate --tester-port N` is +the only path that writes a new Console flag into the pointer today. + +## Jason's steps + +| # | Step | Why it's Jason's | +|---|---|---| +| J1 | The go on Part B itself. | It changes who can reach the Console from outside (Q173 exclusion). | +| J2 | The uid separation on #385: the Console runs under a uid the T3 seats don't have. Today the Console and every seat run as jwoltje, so any seat can read the proof file (brief :57-62). | Host and service change, infra (Q173 exclusion). Without it the proof keeps out other hosts' and hostNetwork pods' requests but not a local seat. | +| J3 | The k3s side: a SealedSecret holding the proof value, and a Traefik `headers.customRequestHeaders` middleware on the Console route in the mosaic-preview Argo app that sets `X-Mosaic-Proof` from it. The brief calls this ops-01 under R27. | k3s and infra (Q173 exclusion). | +| J4 | Sealing the value into J3's SealedSecret from the slot file A1 writes, without printing it. | The value crosses into the cluster; only Jason's kubeseal context does that. | +| J5 | The outside check after B5: sign in through `https://mosaic.woltje.com/` and see the Console. | Only Jason has that sign-in, and no agent acts as Jason. | +| J6 | The go on the rollback order if B5 or J5 fails: flags off first (B-R1), then the middleware (J3 undone). | The middleware is his. | + +## Agent steps, after Jason's go + +| # | Who | Step | +|---|---|---| +| A0 | Sage | A tool row, filed after Part A lands: `activate --proof-header NAME --proof-file PATH` writes the pair into the pointer and the unit the way `--tester-port` does, refuses before anything stops when the target copy's Console doesn't take the pair, and a `rollback` to such a copy drops it and says so. With tests and a review. Until it lands, Part B can't run. | +| A1 | Darkwing | The slot: `umask 077`, then write one line of at least 43 characters from `[A-Za-z0-9_-]` to `~/.config/mosaic-dev/secrets/mosaic-stack/console-proof.token` from a random source, never printed. Check only with `stat -c '%a %U %s'`: 600, jwoltje, 44 or more bytes. Under J2 the owner becomes the Console's uid. | +| A2 | Mos | The plan check of a Part B window file at A0's landing, with Part A's backup and STATE rules. | +| B1 | Darkwing | Backup: the activate's own store backup (Part A's row), and the rollback set. | +| B2 | Jason | J3 and J4 applied, the middleware live on the route. Before B3, a request through the public name still signs in with the proof off, since the Console ignores the extra header. | +| B3 | Darkwing | `activate mosaic-stack --pm --proof-header X-Mosaic-Proof --proof-file --plan`, then the real run. The journal says `Proxy: proxy proof on`. | +| B4 | Darkwing | The matrix with the proof on: (b) is 401 `proxy proof required`, (c) with a wrong value is 401 `proxy proof required`, (d) with the proof header on a loopback Host is 403 `proxy proof Host refused`, (g) is 403 `proxy proof header refused`. No request carries the real value. | +| B5 | Jason | J5. | +| B-R1 | Darkwing, on Jason's go | Rollback: a plain `rollback` to the previous copy, or an activate without the pair once A0 lets activate drop it. Then Jason takes the middleware off (J6). | + +#385 stays open until J2 is done and Jason closes it. diff --git a/docs/plans/2026-10-20_activate-always-backs-up.md b/docs/plans/2026-10-20_activate-always-backs-up.md new file mode 100644 index 000000000..2877ca401 --- /dev/null +++ b/docs/plans/2026-10-20_activate-always-backs-up.md @@ -0,0 +1,70 @@ +# Brief: every activate backs up the stopped store + +Sage, 2026-10-20, for mos-0928 Part A (`agents/sage/work/window-plan/repin-rows-177-185.md`). Gitea #1683. Owner Darkwing, +reviewer Filbert, gate owner Sage. Base: the refactor head at briefing, 9f5153deb or later. No other open row +touches `scripts/stack-release.sh`. Line numbers are at 9f5153deb. + +Nothing here runs against the live stack. Every test uses the stand-in `systemctl`, units, stores and data +root that `packages/cli/tests/stack-release.test.mjs` already builds. + +## Why + +Mos's mos-0928 asks for a re-pin from 89af38a83 to the refactor head with a backup first and the row 181 +restore guard in the rollback path. Both copies are at schema 3i, so the activate runs no migration, and +`backup_store` (:349) runs only in the migration branch of `run_steps` (:839). A same-schema activate takes +no store backup. `rollback --restore` then has nothing to name. The live root holds two backups, a 3f one from the +8e7ea89a1 window and a 3h one from the merged window. `do_rollback` refuses both `restore-mismatch` because +their SCHEMA isn't the target's (:904-905). + +A backup made by hand would sit outside the tool's layout, and restoring it by hand skips the row 181 guard, +which is what Mos asked for. So the activate itself takes the backup, under the activation id the rollback +then names. + +## The change + +1. `run_steps migrate` backs up the stopped store on every activate where the store exists, after the + `store-unclean` and schema reads (:831-833) and before any migration. A failed backup rolls back with + `backup` as today. A missing store takes no backup, as today. +2. The in-run restore stays a migration-only step. `TAKEN` (:367, read at :543) is set only once a migration + is about to run, so a gate failure on a same-schema activate puts back the units and the wrapper and + leaves the store as it is, as today. `BACKUP` is set by every backup, so the log line names it and + `from_log backup` finds it. The builder says in BUILD.md how they split the two and why. +3. `--plan` for an activate prints one line that says a backup of the stopped store is taken under + `/backups/stack//`. Keep the migration lines as they are. +4. `rollback` and `pm-on` are unchanged. A rollback with `--restore` already moves the store it replaces to + the post-attempt path, and pm-on never touches the store. +5. `docs/TOOLS.md` "Pinned stack update" step 5 and step 6 say what the run now does: a backup on every + activate, a restore after a gate failure only when a migration ran. Step 7 says a same-schema rollback can + take `--restore` with that backup too. + +## Tests + +1. A same-schema activate leaves `backups/stack//` with SHA256SUMS, DATA_ROOT, SCHEMA equal to the + store's, and STAMP, and the log line's `backup` names it. Update T5 if it asserts no backup. +2. A gate failure on a same-schema activate rolls back without restoring: the store's sha after the rollback + equals its sha after the failed gate, and no post-attempt store appears. T8's migration case still + restores. +3. A same-schema `rollback --restore ` with no rows after the STAMP restores and goes live. + With one `instance_names` row after the STAMP it refuses `post-backup-events`, and `--events 1` passes. + This is the path Part A's rollback uses. +4. `--plan` prints the backup line and writes nothing. +5. A missing store still takes no backup. + +Mutants, each killed by some gate test (mos-0862): + +- the backup runs only when the schemas differ (today's code) +- `TAKEN` is set on a same-schema backup, so a gate failure restores +- the log line's `backup` is empty on a same-schema activate + +## Gate + +Filbert approves the candidate manifest. Cli suite and every `scripts/test-*.sh` green on Sage's gate, run +from a git worktree of the candidate. Touched files: `scripts/stack-release.sh`, +`packages/cli/tests/stack-release.test.mjs`, `docs/TOOLS.md`, and the packet. Anything else gets named in +BUILD.md with the reason. + +## Out of scope + +Pruning backups (nothing prunes them; each live one is about 2.2 MB). A backup on rollback or pm-on. Any +change to the backup layout, the restore guard, a refusal code or a flag. The row 178 proof flags in +`activate`, which mos-0928 Part B names as a later row. Any run against `~/.mosaic-dev` or the live units.