Skip to content

fix(mobile): keep reconnect backoff across foreground nudges for failing hosts - #36352

Open
luben93 wants to merge 2 commits into
stablyai:mainfrom
luben93:luben93/mobile-offline-host-backoff
Open

luben93 wants to merge 2 commits into
stablyai:mainfrom
luben93:luben93/mobile-offline-host-backoff

Conversation

@luben93

@luben93 luben93 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

If a paired computer is switched off on purpose, the phone app kept redialing it every time you switched apps or changed network, starting again from the fastest retry speed. This makes the app remember how many times it already failed, so it stops hammering a host that is clearly off.

What Changed

  • A foreground or network-change nudge on a reconnecting host now pulls the next attempt forward but no longer resets the backoff. Only an authenticated connection resets it (RpcClientReconnectSchedule.redialOnNudge, direct-rpc-client.ts notifyForeground).
  • A host that has not connected this app session and has used up the 12-attempt limit becomes dormant: nudges are ignored, the slow retry becomes 5 minutes instead of 90 s, and it does not fire while the app is outside the foreground (isAppOutsideForeground in socket-deadline-clock.ts).
  • A new client (manual Connect, re-pairing) still dials immediately. Hosts that connected earlier in the session keep the existing 90 s retry. Web never records app state, so the background pause only applies on native.

Before: every foreground or network change gave each reconnecting host a fresh burst of dials starting at 0.5 s, plus a retry every 90 s indefinitely. After: failing hosts keep escalating, and an expected-offline host settles into a rare retry.

Why

