Repository navigation
fix(mobile): faster relay recovery after an app switch and on a late desktop data link - #30607
Conversation
…ort probe, and retry an attach timeout through the director once Refs STA-11130. Co-Authored-By: Claude <[email protected]>
…e-resolving Aligns with the relay step 6 design: reason string attach-timeout, no director re-resolve (the director names the cell the host is seated on). Co-Authored-By: Claude <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
0ffd9ecd-474b-477e-beed-c123b9db77c4
📒 Files selected for processing: 17
cloud/packages/relay-contract/src/close-codes.tscloud/packages/relay-contract/src/contract.test.tsmobile/src/transport/mobile-endpoint-supervisor-attach-timeout.test.tsmobile/src/transport/mobile-relay-e2ee-link.test.tsmobile/src/transport/mobile-relay-e2ee-link.tsmobile/src/transport/mobile-relay-error-timer-cleanup.test.tsmobile/src/transport/mobile-relay-reconnect-controller.test.tsmobile/src/transport/mobile-relay-reconnect-controller.tsmobile/src/transport/mobile-relay-retry-delays.tsmobile/src/transport/mobile-relay-rpc-session-liveness.test.tsmobile/src/transport/mobile-relay-rpc-session.tsmobile/src/transport/relay-host-signed-out-verdict.test.tsmobile/src/transport/relay-recovery-failure-count.tsmobile/src/transport/rpc-session-liveness-watchdog.test.tsmobile/src/transport/rpc-session-liveness-watchdog.tssrc/shared/mobile-relay-close-codes.test.tssrc/shared/mobile-relay-close-codes.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
|
|
||
| // The cell held the dial for the desktop's data link, which never attached while | ||
| // its control looked alive. No re-resolve: the director names the seated cell. | ||
| function isHostAttachTimeout(error: Error | null): boolean { | ||
| return ( | ||
| error instanceof RelayOuterError && | ||
| error.code === MOBILE_RELAY_CLOSE_CODE.HOST_OFFLINE && | ||
| error.closeReason === MOBILE_RELAY_PHONE_CLOSE_REASON.HOST_ATTACH_TIMEOUT | ||
| ) | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
rg -n 'hostAttachDeadlineMs|attach-timeout|HOST_ATTACH_TIMEOUT' cloud/packages mobile/src/transport src/shared/mobile-relay-close-codes.ts
sed -n '55,70p' mobile/src/transport/relay-recovery-failure-count.tsRepository: stablyai/orca
Length of output: 1942
🏁 Script executed:
set -eu
printf '%s\n' '--- cloud close-code and protocol definitions ---'
sed -n '1,120p' cloud/packages/relay-contract/src/close-codes.ts
sed -n '1,100p' cloud/packages/relay-contract/src/protocol-limits.ts
printf '%s\n' '--- cloud producer references ---'
rg -n -F --glob '*.ts' -e 'hostAttachDeadlineMs' -e 'HOST_ATTACH_TIMEOUT' -e 'HOST_OFFLINE' -e 'close(' -e 'destroy(' cloud/packages | head -240
printf '%s\n' '--- cloud contract test ---'
sed -n '1,110p' cloud/packages/relay-contract/src/contract.test.ts
printf '%s\n' '--- mobile error path references ---'
rg -n -F --glob '*.ts' -e 'class RelayOuterError' -e 'RelayOuterError' -e 'onclose' -e 'closeReason' mobile/src/transport | head -280
printf '%s\n' '--- mobile e2ee link implementation candidates ---'
rg -n -F --glob '*.ts' -e 'mobile-relay-e2ee-link' -e 'new RelayOuterError' mobile/src/transportRepository: stablyai/orca
Length of output: 41761
🏁 Script executed:
set -eu
printf '%s\n' '--- all-repository producer search ---'
rg -n -F --glob '*.ts' --glob '*.tsx' --glob '*.js' --glob '*.mjs' --glob '*.go' --glob '*.rs' \
-e 'hostAttachDeadlineMs' -e 'HOST_ATTACH_TIMEOUT' -e 'attach-timeout' -e 'RELAY_CLOSE_CODE.HOST_OFFLINE' -e 'RELAY_PHONE_CLOSE_REASON' . || test "$?" -eq 1
printf '%s\n' '--- RelayOuterError and E2EE link ---'
sed -n '1,210p' mobile/src/transport/mobile-relay-e2ee-link.ts
printf '%s\n' '--- physical client ---'
sed -n '1,190p' mobile/src/transport/mobile-relay-physical-client.ts
printf '%s\n' '--- relevant callers and failure propagation ---'
rg -n -F --glob '*.ts' -e 'connectMobileRelayForPairing' -e 'new MobileRelayE2eeLink' -e 'claimAttachTimeoutRedial' -e 'error.closeReason' mobile/src/transport | head -220Repository: stablyai/orca
Length of output: 23682
🏁 Script executed:
set -eu
printf '%s\n' '--- cloud host attach timeout and rejectClient ---'
sed -n '820,990p' cloud/apps/relay/src/host-session-registry.ts
rg -n -F --glob '*.ts' -e 'function rejectClient' -e 'rejectClient(' cloud/apps/relay/src/host-session-registry.ts cloud/apps/relay/src
printf '%s\n' '--- E2EE link failure tail ---'
sed -n '135,235p' mobile/src/transport/mobile-relay-e2ee-link.ts
printf '%s\n' '--- reconnect controller path ---'
sed -n '235,310p' mobile/src/transport/mobile-relay-reconnect-controller.ts
sed -n '40,95p' mobile/src/transport/mobile-relay-rpc-session.ts
printf '%s\n' '--- cloud timeout tests ---'
rg -n -F --glob '*.test.ts' -e 'attach deadline' -e 'attach-timeout' -e 'hostAttachDeadlineMs' cloud/apps/relay cloud/packagesRepository: stablyai/orca
Length of output: 18526
🏁 Script executed:
set -eu
printf '%s\n' '--- rejectClient implementation ---'
sed -n '2400,2455p' cloud/apps/relay/src/host-session-registry.ts
printf '%s\n' '--- attach timeout test block ---'
sed -n '1,120p' cloud/apps/relay/src/host-session-client-accept.test.ts
printf '%s\n' '--- exact matcher and delay behavior ---'
sed -n '1,90p' mobile/src/transport/relay-recovery-failure-count.ts
sed -n '1,85p' mobile/src/transport/mobile-relay-reconnect-controller.tsRepository: stablyai/orca
Length of output: 12657
🏁 Script executed:
set -eu
printf '%s\n' '--- host-session-registry imports ---'
sed -n '1,75p' cloud/apps/relay/src/host-session-registry.ts
printf '%s\n' '--- close reason declarations and websocket close helper ---'
rg -n -F --glob '*.ts' -e 'type RelayHostCloseReason' -e 'RELAY_HOST_CLOSE_REASON' -e 'function closeRelayWebSocket' -e 'closeRelayWebSocket' cloud/packages cloud/apps/relayRepository: stablyai/orca
Length of output: 8374
Send attach-timeout with the attach-deadline close.
When the data-link attach timer expires, the cloud relay sends HOST_OFFLINE with the default reason relay connection rejected. The mobile path preserves that reason, so isHostAttachTimeout cannot match and the intended one-second redial is skipped.
Suggested fix
RELAY_PROTOCOL_LIMITS,
RELAY_CLOSE_CODE,
+ RELAY_PHONE_CLOSE_REASON,
...
- this.rejectClient(socket, RELAY_CLOSE_CODE.HOST_OFFLINE)
+ this.rejectClient(
+ socket,
+ RELAY_CLOSE_CODE.HOST_OFFLINE,
+ RELAY_PHONE_CLOSE_REASON.HOST_ATTACH_TIMEOUT
+ )
...
- hostCloseReason?: RelayHostCloseReason | null
+ hostCloseReason?:
+ | RelayHostCloseReason
+ | typeof RELAY_PHONE_CLOSE_REASON.HOST_ATTACH_TIMEOUT
+ | null…nd jitter the attach-timeout redial Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
d0302e6e-16b2-45e1-b850-3d9403a32e1b
📒 Files selected for processing: 11
mobile/src/transport/mobile-endpoint-supervisor-attach-timeout.test.tsmobile/src/transport/mobile-endpoint-supervisor-test-fakes.tsmobile/src/transport/mobile-relay-background-lifecycle.test.tsmobile/src/transport/mobile-relay-reconnect-controller.test.tsmobile/src/transport/mobile-relay-reconnect-controller.tsmobile/src/transport/mobile-relay-retry-delays.tsmobile/src/transport/mobile-relay-rpc-session-liveness.test.tsmobile/src/transport/mobile-relay-rpc-session.tsmobile/src/transport/mobile-relay-runtime-failover.test.tsmobile/src/transport/relay-host-reachability-verdict.test.tsmobile/src/transport/relay-host-signed-out-verdict.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
| getFailure: () => failure | ||
| getFailure: () => failure, | ||
| probeAfterBackground: () => | ||
| state === 'connected' && livenessWatchdog.probeNow(livenessIdentity, RELAY_RESUME_PROBE_MS) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Do not let the voluntary probe limit suppress the background-return probe.
If a foreground probe receives a reply shortly before backgrounding, probeNow keeps its 10-second timestamp. On a return within that interval, this call sends no probe. If the relay died while backgrounded and no direct path is available, idleProbeMs: null leaves the session connected without another liveness check. An unanswered foreground probe also blocks this call and retains the two-miss timeout. Give the background-return probe a watchdog path that bypasses the voluntary limit and replaces or upgrades an active probe. (raw.githubusercontent.com)
…probe tests Co-Authored-By: Claude <[email protected]>
…hone renewal (#30666) * feat(relay): add the per-cell phonePath switch, effective only in reserve 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. * feat(relay): resume paired phones from one device read on memory cells 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. * feat(relay): keep a memory resume's basis in the cell and confirm it 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. * test(relay): roll a memory phone cell back with confirms in flight 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. * feat(relay): batch a memory cell's resume-confirmed audit rows 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. * feat(relay): count and log phone-path failures, and every attach deadline 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. * feat(relay): close an attach-deadline 4404 with the attach-timeout reason 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. * test(relay): drill a memory cell through a database outage, and pin phone 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. * fix(relay-ops): store phonePath=db as no key, so old images keep taking 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. * fix(relay): log a failed no-seat read, recheck the switch after the device 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. * fix(relay): log a failed memory renewal; test flips, replays and basis 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. * test(relay): assert a rolled-back memory splice issues no statement when it closes * fix(relay): flush resume audit early only on crossing the batch size, 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. * test(relay): assert the aged audit rows were dropped, not written --------- Co-authored-by: E2E Test <[email protected]>
ELI5
When you switch away from the Orca phone app and come back, the phone sometimes takes about 30 seconds to reconnect to your desktop through the relay. Two things on the phone made that slow. This change makes the phone notice a dead connection faster, and makes it retry sooner in one specific case where the relay already knows the desktop is probably still there.
What Changed
1. Coming back to the app (within the 30 s background grace).
app-resumenudges keep the current two-probe, 4-second behaviour; these include the manual reconnect button and nudges that arrive while the app is already in the foreground. The timeout stays 4 s rather than anything shorter, because the first packet after a resume on weak cellular can pay for radio wake-up plus a TCP retransmit. A false miss would tear down a healthy session and cost the relay a new accept. The 30 s grace is unchanged, and no second connection is opened alongside the check.2. "Desktop offline" that is really "desktop's data link was late".
attach-timeout, to the second case. When the phone sees it, it redials the same cell once, after a random 1–2 s delay, so that a problem across a whole cell doesn't make every phone redial at the same moment. If that redial fails the same way, the phone falls back to the normal 5–15 s wait. The quick redial is available once per failure streak; returning to the app, a direct connection, or a relay connection that lasted at least 30 s makes it available again.MOBILE_RELAY_PHONE_CLOSE_REASON.HOST_ATTACH_TIMEOUTinsrc/shared/mobile-relay-close-codes.ts, andRELAY_PHONE_CLOSE_REASON.HOST_ATTACH_TIMEOUTincloud/packages/relay-contract/src/close-codes.ts. It is a phone-only set and not part ofRELAY_HOST_CLOSE_REASON, which describes desktop control-socket closes. This PR changes nothing on the relay side.relay-helloframe and then a close frame, and only the close frame carries the reason (the hello frame's format is strict, so it cannot carry one). Today the phone fails as soon as it reads the refusal frame, so the reason was lost. Now, after a refusal frame, the phone waits for the close frame before failing, for at most 250 ms (the same limit it already uses after a transport error). The failure error now includes the close reason text.Why
Linked Issue
STA-11130
Visual Proof
N/A: this changes reconnect timing only and adds no UI. Tests cover the timing.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
New
mobile-endpoint-supervisor-attach-timeout.test.ts: redials the same cell after the 1–2 s delay without asking the director; falls back to the 5–15 s wait after a second attach timeout; a 4404 without the reason behaves as before; returning to the app makes the quick redial available again. The controller test covers the jittered delay and a stable connection making the redial available again.Link: a refusal frame followed by a close frame produces an error that carries the reason; a refusal with no close frame fails after 250 ms.
Watchdog and relay session: the background-return probe disconnects after one 4 s miss; an answered probe keeps the session; an
app-resumenudge alone still needs two 4 s misses. The background lifecycle and controller tests check that only a relay the grace kept is probed, that a nudge in the foreground doesn't trigger the probe, and that a relay released after the grace isn't probed.mobile/:vitest run src/transportpasses (147 files). The fullsrcrun passes, apart from 6 suites that can't load in this lane because root-level dependencies aren't installed (zod and@orca/process-hostimported through../src).tsc --noEmitshows only those same missing-dependency errors and none in changed files. The new test file type-checks undertsconfig.test.json.oxlintandformat:checkare clean.src/shared/mobile-relay-close-codes.test.tspasses. The cloudcontract.test.tsassertion was not run locally because this lane has no cloud dependencies; CI covers it.Review
Agent skill upstream boundary
Notes
Mobile ships JavaScript updates only; this change touches no native code. Desktop, SSH, and the relay server are unchanged.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)