From 21bf53ed641ea754d393dd4e64e1e56265dd717a Mon Sep 17 00:00:00 2001 From: Leo <91056950+Nardo021@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:57:45 +1100 Subject: [PATCH 01/11] chore(cloud): make staging Worker unroutable by default and pin migration ledger --- cloud/wrangler.staging.example.jsonc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cloud/wrangler.staging.example.jsonc b/cloud/wrangler.staging.example.jsonc index 5f372f5..76e9385 100644 --- a/cloud/wrangler.staging.example.jsonc +++ b/cloud/wrangler.staging.example.jsonc @@ -6,7 +6,7 @@ "compatibility_flags": [ "nodejs_compat" ], - "workers_dev": true, + "workers_dev": false, "observability": { "enabled": true }, @@ -19,7 +19,8 @@ "binding": "CLOUD_DB", "database_name": "mote-cloud-staging", "database_id": "REPLACE_WITH_NEW_STAGING_D1_ID", - "migrations_dir": "migrations" + "migrations_dir": "migrations", + "migrations_table": "d1_migrations" } ], "durable_objects": { From 067da0530b89327a90f348f8ed6f640f39fb3429 Mon Sep 17 00:00:00 2001 From: Leo <91056950+Nardo021@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:58:48 +1100 Subject: [PATCH 02/11] build(cloud): add fail-closed staging config and remote D1 ledger preflight --- cloud/scripts/check-staging-preflight.mjs | 153 ++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 cloud/scripts/check-staging-preflight.mjs diff --git a/cloud/scripts/check-staging-preflight.mjs b/cloud/scripts/check-staging-preflight.mjs new file mode 100644 index 0000000..f187214 --- /dev/null +++ b/cloud/scripts/check-staging-preflight.mjs @@ -0,0 +1,153 @@ +#!/usr/bin/env node +/** + * Mote Cloud staging preflight: read-only unless --render is explicitly used. + * + * Examples: + * node cloud/scripts/check-staging-preflight.mjs + * node cloud/scripts/check-staging-preflight.mjs --verify-remote + * node cloud/scripts/check-staging-preflight.mjs --verify-remote --render + * + * Never puts API tokens or staging gate secrets into a Wrangler config. + */ +import assert from "node:assert/strict"; +import { existsSync, readFileSync, writeFileSync } from "node:fs"; +import { resolve, dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +const root = resolve(dirname(fileURLToPath(import.meta.url)), "..", ".."); +const templatePath = join(root, "cloud", "wrangler.staging.example.jsonc"); +const outPath = join(root, "cloud", "wrangler.staging.jsonc"); +const expectedFiles = ["0001_core.sql", "0002_auth.sql", "0003_pairing_claim.sql"]; +const args = new Set(process.argv.slice(2)); +const allowed = new Set(["--verify-remote", "--render"]); +const requiredTables = [ + "cloud_accounts", "cloud_sessions", "cloud_devices", + "cloud_pairing_tickets", "cloud_auth_challenges", +]; +const requiredIndexes = [ + "idx_cloud_sessions_account", "idx_cloud_sessions_expires", + "idx_cloud_devices_owner_status", "idx_cloud_pairing_one_pending_device", + "idx_cloud_pairing_expiry", "idx_cloud_sessions_access_token_hash", + "idx_cloud_sessions_refresh_token_hash", "idx_cloud_auth_challenges_expiry", +]; +const requiredTriggers = [ + "cloud_pairing_only_active_account", "cloud_pairing_approve_create_device", + "cloud_pairing_prevent_approved_reuse", +]; +function exactSet(actual, expected, label) { + const sort = items => [...items].sort(); + assert.deepEqual(sort(actual), sort(expected), label); +} +function fail(reason) { + // Do not log credential values, raw Cloudflare responses or sensitive env. + console.error(`MOTE_STAGING_PREFLIGHT_BLOCKED: ${reason}`); + process.exitCode = 1; +} +function validUUID(value) { + return typeof value === "string" && + /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(value); +} +function templateCheck() { + assert.equal(args.size, [...args].filter(a => allowed.has(a)).length, "Unknown arguments"); + const cfg = JSON.parse(readFileSync(templatePath, "utf8")); + assert.equal(cfg.name, "mote-cloud-staging"); + assert.equal(cfg.main, "../relay/src/cloud/cloudWorker.ts"); + assert.equal(cfg.workers_dev, false, "Staging MUST NOT be routable by default"); + assert.ok(!cfg.routes && !cfg.route && !cfg.triggers, "No public routes or schedules"); + assert.equal(cfg.vars?.MOTE_CLOUD_STAGING_ENABLED, "false", "Staging must default OFF"); + assert.equal(cfg.vars?.APPLE_CLIENT_ID, "REPLACE_WITH_REAL_IOS_BUNDLE_ID"); + assert.ok(!JSON.stringify(cfg).includes("MOTE_CLOUD_STAGING_GATE")); + assert.ok(!JSON.stringify(cfg).includes("MOTE_CLOUD_INTERNAL_SECRET")); + assert.equal(cfg.d1_databases?.length, 1); + const db = cfg.d1_databases[0]; + assert.equal(db.binding, "CLOUD_DB"); + assert.equal(db.database_name, "mote-cloud-staging"); + assert.equal(db.database_id, "REPLACE_WITH_NEW_STAGING_D1_ID"); + assert.equal(db.migrations_table, "d1_migrations"); + assert.equal(db.migrations_dir, "migrations"); + assert.equal(cfg.durable_objects?.bindings?.length, 1); + assert.equal(cfg.durable_objects.bindings[0].name, "CLOUD_TENANTS"); + assert.equal(cfg.durable_objects.bindings[0].class_name, "MoteCloudTenant"); + assert.equal(cfg.migrations?.[0]?.new_sqlite_classes?.[0], "MoteCloudTenant"); + assert.equal(cfg.migrations?.length, 1); + exactSet( + expectedFiles.filter(file => existsSync(join(root, "cloud", "migrations", file))), + expectedFiles, + "Missing source migration file", + ); + return cfg; +} +async function remoteCheck() { + const token = process.env.CLOUDFLARE_API_TOKEN; + const account = process.env.CLOUDFLARE_ACCOUNT_ID; + const databaseId = process.env.MOTE_CLOUD_STAGING_DB_ID; + if (!token || !/^[a-f0-9]{32}$/i.test(account ?? "") || + !validUUID(databaseId) || + process.env.MOTE_STAGING_D1_CONFIRM !== "mote-cloud-staging") { + throw new Error("Remote checks require token, account/DB IDs and exact staging confirmation"); + } + const base = `https://api.cloudflare.com/client/v4/accounts/${account}/d1/database/${databaseId}`; + async function api(suffix, method = "GET", body) { + const response = await fetch(base + suffix, { + method, + headers: { + Authorization: `Bearer ${token}`, + ...(body === undefined ? {} : { "Content-Type": "application/json" }), + }, + ...(body === undefined ? {} : { body: JSON.stringify(body) }), + signal: AbortSignal.timeout(12_000), + }); + const payload = await response.json(); + if (!response.ok || !payload.success || (Array.isArray(payload.result) && + payload.result.some(result => !result.success))) { + throw new Error("Cloudflare staging read-only query failed"); + } + return payload.result; + } + const database = await api(""); + assert.equal(database.name, "mote-cloud-staging"); + const sql = `SELECT type,name FROM sqlite_master + WHERE name LIKE 'cloud_%' OR name LIKE 'idx_cloud_%' + OR name='d1_migrations' ORDER BY type,name`; + const objects = (await api("/query", "POST", { sql }))[0].results; + exactSet(objects.filter(o => o.type === "table" && o.name !== "d1_migrations").map(o => o.name), + requiredTables, "Staging database tables drifted"); + exactSet(objects.filter(o => o.type === "index").map(o => o.name), + requiredIndexes, "Staging indexes drifted"); + exactSet(objects.filter(o => o.type === "trigger").map(o => o.name), + requiredTriggers, "Staging triggers drifted"); + assert.ok(objects.some(o => o.name === "d1_migrations" && o.type === "table")); + const ledger = (await api("/query", "POST", { + sql: "SELECT name FROM d1_migrations ORDER BY id", + }))[0].results; + exactSet(ledger.map(row => row.name), expectedFiles, "Migration ledger has unexpected entries"); + return databaseId; +} +async function main() { + const cfg = templateCheck(); + if (args.has("--render") && !args.has("--verify-remote")) { + throw new Error("--render requires an actual remote D1 verification"); + } + if (args.has("--verify-remote")) await remoteCheck(); + if (args.has("--render")) { + const id = process.env.MOTE_CLOUD_STAGING_DB_ID; + const audience = process.env.APPLE_CLIENT_ID; + if (!validUUID(id) || !/^[A-Za-z][A-Za-z0-9-]*(\.[A-Za-z][A-Za-z0-9-]*){2,}$/.test(audience ?? "") || + audience?.includes("example") || audience?.includes("REPLACE") || + audience?.includes("testing")) { + throw new Error("A real iOS Apple Bundle ID must be provided"); + } + if (existsSync(outPath)) throw new Error("Refusing to overwrite existing staging config"); + cfg.d1_databases[0].database_id = id; + cfg.vars.APPLE_CLIENT_ID = audience; + // Never enable the app or workers.dev in the rendered configuration. + assert.equal(cfg.vars.MOTE_CLOUD_STAGING_ENABLED, "false"); + assert.equal(cfg.workers_dev, false); + writeFileSync(outPath, JSON.stringify(cfg, null, 2) + "\n", { flag: "wx", mode: 0o600 }); + console.log("MOTE_STAGING_PREFLIGHT_PASS: isolated disabled config generated"); + } else { + console.log("MOTE_STAGING_PREFLIGHT_PASS: offline config safe" + + (args.has("--verify-remote") ? "; D1 schema/ledger verified" : "")); + } +} +main().catch(error => fail(error instanceof Error ? error.message : "unknown error")); From e78805393fa8aa45b57888aed829fa2552c82d4b Mon Sep 17 00:00:00 2001 From: Leo <91056950+Nardo021@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:59:02 +1100 Subject: [PATCH 03/11] ci(cloud): enforce disabled-by-default staging and D1 ledger preflight --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf561aa..dc37ddd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -203,6 +203,10 @@ jobs: npm ci --prefix relay - name: Validate opt-in D1 remote verification harness syntax run: node --check cloud/scripts/verify-staging-d1.mjs + - name: Validate staging fail-closed configuration and migration files + run: | + node --check cloud/scripts/check-staging-preflight.mjs + node cloud/scripts/check-staging-preflight.mjs - name: Bundle staged Cloud Worker without bindings or deployment run: npx wrangler deploy --config cloud/wrangler.ci.jsonc --dry-run --outdir dist/cloud From f0c5dba1f4102736d929eee2a4a68bd3e5b30664 Mon Sep 17 00:00:00 2001 From: Leo <91056950+Nardo021@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:59:45 +1100 Subject: [PATCH 04/11] ci(cloud): smoke-test disabled staging Worker in local workerd runtime --- .github/workflows/ci.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc37ddd..28996f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -209,6 +209,33 @@ jobs: node cloud/scripts/check-staging-preflight.mjs - name: Bundle staged Cloud Worker without bindings or deployment run: npx wrangler deploy --config cloud/wrangler.ci.jsonc --dry-run --outdir dist/cloud + - name: Verify local Cloud Worker rejects traffic when disabled + shell: bash + run: | + set -euo pipefail + npx wrangler dev --config cloud/wrangler.ci.jsonc --local --ip 127.0.0.1 --port 8797 > "${RUNNER_TEMP}/mote-cloud-disabled.log" 2>&1 & + pid=$! + trap 'kill "$pid" 2>/dev/null || true' EXIT + status="" + for attempt in $(seq 1 50); do + status=$(curl -sS -o /dev/null -w '%{http_code}' --max-time 2 http://127.0.0.1:8797/cloud/v1/health 2>/dev/null || true) + if [[ "$status" == "503" ]]; then + break + fi + sleep 0.4 + done + if [[ "$status" != "503" ]]; then + echo "Cloud Worker local runtime failed to start fail-closed." + tail -n 60 "${RUNNER_TEMP}/mote-cloud-disabled.log" + exit 1 + fi + for route in "/cloud/v1/health" "/cloud/v1/devices" "/cloud/v1/pairings"; do + code=$(curl -sS -o /dev/null -w '%{http_code}' --max-time 3 \ + -H 'X-Mote-Staging-Gate: attacker-controlled-value' \ + -X POST "http://127.0.0.1:8797${route}") + [[ "$code" == "503" ]] || { echo "FAIL: unsafe Cloud response on ${route}: ${code}"; exit 1; } + done + echo "PASS: Worker runtime rejects all tested routes with staging disabled." consistency: name: Repository consistency From 7a4ff06ff2ad8958b0b012bfc532b9958fa55821 Mon Sep 17 00:00:00 2001 From: Leo <91056950+Nardo021@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:00:20 +1100 Subject: [PATCH 05/11] test(cloud): validate real D1 critical fields and atomic trigger before generating staging config --- cloud/scripts/check-staging-preflight.mjs | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cloud/scripts/check-staging-preflight.mjs b/cloud/scripts/check-staging-preflight.mjs index f187214..9c44e29 100644 --- a/cloud/scripts/check-staging-preflight.mjs +++ b/cloud/scripts/check-staging-preflight.mjs @@ -117,6 +117,32 @@ async function remoteCheck() { exactSet(objects.filter(o => o.type === "trigger").map(o => o.name), requiredTriggers, "Staging triggers drifted"); assert.ok(objects.some(o => o.name === "d1_migrations" && o.type === "table")); + const sessionCols = (await api("/query", "POST", { + sql: "PRAGMA table_info(cloud_sessions)", + }))[0].results.map(row => row.name); + for (const column of [ + "id", "account_id", "refresh_token_hash", "access_token_hash", + "expires_at_ms", "access_expires_at_ms", "revoked_at_ms", + ]) assert.ok(sessionCols.includes(column), "Session schema missing mandatory field"); + + const claimCols = (await api("/query", "POST", { + sql: "PRAGMA table_info(cloud_pairing_tickets)", + }))[0].results.map(row => row.name); + for (const column of [ + "id", "device_id", "claim_secret_hash", "poll_secret_hash", + "device_credential_hash", "status", "claimed_by_account_id", + ]) assert.ok(claimCols.includes(column), "Pairing schema missing mandatory field"); + + const triggerBody = (await api("/query", "POST", { + sql: "SELECT sql FROM sqlite_master WHERE type='trigger' AND name='cloud_pairing_approve_create_device'", + }))[0].results[0]?.sql ?? ""; + assert.match(triggerBody, /AFTER\\s+UPDATE\\s+OF\\s+status/i); + assert.match(triggerBody, /INSERT\\s+INTO\\s+cloud_devices/i); + const uniquePending = (await api("/query", "POST", { + sql: "SELECT sql FROM sqlite_master WHERE type='index' AND name='idx_cloud_pairing_one_pending_device'", + }))[0].results[0]?.sql ?? ""; + assert.match(uniquePending, /CREATE\\s+UNIQUE\\s+INDEX/i); + assert.match(uniquePending, /WHERE\\s+status\\s*=\\s*'pending'/i); const ledger = (await api("/query", "POST", { sql: "SELECT name FROM d1_migrations ORDER BY id", }))[0].results; From 4b6494dacad52ff3ebc3d8a058382ef806c3d762 Mon Sep 17 00:00:00 2001 From: Leo <91056950+Nardo021@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:00:44 +1100 Subject: [PATCH 06/11] fix(cloud): use whitespace matching in live D1 schema preflight expressions --- cloud/scripts/check-staging-preflight.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cloud/scripts/check-staging-preflight.mjs b/cloud/scripts/check-staging-preflight.mjs index 9c44e29..ca08158 100644 --- a/cloud/scripts/check-staging-preflight.mjs +++ b/cloud/scripts/check-staging-preflight.mjs @@ -136,13 +136,13 @@ async function remoteCheck() { const triggerBody = (await api("/query", "POST", { sql: "SELECT sql FROM sqlite_master WHERE type='trigger' AND name='cloud_pairing_approve_create_device'", }))[0].results[0]?.sql ?? ""; - assert.match(triggerBody, /AFTER\\s+UPDATE\\s+OF\\s+status/i); - assert.match(triggerBody, /INSERT\\s+INTO\\s+cloud_devices/i); + assert.match(triggerBody, /AFTER\s+UPDATE\s+OF\s+status/i); + assert.match(triggerBody, /INSERT\s+INTO\s+cloud_devices/i); const uniquePending = (await api("/query", "POST", { sql: "SELECT sql FROM sqlite_master WHERE type='index' AND name='idx_cloud_pairing_one_pending_device'", }))[0].results[0]?.sql ?? ""; - assert.match(uniquePending, /CREATE\\s+UNIQUE\\s+INDEX/i); - assert.match(uniquePending, /WHERE\\s+status\\s*=\\s*'pending'/i); + assert.match(uniquePending, /CREATE\s+UNIQUE\s+INDEX/i); + assert.match(uniquePending, /WHERE\s+status\s*=\s*'pending'/i); const ledger = (await api("/query", "POST", { sql: "SELECT name FROM d1_migrations ORDER BY id", }))[0].results; From 69bfe69286baccc32e758ed34fcff56ca404ea2e Mon Sep 17 00:00:00 2001 From: Leo <91056950+Nardo021@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:01:40 +1100 Subject: [PATCH 07/11] docs(cloud): capture reconciled D1 ledger, disabled staging preflight, and honest deployment gates --- docs/cloud-p0c3b-staging-gates.md | 138 ++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 docs/cloud-p0c3b-staging-gates.md diff --git a/docs/cloud-p0c3b-staging-gates.md b/docs/cloud-p0c3b-staging-gates.md new file mode 100644 index 0000000..4ccad4d --- /dev/null +++ b/docs/cloud-p0c3b-staging-gates.md @@ -0,0 +1,138 @@ +# Mote Cloud P0C3B — Staging Migration Baseline and Fail-Closed Deployment Gate + +**Recorded:** 2026-11-17 (Australia/Sydney) +**Status:** D1 ledger reconciled on actual Cloudflare staging; deploy preflight implemented. **Cloud Worker/DO NOT DEPLOYED.** +**Parent:** P0C3A Draft PR #6. This phase must remain stacked, Draft and not public-ready. + +## Verified Cloudflare operations + +Connected Cloudflare account: `Leo`. Dedicated database: +`mote-cloud-staging` (`3ac5c176-9975-433a-992f-411245118d91`). + +The three schema migrations in this repository had already been executed successfully +**against this staging D1 database** using the D1 REST API in P0C3A. Prior +to reconciliation there were 5 application tables, 8 named indexes and 3 +triggers. Session columns added by migration 0002 were also present. The +database contained no real or synthetic accounts, devices or pairing tickets. + +Wrangler's expected ledger table did **not** yet exist, because the SQL +had not been run through `wrangler d1 migrations apply --remote`. Based on +the source-controlled SQL already executed and the Cloudflare Wrangler +migration helper schema, a ledger table was created with the official form: + +```sql +CREATE TABLE IF NOT EXISTS d1_migrations ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT UNIQUE, + applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL +); +``` + +Only the **previously applied**, verified migrations were recorded: + +- `0001_core.sql` +- `0002_auth.sql` +- `0003_pairing_claim.sql` + +A follow-up **real D1 read** confirmed all three rows. This is +reconciliation of known execution evidence, **not an assertion that Wrangler +executed those statements**. It must not be repeated for another database +without first checking that database's actual schema and history. No +unrelated Cloudflare Workers, databases or DNS were changed. + +Sources: +[Cloudflare's current D1 migration documentation](https://developers.cloudflare.com/d1/reference/migrations/) +and the [Wrangler migration table helper](https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/d1/migrations/helpers.ts). + +## Source changes in this PR + +1. `cloud/wrangler.staging.example.jsonc` now has + `workers_dev: false`, **no routes**, `MOTE_CLOUD_STAGING_ENABLED=false`, + and an explicit `migrations_table: "d1_migrations"`. It still carries + placeholder IDs, and **never** contains a private gate or DO secret. +2. `cloud/scripts/check-staging-preflight.mjs` verifies that the template + names ONLY the new Cloud Worker, D1 and tenant DO, stays disabled and + unroutable, and includes the three existing SQL migration files. +3. In opt-in `--verify-remote` mode, the checker demands a verified + `mote-cloud-staging` database name and exact migration ledger, then + checks all 5 tables, 8 named indexes, 3 triggers, critical session/pairing + columns and the trigger's atomic INSERT behavior from `sqlite_master`. + It makes **read-only** Cloudflare REST requests, and requires the operator's + API token in their own environment. +4. `--render` requires that remote verification passed and a **real, + non-placeholder Apple Bundle ID** was supplied through the operator's + environment. It writes the explicitly disabled local config only once to + `cloud/wrangler.staging.jsonc`, which is gitignored. It **does not + deploy**, activate, publish a route or generate/store any secret. +5. CI executes the offline config checks, syntax-checks the verifier and + builds the Cloud Worker by Wrangler dry-run. It also starts the local + workerd runtime and asserts unauthenticated health/devices/pairings traffic + stays HTTP 503 when the staging flag is off. No Cloudflare account access + or secrets are required in CI. + +## Safe operator-only workflow (NOT executed by this PR) + +From the repository checkout with Node 22 and the current Wrangler dependency: + +```sh +npm ci +npm ci --prefix relay + +# Offline guard: does not use Cloudflare credentials. +node cloud/scripts/check-staging-preflight.mjs + +# Operator supplies these outside source control. +export CLOUDFLARE_API_TOKEN='(set locally; never commit)' +export CLOUDFLARE_ACCOUNT_ID='(real Cloudflare account ID)' +export MOTE_CLOUD_STAGING_DB_ID='(verified Mote Cloud Staging D1 UUID)' +export MOTE_STAGING_D1_CONFIRM='mote-cloud-staging' + +# READ-ONLY on Cloudflare. Verifies migration history & schema. +node cloud/scripts/check-staging-preflight.mjs --verify-remote + +# Only once the genuine Apple iOS Bundle ID is known and verified: +export APPLE_CLIENT_ID='(real iOS Bundle ID)' +node cloud/scripts/check-staging-preflight.mjs --verify-remote --render + +# An operator may inspect the generated disabled config: +npx wrangler d1 migrations list mote-cloud-staging \ + --config cloud/wrangler.staging.jsonc --remote +npx wrangler deploy --config cloud/wrangler.staging.jsonc --dry-run +``` + +**Do not run** `d1 migrations apply --remote` as a speculative bootstrap +step. The existing database has a verified schema and a recorded baseline. +For future migrations, review the list and new SQL files, obtain a D1 +backup/bookmark and make a separate migration PR. + +Only after explicit review of the generated disabled configuration, signed +Apple identity flow, tenant DO runtime, logging, abuse controls and deployment +target may an operator deploy a **non-routed, disabled** staging Worker. +Both `MOTE_CLOUD_STAGING_GATE` and `MOTE_CLOUD_INTERNAL_SECRET` must be +configured as **separate Cloudflare secret bindings**, never as `vars` or +in released clients. Do not enable `workers_dev`, routes or +`MOTE_CLOUD_STAGING_ENABLED` before additional security review. + +## Exit gates before real multi-account hardware tests + +- [x] Real D1 tables, indexes and SQLite triggers observed on staging. +- [x] Real D1 atomic double-claim, replay and collision-rollback tested (P0C3A). +- [x] Manually applied past migrations reconciled with a real three-row + Wrangler-format ledger; reading it back succeeded. +- [ ] New Cloud **runtime** deployed in the dedicated account without + accidentally updating the personal `mote-rc` Worker. +- [ ] Real Apple iOS Bundle ID and Sign in with Apple token tested against + the new staging service. +- [ ] Private staging gate/internal DO secret provisioned by the operator; + no secrets are committed to GitHub/Notion or bundled in clients. +- [ ] Real Cloudflare Durable Object WebSocket/auth/command/hibernation and + revocation results verified, not merely compiled. +- [ ] Full iPhone → Cloud → Windows/macOS lock tested on real hardware. +- [ ] Public abuse/rate limits, account deletion, telemetry/privacy, + signed installers, Self-host docs and App Store requirements addressed. + +**Do not confuse a successful CLI dry-run, a disabled local workerd smoke +test or D1 REST schema verification with a deployed multi-tenant service.** + +Also see [P0C3A live D1 record](cloud-p0c3a-real-d1.md) and +[P0C2 WebSocket design](cloud-p0c2-realtime.md). From 0ad449f971e3a51c5075dd117ac4eb7cd8755ef2 Mon Sep 17 00:00:00 2001 From: Leo <91056950+Nardo021@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:03:35 +1100 Subject: [PATCH 08/11] fix(cloud): align isolated staging compatibility date with pinned workerd runtime --- cloud/wrangler.ci.jsonc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/wrangler.ci.jsonc b/cloud/wrangler.ci.jsonc index 5e249e7..b48f51d 100644 --- a/cloud/wrangler.ci.jsonc +++ b/cloud/wrangler.ci.jsonc @@ -2,7 +2,7 @@ "$schema": "../node_modules/wrangler/config-schema.json", "name": "mote-cloud-ci-dry-run", "main": "../relay/src/cloud/cloudWorker.ts", - "compatibility_date": "2026-11-16", + "compatibility_date": "2026-09-28", "compatibility_flags": [ "nodejs_compat" ], From 1cc5627eaaa16cd523a1108541c0b3c013f5d4bc Mon Sep 17 00:00:00 2001 From: Leo <91056950+Nardo021@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:03:38 +1100 Subject: [PATCH 09/11] fix(cloud): align isolated staging compatibility date with pinned workerd runtime --- cloud/wrangler.staging.example.jsonc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/wrangler.staging.example.jsonc b/cloud/wrangler.staging.example.jsonc index 76e9385..2fd7a02 100644 --- a/cloud/wrangler.staging.example.jsonc +++ b/cloud/wrangler.staging.example.jsonc @@ -2,7 +2,7 @@ "$schema": "../node_modules/wrangler/config-schema.json", "name": "mote-cloud-staging", "main": "../relay/src/cloud/cloudWorker.ts", - "compatibility_date": "2026-11-16", + "compatibility_date": "2026-09-28", "compatibility_flags": [ "nodejs_compat" ], From f05b2a21ebd6d5275f3fbda720e6dbe210d23ea9 Mon Sep 17 00:00:00 2001 From: Leo <91056950+Nardo021@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:03:51 +1100 Subject: [PATCH 10/11] ci(cloud): assert staging and CI use same supported workerd compatibility date --- cloud/scripts/check-staging-preflight.mjs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cloud/scripts/check-staging-preflight.mjs b/cloud/scripts/check-staging-preflight.mjs index ca08158..1dad425 100644 --- a/cloud/scripts/check-staging-preflight.mjs +++ b/cloud/scripts/check-staging-preflight.mjs @@ -52,6 +52,10 @@ function templateCheck() { const cfg = JSON.parse(readFileSync(templatePath, "utf8")); assert.equal(cfg.name, "mote-cloud-staging"); assert.equal(cfg.main, "../relay/src/cloud/cloudWorker.ts"); + const ciCfg = JSON.parse(readFileSync(join(root, "cloud", "wrangler.ci.jsonc"), "utf8")); + assert.equal(cfg.compatibility_date, "2026-09-28"); + assert.equal(ciCfg.compatibility_date, cfg.compatibility_date, + "Staging and locally tested Cloud compatibility dates must match"); assert.equal(cfg.workers_dev, false, "Staging MUST NOT be routable by default"); assert.ok(!cfg.routes && !cfg.route && !cfg.triggers, "No public routes or schedules"); assert.equal(cfg.vars?.MOTE_CLOUD_STAGING_ENABLED, "false", "Staging must default OFF"); From b61a0ff0b218199862e99dabe39d4a787bbd6efe Mon Sep 17 00:00:00 2001 From: Leo <91056950+Nardo021@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:04:04 +1100 Subject: [PATCH 11/11] docs(cloud): record observed workerd compatibility limit and isolated date correction --- docs/cloud-p0c3b-staging-gates.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/cloud-p0c3b-staging-gates.md b/docs/cloud-p0c3b-staging-gates.md index 4ccad4d..80e213c 100644 --- a/docs/cloud-p0c3b-staging-gates.md +++ b/docs/cloud-p0c3b-staging-gates.md @@ -44,6 +44,18 @@ Sources: [Cloudflare's current D1 migration documentation](https://developers.cloudflare.com/d1/reference/migrations/) and the [Wrangler migration table helper](https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/d1/migrations/helpers.ts). +## Runtime compatibility discovered by CI + +The initial local-workerd smoke job failed even though the Cloud Worker +bundle compiled: Wrangler 4.137.0's pinned workerd binary supports a latest +compatibility date of `2026-09-28`, while the new Cloud configs specified +`2026-11-16`. The **Cloud-only** CI and staging configuration now use the +same supported date `2026-09-28` to test actual local runtime behavior. +This changes neither the existing personal Relay config nor its code. +Before raising the Cloud compatibility date, upgrade Wrangler/workerd in +a separate reviewed dependency update and repeat the local and real +staging acceptance tests. + ## Source changes in this PR 1. `cloud/wrangler.staging.example.jsonc` now has