From fc0e3593007b9c71a19e6f0b82b3fdbb1dd874d6 Mon Sep 17 00:00:00 2001 From: Ryuz Date: Thu, 19 Nov 2026 11:39:41 +0100 Subject: [PATCH 1/6] Delete stale CELLD_* and OUTER_CELLD_BIN refusals - Prod gets a fresh outer.env: no carried-over names to catch, so the - check-config/serve fail-closed shims go, with their tests. - New test: stale names are ignored (fails before: they refused). - Tenant CELLD_ reservation stays in fleet/sandbox.rs (cello refuses to start with any CELLD_*, so a tenant secret with that prefix would brick the fleet). --- crates/outer/src/config.rs | 64 ++++++-------------------------------- deploy/outer.env.example | 8 ++--- 2 files changed, 14 insertions(+), 58 deletions(-) diff --git a/crates/outer/src/config.rs b/crates/outer/src/config.rs index 8286605..4f362bb 100644 --- a/crates/outer/src/config.rs +++ b/crates/outer/src/config.rs @@ -427,33 +427,8 @@ impl Config { pub fn from_vars(vars: &BTreeMap) -> Result> { let get = |name: &str| vars.get(name).map(|v| v.trim()).filter(|v| !v.is_empty()); let mut problems = Vec::new(); - // Cello 0.1.0 renamed every `CELLD_*` variable to `CELLO_*` (and - // `OUTER_CELLD_BIN` to `OUTER_CELLO_BIN`), with no aliases: cello - // refuses to start with any `CELLD_*` set, and Outer no longer - // emits any. A carried-over setting is dead config at best, so fail - // here, in both `serve` and `check-config` (the release preflight - // runs the latter against prod's env file): the release aborts - // before prod is touched, naming the exact rename. - { - let mut renamed: Vec<(&String, String)> = vars - .keys() - .filter_map(|name| { - if let Some(suffix) = name.strip_prefix("CELLD_") { - Some((name, format!("CELLO_{suffix}"))) - } else if name == "OUTER_CELLD_BIN" { - Some((name, "OUTER_CELLO_BIN".to_string())) - } else { - None - } - }) - .collect(); - renamed.sort(); - for (old, new) in renamed { - problems.push(format!( - "{old} was renamed to {new}: set {new} instead of {old} (stale pre-Cello names fail closed)" - )); - } - } + // No rename shims: production restarts from a wiped database and a + // fresh `outer.env`, so there are no carried-over names to catch. let domain = get("OUTER_DOMAIN") .unwrap_or(DEFAULT_DOMAIN) @@ -1647,37 +1622,18 @@ mod tests { } #[test] - fn stale_celld_env_refuses_with_the_cello_spelling() { - let err = Config::from_vars(&vars(&[ + fn stale_celld_names_are_ignored_after_the_wipe() { + // No rename shims: a carried-over `CELLD_*` or `OUTER_CELLD_BIN` + // is dead config, not a refusal. (The runtime still refuses to + // start a fleet with `CELLD_*` set; that reservation lives in + // `fleet::sandbox`, not here.) + let cfg = Config::from_vars(&vars(&[ ("OUTER_STORE", "memory"), ("CELLD_OPERATOR_TOKEN", "stale"), - ("CELLD_DURABILITY", "bucket"), - ])) - .unwrap_err(); - assert!( - err.iter() - .any(|p| p.contains("CELLD_OPERATOR_TOKEN was renamed to CELLO_OPERATOR_TOKEN")), - "missing operator-token rename: {err:?}" - ); - assert!( - err.iter() - .any(|p| p.contains("CELLD_DURABILITY was renamed to CELLO_DURABILITY")), - "missing durability rename: {err:?}" - ); - } - - #[test] - fn stale_outer_celld_bin_refuses_with_the_cello_spelling() { - let err = Config::from_vars(&vars(&[ - ("OUTER_STORE", "memory"), ("OUTER_CELLD_BIN", "celld"), ])) - .unwrap_err(); - assert!( - err.iter() - .any(|p| p.contains("OUTER_CELLD_BIN was renamed to OUTER_CELLO_BIN")), - "missing bin rename: {err:?}" - ); + .unwrap(); + assert_eq!(cfg.runtime.cello_bin, "cello"); } #[test] diff --git a/deploy/outer.env.example b/deploy/outer.env.example index 0209ae2..0de0d9e 100644 --- a/deploy/outer.env.example +++ b/deploy/outer.env.example @@ -3,10 +3,10 @@ # each; unset entries fall back to the dev default shown. Secrets stay blank # here by design — never commit the filled file. # -# Cello note: the runtime refuses to start with ANY `CELLD_*` variable set -# (every one was renamed to `CELLO_*`). If `outer check-config` fails with -# e.g. `CELLD_OPERATOR_TOKEN was renamed to CELLO_OPERATOR_TOKEN`, rename -# that line here and re-run the release. +# Cello note: the runtime refuses to start with ANY `CELLD_*` variable set, +# so never add one — use the `CELLO_*` names below. (Tenant app secrets with +# a `CELLD_*` prefix are rejected for the same reason: they would brick the +# fleet at wake.) # Platform host; apps live at .. OUTER_DOMAIN=outer.now From 901a09767edc7995a3be80f2d0d77d50fc4f7715 Mon Sep 17 00:00:00 2001 From: Ryuz Date: Thu, 19 Nov 2026 11:39:46 +0100 Subject: [PATCH 2/6] Rename remaining Outer-owned celld references to Cello - Comments now name the current runtime; version provenance that would falsify (verified-against notes) points at Cello 0.1.0. - Delete the /guides/celld and /agents/platform/celld redirects (fresh site). - Reconcile the deploy/images read-grant comment (covered by deploy/). - Kept, classified: CELLD_ tenant reservation, celld-config (external outer-templates name), celld.dev doc links + Dockerfile fork lineage (Cello-owned, pin step). - Legacy node-cells//wake- grants kept: still required by Cello 0.1 (dead_node_gc list, wake_format ensure_legacy_layout). --- crates/outer/src/deploy/migrate.rs | 3 +- crates/outer/src/deploy/pipeline.rs | 32 +++++++++---------- crates/outer/src/fleet/manager.rs | 10 +++--- crates/outer/src/http/console_data/d1.rs | 4 +-- crates/outer/src/http/console_data/durable.rs | 2 +- crates/outer/src/http/console_data/r2.rs | 6 ++-- crates/outer/src/observe/logs.rs | 2 +- crates/outer/src/observe/sourcemaps.rs | 4 +-- web/blume.config.ts | 2 -- 9 files changed, 31 insertions(+), 34 deletions(-) diff --git a/crates/outer/src/deploy/migrate.rs b/crates/outer/src/deploy/migrate.rs index 40b2266..76f091e 100644 --- a/crates/outer/src/deploy/migrate.rs +++ b/crates/outer/src/deploy/migrate.rs @@ -41,8 +41,7 @@ //! are contained under their base, so a hostile config cannot make Outer //! read or write outside the deploy root. //! -//! Cross-app reachability (verified against `d1 --help` under celld 0.6.2; -//! the flags are unchanged in Cello 0.1.0, see +//! Cross-app reachability (verified against `d1 --help` under Cello 0.1.0, see //! https://celld.dev/docs/services/d1): `cello d1 migrations apply` finds a //! node through the *bucket's* node leases and signs each request with the //! fleet's shared secret read from the bucket. Outer passes diff --git a/crates/outer/src/deploy/pipeline.rs b/crates/outer/src/deploy/pipeline.rs index 31901be..bb44d40 100644 --- a/crates/outer/src/deploy/pipeline.rs +++ b/crates/outer/src/deploy/pipeline.rs @@ -1640,10 +1640,10 @@ impl Deployer { Ok((DeployRoot { root, config }, crons, out)) } - /// Whether this `cello` writes Worker maps: the Cello fork's `deploy --sourcemap` - /// (0.6.3-ryuzcorp.8+). Best-effort `deploy --help` probe, so machines on - /// upstream celld keep deploying without maps instead of failing on an - /// unknown flag. No credentials, no side effects — one help print. + /// Whether this `cello` writes Worker maps: `deploy --sourcemap`. + /// Best-effort `deploy --help` probe, so a runtime without the flag + /// keeps deploying without maps instead of failing on an unknown flag. + /// No credentials, no side effects — one help print. async fn cello_sourcemap_support(&self) -> bool { let out = tokio::process::Command::new(&self.settings.cello_bin) .arg("deploy") @@ -1664,13 +1664,13 @@ impl Deployer { /// The `cello deploy ... --json` upload; returns /// (output, version, map read). Bucket credentials come from the /// per-prefix cache when fresh (minted on a miss), so the step env never - /// carries the parent keys. The fork confines project reads to the - /// config's directory (a `dist/` deploy root can no longer pull a - /// root-level Dockerfile or hoisted packages), so the upload names the - /// checkout with `--read-root` and deploys keep building exactly what - /// upstream celld accepted. With the Cello fork, `--sourcemap` collects - /// the Worker map into the work dir (outside the deploy root, so it can - /// never enter the bundle); the caller stores it per deploy sha. + /// carries the parent keys. Cello confines project reads to the config's + /// directory (a `dist/` deploy root can no longer pull a root-level + /// Dockerfile or hoisted packages), so the upload names the checkout + /// with `--read-root` and deploys keep building exactly the same tree + /// as before. Cello's `--sourcemap` collects the Worker map into the + /// work dir (outside the deploy root, so it can never enter the + /// bundle); the caller stores it per deploy sha. async fn cello_deploy( &self, app: &App, @@ -1697,10 +1697,10 @@ impl Deployer { if let Some(esbuild) = &self.settings.esbuild_bin { env.push(("CELLO_ESBUILD".to_string(), esbuild.clone())); } - // The fork admits build inputs from beyond the config's directory + // Cello admits build inputs from beyond the config's directory // only through `--read-root`: name the checkout, so a `dist/` // deploy root still builds against hoisted packages and a - // root-level Dockerfile exactly as upstream celld did. + // root-level Dockerfile exactly as before. let mut args = vec![ "deploy".to_string(), deploy_root.root.to_string_lossy().into_owned(), @@ -2111,7 +2111,7 @@ impl Deployer { /// credentials (the same grant shape `cello deploy` uses: cello reads /// the fleet's shared secret from the bucket, so it needs the prefix /// grant, never the parent keys). - /// No `--` before the positionals on purpose: celld 0.6.2's leaf parsers + /// No `--` before the positionals on purpose: Cello's leaf parsers /// honor neither `--help` nor `--` (`migrations list -- foo` still /// reports "needs a database name"), so a `--` would break the call /// instead of protecting it. Option injection is closed one layer up: @@ -4696,9 +4696,9 @@ exit 0 } /// The `cello deploy` upload names the checkout with `--read-root`: - /// the fork confines project reads to the config's directory, so a + /// Cello confines project reads to the config's directory, so a /// `dist/` deploy root needs the checkout admitted for build inputs - /// (hoisted packages, a root-level Dockerfile) that upstream celld + /// (hoisted packages, a root-level Dockerfile) that older runtimes /// resolved without a flag. #[tokio::test] async fn deploy_names_the_checkout_as_cello_read_root() { diff --git a/crates/outer/src/fleet/manager.rs b/crates/outer/src/fleet/manager.rs index 226d03d..5d7e666 100644 --- a/crates/outer/src/fleet/manager.rs +++ b/crates/outer/src/fleet/manager.rs @@ -143,11 +143,11 @@ impl FleetStorage { } /// The deployment artifacts a running fleet only reads: the pointer, - /// named pointers, manifests, bundles, queue consumer attachments - /// (`deploy/`), asset bodies (`deploy-blobs/`), and container image - /// tars (`deploy/images/`). Minted read-only, so a credential copied out - /// of a fleet's environment can serve a deployment but never publish - /// one. + /// named pointers, manifests, bundles, queue consumer attachments and + /// container image tars (`deploy/`, including `deploy/images/`), and + /// asset bodies (`deploy-blobs/`). Minted read-only, so a credential + /// copied out of a fleet's environment can serve a deployment but never + /// publish one. pub fn deploy_read_prefixes(slug: &str) -> Vec { ["deploy/", "deploy-blobs/"] .into_iter() diff --git a/crates/outer/src/http/console_data/d1.rs b/crates/outer/src/http/console_data/d1.rs index 9635ec7..8520cff 100644 --- a/crates/outer/src/http/console_data/d1.rs +++ b/crates/outer/src/http/console_data/d1.rs @@ -505,7 +505,7 @@ pub fn build_delete_keys( .to_string()) } -/// Most `UNION ALL` terms one `cello d1 execute` takes. Prod celld 0.6.2 +/// Most `UNION ALL` terms one `cello d1 execute` takes. Cello /// refuses 6+ terms (`D1_EXEC_ERROR: too many terms in compound SELECT`; /// without a trailing semicolon it misleadingly says "incomplete /// statement"), so counts for more tables run as several execs. Found live: @@ -772,7 +772,7 @@ async fn deployed_state(ctx: &D1Ctx, slug: &str) -> Result Result { dbs.iter() diff --git a/crates/outer/src/http/console_data/durable.rs b/crates/outer/src/http/console_data/durable.rs index bd49135..219c5ac 100644 --- a/crates/outer/src/http/console_data/durable.rs +++ b/crates/outer/src/http/console_data/durable.rs @@ -113,7 +113,7 @@ pub fn durable_objects(value: &serde_json::Value) -> anyhow::Result anyhow::Result<()> { if name.is_empty() || name.len() > 64 { diff --git a/crates/outer/src/http/console_data/r2.rs b/crates/outer/src/http/console_data/r2.rs index 9e3ebc9..9841de9 100644 --- a/crates/outer/src/http/console_data/r2.rs +++ b/crates/outer/src/http/console_data/r2.rs @@ -230,7 +230,7 @@ pub fn r2_decode(stored: &str) -> String { /// A key the browser may write or delete: 1..=1024 bytes, no absolute path /// and no `..` segment, no control character, and never starting with `-`. /// A trailing `/` is legal — it is the folder marker. Keys travel -/// positionally to `cello r2 put` / `cello r2 delete`, and celld 0.6.2 +/// positionally to `cello r2 put` / `cello r2 delete`, and Cello /// honors no `--` separator, so the leading-dash rule closes option /// injection there. pub fn r2_key_ok(key: &str) -> bool { @@ -1121,7 +1121,7 @@ async fn delete_inner( mod tests { use super::*; - /// Stored forms captured from celld 0.6.1 (the key form is unchanged in Cello 0.1.0): `cello r2 put` for each key, + /// Stored forms (the key form Cello 0.1.0 writes): `cello r2 put` for each key, /// then a raw `ListObjectsV2`. The encoder must reproduce them byte for /// byte, and the decoder must bring them back — a browser that lists S3 /// directly depends on both. (Vectors from Noite @ 58a977a.) @@ -1205,7 +1205,7 @@ mod tests { #[test] fn write_keys_reject_leading_dash_option_injection() { // Keys travel positionally to `cello r2 put` / `cello r2 delete` - // (celld 0.6.2 honors no `--` separator): a leading `-` would parse + // (Cello honors no `--` separator): a leading `-` would parse // as an option. Dashes elsewhere are inert and stay legal. assert!(!r2_key_ok("-evil")); assert!(!r2_key_ok("-")); diff --git a/crates/outer/src/observe/logs.rs b/crates/outer/src/observe/logs.rs index c626c3d..1eae038 100644 --- a/crates/outer/src/observe/logs.rs +++ b/crates/outer/src/observe/logs.rs @@ -1240,7 +1240,7 @@ mod tests { assert_eq!(seen, ring, "no line falls behind the cursor"); } - /// (captured from a real fleet on the VPS under celld 0.6.2; the prefix shape is unchanged in Cello 0.1.0): a Worker's + /// (captured from a real Cello 0.1.0 fleet on the VPS): a Worker's /// uncaught `JSON.parse` failure arrives as tracing INFO under /// `cell_console`, the console level as the first word, then V8 frames. #[test] diff --git a/crates/outer/src/observe/sourcemaps.rs b/crates/outer/src/observe/sourcemaps.rs index 1f13eb6..669d9e1 100644 --- a/crates/outer/src/observe/sourcemaps.rs +++ b/crates/outer/src/observe/sourcemaps.rs @@ -43,8 +43,8 @@ pub const MAX_MAP_BYTES: u64 = 8 * 1024 * 1024; /// older than this still render — with their raw, unsymbolicated stacks. pub const KEEP_DEPLOY_SHAS: usize = 10; -/// The Worker bundle's report names: upstream celld serves the entry as -/// `worker.js`, the Cello fork as its `index.js` module name — workerd +/// The Worker bundle's report names: the pre-rename runtime serves the entry as +/// `worker.js`, Cello as its `index.js` module name — workerd /// prints the entry bare in both cases, never an app path. Only these two /// names map: /// the token lookup is purely positional (greatest-lower-bound), so any diff --git a/web/blume.config.ts b/web/blume.config.ts index f6cb04c..f8f5e4d 100644 --- a/web/blume.config.ts +++ b/web/blume.config.ts @@ -62,8 +62,6 @@ export default defineConfig({ { from: "/guides/ilha", to: "/agents/frontend/ilha", status: 301 }, { from: "/guides/void", to: "/agents/frontend/void", status: 301 }, { from: "/guides/website", to: "/agents/frontend/website", status: 301 }, - { from: "/guides/celld", to: "/agents/platform/cello", status: 301 }, - { from: "/agents/platform/celld", to: "/agents/platform/cello", status: 301 }, { from: "/guides/limits", to: "/agents/platform/limits", status: 301 }, { from: "/guides/storage", to: "/agents/backend/files", status: 301 }, { from: "/guides/export", to: "/agents/deploy/export", status: 301 }, From 6faa90b48c49d1748f03b7166685e8e065986075 Mon Sep 17 00:00:00 2001 From: Ryuz Date: Thu, 19 Nov 2026 11:39:49 +0100 Subject: [PATCH 3/6] Add release.sh --fresh-install, drop handoff fallback, add WIPE.md - --fresh-install: documented fresh path for a wiped box. Skips the migration-checksum gate (no prod DB to read), requires the remote DB absent (refuses if it exists), and composes up directly instead of a handoff. Normal-release gate untouched. - Shell cases 9-11: refuses over live state, skips gate + composes up on a wiped box, unknown flag refuses. 11/11 pass. - handoff.sh: delete the pre-SO_REUSEPORT stop/start fallback. - deploy/WIPE.md: prod wipe runbook from code-verified paths. --- deploy/WIPE.md | 88 +++++++++++++++++++++++++++++++ deploy/handoff.sh | 46 +++++----------- deploy/release.sh | 90 ++++++++++++++++++++++---------- deploy/test-release-preflight.sh | 47 ++++++++++++++++- 4 files changed, 208 insertions(+), 63 deletions(-) create mode 100644 deploy/WIPE.md diff --git a/deploy/WIPE.md b/deploy/WIPE.md new file mode 100644 index 0000000..324283c --- /dev/null +++ b/deploy/WIPE.md @@ -0,0 +1,88 @@ +# Production wipe runbook (Cello 0.2.0 clean break) + +Outer has no real users yet: production restarts from a wiped database, +a wiped bucket, and a fresh `outer.env`. There is no rollback after a +wipe — `OUTER_PREVIOUS_IMAGE` points at a build that cannot read the new +DB/snapshot, and the pre-wipe SQLite copy below is kept only until the +new prod has taken its first snapshot + backup cycle. + +Do not run any of this until the Cello 0.2.0 image pin is in +(`docker/Dockerfile`: `CELLO_VERSION`/`CELLO_DIGEST`); the box must boot +the renamed build first time up. Nothing here is automated on purpose: +every step is an explicit operator command. + +## What gets deleted, what stays + +Live state (verified against `config.rs`, `compose.yaml`, `store/*`): + +- DB: `/srv/outer/data/outer.sqlite*` (`OUTER_DATA` → `/data` in the + container, host-mounted at `/srv/outer/data`; `config.rs` joins + `data_dir` + `"outer.sqlite"`). +- Handoff flag: `/srv/outer/data/handoff` (`handoff.sh` `HANDOFF_FILE`, + `handoff.rs` `FLAG` under the data dir). +- Local fleet/work state, rebuilt from the bucket: everything else under + `/srv/outer/data` (fleet dirs `fleets/{slug}`, worktrees, mirrors, + caches). List first; keep the dir itself. +- Bucket `outer` (`OUTER_R2_BUCKET`, default `outer`): prefixes + `fleets/` (live app state + `fleets/{slug}--preview/` previews), + `git/` (repo WAL/bundles), `outer/state/` (snapshot `outer.sqlite.zst` + + `outer.sqlite.meta.json` + `owner.json` claim + `history/`), + `outer/backups/` (per-app D1 dumps under `outer/backups/{slug}/`), + `outer/exports/` (Pro code exports under `outer/exports/{slug}/`). + No other bucket is used by Outer itself. +- Minted R2 credentials (default TTL 7 d, `OUTER_R2_CREDENTIAL_TTL_S`) + are orphaned by the wipe; stopping the container kills the fleets that + hold them, and the fresh boot mints new ones. + +Kept untouched: + +- `/srv/outer/outer.env` — replaced beforehand with a FRESH copy from + `deploy/outer.env.example` (fill blanks, `chmod 600`). The runtime + refuses to start with any `CELLD_*` set, so never carry one over. +- `/srv/outer/release.env`, `/srv/outer/tls/` (`origin.pem`, + `origin.key`, `origin-pull-ca.pem`), the firewall units/table + (`inet outer_fw`). + +## Steps + +1. Freeze: announce maintenance; refuse new deploys (set the handoff + flag or stop the container after step 2). Record image tags: + `grep -E 'OUTER_(PREVIOUS_)?IMAGE' /srv/outer/release.env`. +2. Safety copy (off-box, optional): + `sqlite3 /srv/outer/data/outer.sqlite ".backup '/root/outer-prewipe-$(date +%F).sqlite'"`. + Keep until the new prod has snapshotted + backed up once. +3. Stop the world: `docker compose -f /srv/outer/compose.yaml stop outer` + (or `docker stop -t 900 outer`). Confirm no fleet processes remain + (`ps aux | grep cello` shows none; each fleet ran as its app uid). +4. Wipe the bucket (`outer`, via the S3-compatible endpoint in + `OUTER_R2_ENDPOINT`; `EP` = that endpoint, credentials from the + matching `OUTER_R2_*` keys): + ``` + for p in fleets/ git/ outer/state/ outer/backups/ outer/exports/; do + aws s3 rm --recursive --endpoint-url "$EP" "s3://outer/$p" + aws s3 ls --endpoint-url "$EP" "s3://outer/$p" # must list nothing + done + ``` +5. Wipe host state: + ``` + rm -f /srv/outer/data/outer.sqlite* /srv/outer/data/handoff + rm -rf /srv/outer/data/fleets /srv/outer/data/work /srv/outer/data/cache /srv/outer/data/git-mirrors + ``` + +6. Cut the code: from a clean tree at the renamed commit, + `deploy/release.sh --fresh-install`. The flag requires + the remote DB to be absent (refuses if it exists) and skips the + migration-checksum gate, which cannot read a prod DB that does not + exist; the rollout then brings the compose service up directly + instead of a handoff. The preflight `check-config` still validates + the fresh `outer.env` before anything changes prod. + +7. Verify empty: + - `/health` + `/ready` (200 once the fresh DB and bucket answer; the + first snapshot writes a fresh `owner.json` claim under `outer/state/`). + - `docs` tool lists `cello`, not `celld`; `outer check-config` clean. + - Create one scratch app, deploy, `GET /.well-known/cello/health` + (synthetic, no wake), stop the fleet, delete the app (exercises the + `fleets/`, `git/`, `outer/backups/`, `outer/exports/` delete paths), + confirm the bucket prefixes are empty again; delete the scratch data. + - Purge the Cloudflare cache for the test host if one was used. diff --git a/deploy/handoff.sh b/deploy/handoff.sh index bcc18a1..222da86 100755 --- a/deploy/handoff.sh +++ b/deploy/handoff.sh @@ -184,43 +184,21 @@ handoff_to() { handoff_abort return 1 } - if ! wait_for_listening outer-next "$image"; then - # First-handoff fallback: an old container that predates SO_REUSEPORT - # cannot share 443, so the newcomer bind fails with EADDRINUSE. - # Stop/start once (seconds of blackout; the idle wait above keeps - # in-flight deploys off the old build) — every later handoff - # overlaps. - if docker logs outer-next 2>&1 | grep -qi "address already in use" \ - && [[ "$(docker inspect -f '{{.State.Running}}' "$old")" == "true" ]]; then - echo "remote: old container predates SO_REUSEPORT; one-time stop/start fallback" >&2 - docker stop -t 60 "$old" - docker rm "$old" - docker start outer-next >/dev/null - wait_for_listening outer-next "$image" || { - handoff_abort - return 1 - } - old="" - else - handoff_abort - return 1 - fi - fi + wait_for_listening outer-next "$image" || { + handoff_abort + return 1 + } # Drain the old container: SIGTERM refuses new deploys and the process # exits once in-flight ones finish. -t 900 bounds a wedged deploy with # SIGKILL; the newcomer's handoff catch-up closes whatever is left. - # (Skipped on the fallback path above: the old container is already - # gone.) - if [[ -n "$old" ]]; then - docker stop -t 900 "$old" || { - handoff_abort - return 1 - } - docker rm "$old" || { - handoff_abort - return 1 - } - fi + docker stop -t 900 "$old" || { + handoff_abort + return 1 + } + docker rm "$old" || { + handoff_abort + return 1 + } record_image "$image" # Recreate the compose service onto the same image: it overlaps the # newcomer via SO_REUSEPORT (same-version, no schema skew), then the diff --git a/deploy/release.sh b/deploy/release.sh index 1200a7d..3d4ab1c 100755 --- a/deploy/release.sh +++ b/deploy/release.sh @@ -3,7 +3,14 @@ # Outer release: build the image from the current HEAD and roll it out with # no downtime (deploy/handoff.sh). # -# deploy/release.sh +# deploy/release.sh [--fresh-install] +# +# `--fresh-install` is the documented fresh path for a wiped box (see +# deploy/WIPE.md): the migration-checksum gate below cannot read a prod DB +# that does not exist, so the flag skips it — and refuses when the remote +# DB is present, so a fresh release can never run over live state. The +# rollout then brings the compose service up directly instead of a +# handoff (there is no old container to drain). # # Engine: OUTER_ENGINE=docker|podman selects the local container engine for # build and save. OUTER_ENGINE=auto (the default when unset or empty) keeps @@ -41,8 +48,14 @@ # No secrets in args or logs (only image tags travel in release.env). set -euo pipefail - -TARGET="${1:?usage: deploy/release.sh }" +TARGET="${1:?usage: deploy/release.sh [--fresh-install]}" +FRESH_INSTALL=0 +if [[ "${2:-}" == "--fresh-install" ]]; then + FRESH_INSTALL=1 +elif [[ -n "${2:-}" ]]; then + echo "release.sh: usage: deploy/release.sh [--fresh-install]" >&2 + exit 1 +fi ROOT="$(git rev-parse --show-toplevel)" cd "$ROOT" @@ -61,26 +74,36 @@ SHA="$(git rev-parse --short HEAD)" # SHA-384 of the file), and by then the old container is already stopped. # So before building: every migration the production database has applied # must exist here with the same SHA-384. New, unapplied files are fine. +# On `--fresh-install` the gate is skipped instead: a wiped box has no DB +# to read, and the missing DB is required (a surviving DB refuses below, +# so a fresh release can never run over live state). MIGRATIONS="crates/outer/migrations" -APPLIED="$(ssh "$TARGET" "sqlite3 -separator ' ' /srv/outer/data/outer.sqlite \ - 'SELECT version, lower(hex(checksum)) FROM _sqlx_migrations ORDER BY version'" 2>/dev/null)" || { - echo "release.sh: cannot read prod migrations from $TARGET (is outer up?)" >&2 - exit 1 -} -while read -r version checksum; do - [[ -n "$version" ]] || continue - file="$(printf '%s/%04d_' "$MIGRATIONS" "$version")" - matches=("$file"*.sql) - [[ -f "${matches[0]}" ]] || { - echo "release.sh: migration $version is applied on $TARGET but missing from this tree" >&2 +if [[ "$FRESH_INSTALL" == 1 ]]; then + if ssh "$TARGET" "test -e /srv/outer/data/outer.sqlite" 2>/dev/null; then + echo "release.sh: --fresh-install refuses: /srv/outer/data/outer.sqlite exists on $TARGET (run a normal release)" >&2 exit 1 - } - local_sum="$(sha384sum "${matches[0]}" | cut -d' ' -f1)" - [[ "$local_sum" == "$checksum" ]] || { - echo "release.sh: ${matches[0]} differs from the copy applied on $TARGET; migrations are append-only (restore it byte-for-byte)" >&2 + fi +else + APPLIED="$(ssh "$TARGET" "sqlite3 -separator ' ' /srv/outer/data/outer.sqlite \ + 'SELECT version, lower(hex(checksum)) FROM _sqlx_migrations ORDER BY version'" 2>/dev/null)" || { + echo "release.sh: cannot read prod migrations from $TARGET (is outer up?)" >&2 exit 1 } -done <<<"$APPLIED" + while read -r version checksum; do + [[ -n "$version" ]] || continue + file="$(printf '%s/%04d_' "$MIGRATIONS" "$version")" + matches=("$file"*.sql) + [[ -f "${matches[0]}" ]] || { + echo "release.sh: migration $version is applied on $TARGET but missing from this tree" >&2 + exit 1 + } + local_sum="$(sha384sum "${matches[0]}" | cut -d' ' -f1)" + [[ "$local_sum" == "$checksum" ]] || { + echo "release.sh: ${matches[0]} differs from the copy applied on $TARGET; migrations are append-only (restore it byte-for-byte)" >&2 + exit 1 + } + done <<<"$APPLIED" +fi # Local container engine for build and save. OUTER_ENGINE=auto (the default # when unset or empty) keeps today's behaviour: prefer podman, fall back to # docker. An explicit engine must exist on PATH; anything else refuses. @@ -153,10 +176,12 @@ scp deploy/compose.yaml deploy/handoff.sh deploy/firewall.sh deploy/firewall.ser "$TARGET:/srv/outer/" # Remote rollout. SHA is hex (validated above), so interpolating it into the -# remote script is safe; the heredoc is otherwise quoted. -ssh "$TARGET" bash -s -- "$SHA" <<'EOF' +# remote script is safe; the heredoc is otherwise quoted. FRESH_INSTALL is +# 0/1 from this script's own flag parsing, never operator input. +ssh "$TARGET" bash -s -- "$SHA" "$FRESH_INSTALL" <<'EOF' set -euo pipefail SHA="$1" +FRESH_INSTALL="${2:-0}" cd /srv/outer [[ -f /srv/outer/outer.env ]] || { @@ -180,9 +205,6 @@ if ! nft list table inet outer_fw >/dev/null 2>&1; then fi source /srv/outer/handoff.sh -# Whatever fails below, the heartbeat must not outlive the release: abort -# clears the flag and removes outer-next only while a compose outer serves. -trap 'handoff_abort' EXIT # Lineage across the handoff needs no release-time step: the upload gate # adopts a pre-lineage bucket meta naming this host on every attempt # (re-applied while the bucket meta stays legacy, so the old container's @@ -193,15 +215,29 @@ trap 'handoff_abort' EXIT # outer/state/history/release--.sqlite.zst from the # bucket's live snapshot before the newcomer can migrate it, so a bad # migration reaching the live key can be restored from history. Skips -# (exit 0) when the bucket holds no snapshot yet. SHA is hex (validated +# (exit 0) when the bucket holds no snapshot yet — the fresh-box case — so +# this step runs on both paths. SHA is hex (validated # above), so interpolating it into the docker args is safe. No data mount: # the subcommand only reads config env and the bucket, never the local DB. # validation reads files under /tls (e.g. OUTER_REVIEW_LOGINS_FILE). # --pull=never: the image is local-only (same as the preflight above). docker run --rm --pull=never --env-file /srv/outer/outer.env -v /srv/outer/tls:/tls:ro \ "outer:$SHA" state release-backup --sha "$SHA" -handoff_to "outer:$SHA" -trap - EXIT +if [[ "$FRESH_INSTALL" == 1 ]]; then + # Fresh box: no old container to drain and no handoff heartbeat — the + # DB-absent gate above already refused a non-wiped box. Bring the + # compose service up directly on the new image. + docker compose --env-file /srv/outer/release.env \ + -f /srv/outer/compose.yaml up -d + record_image "outer:$SHA" + wait_for_listening outer-outer-1 "outer:$SHA" +else + # Whatever fails below, the heartbeat must not outlive the release: abort + # clears the flag and removes outer-next only while a compose outer serves. + trap 'handoff_abort' EXIT + handoff_to "outer:$SHA" + trap - EXIT +fi EOF echo "released $IMAGE to $TARGET" diff --git a/deploy/test-release-preflight.sh b/deploy/test-release-preflight.sh index 031a636..8c3b87f 100755 --- a/deploy/test-release-preflight.sh +++ b/deploy/test-release-preflight.sh @@ -34,6 +34,7 @@ if [ ! -t 0 ]; then cat >"$STUB_LOG/stdin-$n.bin"; else : >"$STUB_LOG/stdin-$n.b printf 'SSH: %s\n' "$*" >>"$STUB_LOG/ssh.log" case "$*" in *sqlite3*) exit 0 ;; +*outer.sqlite*) exit "${STUB_DB_EXISTS:-1}" ;; *check-config*) exit "${STUB_CHECK_CONFIG_EXIT:-0}" ;; *docker\ tag\ localhost*) exit "${STUB_RETAG_EXIT:-0}" ;; *) exit 0 ;; @@ -81,14 +82,16 @@ reset_case() { chmod +x "$BIN/ssh" "$BIN/scp" "$BIN/docker" [[ -f "$BIN/podman" ]] && chmod +x "$BIN/podman" || true unset OUTER_ENGINE || true - export STUB_CHECK_CONFIG_EXIT=0 STUB_RETAG_EXIT=0 + export STUB_CHECK_CONFIG_EXIT=0 STUB_RETAG_EXIT=0 STUB_DB_EXISTS=1 } run_release() { (cd "$FIX" && bash "$RELEASE_SH" fake-target "$LOG/out.log" 2>"$LOG/err.log"; echo "$?") } -# --- case 1: failing check-config aborts before any prod-changing step ----- +run_release_fresh() { + (cd "$FIX" && bash "$RELEASE_SH" fake-target --fresh-install "$LOG/out.log" 2>"$LOG/err.log"; echo "$?") +} reset_case "docker,podman" export STUB_CHECK_CONFIG_EXIT=1 code="$(run_release)" @@ -177,5 +180,45 @@ preflight_vols="$(echo "$preflight_line" | grep -o -- '-v /srv/outer/[^ ]*' | se [[ "$compose_vols" == "$preflight_vols" ]] || fail "compose volumes != preflight mounts: [$compose_vols] vs [$preflight_vols]" if echo "$preflight_line" | grep -o -- '-v /srv/outer/[^ ]*' | grep -vq ':ro$'; then fail "a preflight mount is not read-only"; fi echo "case 8 ok: compose and preflight agree on service identity and mounts" +# --- case 9: --fresh-install refuses when the remote DB exists -------------- +# A fresh release over live state would orphan it: the DB-absent gate is the +# whole point of the flag, so it runs before any build output matters and +# aborts before scp or the rollout. +reset_case "docker,podman" +export STUB_DB_EXISTS=0 +code="$(run_release_fresh)" +[[ "$code" != 0 ]] || fail "fresh-install over an existing DB exited 0 (expected refuse)" +grep -q "outer.sqlite exists" "$LOG/err.log" || fail "fresh-install refusal names no DB path" +[[ ! -f "$LOG/scp.log" ]] || fail "scp upload ran after a refused fresh-install" +if grep -q "bash -s" "$LOG/ssh.log"; then fail "rollout ran after a refused fresh-install"; fi +echo "case 9 ok: --fresh-install refuses when the remote DB exists (exit $code)" + +# --- case 10: --fresh-install proceeds on a wiped box, skipping the gate ---- +# No migration query runs (there is no DB to read); the preflight still +# runs, uploads still happen, and the rollout brings compose up directly +# instead of a handoff (no old container to drain). +reset_case "docker,podman" +export STUB_DB_EXISTS=1 +code="$(run_release_fresh)" +[[ "$code" == 0 ]] || fail "fresh-install on a wiped box exited $code" +if grep -q "sqlite3" "$LOG/ssh.log"; then fail "migration gate ran on --fresh-install"; fi +grep -q "check-config" "$LOG/ssh.log" || fail "preflight check-config never ran on --fresh-install" +[[ -f "$LOG/scp.log" ]] || fail "uploads never ran on --fresh-install" +fresh_rollout="$(grep -l "FRESH_INSTALL" "$LOG"/stdin-*.bin 2>/dev/null || true)" +[[ -n "$fresh_rollout" ]] || fail "rollout heredoc missing on --fresh-install" +fresh_line="$(grep -n 'FRESH_INSTALL" == 1' "$fresh_rollout" | head -n1 | cut -d: -f1 || true)" +up_line="$(grep -n "compose.yaml up -d" "$fresh_rollout" | head -n1 | cut -d: -f1 || true)" +hand_line="$(grep -n 'handoff_to "outer' "$fresh_rollout" | head -n1 | cut -d: -f1 || true)" +[[ -n "$fresh_line" && -n "$up_line" && -n "$hand_line" && "$fresh_line" -lt "$up_line" && "$up_line" -lt "$hand_line" ]] \ + || fail "rollout does not compose-up first on the fresh branch (fresh=$fresh_line up=$up_line handoff=$hand_line)" +echo "case 10 ok: --fresh-install skips the gate and composes up directly (exit 0)" + +# --- case 11: an unknown second arg refuses --------------------------------- +reset_case "docker" +code="$(cd "$FIX" && bash "$RELEASE_SH" fake-target --bogus "$LOG/out.log" 2>"$LOG/err.log"; echo "$?")" +[[ "$code" != 0 ]] || fail "unknown flag exited 0 (expected refuse)" +grep -q "usage:" "$LOG/err.log" || fail "unknown flag prints no usage" +[[ ! -f "$LOG/ssh.log" ]] || fail "ssh ran after an unknown flag" +echo "case 11 ok: unknown second arg refuses before any ssh (exit $code)" echo "test-release-preflight: all cases passed" From 295c3e63355a91876f88ecff7054a8e1920e283a Mon Sep 17 00:00:00 2001 From: Ryuz Date: Thu, 19 Nov 2026 11:39:57 +0100 Subject: [PATCH 4/6] Squash control-DB migrations into one 0001_init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Production restarts from a wiped database: one fresh 0001_init.sql (45 tables, 30 indexes) with a one-line reset header, no departure narrative; the old chain is deleted. - Equivalence proof: sqlite_schema dumped from the old chain and from the squashed file, canonicalized and sorted — identical (75/75). - Keeps current product surface: slug_redirect, previews, prefix_cleanup, compatibility_date-adjacent tables, memory-store path, snapshot fencing. --- crates/outer/migrations/0001_init.sql | 805 ++++++++++-------- crates/outer/migrations/0002_invite_code.sql | 20 - .../migrations/0003_slug_rename_redirect.sql | 18 - crates/outer/migrations/0004_error_triage.sql | 8 - .../outer/migrations/0005_account_action.sql | 17 - crates/outer/migrations/0006_look_quota.sql | 10 - crates/outer/migrations/0007_app_export.sql | 12 - crates/outer/migrations/0008_alerts.sql | 20 - crates/outer/migrations/0009_always_on.sql | 11 - crates/outer/migrations/0010_d1_backups.sql | 15 - .../outer/migrations/0011_preview_deploys.sql | 16 - .../migrations/0012_downgrade_retention.sql | 7 - .../migrations/0013_drop_slug_quarantine.sql | 17 - .../outer/migrations/0015_tool_telemetry.sql | 22 - crates/outer/migrations/0016_plan_limits.sql | 12 - .../outer/migrations/0017_inactive_apps.sql | 5 - .../migrations/0019_after_live_crawl.sql | 6 - crates/outer/migrations/0020_mcp_drafts.sql | 15 - .../outer/migrations/0021_app_access_gate.sql | 7 - 19 files changed, 452 insertions(+), 591 deletions(-) delete mode 100644 crates/outer/migrations/0002_invite_code.sql delete mode 100644 crates/outer/migrations/0003_slug_rename_redirect.sql delete mode 100644 crates/outer/migrations/0004_error_triage.sql delete mode 100644 crates/outer/migrations/0005_account_action.sql delete mode 100644 crates/outer/migrations/0006_look_quota.sql delete mode 100644 crates/outer/migrations/0007_app_export.sql delete mode 100644 crates/outer/migrations/0008_alerts.sql delete mode 100644 crates/outer/migrations/0009_always_on.sql delete mode 100644 crates/outer/migrations/0010_d1_backups.sql delete mode 100644 crates/outer/migrations/0011_preview_deploys.sql delete mode 100644 crates/outer/migrations/0012_downgrade_retention.sql delete mode 100644 crates/outer/migrations/0013_drop_slug_quarantine.sql delete mode 100644 crates/outer/migrations/0015_tool_telemetry.sql delete mode 100644 crates/outer/migrations/0016_plan_limits.sql delete mode 100644 crates/outer/migrations/0017_inactive_apps.sql delete mode 100644 crates/outer/migrations/0019_after_live_crawl.sql delete mode 100644 crates/outer/migrations/0020_mcp_drafts.sql delete mode 100644 crates/outer/migrations/0021_app_access_gate.sql diff --git a/crates/outer/migrations/0001_init.sql b/crates/outer/migrations/0001_init.sql index a174227..e038531 100644 --- a/crates/outer/migrations/0001_init.sql +++ b/crates/outer/migrations/0001_init.sql @@ -1,497 +1,596 @@ --- Outer's platform state (spec §17). Schema reset on 2026-10-24: the auth --- tables now follow the Better Auth database structure (table names and --- column names from https://better-auth.com/docs/concepts/database and the --- api-key / admin / oauth-provider / mcp plugin schemas), so the schema is --- the one the Better Auth ecosystem knows. Migrations are append-only from --- this 0001 on; earlier history was squashed because production restarts --- from a wiped database. --- --- Auth tables follow Better Auth (`user`, `session`, `account`, --- `verification`, `apikey`, `oauth*`); `oauth_request`, `beta_allowlist` --- and `waitlist` stay Outer-shaped. Secret columns hold ONLY sha256 hashes. --- --- Deliberate departures from Better Auth, documented where used: --- 1. Dates are INTEGER unix milliseconds everywhere (Outer convention), --- not the `date` affinity (ISO-8601 text) Better Auth's SQLite DDL --- emits. Every timestamp comparison in the codebase is integer math. --- 2. Secret columns hold ONLY sha256 hex digests, never raw secrets: --- `session.token`, `verification.value`, `apikey.key`, --- `oauthAccessToken.token`, `oauthRefreshToken.token`. Better Auth --- stores session tokens raw and hashes API keys; Outer hashes both. --- 3. `*_uris` / `scopes`-style `string[]` fields and `json`/`metadata` --- fields are TEXT holding JSON (same storage as Better Auth on SQLite). --- `oauthConsent.scopes`/`resources` hold Outer's single scope/resource --- string verbatim (e.g. `apps`), not a JSON array. --- 4. Outer-specific additional fields (Better Auth's additional-fields --- mechanism): `user.plan/planStatus/stripe*/graceUntil/terms*/lastActiveAt`, --- `apikey.clientName/clientVersion`, `oauthClient.kind/host/verified/ --- fetchedAt/lastTokenAt`, `oauthConsent.clientName/clientVersion/ --- lastUsedAt/revokedAt`, `verification.attempts`. OAuth token rows point --- at their consent via `referenceId`. --- 5. No Better Auth equivalent exists for the pending-authorization row, so --- `oauthRequest` stays Outer-shaped (only `account_id` renamed to --- `userId`). `beta_allowlist` and `waitlist` (closed-beta state) also --- stay Outer-shaped. The `account` table (social/credential logins) is --- created for ecosystem familiarity; Outer only does email OTP and never --- writes it. +-- Schema reset on 2026-11-19: production restarts from a wiped database. CREATE TABLE user ( - id TEXT PRIMARY KEY, - name TEXT, - email TEXT NOT NULL UNIQUE, - emailVerified INTEGER NOT NULL DEFAULT 0, - image TEXT, - role TEXT, - banned INTEGER NOT NULL DEFAULT 0, - banReason TEXT, - banExpires INTEGER, - plan TEXT NOT NULL DEFAULT 'free' CHECK (plan IN ('free', 'pro')), - planStatus TEXT CHECK (planStatus IN ('active', 'past_due', 'canceled')), - stripeCustomerId TEXT UNIQUE, + id TEXT PRIMARY KEY, + name TEXT, + email TEXT NOT NULL UNIQUE, + emailVerified INTEGER NOT NULL DEFAULT 0, + image TEXT, + role TEXT, + banned INTEGER NOT NULL DEFAULT 0, + banReason TEXT, + banExpires INTEGER, + plan TEXT NOT NULL DEFAULT 'free' CHECK (plan IN ('free', 'pro')), + planStatus TEXT CHECK (planStatus IN ('active', 'past_due', 'canceled')), + stripeCustomerId TEXT UNIQUE, stripeSubscriptionId TEXT, - graceUntil INTEGER, - termsVersion TEXT, - termsAcceptedAt INTEGER, - lastActiveAt INTEGER NOT NULL, - createdAt INTEGER NOT NULL, - updatedAt INTEGER NOT NULL + graceUntil INTEGER, + termsVersion TEXT, + termsAcceptedAt INTEGER, + lastActiveAt INTEGER NOT NULL, + createdAt INTEGER NOT NULL, + updatedAt INTEGER NOT NULL ); CREATE TABLE session ( - id TEXT PRIMARY KEY, - token TEXT NOT NULL UNIQUE, - expiresAt INTEGER NOT NULL, - createdAt INTEGER NOT NULL, - updatedAt INTEGER NOT NULL, - ipAddress TEXT, - userAgent TEXT, - userId TEXT NOT NULL REFERENCES user (id) ON DELETE CASCADE, + id TEXT PRIMARY KEY, + token TEXT NOT NULL UNIQUE, + expiresAt INTEGER NOT NULL, + createdAt INTEGER NOT NULL, + updatedAt INTEGER NOT NULL, + ipAddress TEXT, + userAgent TEXT, + userId TEXT NOT NULL REFERENCES user (id) ON DELETE CASCADE, impersonatedBy TEXT ); -CREATE INDEX session_userId ON session (userId); CREATE TABLE account ( - id TEXT PRIMARY KEY, - accountId TEXT NOT NULL, - providerId TEXT NOT NULL, - userId TEXT NOT NULL REFERENCES user (id) ON DELETE CASCADE, - accessToken TEXT, - refreshToken TEXT, - idToken TEXT, - accessTokenExpiresAt INTEGER, + id TEXT PRIMARY KEY, + accountId TEXT NOT NULL, + providerId TEXT NOT NULL, + userId TEXT NOT NULL REFERENCES user (id) ON DELETE CASCADE, + accessToken TEXT, + refreshToken TEXT, + idToken TEXT, + accessTokenExpiresAt INTEGER, refreshTokenExpiresAt INTEGER, - scope TEXT, - password TEXT, - createdAt INTEGER NOT NULL, - updatedAt INTEGER NOT NULL + scope TEXT, + password TEXT, + createdAt INTEGER NOT NULL, + updatedAt INTEGER NOT NULL ); -CREATE INDEX account_userId ON account (userId); CREATE TABLE verification ( - id TEXT PRIMARY KEY, + id TEXT PRIMARY KEY, identifier TEXT NOT NULL UNIQUE, - value TEXT NOT NULL, - expiresAt INTEGER NOT NULL, - createdAt INTEGER NOT NULL, - updatedAt INTEGER NOT NULL, - attempts INTEGER NOT NULL DEFAULT 0 + value TEXT NOT NULL, + expiresAt INTEGER NOT NULL, + createdAt INTEGER NOT NULL, + updatedAt INTEGER NOT NULL, + attempts INTEGER NOT NULL DEFAULT 0, + inviteCode TEXT ); CREATE TABLE beta_allowlist ( - email TEXT PRIMARY KEY, + email TEXT PRIMARY KEY, added_by TEXT, added_at INTEGER NOT NULL ); CREATE TABLE waitlist ( - email TEXT PRIMARY KEY, + email TEXT PRIMARY KEY, first_seen INTEGER NOT NULL, - attempts INTEGER NOT NULL DEFAULT 1 + attempts INTEGER NOT NULL DEFAULT 1 ); CREATE TABLE apikey ( - id TEXT PRIMARY KEY, - name TEXT, - start TEXT, - prefix TEXT, - key TEXT NOT NULL UNIQUE, - referenceId TEXT NOT NULL REFERENCES user (id) ON DELETE CASCADE, - refillInterval INTEGER, - refillAmount INTEGER, - lastRefillAt INTEGER, - enabled INTEGER NOT NULL DEFAULT 1, - rateLimitEnabled INTEGER NOT NULL DEFAULT 1, - rateLimitTimeWindow INTEGER, - rateLimitMax INTEGER, - requestCount INTEGER NOT NULL DEFAULT 0, - remaining INTEGER, - lastRequest INTEGER, - expiresAt INTEGER, - createdAt INTEGER NOT NULL, - updatedAt INTEGER NOT NULL, - permissions TEXT, - metadata TEXT, - configId TEXT NOT NULL DEFAULT 'default', - clientName TEXT, - clientVersion TEXT + id TEXT PRIMARY KEY, + name TEXT, + start TEXT, + prefix TEXT, + key TEXT NOT NULL UNIQUE, + referenceId TEXT NOT NULL REFERENCES user (id) ON DELETE CASCADE, + refillInterval INTEGER, + refillAmount INTEGER, + lastRefillAt INTEGER, + enabled INTEGER NOT NULL DEFAULT 1, + rateLimitEnabled INTEGER NOT NULL DEFAULT 1, + rateLimitTimeWindow INTEGER, + rateLimitMax INTEGER, + requestCount INTEGER NOT NULL DEFAULT 0, + remaining INTEGER, + lastRequest INTEGER, + expiresAt INTEGER, + createdAt INTEGER NOT NULL, + updatedAt INTEGER NOT NULL, + permissions TEXT, + metadata TEXT, + configId TEXT NOT NULL DEFAULT 'default', + clientName TEXT, + clientVersion TEXT ); -CREATE INDEX apikey_reference ON apikey (referenceId); CREATE TABLE oauthClient ( - id TEXT PRIMARY KEY, - clientId TEXT NOT NULL UNIQUE, - clientSecret TEXT, - clientDiscoveryId TEXT, - disabled INTEGER, - skipConsent INTEGER, - enableEndSession INTEGER, - subjectType TEXT, - scopes TEXT, - clientCredentialsScopes TEXT, - userId TEXT REFERENCES user (id) ON DELETE CASCADE, - createdAt INTEGER, - updatedAt INTEGER, - name TEXT, - uri TEXT, - icon TEXT, - contacts TEXT, - tos TEXT, - policy TEXT, - softwareId TEXT, - softwareVersion TEXT, - softwareStatement TEXT, - redirectUris TEXT NOT NULL, - postLogoutRedirectUris TEXT, - backchannelLogoutUri TEXT, + id TEXT PRIMARY KEY, + clientId TEXT NOT NULL UNIQUE, + clientSecret TEXT, + clientDiscoveryId TEXT, + disabled INTEGER, + skipConsent INTEGER, + enableEndSession INTEGER, + subjectType TEXT, + scopes TEXT, + clientCredentialsScopes TEXT, + userId TEXT REFERENCES user (id) ON DELETE CASCADE, + createdAt INTEGER, + updatedAt INTEGER, + name TEXT, + uri TEXT, + icon TEXT, + contacts TEXT, + tos TEXT, + policy TEXT, + softwareId TEXT, + softwareVersion TEXT, + softwareStatement TEXT, + redirectUris TEXT NOT NULL, + postLogoutRedirectUris TEXT, + backchannelLogoutUri TEXT, backchannelLogoutSessionRequired INTEGER, - tokenEndpointAuthMethod TEXT, - applicationType TEXT, - jwks TEXT, - jwksUri TEXT, - grantTypes TEXT, - responseTypes TEXT, - requirePKCE INTEGER, - dpopBoundAccessTokens INTEGER NOT NULL DEFAULT 0, - referenceId TEXT, - metadata TEXT, - kind TEXT NOT NULL CHECK (kind IN ('cimd', 'dcr')), - host TEXT, - verified INTEGER NOT NULL DEFAULT 0, - fetchedAt INTEGER, - lastTokenAt INTEGER + tokenEndpointAuthMethod TEXT, + applicationType TEXT, + jwks TEXT, + jwksUri TEXT, + grantTypes TEXT, + responseTypes TEXT, + requirePKCE INTEGER, + dpopBoundAccessTokens INTEGER NOT NULL DEFAULT 0, + referenceId TEXT, + metadata TEXT, + kind TEXT NOT NULL CHECK (kind IN ('cimd', 'dcr')), + host TEXT, + verified INTEGER NOT NULL DEFAULT 0, + fetchedAt INTEGER, + lastTokenAt INTEGER ); -CREATE INDEX oauthClient_user ON oauthClient (userId); CREATE TABLE oauth_request ( - id TEXT PRIMARY KEY, - client_id TEXT NOT NULL, - redirect_uri TEXT NOT NULL, - state TEXT, + id TEXT PRIMARY KEY, + client_id TEXT NOT NULL, + redirect_uri TEXT NOT NULL, + state TEXT, code_challenge TEXT NOT NULL, - scope TEXT, - resource TEXT, - userId TEXT REFERENCES user (id) ON DELETE CASCADE, - csrf TEXT NOT NULL, - code_hash TEXT UNIQUE, - expires_at INTEGER NOT NULL + scope TEXT, + resource TEXT, + userId TEXT REFERENCES user (id) ON DELETE CASCADE, + csrf TEXT NOT NULL, + code_hash TEXT UNIQUE, + expires_at INTEGER NOT NULL ); CREATE TABLE oauthConsent ( - id TEXT PRIMARY KEY, - clientId TEXT NOT NULL REFERENCES oauthClient (clientId), - userId TEXT NOT NULL REFERENCES user (id) ON DELETE CASCADE, - referenceId TEXT, - resources TEXT, + id TEXT PRIMARY KEY, + clientId TEXT NOT NULL REFERENCES oauthClient (clientId), + userId TEXT NOT NULL REFERENCES user (id) ON DELETE CASCADE, + referenceId TEXT, + resources TEXT, requestedUserInfoClaims TEXT, - scopes TEXT NOT NULL, - createdAt INTEGER, - updatedAt INTEGER, - clientName TEXT, - clientVersion TEXT, - lastUsedAt INTEGER, - revokedAt INTEGER + scopes TEXT NOT NULL, + createdAt INTEGER, + updatedAt INTEGER, + clientName TEXT, + clientVersion TEXT, + lastUsedAt INTEGER, + revokedAt INTEGER ); -CREATE INDEX oauthConsent_user ON oauthConsent (userId); -CREATE INDEX oauthConsent_client ON oauthConsent (clientId); CREATE TABLE oauthAccessToken ( - id TEXT PRIMARY KEY, - token TEXT UNIQUE, - clientId TEXT NOT NULL REFERENCES oauthClient (clientId), - sessionId TEXT REFERENCES session (id) ON DELETE SET NULL, - userId TEXT REFERENCES user (id) ON DELETE CASCADE, - referenceId TEXT REFERENCES oauthConsent (id) ON DELETE CASCADE, - authorizationCodeId TEXT, - resources TEXT, + id TEXT PRIMARY KEY, + token TEXT UNIQUE, + clientId TEXT NOT NULL REFERENCES oauthClient (clientId), + sessionId TEXT REFERENCES session (id) ON DELETE SET NULL, + userId TEXT REFERENCES user (id) ON DELETE CASCADE, + referenceId TEXT REFERENCES oauthConsent (id) ON DELETE CASCADE, + authorizationCodeId TEXT, + resources TEXT, requestedUserInfoClaims TEXT, - refreshId TEXT REFERENCES oauthRefreshToken (id), - expiresAt INTEGER, - createdAt INTEGER, - revoked INTEGER, - confirmation TEXT, - scopes TEXT NOT NULL + refreshId TEXT REFERENCES oauthRefreshToken (id), + expiresAt INTEGER, + createdAt INTEGER, + revoked INTEGER, + confirmation TEXT, + scopes TEXT NOT NULL ); -CREATE INDEX oauthAccessToken_client ON oauthAccessToken (clientId); -CREATE INDEX oauthAccessToken_user ON oauthAccessToken (userId); -CREATE INDEX oauthAccessToken_reference ON oauthAccessToken (referenceId); CREATE TABLE oauthRefreshToken ( - id TEXT PRIMARY KEY, - token TEXT NOT NULL UNIQUE, - clientId TEXT NOT NULL REFERENCES oauthClient (clientId), - sessionId TEXT REFERENCES session (id) ON DELETE SET NULL, - userId TEXT NOT NULL REFERENCES user (id) ON DELETE CASCADE, - referenceId TEXT REFERENCES oauthConsent (id) ON DELETE CASCADE, - authorizationCodeId TEXT, - resources TEXT, + id TEXT PRIMARY KEY, + token TEXT NOT NULL UNIQUE, + clientId TEXT NOT NULL REFERENCES oauthClient (clientId), + sessionId TEXT REFERENCES session (id) ON DELETE SET NULL, + userId TEXT NOT NULL REFERENCES user (id) ON DELETE CASCADE, + referenceId TEXT REFERENCES oauthConsent (id) ON DELETE CASCADE, + authorizationCodeId TEXT, + resources TEXT, requestedUserInfoClaims TEXT, - expiresAt INTEGER, - createdAt INTEGER, - revoked INTEGER, - rotatedAt INTEGER, - rotationReplayResponse TEXT, + expiresAt INTEGER, + createdAt INTEGER, + revoked INTEGER, + rotatedAt INTEGER, + rotationReplayResponse TEXT, rotationReplayExpiresAt INTEGER, - authTime INTEGER, - confirmation TEXT, - scopes TEXT NOT NULL + authTime INTEGER, + confirmation TEXT, + scopes TEXT NOT NULL ); -CREATE INDEX oauthRefreshToken_client ON oauthRefreshToken (clientId); -CREATE INDEX oauthRefreshToken_user ON oauthRefreshToken (userId); -CREATE INDEX oauthRefreshToken_reference ON oauthRefreshToken (referenceId); CREATE TABLE oauthClientAssertion ( - id TEXT PRIMARY KEY, + id TEXT PRIMARY KEY, expiresAt INTEGER NOT NULL ); --- The MCP plugin uses the same tables as the OAuth Provider plugin --- (`oauthClient`, `oauthAccessToken`, `oauthRefreshToken`, `oauthConsent`, --- `oauthClientAssertion`); no extra tables. - CREATE TABLE app ( - id TEXT PRIMARY KEY, - slug TEXT NOT NULL UNIQUE, - owner_id TEXT NOT NULL REFERENCES user (id), - name TEXT, - uid INTEGER NOT NULL UNIQUE, - port INTEGER UNIQUE, - internal_port INTEGER UNIQUE, - desired_state TEXT NOT NULL DEFAULT 'running' CHECK (desired_state IN ('running', 'stopped')), - asleep_since INTEGER, - last_request_at INTEGER, - last_deploy_sha TEXT, - visibility TEXT NOT NULL DEFAULT 'unlisted' CHECK (visibility IN ('unlisted', 'public')), - moderation_state TEXT NOT NULL DEFAULT 'ok' CHECK (moderation_state IN ('ok', 'held', 'suspended')), - paused_reason TEXT, - last_activity_at INTEGER NOT NULL, + id TEXT PRIMARY KEY, + slug TEXT NOT NULL UNIQUE, + owner_id TEXT NOT NULL REFERENCES user (id), + name TEXT, + uid INTEGER NOT NULL UNIQUE, + port INTEGER UNIQUE, + internal_port INTEGER UNIQUE, + desired_state TEXT NOT NULL DEFAULT 'running' CHECK (desired_state IN ('running', 'stopped')), + asleep_since INTEGER, + last_request_at INTEGER, + last_deploy_sha TEXT, + visibility TEXT NOT NULL DEFAULT 'unlisted' CHECK (visibility IN ('unlisted', 'public')), + moderation_state TEXT NOT NULL DEFAULT 'ok' CHECK (moderation_state IN ('ok', 'held', 'suspended')), + paused_reason TEXT, + last_activity_at INTEGER NOT NULL, inactivity_notices INTEGER NOT NULL DEFAULT 0, - expired_at INTEGER, - created_at INTEGER NOT NULL + expired_at INTEGER, + created_at INTEGER NOT NULL, + always_on INTEGER NOT NULL DEFAULT 0 CHECK (always_on IN (0, 1)), + preview_sha TEXT, + preview_updated_at INTEGER, + preview_port INTEGER, + preview_internal_port INTEGER, + downgraded_stopped_at INTEGER, + downgrade_purge_warned_at INTEGER, + storage_frozen_at INTEGER, + storage_frozen_detail TEXT, + r2_measured_bytes INTEGER, + last_crawl_at INTEGER, + access_mode TEXT NOT NULL DEFAULT 'open', + access_hash TEXT, + access_version INTEGER NOT NULL DEFAULT 0 ); -CREATE INDEX app_owner ON app (owner_id); CREATE TABLE app_collaborator ( - app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, - email TEXT NOT NULL, - userId TEXT REFERENCES user (id) ON DELETE SET NULL, - added_at INTEGER NOT NULL, + app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, + email TEXT NOT NULL, + userId TEXT REFERENCES user (id) ON DELETE SET NULL, + added_at INTEGER NOT NULL, PRIMARY KEY (app_id, email) ); -CREATE INDEX app_collaborator_user ON app_collaborator (userId); CREATE TABLE deploy ( - id TEXT PRIMARY KEY, - app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, - sha TEXT NOT NULL, - actor_id TEXT, - status TEXT NOT NULL CHECK (status IN ('queued', 'building', 'reviewing', 'deploying', 'success', 'failed', 'blocked')), - steps TEXT, - error TEXT, - findings TEXT, - log_tail TEXT, - created_at INTEGER NOT NULL, - finished_at INTEGER + id TEXT PRIMARY KEY, + app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, + sha TEXT NOT NULL, + actor_id TEXT, + status TEXT NOT NULL CHECK (status IN ('queued', 'building', 'reviewing', 'deploying', 'success', 'failed', 'blocked')), + steps TEXT, + error TEXT, + findings TEXT, + log_tail TEXT, + created_at INTEGER NOT NULL, + finished_at INTEGER, + kind TEXT NOT NULL DEFAULT 'main' CHECK (kind IN ('main', 'preview')) ); -CREATE INDEX deploy_app ON deploy (app_id, created_at); CREATE TABLE app_secret ( - app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, - name TEXT NOT NULL, - value_enc BLOB NOT NULL, + app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, + name TEXT NOT NULL, + value_enc BLOB NOT NULL, updated_at INTEGER NOT NULL, PRIMARY KEY (app_id, name) ); CREATE TABLE app_domain ( - hostname TEXT PRIMARY KEY, - app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, + hostname TEXT PRIMARY KEY, + app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, cf_custom_hostname_id TEXT NOT NULL, - status TEXT NOT NULL, - created_at INTEGER NOT NULL -); - -CREATE TABLE slug_quarantine ( - slug TEXT PRIMARY KEY, - until INTEGER NOT NULL + status TEXT NOT NULL, + created_at INTEGER NOT NULL ); CREATE TABLE metric_minute ( - app_id TEXT NOT NULL, - minute INTEGER NOT NULL, - requests INTEGER NOT NULL DEFAULT 0, - s4xx INTEGER NOT NULL DEFAULT 0, - s5xx INTEGER NOT NULL DEFAULT 0, + app_id TEXT NOT NULL, + minute INTEGER NOT NULL, + requests INTEGER NOT NULL DEFAULT 0, + s4xx INTEGER NOT NULL DEFAULT 0, + s5xx INTEGER NOT NULL DEFAULT 0, latency_hist TEXT, - bytes_out INTEGER NOT NULL DEFAULT 0, - visitors INTEGER NOT NULL DEFAULT 0, + bytes_out INTEGER NOT NULL DEFAULT 0, + visitors INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (app_id, minute) ); CREATE TABLE path_hour ( - app_id TEXT NOT NULL, - hour INTEGER NOT NULL, - path TEXT NOT NULL, + app_id TEXT NOT NULL, + hour INTEGER NOT NULL, + path TEXT NOT NULL, requests INTEGER NOT NULL DEFAULT 0, - s5xx INTEGER NOT NULL DEFAULT 0, + s5xx INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (app_id, hour, path) ); CREATE TABLE app_log ( app_id TEXT NOT NULL, - seq INTEGER NOT NULL, - ts INTEGER NOT NULL, + seq INTEGER NOT NULL, + ts INTEGER NOT NULL, stream TEXT NOT NULL, - line TEXT NOT NULL, + line TEXT NOT NULL, PRIMARY KEY (app_id, seq) ); CREATE TABLE error_issue ( - app_id TEXT NOT NULL, + app_id TEXT NOT NULL, fingerprint TEXT NOT NULL, - message TEXT NOT NULL, - frame TEXT, - count INTEGER NOT NULL DEFAULT 0, - first_seen INTEGER NOT NULL, - last_seen INTEGER NOT NULL, - status TEXT NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'resolved', 'ignored')), + message TEXT NOT NULL, + frame TEXT, + count INTEGER NOT NULL DEFAULT 0, + first_seen INTEGER NOT NULL, + last_seen INTEGER NOT NULL, + status TEXT NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'resolved', 'ignored')), + resolved_at INTEGER, PRIMARY KEY (app_id, fingerprint) ); CREATE TABLE usage_day ( - userId TEXT NOT NULL, - day TEXT NOT NULL, - code_changes INTEGER NOT NULL DEFAULT 0, - build_ms INTEGER NOT NULL DEFAULT 0, - codemode_runs INTEGER NOT NULL DEFAULT 0, + userId TEXT NOT NULL, + day TEXT NOT NULL, + code_changes INTEGER NOT NULL DEFAULT 0, + build_ms INTEGER NOT NULL DEFAULT 0, + codemode_runs INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (userId, day) ); CREATE TABLE usage_month ( - userId TEXT NOT NULL, - month TEXT NOT NULL, - requests INTEGER NOT NULL DEFAULT 0, + userId TEXT NOT NULL, + month TEXT NOT NULL, + requests INTEGER NOT NULL DEFAULT 0, storage_peak_bytes INTEGER NOT NULL DEFAULT 0, - egress_bytes INTEGER NOT NULL DEFAULT 0, + egress_bytes INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (userId, month) ); CREATE TABLE rate_limit_events ( - subject TEXT NOT NULL, - action TEXT NOT NULL, + subject TEXT NOT NULL, + action TEXT NOT NULL, created_at INTEGER NOT NULL ); -CREATE INDEX rate_limit_events_lookup ON rate_limit_events (subject, action, created_at); CREATE TABLE moderation_text ( - app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, - text_hash TEXT NOT NULL, - verdict TEXT NOT NULL CHECK (verdict IN ('clear', 'allowed', 'recheck')), + app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, + text_hash TEXT NOT NULL, + verdict TEXT NOT NULL CHECK (verdict IN ('clear', 'allowed', 'recheck')), checked_at INTEGER NOT NULL, PRIMARY KEY (app_id, text_hash) ); CREATE TABLE moderation_check ( - id TEXT PRIMARY KEY, - app_id TEXT NOT NULL, - deploy_id TEXT, - sha TEXT, - stage TEXT NOT NULL CHECK (stage IN ('gate', 'crawl', 'report')), - findings TEXT, - scores TEXT, - verdict TEXT, + id TEXT PRIMARY KEY, + app_id TEXT NOT NULL, + deploy_id TEXT, + sha TEXT, + stage TEXT NOT NULL CHECK (stage IN ('gate', 'crawl', 'report')), + findings TEXT, + scores TEXT, + verdict TEXT, reviewed_by TEXT, reviewed_at INTEGER, - created_at INTEGER NOT NULL + created_at INTEGER NOT NULL ); -CREATE INDEX moderation_check_app ON moderation_check (app_id, created_at); CREATE TABLE stripe_event ( - id TEXT PRIMARY KEY, - type TEXT NOT NULL, + id TEXT PRIMARY KEY, + type TEXT NOT NULL, received_at INTEGER NOT NULL ); CREATE TABLE app_cron ( - app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, - expr TEXT NOT NULL, - next_at INTEGER NOT NULL, + app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, + expr TEXT NOT NULL, + next_at INTEGER NOT NULL, PRIMARY KEY (app_id, expr) ); -CREATE INDEX app_cron_due ON app_cron (next_at); CREATE TABLE rollback_day ( app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, - day TEXT NOT NULL, - count INTEGER NOT NULL DEFAULT 0, + day TEXT NOT NULL, + count INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (app_id, day) ); --- Console agent action log (spec §13.1, §17): one row per MCP tool call --- that targets an app. `user_id` is the acting user, `consent_id` the --- `oauthConsent` row (OAuth calls) or NULL, `apikey_id` the `apikey` row --- (API-key calls) or NULL. Pruned with the plan's log retention (7 d Free, --- 30 d Pro); the app row's CASCADE drops an app's log on delete. CREATE TABLE agent_action ( - id TEXT NOT NULL PRIMARY KEY, - app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, - user_id TEXT NOT NULL, - consent_id TEXT NULL, - apikey_id TEXT NULL, - tool TEXT NOT NULL, - summary TEXT NOT NULL, - outcome TEXT NOT NULL, - error_code TEXT NULL, + id TEXT NOT NULL PRIMARY KEY, + app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, + user_id TEXT NOT NULL, + consent_id TEXT NULL, + apikey_id TEXT NULL, + tool TEXT NOT NULL, + summary TEXT NOT NULL, + outcome TEXT NOT NULL, + error_code TEXT NULL, duration_ms INTEGER NOT NULL, - created_at INTEGER NOT NULL + created_at INTEGER NOT NULL ); -CREATE INDEX idx_agent_action_app_created - ON agent_action (app_id, created_at DESC); -CREATE INDEX idx_agent_action_created ON agent_action (created_at); CREATE TABLE visitor_day ( - app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, - day INTEGER NOT NULL, + app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, + day INTEGER NOT NULL, visitors INTEGER NOT NULL, PRIMARY KEY (app_id, day) ); --- D1 migrations applied by the deploy pipeline (spec §10.1 step 7): one --- row per migration file Outer applied to an app's database, so an --- edited-after-apply file fails the deploy instead of silently drifting --- from what celld recorded in the app's own `d1_migrations` table. --- celld skips by name; this table pins the content hash Outer saw. --- The row is keyed by the effective identity celld applies to: --- `database_id` when the wrangler declaration has one, else --- `database_name` (celld uses the id as the stable identity when present). --- `database_name` stays alongside for humans. Changing the id under the --- same name therefore starts clean against the new (empty) database --- instead of skipping as "already applied". CREATE TABLE d1_migration ( - app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, - database_name TEXT NOT NULL, + app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, + database_name TEXT NOT NULL, database_identity TEXT NOT NULL, - name TEXT NOT NULL, - sha256 TEXT NOT NULL, - applied_at INTEGER NOT NULL, + name TEXT NOT NULL, + sha256 TEXT NOT NULL, + applied_at INTEGER NOT NULL, PRIMARY KEY (app_id, database_identity, name) ); + +CREATE TABLE invite_code ( + code TEXT PRIMARY KEY, + createdBy TEXT REFERENCES user(id) ON DELETE CASCADE, + kind TEXT NOT NULL CHECK (kind IN ('admin', 'grant')), + note TEXT, + redeemedBy TEXT UNIQUE REFERENCES user(id) ON DELETE SET NULL, + redeemedAt INTEGER, + revokedAt INTEGER, + createdAt INTEGER NOT NULL +); + +CREATE TABLE prefix_cleanup ( + prefix TEXT PRIMARY KEY, + reason TEXT NOT NULL, + created_at INTEGER NOT NULL +); + +CREATE TABLE account_action ( + id TEXT NOT NULL PRIMARY KEY, + user_id TEXT NOT NULL, + tool TEXT NOT NULL, + summary TEXT NOT NULL, + outcome TEXT NOT NULL, + error_code TEXT NULL, + duration_ms INTEGER NOT NULL, + created_at INTEGER NOT NULL +); + +CREATE TABLE look_hour ( + userId TEXT NOT NULL, + hour TEXT NOT NULL, + looks INTEGER NOT NULL DEFAULT 0, + PRIMARY KEY (userId, hour) +); + +CREATE TABLE app_export ( + key TEXT PRIMARY KEY, + app_id TEXT NOT NULL REFERENCES app(id) ON DELETE CASCADE, + sha TEXT NOT NULL, + bytes INTEGER NOT NULL, + created_at INTEGER NOT NULL +); + +CREATE TABLE alert_prefs ( + user_id TEXT NOT NULL PRIMARY KEY, + deploy_failed INTEGER NOT NULL DEFAULT 1, + error_spike INTEGER NOT NULL DEFAULT 1, + quota INTEGER NOT NULL DEFAULT 1, + updated_at INTEGER NOT NULL, + inactivity INTEGER NOT NULL DEFAULT 1 +); + +CREATE TABLE alert_send ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + subject TEXT NOT NULL, + kind TEXT NOT NULL, + sent_at INTEGER NOT NULL +); + +CREATE TABLE d1_backup ( + id TEXT NOT NULL PRIMARY KEY, + app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, + binding TEXT NOT NULL, + store_key TEXT NOT NULL UNIQUE, + created_at INTEGER NOT NULL, + size_bytes INTEGER NOT NULL +); + +CREATE TABLE slug_redirect ( + slug TEXT PRIMARY KEY, + renamed_to TEXT NOT NULL +); + +CREATE TABLE tool_call ( + id TEXT NOT NULL PRIMARY KEY, + tool TEXT NOT NULL, + account_id TEXT NULL, + app_id TEXT NULL REFERENCES app (id) ON DELETE SET NULL, + app_slug TEXT NULL, + client TEXT NULL, + session TEXT NOT NULL, + duration_ms INTEGER NOT NULL, + ok INTEGER NOT NULL, + error_code TEXT NULL, + response_bytes INTEGER NOT NULL, + created_at INTEGER NOT NULL +); + +CREATE TABLE usage_rollup_cursor ( + id TEXT PRIMARY KEY, + last_minute INTEGER NOT NULL +); + +CREATE TABLE draft ( + app_id TEXT NOT NULL, + account_id TEXT NOT NULL, + base_sha TEXT NOT NULL, + ops TEXT NOT NULL DEFAULT '{}', + updated_at INTEGER NOT NULL, + PRIMARY KEY (app_id, account_id), + FOREIGN KEY (app_id) REFERENCES app(id) ON DELETE CASCADE +); + +CREATE INDEX session_userId ON session (userId); + +CREATE INDEX account_userId ON account (userId); + +CREATE INDEX apikey_reference ON apikey (referenceId); + +CREATE INDEX oauthClient_user ON oauthClient (userId); + +CREATE INDEX oauthConsent_user ON oauthConsent (userId); + +CREATE INDEX oauthConsent_client ON oauthConsent (clientId); + +CREATE INDEX oauthAccessToken_client ON oauthAccessToken (clientId); + +CREATE INDEX oauthAccessToken_user ON oauthAccessToken (userId); + +CREATE INDEX oauthAccessToken_reference ON oauthAccessToken (referenceId); + +CREATE INDEX oauthRefreshToken_client ON oauthRefreshToken (clientId); + +CREATE INDEX oauthRefreshToken_user ON oauthRefreshToken (userId); + +CREATE INDEX oauthRefreshToken_reference ON oauthRefreshToken (referenceId); + +CREATE INDEX app_owner ON app (owner_id); + +CREATE INDEX app_collaborator_user ON app_collaborator (userId); + +CREATE INDEX deploy_app ON deploy (app_id, created_at); + +CREATE INDEX rate_limit_events_lookup ON rate_limit_events (subject, action, created_at); + +CREATE INDEX moderation_check_app ON moderation_check (app_id, created_at); + +CREATE INDEX app_cron_due ON app_cron (next_at); + +CREATE INDEX idx_agent_action_app_created ON agent_action (app_id, created_at DESC); + +CREATE INDEX idx_agent_action_created ON agent_action (created_at); + +CREATE INDEX invite_code_createdBy ON invite_code (createdBy); + +CREATE INDEX idx_account_action_user_created ON account_action (user_id, created_at DESC); + +CREATE INDEX idx_account_action_created ON account_action (created_at); + +CREATE INDEX idx_app_export_created ON app_export (created_at); + +CREATE INDEX idx_alert_send_subject_kind_sent ON alert_send (subject, kind, sent_at DESC); + +CREATE INDEX idx_d1_backup_app_created ON d1_backup (app_id, created_at DESC); + +CREATE INDEX idx_deploy_app_kind_created ON deploy (app_id, kind, created_at DESC); + +CREATE INDEX idx_tool_call_tool_created ON tool_call (tool, created_at); + +CREATE INDEX idx_tool_call_session_created ON tool_call (session, created_at); + +CREATE INDEX idx_tool_call_created ON tool_call (created_at); diff --git a/crates/outer/migrations/0002_invite_code.sql b/crates/outer/migrations/0002_invite_code.sql deleted file mode 100644 index 277dc02..0000000 --- a/crates/outer/migrations/0002_invite_code.sql +++ /dev/null @@ -1,20 +0,0 @@ --- Invite codes (spec §6.5.1): single-use admission codes plus the 3 --- grant codes every new account gets to share. Stored as-is (shown again --- to their owner); 40 bits plus the sign-up rate limits make guessing --- pointless. camelCase like the Better Auth tables in 0001. -CREATE TABLE invite_code ( - code TEXT PRIMARY KEY, - createdBy TEXT REFERENCES user(id) ON DELETE CASCADE, - kind TEXT NOT NULL CHECK (kind IN ('admin', 'grant')), - note TEXT, - redeemedBy TEXT UNIQUE REFERENCES user(id) ON DELETE SET NULL, - redeemedAt INTEGER, - revokedAt INTEGER, - createdAt INTEGER NOT NULL -); -CREATE INDEX invite_code_createdBy ON invite_code (createdBy); - --- The pending OTP row carries the invite code that gated admission, so --- `verify_code` can consume it in the same transaction that creates the --- account. NULL for existing/allowlisted/admin emails (ignored, §6.5.1). -ALTER TABLE verification ADD COLUMN inviteCode TEXT; diff --git a/crates/outer/migrations/0003_slug_rename_redirect.sql b/crates/outer/migrations/0003_slug_rename_redirect.sql deleted file mode 100644 index 7b2551e..0000000 --- a/crates/outer/migrations/0003_slug_rename_redirect.sql +++ /dev/null @@ -1,18 +0,0 @@ --- Rename redirects: `apps::rename` quarantines the OLD slug with --- `renamed_to` naming the app's new slug, so the proxy can answer 308 to --- the new host while the quarantine holds. Plain deletes leave it NULL and --- keep the old 404 behavior. Rows expire with `until` like any quarantine. -ALTER TABLE slug_quarantine ADD COLUMN renamed_to TEXT; - --- Crash-safe rename cleanup: `apps::rename` records the target prefixes --- before copying and swaps them for the old prefixes in the flip --- transaction. Any row here blocks the slug it names (create and rename --- both refuse it, even past its quarantine), and the maintenance drain --- (`drain_prefix_cleanup`, run at startup and on every sleep-sweep tick) --- deletes the prefix and the row. A leftover row is never inherited: the --- drain deletes the data before the slug becomes claimable again. -CREATE TABLE prefix_cleanup ( - prefix TEXT PRIMARY KEY, - reason TEXT NOT NULL, - created_at INTEGER NOT NULL -); diff --git a/crates/outer/migrations/0004_error_triage.sql b/crates/outer/migrations/0004_error_triage.sql deleted file mode 100644 index e24a4da..0000000 --- a/crates/outer/migrations/0004_error_triage.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Error triage (console wave 2, spec §13): when the owner last put an --- issue into `resolved` or `ignored`. NULL for never-triaged issues. A --- resolved issue that recurs (a new event with `last_seen` past --- `resolved_at`) flips back to `open` automatically but keeps --- `resolved_at`, so the console can badge it `Regressed`. Ignored issues --- keep counting and never flip. A manual reopen clears `resolved_at`, --- so only an automatic reopen reads as a regression. -ALTER TABLE error_issue ADD COLUMN resolved_at INTEGER; diff --git a/crates/outer/migrations/0005_account_action.sql b/crates/outer/migrations/0005_account_action.sql deleted file mode 100644 index 3d48bd7..0000000 --- a/crates/outer/migrations/0005_account_action.sql +++ /dev/null @@ -1,17 +0,0 @@ --- Console account actions (spec §13.1, wave 2): audit for account-level --- console mutations (connections, API keys, sessions, delete). Unlike --- `agent_action`, this table is NOT keyed by app (these actions target the --- account), so `user_id` carries no foreign key: the `delete_account` row --- itself survives the account it describes. -CREATE TABLE account_action ( - id TEXT NOT NULL PRIMARY KEY, - user_id TEXT NOT NULL, - tool TEXT NOT NULL, - summary TEXT NOT NULL, - outcome TEXT NOT NULL, - error_code TEXT NULL, - duration_ms INTEGER NOT NULL, - created_at INTEGER NOT NULL -); -CREATE INDEX idx_account_action_user_created ON account_action (user_id, created_at DESC); -CREATE INDEX idx_account_action_created ON account_action (created_at); diff --git a/crates/outer/migrations/0006_look_quota.sql b/crates/outer/migrations/0006_look_quota.sql deleted file mode 100644 index a2fb4ca..0000000 --- a/crates/outer/migrations/0006_look_quota.sql +++ /dev/null @@ -1,10 +0,0 @@ --- look_at_app hourly quota (wave 3 feature 1): one row per caller per --- UTC hour (`YYYY-MM-DDTHH`). The UPSERT guard in `claim_look` refuses --- past 30 looks; exhaustion is `rate_limited` with `retry_after_s` to the --- next hour. Stale rows are never read, so no sweep deletes them. -CREATE TABLE look_hour ( - userId TEXT NOT NULL, - hour TEXT NOT NULL, - looks INTEGER NOT NULL DEFAULT 0, - PRIMARY KEY (userId, hour) -); diff --git a/crates/outer/migrations/0007_app_export.sql b/crates/outer/migrations/0007_app_export.sql deleted file mode 100644 index 456163e..0000000 --- a/crates/outer/migrations/0007_app_export.sql +++ /dev/null @@ -1,12 +0,0 @@ --- Pro code exports (spec §7.5): one row per uploaded --- `outer/exports/{slug}/-.zip`, so the daily retention --- sweep can delete objects older than 24 h. The app row cascades, taking --- its exports with it on delete. -CREATE TABLE app_export ( - key TEXT PRIMARY KEY, - app_id TEXT NOT NULL REFERENCES app(id) ON DELETE CASCADE, - sha TEXT NOT NULL, - bytes INTEGER NOT NULL, - created_at INTEGER NOT NULL -); -CREATE INDEX idx_app_export_created ON app_export (created_at); diff --git a/crates/outer/migrations/0008_alerts.sql b/crates/outer/migrations/0008_alerts.sql deleted file mode 100644 index e853276..0000000 --- a/crates/outer/migrations/0008_alerts.sql +++ /dev/null @@ -1,20 +0,0 @@ --- Email alerts (wave 3, feature #2): per-account toggles and the send --- ledger behind the debounce windows. `alert_prefs` has one row per --- account that changed a default; absence means all three on. --- `alert_send.subject` is the debounced scope: the app id for deploy and --- error alerts, the account id for quota alerts. -CREATE TABLE alert_prefs ( - user_id TEXT NOT NULL PRIMARY KEY, - deploy_failed INTEGER NOT NULL DEFAULT 1, - error_spike INTEGER NOT NULL DEFAULT 1, - quota INTEGER NOT NULL DEFAULT 1, - updated_at INTEGER NOT NULL -); - -CREATE TABLE alert_send ( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - subject TEXT NOT NULL, - kind TEXT NOT NULL, - sent_at INTEGER NOT NULL -); -CREATE INDEX idx_alert_send_subject_kind_sent ON alert_send (subject, kind, sent_at DESC); diff --git a/crates/outer/migrations/0009_always_on.sql b/crates/outer/migrations/0009_always_on.sql deleted file mode 100644 index d823855..0000000 --- a/crates/outer/migrations/0009_always_on.sql +++ /dev/null @@ -1,11 +0,0 @@ --- Keep-warm for Pro apps (spec §12.3, feature #6): a per-app `always_on` --- flag. The sleep sweep skips flagged apps on Pro owners (up to --- OUTER_ALWAYS_ON_MAX awake at once; the oldest-idle sleep past the cap), --- and the warm-up wakes flagged apps that stopped (restart/crash). --- Downgrade to Free leaves the flag stored but ignored, so an upgrade --- restores warmth without re-toggling. -ALTER TABLE app ADD COLUMN always_on INTEGER NOT NULL DEFAULT 0 - CHECK (always_on IN (0, 1)); --- New Pro apps default on at create (the MCP `create_app` path); existing --- Pro apps opt in retroactively here so the upgrade lever applies to them. -UPDATE app SET always_on = 1 WHERE owner_id IN (SELECT id FROM user WHERE plan = 'pro'); diff --git a/crates/outer/migrations/0010_d1_backups.sql b/crates/outer/migrations/0010_d1_backups.sql deleted file mode 100644 index c9ec0c0..0000000 --- a/crates/outer/migrations/0010_d1_backups.sql +++ /dev/null @@ -1,15 +0,0 @@ --- Daily D1 backups (wave 3, feature #4): one row per stored `.sql` dump. --- The bytes live in R2 under `outer/backups/{slug}/` (NOT under --- `fleets/{slug}/`, so app code can never touch them); the row carries the --- key, the binding, and the size for the Console/MCP list. Rows are keyed --- by `app_id`, so a rename moves only the bucket prefix while the rows --- follow untouched; `delete_app` removes both explicitly. -CREATE TABLE d1_backup ( - id TEXT NOT NULL PRIMARY KEY, - app_id TEXT NOT NULL REFERENCES app (id) ON DELETE CASCADE, - binding TEXT NOT NULL, - store_key TEXT NOT NULL UNIQUE, - created_at INTEGER NOT NULL, - size_bytes INTEGER NOT NULL -); -CREATE INDEX idx_d1_backup_app_created ON d1_backup (app_id, created_at DESC); diff --git a/crates/outer/migrations/0011_preview_deploys.sql b/crates/outer/migrations/0011_preview_deploys.sql deleted file mode 100644 index 81cb783..0000000 --- a/crates/outer/migrations/0011_preview_deploys.sql +++ /dev/null @@ -1,16 +0,0 @@ --- Preview deploys (Pro): one active preview per app, served at --- `--preview.` from a fresh data namespace --- (`fleets/{slug}--preview/`), never touching live data. The preview fleet --- is short-lived: the sleep sweep stops it on idleness and the preview --- sweep discards the row after 24 h without a preview request. --- --- `deploy.kind` separates preview pipeline runs from the live history: --- every live-history query filters `kind = 'main'`, so a preview deploy --- never becomes the rollback target or the console's latest deploy. -ALTER TABLE app ADD COLUMN preview_sha TEXT; -ALTER TABLE app ADD COLUMN preview_updated_at INTEGER; -ALTER TABLE app ADD COLUMN preview_port INTEGER; -ALTER TABLE app ADD COLUMN preview_internal_port INTEGER; -ALTER TABLE deploy ADD COLUMN kind TEXT NOT NULL DEFAULT 'main' - CHECK (kind IN ('main', 'preview')); -CREATE INDEX idx_deploy_app_kind_created ON deploy (app_id, kind, created_at DESC); diff --git a/crates/outer/migrations/0012_downgrade_retention.sql b/crates/outer/migrations/0012_downgrade_retention.sql deleted file mode 100644 index 13d4909..0000000 --- a/crates/outer/migrations/0012_downgrade_retention.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Downgrade retention (spec §3): apps stopped by a downgrade are kept --- 30 days, then purged after an email warning. `downgraded_stopped_at` is --- stamped by `downgrade_account` on every stopped app (unix seconds) and --- cleared for the kept oldest app and on re-upgrade; the retention sweep --- records the warning in `downgrade_purge_warned_at` so it mails once. -ALTER TABLE app ADD COLUMN downgraded_stopped_at INTEGER; -ALTER TABLE app ADD COLUMN downgrade_purge_warned_at INTEGER; diff --git a/crates/outer/migrations/0013_drop_slug_quarantine.sql b/crates/outer/migrations/0013_drop_slug_quarantine.sql deleted file mode 100644 index cf53c22..0000000 --- a/crates/outer/migrations/0013_drop_slug_quarantine.sql +++ /dev/null @@ -1,17 +0,0 @@ --- Drop the 30-day slug reservation: a deleted or renamed-away slug is --- claimable again immediately. The crash-safety guard (`prefix_cleanup`, --- created in 0003) is untouched: pending cleanup rows still block a claim --- until the maintenance drain deletes the leftover prefixes. --- --- Rename redirects survive as plain, never-blocking rows: the proxy 308s an --- old hostname to its renamed app until someone claims the old slug (the --- claim deletes the redirect row). Only live redirects carry over — an --- already-expired one had stopped redirecting, so it stays gone. -CREATE TABLE slug_redirect ( - slug TEXT PRIMARY KEY, - renamed_to TEXT NOT NULL -); -INSERT INTO slug_redirect (slug, renamed_to) - SELECT slug, renamed_to FROM slug_quarantine - WHERE renamed_to IS NOT NULL AND until > (strftime('%s', 'now') * 1000); -DROP TABLE slug_quarantine; diff --git a/crates/outer/migrations/0015_tool_telemetry.sql b/crates/outer/migrations/0015_tool_telemetry.sql deleted file mode 100644 index 90c50b9..0000000 --- a/crates/outer/migrations/0015_tool_telemetry.sql +++ /dev/null @@ -1,22 +0,0 @@ --- Tool telemetry (Wave 4, `open_app` + INSTRUCTIONS + telemetry): one row --- per MCP `tools/call` — tool, caller, app slug when the call names one, --- client name, session key, latency, outcome and response size. Arguments --- and outputs are NEVER stored here (they hold code and secrets). --- Pruned after 30 days by the metrics sweep. -CREATE TABLE tool_call ( - id TEXT NOT NULL PRIMARY KEY, - tool TEXT NOT NULL, - account_id TEXT NULL, - app_id TEXT NULL REFERENCES app (id) ON DELETE SET NULL, - app_slug TEXT NULL, - client TEXT NULL, - session TEXT NOT NULL, - duration_ms INTEGER NOT NULL, - ok INTEGER NOT NULL, - error_code TEXT NULL, - response_bytes INTEGER NOT NULL, - created_at INTEGER NOT NULL -); -CREATE INDEX idx_tool_call_tool_created ON tool_call (tool, created_at); -CREATE INDEX idx_tool_call_session_created ON tool_call (session, created_at); -CREATE INDEX idx_tool_call_created ON tool_call (created_at); diff --git a/crates/outer/migrations/0016_plan_limits.sql b/crates/outer/migrations/0016_plan_limits.sql deleted file mode 100644 index c33911a..0000000 --- a/crates/outer/migrations/0016_plan_limits.sql +++ /dev/null @@ -1,12 +0,0 @@ --- Plan limits (owner-set 2026-10-26): per-app storage freeze flag for the --- storage sweep (refuse writes at the D1/R2 caps; never delete data), the --- sweep's last measured R2 bytes per app (NULL until the first sweep sizes --- it; the Console upload gate reads it prospectively and adjusts it on --- put/delete), and the request-rollup watermark cursor. -ALTER TABLE app ADD COLUMN storage_frozen_at INTEGER; -ALTER TABLE app ADD COLUMN storage_frozen_detail TEXT; -ALTER TABLE app ADD COLUMN r2_measured_bytes INTEGER; -CREATE TABLE usage_rollup_cursor ( - id TEXT PRIMARY KEY, - last_minute INTEGER NOT NULL -); diff --git a/crates/outer/migrations/0017_inactive_apps.sql b/crates/outer/migrations/0017_inactive_apps.sql deleted file mode 100644 index b5d10e8..0000000 --- a/crates/outer/migrations/0017_inactive_apps.sql +++ /dev/null @@ -1,5 +0,0 @@ --- Inactive-app deletion (spec §7.8): the app-side clock columns landed in --- 0001 (`app.last_activity_at`, the `app.inactivity_notices` reminder --- bitmask, `app.expired_at`); this migration only adds the alert-prefs --- toggle behind the reminder emails. Absence of a row means all four on. -ALTER TABLE alert_prefs ADD COLUMN inactivity INTEGER NOT NULL DEFAULT 1; diff --git a/crates/outer/migrations/0019_after_live_crawl.sql b/crates/outer/migrations/0019_after_live_crawl.sql deleted file mode 100644 index 3a50dad..0000000 --- a/crates/outer/migrations/0019_after_live_crawl.sql +++ /dev/null @@ -1,6 +0,0 @@ --- After-live crawl scheduling (spec §15.2): the last time the crawl engine --- checked the app's rendered pages. NULL means never crawled since the --- latest deploy; the crawl sweep treats NULL as due. Updated by the crawl --- itself (pass, hold, suspend, queue or Jev-outage error alike), so the --- periodic re-crawl of live public/unlisted apps has a watermark. -ALTER TABLE app ADD COLUMN last_crawl_at INTEGER; diff --git a/crates/outer/migrations/0020_mcp_drafts.sql b/crates/outer/migrations/0020_mcp_drafts.sql deleted file mode 100644 index a229a65..0000000 --- a/crates/outer/migrations/0020_mcp_drafts.sql +++ /dev/null @@ -1,15 +0,0 @@ --- MCP drafts (spec §1.5, owner proposal 2026-10-26): per-account staged --- changes that survive restarts. `ops` is JSON --- `{writes: [{path, content?, base64?}], edits: [{path, old, new, --- replace_all?}], deletes: [path], moves: [{from, to}]}` in the same shapes --- as `commit`; `base_sha` is the main head the draft was staged against, so --- `ship` can rebase when the head moved underneath it. -CREATE TABLE draft ( - app_id TEXT NOT NULL, - account_id TEXT NOT NULL, - base_sha TEXT NOT NULL, - ops TEXT NOT NULL DEFAULT '{}', - updated_at INTEGER NOT NULL, - PRIMARY KEY (app_id, account_id), - FOREIGN KEY (app_id) REFERENCES app(id) ON DELETE CASCADE -); diff --git a/crates/outer/migrations/0021_app_access_gate.sql b/crates/outer/migrations/0021_app_access_gate.sql deleted file mode 100644 index 662b613..0000000 --- a/crates/outer/migrations/0021_app_access_gate.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Pro app access gate (PIN/password): per-app lock enforced by the proxy. --- `access_mode` is 'open' (default), 'pin' or 'password'; `access_hash` is the --- Argon2id hash (NULL when open); `access_version` bumps on every change so a --- secret change signs every issued cookie out. -ALTER TABLE app ADD COLUMN access_mode TEXT NOT NULL DEFAULT 'open'; -ALTER TABLE app ADD COLUMN access_hash TEXT; -ALTER TABLE app ADD COLUMN access_version INTEGER NOT NULL DEFAULT 0; From 03a9319403695a1d406a1d32aeab63e8be0018bd Mon Sep 17 00:00:00 2001 From: Ryuz Date: Thu, 19 Nov 2026 11:45:13 +0100 Subject: [PATCH 5/6] WIPE: empty the whole data dir; release.sh re-checks DB absence before a fresh start Security review on #150: the runbook named a nonexistent git-mirrors dir and missed git/, maps/, checks/, secret-sidecars/; the fresh-install absence check ran minutes before compose up. --- deploy/WIPE.md | 15 ++++++++++----- deploy/release.sh | 11 ++++++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/deploy/WIPE.md b/deploy/WIPE.md index 324283c..4365e20 100644 --- a/deploy/WIPE.md +++ b/deploy/WIPE.md @@ -37,8 +37,9 @@ Live state (verified against `config.rs`, `compose.yaml`, `store/*`): Kept untouched: - `/srv/outer/outer.env` — replaced beforehand with a FRESH copy from - `deploy/outer.env.example` (fill blanks, `chmod 600`). The runtime - refuses to start with any `CELLD_*` set, so never carry one over. + `deploy/outer.env.example` (fill blanks, `chmod 600`). Outer no longer + reads any `CELLD_*` or `OUTER_CELLD_BIN` key; a fresh copy keeps the + file free of dead config. - `/srv/outer/release.env`, `/srv/outer/tls/` (`origin.pem`, `origin.key`, `origin-pull-ca.pem`), the firewall units/table (`inet outer_fw`). @@ -63,10 +64,14 @@ Kept untouched: aws s3 ls --endpoint-url "$EP" "s3://outer/$p" # must list nothing done ``` -5. Wipe host state: +5. Wipe host state. Everything under `/srv/outer/data` is state or derived + from it: the DB, the handoff flag, `fleets/`, `work/`, `cache/`, `git/` + (repo mirrors), `maps/` (tenant sourcemaps), `checks/` (build scratch), + `examples/`, and `secret-sidecars/` (transient plaintext secret files). + Empty the directory itself; TLS and env live outside it: ``` - rm -f /srv/outer/data/outer.sqlite* /srv/outer/data/handoff - rm -rf /srv/outer/data/fleets /srv/outer/data/work /srv/outer/data/cache /srv/outer/data/git-mirrors + find /srv/outer/data -mindepth 1 -delete + ls -A /srv/outer/data # must print nothing ``` 6. Cut the code: from a clean tree at the renamed commit, diff --git a/deploy/release.sh b/deploy/release.sh index 3d4ab1c..c412fc5 100755 --- a/deploy/release.sh +++ b/deploy/release.sh @@ -224,9 +224,14 @@ source /srv/outer/handoff.sh docker run --rm --pull=never --env-file /srv/outer/outer.env -v /srv/outer/tls:/tls:ro \ "outer:$SHA" state release-backup --sha "$SHA" if [[ "$FRESH_INSTALL" == 1 ]]; then - # Fresh box: no old container to drain and no handoff heartbeat — the - # DB-absent gate above already refused a non-wiped box. Bring the - # compose service up directly on the new image. + # Fresh box: no old container to drain and no handoff heartbeat. Re-check + # the DB is still absent right before starting (the local gate ran + # minutes earlier, before the build), then bring the compose service up + # directly on the new image. + if test -e /srv/outer/data/outer.sqlite; then + echo "release.sh: --fresh-install refuses: /srv/outer/data/outer.sqlite appeared during the release" >&2 + exit 1 + fi docker compose --env-file /srv/outer/release.env \ -f /srv/outer/compose.yaml up -d record_image "outer:$SHA" From ddaa886babf71c901fc11062977ef1cc0a2c042e Mon Sep 17 00:00:00 2001 From: Ryuz Date: Thu, 19 Nov 2026 11:59:41 +0100 Subject: [PATCH 6/6] release.sh records the new image before a fresh compose up; WIPE stops outer-next; stale-name test independent of installed cello CodeRabbit on #150: compose reads OUTER_IMAGE from the kept release.env, so a fresh install started the pre-wipe image; the runbook stop command lacked --env-file and missed outer-next; the config test depended on /usr/local/bin/cello. --- crates/outer/src/config.rs | 5 ++++- deploy/WIPE.md | 12 +++++++++--- deploy/release.sh | 5 ++++- deploy/test-release-preflight.sh | 7 +++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/crates/outer/src/config.rs b/crates/outer/src/config.rs index 4f362bb..f5b58ee 100644 --- a/crates/outer/src/config.rs +++ b/crates/outer/src/config.rs @@ -1627,13 +1627,16 @@ mod tests { // is dead config, not a refusal. (The runtime still refuses to // start a fleet with `CELLD_*` set; that reservation lives in // `fleet::sandbox`, not here.) + // Compare against the same config without the stale names: an + // installed /usr/local/bin/cello resolves either way. + let base = Config::from_vars(&vars(&[("OUTER_STORE", "memory")])).unwrap(); let cfg = Config::from_vars(&vars(&[ ("OUTER_STORE", "memory"), ("CELLD_OPERATOR_TOKEN", "stale"), ("OUTER_CELLD_BIN", "celld"), ])) .unwrap(); - assert_eq!(cfg.runtime.cello_bin, "cello"); + assert_eq!(cfg.runtime.cello_bin, base.runtime.cello_bin); } #[test] diff --git a/deploy/WIPE.md b/deploy/WIPE.md index 4365e20..535a7fd 100644 --- a/deploy/WIPE.md +++ b/deploy/WIPE.md @@ -52,9 +52,15 @@ Kept untouched: 2. Safety copy (off-box, optional): `sqlite3 /srv/outer/data/outer.sqlite ".backup '/root/outer-prewipe-$(date +%F).sqlite'"`. Keep until the new prod has snapshotted + backed up once. -3. Stop the world: `docker compose -f /srv/outer/compose.yaml stop outer` - (or `docker stop -t 900 outer`). Confirm no fleet processes remain - (`ps aux | grep cello` shows none; each fleet ran as its app uid). +3. Stop the world. Stop the compose service, and also `outer-next`, which a + failed earlier handoff can leave running with the data mount and bucket + access. Stop here if any command fails: + ``` + docker compose --env-file /srv/outer/release.env -f /srv/outer/compose.yaml stop -t 900 outer + docker stop -t 900 outer-next 2>/dev/null || true + docker ps --filter name=outer --format '{{.Names}}' # must print nothing + ps aux | grep '[c]ello' # must print nothing + ``` 4. Wipe the bucket (`outer`, via the S3-compatible endpoint in `OUTER_R2_ENDPOINT`; `EP` = that endpoint, credentials from the matching `OUTER_R2_*` keys): diff --git a/deploy/release.sh b/deploy/release.sh index c412fc5..29b4c7a 100755 --- a/deploy/release.sh +++ b/deploy/release.sh @@ -232,9 +232,12 @@ if [[ "$FRESH_INSTALL" == 1 ]]; then echo "release.sh: --fresh-install refuses: /srv/outer/data/outer.sqlite appeared during the release" >&2 exit 1 fi + # Record first: compose reads OUTER_IMAGE from release.env, which the + # wipe keeps, so starting before recording would boot the pre-wipe image + # on the empty data dir. + record_image "outer:$SHA" docker compose --env-file /srv/outer/release.env \ -f /srv/outer/compose.yaml up -d - record_image "outer:$SHA" wait_for_listening outer-outer-1 "outer:$SHA" else # Whatever fails below, the heartbeat must not outlive the release: abort diff --git a/deploy/test-release-preflight.sh b/deploy/test-release-preflight.sh index 8c3b87f..d874483 100755 --- a/deploy/test-release-preflight.sh +++ b/deploy/test-release-preflight.sh @@ -211,6 +211,13 @@ up_line="$(grep -n "compose.yaml up -d" "$fresh_rollout" | head -n1 | cut -d: -f hand_line="$(grep -n 'handoff_to "outer' "$fresh_rollout" | head -n1 | cut -d: -f1 || true)" [[ -n "$fresh_line" && -n "$up_line" && -n "$hand_line" && "$fresh_line" -lt "$up_line" && "$up_line" -lt "$hand_line" ]] \ || fail "rollout does not compose-up first on the fresh branch (fresh=$fresh_line up=$up_line handoff=$hand_line)" +# The fresh branch must record the new image before compose reads release.env. +rec_line="" +while IFS=: read -r n _; do + if (( n > fresh_line )); then rec_line="$n"; break; fi +done < <(grep -n 'record_image "outer:' "$fresh_rollout") +[[ -n "$rec_line" && "$rec_line" -lt "$up_line" ]] \ + || fail "fresh branch starts compose before recording the new image (record=$rec_line up=$up_line)" echo "case 10 ok: --fresh-install skips the gate and composes up directly (exit 0)" # --- case 11: an unknown second arg refuses ---------------------------------