Skip to content

fix(cloud): P0C3A real D1 pairing count and staging verification - #6

Draft
Nardo021 wants to merge 6 commits into
feature/mote-cloud-p0c2-realtime-20261116from
feature/mote-cloud-p0c3-d1-staging-20261117
Draft

Nardo021 wants to merge 6 commits into
feature/mote-cloud-p0c2-realtime-20261116from
feature/mote-cloud-p0c3-d1-staging-20261117

Conversation

@Nardo021

@Nardo021 Nardo021 commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Scope — P0C3A real Cloudflare D1 (still Draft, stacked on PR #5)

The first real Cloudflare staging D1 was created as a separate database mote-cloud-staging in the connected account. The existing mote-rc personal Worker and all existing D1 databases were not changed. This PR does not deploy any Worker, expose a public API, change DNS, or create secrets.

Remote evidence (Cloudflare API, 2026-11-16 UTC)

  • Applied and checked source migrations 0001_core.sql (9 statements), 0002_auth.sql (6), 0003_pairing_claim.sql (3 triggers). Queried sqlite_master: 5 Cloud tables + 3 pairing triggers present.
  • On real D1, concurrent approval of one synthetic ticket gave one winner / one loser; winning statement meta.changes = 2 (ticket UPDATE + trigger device INSERT), losing 0.
  • Replay was denied (0 additional changes); duplicate credential claim was rejected and rolled back, leaving the attempted ticket pending; only one device row existed.
  • Synthetic accounts/devices/tickets were removed; follow-up D1 query verified 0 test accounts, devices and tickets.

Actual bug found & fixed

The previous CloudPairingRepository.approve() expected result.meta.changes === 1, correct in local Node SQLite but false on actual Cloudflare D1 where the trigger contributes a second change. Real clients would receive a failure even after successful device registration. Fixed to accept a safe positive integer changes count for this unique-ID UPDATE with atomic trigger, and added a staging HTTP regression test simulating D1's trigger-inclusive count (while retaining existing Node SQLite tests).

Repeatability & CI

  • New cloud/scripts/verify-staging-d1.mjs: opt-in remote D1 contract verifier with explicit database-name guard, required env values, per-run random fixture IDs and finally-cleanup.
  • CI syntax-checks the remote harness without network or credentials; Relay tests cover the real-D1 change counting difference.
  • docs/cloud-p0c3a-real-d1.md records evidence, safe execution, caveats, and critical warning: migrations applied via D1 REST API, not recorded in Wrangler migration ledger — never blindly reapply SQL via wrangler d1 migrations apply --remote on this database.

Strict release blockers

No Cloud Staging Worker or per-account DO deployed; no genuine Apple identity or iOS app, no live WebSockets, no physical Windows/Mac lock, no real double-account Worker E2E, no revocation broadcast, no public rate limit/account deletion. The stage stays private and disabled; existing self-host Relay is untouched.

Next P0C3B: reconcile Wrangler migration baseline, configure disabled/gated separate Staging Worker with authenticated operator secrets and real Apple app identifier, verify DO runtime and actual hardware E2E before any public access. No unsigned production binaries or App Store claim.

Verified GitHub CI (HEAD 9b58d47c1cc23cc8b2e1cd24a9a622216a2b1875)

CI #43 — 9/9 jobs SUCCESS. Relay / Protocol (including new trigger-count regression), standalone Cloud staging Worker dry-run plus script syntax check, repository consistency, Dashboard, original Worker, macOS, Windows, Windows E2E and Windows test-mode release artifact passed. This validates source/tests; real D1 tests were separately performed via Cloudflare REST API. Cloud Worker/DO, native clients and real remote locks remain not deployed/not live-verified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant