Repository navigation
feat(selfhost): adopt pre-L24 legacy compose installs before upgrading - #2932
Conversation
Installs created before L24 run under the shared `sam-selfhost` Compose project with no compose creation receipt, so `pnpm selfhost:upgrade` refused them and their own checkout still held the pre-snapshot tool. `selfhost:upgrade --adopt-legacy --from <deployed sha>` proves the legacy project belongs to this checkout, takes the encrypted backup, copies the volumes into the canonical project, writes COMPOSE_PROJECT_NAME and the receipts, verifies health and then runs the normal upgrade. It is journaled and resumable, and rolls back to the legacy project on failure. Found by the post-merge L23+L24 smoke on the self-host box (idea 01M7VRD7FTD50WANT5FKWQS678). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@coderabbitai review |
Action not completed
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5a1e199bbf
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
- A failed rollback keeps its journal and .env copy (the outer catch no longer clears them). - Rollback copies the canonical celld cache back over the legacy cache instead of emptying it, so nothing celld kept locally is lost. - A canonical volume created before its CreatedAt was journaled is re-adopted by its random adoption-id label instead of dead-ending the resume. - Stricter journal validation, refusal of an orphaned .env copy and of missing compose labels, and a correct path-containment check. - README: preconditions, flag rules, phases, checkout position after refusal versus rollback, and failed-rollback handling. - Tests: argument guards (no docker call on refusal), resume after a kill past the .env switch followed by a failed verify, and the cache copy-back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 80cce88eab
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
- A killed rollback resumes as a rollback (journaled `rollingBack`), and the forward path refuses to start the canonical stack when a journaled copy is missing, instead of letting Compose recreate it empty. - The copy helper defaults to the digest-pinned Alpine base of the egress fence (a test keeps them equal), and it is pulled before any mutation: installs older than the fence never built a local image. - The chained upgrade marks the adoption journal inside its own completed-marker window (`completeUpgradeJournal` hook, success path only), so a kill after a successful upgrade never replays it. A target re-checkout makes HEAD useless as that evidence. - The legacy stop is journaled as an intent first, so a kill between the stop and the phase write resumes from the stopped stack instead of refusing it and discarding the journal. Each fix has a real-Docker or unit test proven discriminating by deleting its guard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 99a8ccd13d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…tion evidence - Live test (coordinator condition): the helper image is removed before adoption, and the run pulls it before the backup, the stop or any volume creation. It fails without ensureHelperImage, because `docker run` would otherwise pull it mid-copy. - upgradeCompletedTo validates the marker as readPendingFrom does (regular private file, refs, absolute backup path). - A resume that finds a completed marker checks out the target (the deployed version) before cleanup, instead of failing with "uncertain". - A fresh adoption refuses a pre-existing upgrade-pending record. - Task record outcome. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e345f3f260
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…sumable cleanup - Every expected canonical volume name is inspected before the backup and the stop. A label filter misses an unlabelled volume at that name, which previously surfaced only mid-copy and then deadlocked the rollback on the same ownership check. - The adoption journal is removed before its .env copy. A later run removes a leftover copy that is byte-identical to .env, and refuses any other. - The task record states that the post-merge upgrade and rollback belong to the smoke task. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c924b1a607
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Once the canonical stack has run, each of its volumes holds the newest state: the celld cache, renewed Caddy certificates, and with `local-store` the bundled bucket itself. Rollback copied back only the celld cache, so bucket writes accepted before a failed verification were lost (Codex P1). Every present canonical volume is now copied back over its legacy volume (digest-verified) before any canonical volume is removed. The live failed-verify test writes to a second volume and fails when the copy-back is narrowed to the cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 74b4e83ca7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…ckup left stopped The backup stops celld for its delta copy and restarts it in a `finally`, which a kill skips. The adoption journals `backupStarted` before the backup. A resume with an unfinished backup restarts the legacy celld before the ownership proof (which requires it running), and a pre-stop failure after the backup started restarts celld before discarding the journal; if that restart fails, the journal is kept (Codex P1). The live test covers both the returned-failure and kill paths, and each fails without its restart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
…M6 step 4) L24 #2918 (4a40c52): backup, restore, upgrade rollback, exact-ownership teardown; #2932 legacy compose adoption; #2934 restore keeps fence rules readable. Main's version of every operations file. The branch's earlier drafts that main's modules no longer export into are removed: deploy/selfhost/gcp-teardown.sh (main: teardown-gcp*.ts), adopt-check.test.ts, teardown-gcp-constants.test.ts, live/teardown-bucket.live.test.ts, testdata/fake-docker-teardown.mjs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>