On a phone paired with a host that is normally offline (a laptop that is only sometimes on), Orca mobile over Tailscale intermittently stalls and only toggling Tailscale recovers it. That is probably a Tailscale iOS bug (tailscale/tailscale#17967; I opened a possible fix at tailscale/tailscale#22084), but several reporters there fixed it by removing or reviving an offline peer, so the client's dial behaviour toward an offline host is a plausible trigger. It is not confirmed that this is the trigger. Regardless, redialing an offline host from 0.5 s on every app switch is wasteful. I considered detecting the tunnel state and pausing all dials, but iOS gives the app no API for peer state, so this stays purely client-side and independent of multi-endpoint pairing (#15615).

Linked Issue

Refs #13354. It only covers the redial storm toward hosts that keep failing. #13354 also covers reconnect lag on resume for a host that is up and the upstream Tailscale tunnel failure (tailscale/tailscale#17967), which this PR does not claim to fix, so merging it should not close the issue.

Visual Proof

N/A: no visible UI or copy change; only the timing of reconnect attempts changes.

Testing

  • New rpc-client-nudge-backoff.test.ts (fake timers): a nudge does not reset a failing host's attempts; a nudge after a successful connection does; the trickle slows after the threshold and pauses in the background; a new client dials immediately. One assertion in rpc-client.test.ts updated to the new nudge behaviour.

  • pnpm -C mobile test on the four affected transport test files: 48 passed. pnpm check:changed --maxWorkers=2 passes (format, lint, typecheck, affected tests, ratchets).

  • Full local run: lint, typecheck and build pass; pnpm test has 55 unrelated environment-specific failing files on my machine (details in the checklist), so CI is the authoritative full-suite run.

  • Not tested on a physical device; platform coverage is the unit tests on macOS.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Written with Claude: Claude Opus (via a sandboxed devcontainer) wrote the change and tests, and Claude Sonnet orchestrated, ran the checks on the host, and prepared this PR. I reviewed the diff before opening it.

Review

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.

AI code review summary

Reviewed by Claude (Sonnet 5.5, the orchestrating agent) against the diff and mobile/src/transport:

  • Cross-platform: change is TypeScript in the shared mobile transport, so iOS and Android behave the same. Web never records app state (recordSocketDeadlineAppState), so the background pause does not apply there and web keeps dialing on schedule. Desktop is untouched.
  • SSH / remote / local: no protocol or host change. Local, remote and orca serve hosts all use the same direct client; older hosts behave exactly as before. Relay reconnect logic is not modified.
  • Agents and integrations: not affected.
  • Performance risk: fewer dials for hosts that keep failing; one extra timer re-arm while backgrounded and dormant. No new polling.
  • UI quality: no UI or copy change.
  • Security: no new inputs, credentials or network surface. The only risk is a dormant host reconnecting later than before, by design; a manual Connect or re-pairing dials immediately.
  • Residual risk: "this session" means the client's lifetime, and hosts that connected earlier keep the old 90 s retry. Not tested on a physical device.

Platform notes

Tested through unit tests on macOS only. Behaviour on a real iOS or Android device over Tailscale is unverified.

Notes

  • Backwards compatible with older hosts; no protocol change. Remote SSH and desktop are untouched. Relay reconnect logic is not changed.
  • Possible pushback: "this session" means the client's lifetime; the 5-minute slow retry and the 12-attempt threshold are judgement calls and are named constants.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred). Locally: pnpm lint, pnpm typecheck and pnpm build pass, and pnpm check:changed passes. pnpm test ran 140,008 tests with 56 failures in 55 files, none in mobile/src/transport; the ones I inspected are environment-specific on my macOS machine (Playwright browsers not installed, macOS bash 3.2 without mapfile, a native SQLite open error, shell-prompt integration). The 49 transport tests for this change pass. Please let CI cover the full suite.

🤖 Generated with Claude Code

…ing hosts

Every app foreground and network change reset the attempt counter of a
reconnecting host, so a host that is offline on purpose got a fresh burst
of 0.5 s dials each time, plus a retry every 90 s forever.

A nudge now pulls the next attempt forward without resetting the backoff;
only an authenticated connection resets it. A host that has not connected
this session and used up its attempt limit goes dormant: nudges are
ignored, the slow retry becomes 5 minutes and does not fire while the app
is outside the foreground. A new client (manual retry, re-pairing) still
dials immediately.

Refs stablyai#13354

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0be56e85-7c99-4c04-914e-fd0403a467a7
Commits

Reviewing files that changed from the base of the PR and between 8a2b06f and 01f8c05.

Files selected for processing: 2
  • mobile/src/transport/rpc-client-nudge-backoff.test.ts
  • mobile/src/transport/rpc-client-reconnect-schedule.ts
Files skipped from review as they are similar to previous changes: 1
  • mobile/src/transport/rpc-client-nudge-backoff.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

The reconnect scheduler tracks whether a client has authenticated. Dormant clients use a five-minute retry delay after reaching the retry limit, and scheduled retries defer while the app is outside the foreground. Foreground nudges do not trigger an immediate dial for dormant clients. For previously authenticated clients, a nudge can trigger a dial without resetting the retry attempt; authentication resets the attempt count. Tests cover these behaviors and retry behavior after a dormant client is replaced.

Priority: Normal

Merge Risk: Minimal · up to 01f8c

Reconnect nudges retain backoff, while manual Connect still starts a fresh connection. No merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title is concise, specific, and accurately summarizes the main change: preserving reconnect backoff across foreground nudges for failing mobile hosts.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is complete and follows the required structure. It explains the user impact, implementation, motivation, linked issue, visual proof, testing, AI disclosure, platform considerations, ri…
Full details: Description check

Explanation

The description is complete and follows the required structure. It explains the user impact, implementation, motivation, linked issue, visual proof, testing, AI disclosure, platform considerations, risks, and checklist status. It also clearly states that physical-device testing was not performed and that the full test suite had environment-specific failures, despite the broad checklist item being checked.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 5 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5e1be61f-ddf9-41ea-900e-1951dc123048
Commits

Reviewing files that changed from the base of the PR and between ab50d78 and 8a2b06f.

Files selected for processing: 5
  • mobile/src/transport/direct-rpc-client.ts
  • mobile/src/transport/rpc-client-nudge-backoff.test.ts
  • mobile/src/transport/rpc-client-reconnect-schedule.ts
  • mobile/src/transport/rpc-client.test.ts
  • mobile/src/transport/socket-deadline-clock.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

…the retry limit

The attempt that reached the limit still armed the 60 s backoff step, which
re-armed itself every 60 s while the app was backgrounded and dialed again
as soon as it returned to the foreground. Move a never-connected host to its
slow retry on that failure; hosts that connected before keep the existing 90 s
timing.

Refs stablyai#13354

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@luben93

luben93 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 01f8c05: a never-connected host now moves to its slow retry on the failure that uses up the limit, so the 60 s step no longer re-arms in the background. Hosts that connected before keep the existing 90 s timing. Added a test that dials 13 times on the previous code and 12 on this one; pnpm check:changed passes.

tjonestj3 added a commit to tjonestj3/orca that referenced this pull request Nov 11, 2026
nwparker added a commit that referenced this pull request Nov 23, 2026
Use the dormant retry approach from #36352 for cold Tailnet endpoints, while keeping a direct retry available when the user opens the host. Coalesce repeated native callbacks over the cadence observed on iOS.

Co-authored-by: lucas persson <[email protected]>
nwparker added a commit that referenced this pull request Nov 23, 2026
…47217)

* fix(mobile): preserve direct reconnect backoff across network hints

* Preserve explicit retry from downloaded mobile pages

* Preserve fast recovery after a separate network change

* Retry once more when the network settles after a hint

* Let unreachable Tailscale hosts go quiet after retry exhaustion

Use the dormant retry approach from #36352 for cold Tailnet endpoints, while keeping a direct retry available when the user opens the host. Coalesce repeated native callbacks over the cadence observed on iOS.

Co-authored-by: lucas persson <[email protected]>

* Keep resume and manual recovery responsive under retry backoff

* Give dormant hosts a bounded retry when the app returns

---------

Co-authored-by: lucas persson <[email protected]>

This branch has not been deployed

No deployments
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