Skip to content

test(relay): drill a memory cell through a database outage, and pin phone renewal - #30666

Merged
Jinwoo-H merged 42 commits into
mainfrom
relay-step6-drill-and-renewal-tests
Oct 19, 2026
Merged

Jinwoo-H merged 42 commits into
mainfrom
relay-step6-drill-and-renewal-tests

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​179 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​178
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10

ELI5

Two safety checks for the new phone path (step 6), as tests only:

  1. If the relay's database goes away for a while on a cell using the new path, phones that are already connected keep working, new connections fail cleanly and come back, and nothing is written late.
  2. Phones that are already in people's hands keep their pairing alive under the new "renew at most once a day" rule, even if they only ever talk through the relay.

What Changed

Tests only.

  • Database-outage drill (cell-phone-path.blackbox.test.ts, the in-process version of the staging drill E-dep-6). A real reserve-mode cell with phonePath=memory, one desktop and two phones:
    • with every database statement failing, a spliced phone's frames still reach the desktop;
    • a new resume closes 4503, and a confirm fails with a control error;
    • the cell is switched back to admitMode=db during the outage; once the database returns, the in-flight confirm finishes on its memory basis (one device read), and new resumes take the database path again;
    • audit rows held through 11 minutes of failed writes are dropped and counted (resumeAuditDropped), never written late (checked: 2 dropped, 0 written).
  • Phone renewal compatibility (mobile/src/transport/mobile-relay-renewal-compatibility.test.ts), using the shipped phone code (persistResumeConfirmation, RelayLeaseRotationTimer, mobileRelayCredentialNeedsRotation) against a model of the memory cell's answer:
    • a relay-only phone that re-resumes every 6 hours stays valid for 31 days, its lease timer is armed after every confirm, its stored expiry matches the cell's, and the cell writes at most once a day;
    • the rejected alternative (answering renewed: false when renewal is not due) stops the phone's lease timer after the first confirm, which is why the cell never answers that for a current-version confirm.

Why

These pin the two promises the rollout depends on: a database outage costs new connections, not live ones, and the renewal change is invisible to phones already shipped.

Includes #30658 (attach-timeout close reason, reviewed)

Linked Issue

N/A (step 6 of the relay redesign, internal)

Visual Proof

N/A: tests only.

Testing

  • Automated tests added/updated
  • Relay vitest --maxWorkers=2: 1222 passed. Mobile: the new file passes (2 tests); oxfmt and oxlint clean; pnpm run check:code-quality:changed passed.
  • The real staging drill (blocking a staging cell's database for 10 minutes) is not run here: it is an operations step for the rollout ladder.

Review

Stacked on #30658 (top of the cell stack).

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

The mobile test mirrors the cell's renewal rule (30-day expiry, renew when under 29 days left) rather than importing server code into the mobile suite.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for visual proof with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (mobile compatibility covered)
  • Tests pass locally; CI covers the rest

…erve mode

Step 6 of the relay redesign keys every phone-path change on this switch. The cell
reports the effective value in runtime status, and the flag tool refuses phonePath=memory
unless the cell is reserve, and a reserve flip that would turn phones over unnamed.
With phonePath=memory in reserve mode, a phone resume is admitted from one device
read and the cell's own seat, and takes no activity leases. A refused device closes
4401, a failed read 4503, and only a missing device row falls through to the invite
path. A phone whose host has no seat gets one assignment read: 4409 when the row
names another cell or the read fails, otherwise 4404.
…from one read

A phone resumed on the memory path keeps its connection basis in the cell, not in
relay_connection_bases. Its confirm rereads the device row once, renews it only when
less than 29 days remain, and always answers a current-version confirm renewed:true
with the expiry the database holds. Confirms route by where their basis lives, so a
flip between accept and confirm completes either way. Retries answer from a 10-min
in-memory result map.
Flipping back by admitMode=db, phonePath=db or a dead-man trip leaves in-flight
confirms to finish on their memory basis, writes no phone lease and leaks none, and
evacuation still refuses the cell while Postgres records it as reserve.
Memory confirms buffer their audit rows and the cell writes them as one multi-row
insert every 5 s or 500 rows, idempotent by a per-event id. The buffer holds at most
5,000 rows and drops a row older than 10 minutes rather than retrying it, counting
and logging both kinds of drop.
…line

The runtime metrics line gains phone refusals by close code, attach deadlines, accept
database errors, resume confirm failures by code, completed accepts by phone path and
the resume audit drop total. Every attach-deadline 4404 now logs what the cell knew of
the desktop's control (pong age, ping outstanding, control age and round trip), so a
half-open control can be told from a slow data dial.
…ason

The phone close reason from #30607 now rides the close frame of the 4404 a cell
sends when the desktop's data leg misses the attach deadline, so OTA phones can
redial the same cell once instead of waiting out the host-offline delay. The failed
relay-hello frame is unchanged, and old phones ignore the reason.
…hone renewal

A blocked database leaves splices forwarding, closes new resumes 4503 and fails
confirms cleanly, lets an in-flight confirm finish on its memory basis after a flip
back, and drops audit rows past 10 minutes instead of writing them late. On the phone,
a relay-only session lives 31 days under the once-a-day renewal rule, and would not
if a not-due confirm answered renewed:false.
…ng writes

An explicit phonePath=db left in the switch file would make the flag tool refuse every
later write after an image rollback, including a watcher's admitMode=db flip back.
…evice read

A failed assignment read for a phone with no seat now logs a rate-limited line before
its 4409. A switch that turned off during the device read sends the phone down today's
path. resolveResume reuses the one-read lookup, so the expiry and grace rules have one copy.
…s cleanup

A renewal write that fails still answers the stored expiry, but now logs a rate-limited
line so a persistently failing update is visible before phones age toward re-pairing.
… drop the shutdown flush

A failing database no longer takes a 500-row insert per confirm; retries wait for the
5 s timer. The shutdown flush raced the pool closing, so it is gone and the at most 5 s
loss is documented. A stopped buffer no longer re-arms its timer.
…e-logs-metrics

Carries the PR 3 and PR 4 review logs into the renamed phone-connection log, counts
renewal failures in the metrics line, and narrows the confirm-failure count so a lease
release after a committed confirm is not counted.
# Conflicts:
#	cloud/apps/relay/src/cell-phone-path.blackbox.test.ts
…firm

# Conflicts:
#	cloud/apps/relay/src/cell-phone-path.blackbox.test.ts
#	cloud/apps/relay/src/credential-store.ts
#	cloud/apps/relay/src/host-session-registry.ts
#	cloud/apps/relay/src/phone-accept-log.ts
#	cloud/apps/relay/src/test-fixtures/statement-recording-database.ts
@Jinwoo-H
Jinwoo-H changed the base branch from relay-step6-attach-timeout-reason to main October 19, 2026 17:16
…-renewal-tests

# Conflicts:
#	cloud/apps/relay/src/host-session-client-accept.test.ts
#	cloud/apps/relay/src/host-session-registry.ts
@Jinwoo-H
Jinwoo-H merged commit 20fc7af into main Oct 19, 2026
28 checks passed
@coderabbitai

coderabbitai Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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