Summary
The post-merge combined L23+L24 smoke on the self-host box found that no install created before L24 can upgrade to main (idea
01M7VRD7FTD50WANT5FKWQS678). Such installs run under the fixed Compose projectsam-selfhostwith no compose creation receipt. main'spnpm selfhost:upgraderefuses them (upgrade-preflight.ts:assertRollbackReady: "missing installation compose creation receipt", or "legacy shared compose project" when the name is set). Their own checkout also still holds the pre-snapshot tool, and main'sdocker-compose.ymlrequiresCOMPOSE_PROJECT_NAME. The README asked for an "operator-controlled migration" but gave no procedure.This adds
pnpm selfhost:upgrade --adopt-legacy --from <deployed full sha> --to <ref>, run from the target checkout (scripts/selfhost/legacy-adoption.ts:runLegacyAdoption):Ownership proof first (
legacy-adoption-inventory.ts:proveLegacyOwnership):.env;--from's compose configuration (so a wrong--fromrefuses), with exactly one running celld;Anything ambiguous refuses before any change, including another checkout on the host using
sam-selfhost.Backup first: the same encrypted
runBackup, against the explicit legacy project, before the stack stops.Move:
<canonical>_<volume>with a no-network helper carrying the random adoption id, verified by a type/owner/mode/content digest;COMPOSE_PROJECT_NAME(every other.envbyte kept), start the same deployed version under the canonical project and check health;recordInstall), then remove the stopped legacy containers.The legacy volumes are kept, and the exact
docker volume rmcommand is printed.Then the normal L24 upgrade from
--fromto the target, with its own snapshot, automatic rollback and rollback command.Resumable and idempotent: a private, fsynced journal (
.state/legacy-adoption.json) plus a private copy of the original.env. A rerun after a kill resumes at the recorded step, removes only its own orphaned helper (label-checked) and recopies an unfinished volume from empty.Rollback to legacy on any failure or failed verification:
.envbyte for byte;local-storethe bucket), so nothing it wrote is lost;The bucket is never restored, because adoption deploys no code.
Each new module stays under 400 lines;
upgrade-lib.tsis untouched (rule 18).Validation
pnpm lint(eslint on scripts/selfhost, prettier check)pnpm typecheck(scripts/selfhost and live tsconfigs; the two metadata-proxy import errors are pre-existing when its isolated npm deps are not installed, andpnpm selfhost:testinstalls them)pnpm test:pnpm selfhost:test1046 passed, 4 skipped, 57 fileslive/legacy-adoption.live.test.ts, 12/12 pass:assertRollbackReadythrows the exact refusal main gives; afterwards it passes inside the upgrade hook. The upgrade runs from--fromwith the legacy stack stopped. Data (owners, modes, symlink) survives; legacy containers are gone and legacy volumes kept; a second run is refused..envbyte-identical, caddy data intact, and a file the canonical celld wrote carried back into the legacy cache; no canonical containers or volumes remain, and the upgrade is never called..envswitch, resume, failed verify: the rerun resumes atswitched, rolls back, restores the original.envand keeps the data.compose stopand its journal entry: the rerun resumes from the stopped stack and completes.ensureHelperImagethe test goes red, becausedocker runwould pull mid-copy..envrestore, no cache copy-back, no orphan-helper removal, nostopRequested, no completion evidence (2 tests), no rollback resume. A first draft without the orphan-helper removal failed the kill test with "volume ... is also used elsewhere", found by the real test.legacy-adoption.test.ts(22): argument guards (--from, shellCOMPOSE_PROJECT_NAME, dirty tree, run from--from,--tomismatch, resume with another--from, orphaned.envcopy) with no docker call on refusal; journal validation (phase, refs, foreign volume, identical projects, relative backup path, group-readable file), original.envkept across resumes,.envrewrite, and proof refusals (wrong--fromhash, outside bind mount, a volume shared with another container, a volume of another project) plus an accepting control.Staging Verification (REQUIRED for all code changes — merge-blocking)
scripts/selfhost,deploy/selfhost/README.md). It is not part of the Cloudflare Worker, web app or any deployed bundle.Staging Verification Evidence
Reproduction (before the change): on the shared box (
app.vmtest.sam2.party, 7f086c7, legacysam-selfhost), main's realpnpm selfhost:upgrade --to mainwas run from a separate main worktree against the box's.env/.state. It refused in both forms with no mutation (receipt sha256 unchanged).Live gate, before merge: PASS on the real box at PR head
80cce88ea(2026-11-20 06:27–06:33 UTC,app.vmtest.sam2.party, legacy projectsam-selfhostat 7f086c7).agent-testandadmin-r18signed in by email code through the box's mail collector. Hosted-git project01M7VT518EWTAT355S86ACJH6Rwas created with commit6b240bed3dd7…pushed tosmoke/adopt. Project lists were recorded.pnpm selfhost:upgrade --adopt-legacy --from 7f086c72bfbf225cdfbd5b573791eecf4fe15769 --to 80cce88eab3070eeabedc9294348fc98ef3f1992 --encryption-key-file ~/.config/sam/backup.key:backups/pre-adoption-2026-11-20T06-27-22-062Z;sam-selfhost_{caddy-config,caddy-data,celld-data,egress-fence-attestation}→sam-selfhost-0453bcf9d4e3_*;7f086c72bfbf → 80cce88eab30(177 files, compose inputs changed, no D1 migrations):docker volume rmcommand were printed.smoke/adopthas sha6b240bed…andgit fsck --strictis clean;selfhost:verify-fence: "egress fence in effect" (exit 0); public/health200; app 200;.envhasCOMPOSE_PROJECT_NAME=sam-selfhost-0453bcf9d4e3;legacy-adoption.*orupgrade-pending.jsonleft;installation a6fd9767…,compose-project sam-selfhost-0453bcf9d4e3,state-dir,env-file,bucket (reused)and both backups;Changes since the box run (80cce88 → f98892c): fixes for four Codex P1 findings (see below). They change only interrupted, failure and resume paths, plus the copy helper image: it is now the digest-pinned Alpine base of the egress fence, pulled if absent, instead of
sam-selfhost-egress-fence:local. The box is already adopted, so it cannot be adopted again. These paths are proven by the real-Docker live suite (9/9), which uses that same pinned Alpine image. The upgrade-completion hook is also exercised by the post-merge normal upgrade on the box.After merge: a normal L24 upgrade from the PR head to main, then the forced-verify rollback trigger and forward again (combined smoke steps 1, 2 and 4).
UI Compliance Checklist (Required for UI changes)
N/A: no UI changes.
UI Screenshot Evidence
N/A: no UI changes.
End-to-End Verification (Required for multi-component changes)
recordInstallwrites the compose receipt only for the canonical name)Data Flow Trace
upgrade.ts(--adopt-legacy) →legacy-adoption.ts:runLegacyAdoption:--fromcommit and that--tois HEAD; then the journal orstartJournal(installation id fromplatform-keys.json, canonical name viainstall-record.ts:expectedComposeProjectFor);git checkout --detach --from;adopt: removes stale helpers,proveLegacyOwnership(usingdocker compose config --hash '*'),assertCanonicalClear, thenrunBackup(legacy project), thencompose stop;legacy-adoption-volumes.ts:createCanonicalVolume,copyVolume,volumeDigest;.envgetsenvWithProject;compose up -dunder the canonical project;checkHealth;recordInstall; phaseadopted;removeLegacyContainers;opts.upgrade=upgrade-lib.ts:runUpgrade(from → to); on success the journal is cleared.On failure,
rollbackToLegacyrunscompose down, copies every canonical volume back withcopyVolume, removes the owned volumes, restores.env, then runscompose up -d(legacy) andcheckHealth.Untested Gaps
The live suite injects the upgrade step (it asserts the real L24 preflight passes) and stands in for the encrypted backup, which needs a fleet bucket. Both are the existing L24 code, unchanged. The real backup, the chained real
runUpgradeand the real celld stack are exercised on the box after merge.Post-Mortem (Required for bug fix PRs)
What broke
Every self-host install created before L24, including the team's box, had no way to upgrade to main: the new tool refused it, and the old tool would have broken mid-upgrade without a backup.
Root cause
L24 (#2918,
4940559e2) made the Compose project installation-specific (name: ${COMPOSE_PROJECT_NAME:?}) and gated upgrades on a compose creation receipt. Neither exists on older installs, and no migration was shipped.Class of bug
A new required identity or receipt with no migration for existing state (the rule 71 family: a new requirement deletes a capability for every existing install).
Why it wasn't caught
L24's live proofs used fresh disposable installs, never a legacy-project box; the combined post-merge smoke was deferred.
Process fix included in this PR
The upgrade path for legacy installs plus real-Docker tests that start from a legacy fixture. No rule change: rule 71 already covers this class.
Post-mortem file
Idea
01M7VRD7FTD50WANT5FKWQS678; tasktasks/active/2026-11-20-selfhost-legacy-compose-adoption.md.Specialist Review Evidence (Required for agent-authored PRs)
needs-human-reviewlabel added and merge deferred to human.envswitch then failed verify added (live); guard deletions recorded--fromthrew a misleading error; it now checks out the deployed target first) and LOW L1 (marker validation equal toreadPendingFrom) and L2 (a fresh adoption refuses an existing upgrade record) are fixed. L3 (a pull failure on resume after the stop leaves the stack stopped with the journal kept; the rerun recovers) is accepted: it needs the image pruned between runs, and the journal plus README guide the retryCodeRabbit Review Evidence (Required for agent-authored PRs)
CodeRabbit Notes
Requested at ready-for-review, 2026-11-20 06:17 UTC, through the trusted label workflow (both runs succeeded). CodeRabbit answered "Review skipped: auto reviews are disabled" and then "Review rate limited", which ends the wait under rule 25. No CodeRabbit findings.
Codex connector review on 80cce88 raised four P1s. All are fixed in f98892c with discriminating tests, replied to and resolved:
rollingBack, plus a missing-copy check;stopRequestedintent.A second Codex round on e345f3f raised three more:
.envcopy, and a byte-identical leftover copy is removed (8ccbc13, unit tests);A third Codex finding on c924b1a (P1): rollback carried back only the celld cache, so with
local-storebucket writes in the copiedobjectstore-datavolume were lost. Fixed in 74b4e83: once the canonical stack ran, every canonical volume is copied back (digest-verified) before removal. The live test writes into a second volume, and fails when the copy-back is narrowed.A fourth Codex finding on 74b4e83 (P1): a kill inside the backup could leave the legacy celld stopped and the retry unable to recover. Fixed in 2d79678 by journaling
backupStartedand restarting the legacy celld on resume or on a pre-stop failure. The live test covers the returned-failure and kill paths, and each fails without its restart.All threads are replied to and resolved; main is merged in.
Exceptions (If any)
Agent Preflight (Required)
Classification
External References
Docker Compose project-name precedence (
-poverCOMPOSE_PROJECT_NAMEover top-levelname:) anddocker compose config --hash, checked against Compose v5 on the box and in the real-Docker tests. Real box layout captured before the change (4 volumes, 8 containers, host networking only). L24 tasktasks/archive/2026-11-19-l24-selfhost-operations.md, rules 71, 62, 81 and 18.Codebase Impact Analysis
scripts/selfhost/upgrade.tsgains the CLI flags. Newscripts/selfhost/legacy-adoption{,-inventory,-journal,-volumes}.ts. Reused unchanged:backup-lib.ts:runBackup/composeArgs,install-record.ts:recordInstall/expectedComposeProjectFor,upgrade-lib.ts:runUpgrade. No Worker, web or package change.Documentation & Specs
deploy/selfhost/README.md: the "Upgrade" section now documents legacy adoption, resume, rollback and retained volumes, replacing the "operator-controlled migration" placeholder.Constitution & Risk Check
Data-loss risk is limited by: backup before stop; legacy volumes only read (except the cache, which receives the newer canonical copy on rollback); no bucket mutation by adoption; rollback restores
.envexactly. No secrets are printed;.envcopies stay private (0600) in the state directory.🤖 Generated with Claude Code