Skip to content

fix(relay): ask the page's own origin before saying the device is offline where no account service is - #4900

Merged
devswha merged 5 commits into
mainfrom
fix/shell-asks-own-origin
Nov 27, 2026
Merged

devswha merged 5 commits into
mainfrom
fix/shell-asks-own-origin

Conversation

@devswha

@devswha devswha commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Change

#4810 made a phone or browser that says navigator.onLine === false ask the account service before the screen believes it. A page with no account service still believed the flag alone: a hosted app built with OVIS_ACCOUNT_SERVICE_URL=off (no ovis-account-service meta) showed "This device is not connected to the internet" and refused every open on a working network whenever the browser said so.

  • src/lib/useOffline.ts: checkNetwork() now asks the page's own origin, /api/health, when there is no account service. The ask is the same one as before: one no-cors, no-store request, 8 s limit, and any answer counts. The service worker never answers /api/ (public/sw.js), so only the network can answer. Inside the phone app the flag still decides alone, as it did before this change: the app answers its own origin itself, with or without a network (Android's BundledShell serves every path of app.ovis.sh locally, 404 included), so its answer would prove nothing.
  • src/components/RelayShellScreens.tsx, src/components/ConnectStart.tsx: the hold a relay row puts on a click while the device says it is offline is now followUnlessOffline() in useOffline.ts. The accountless Your PCs row, which followed its link without asking, uses it too; with no answer, the offline line above the list says so (no new text). confirmOffline() now waits for an ask that replaced its own (Try again during a tap), so the tap goes on with that answer instead of staying shut.
  • src/conventions.test.ts: navigator.onLine is read only in src/lib/useOffline.ts and src/lib/ws.ts, so a new screen cannot go back to trusting the flag alone.

No new strings, controls, layout or HTTP/WS fields. What a "yes" from the page's own host proves is narrower than an answer from the account service: a network that reaches the shell's host and nothing else counts as online, and the open then fails with its own error. That is the same trade #4810 accepted for the account service.

Reviews

The omo gate review and one Codex adversarial review ran on 2a6471478c. This push (71a4ba7332) addresses them:

  • (HIGH, gate) The accountless Your PCs row opened without a fresh ask: it now holds the click as the account rows do. It never checked on main either.
  • (MEDIUM, gate and Codex) Try again during a tap left the PC shut: the tap now waits for the ask that replaced its own.
  • (LOW, Codex) The test's answers are now 404s, so any answer counts, as on a static host.

Not changed:

  • (MEDIUM, gate) The offline line shows before the first ask answers. That is how fix(relay): ask the account service before saying the device is offline #4810 already works for a page with an account service, and before this PR a page without one showed it with no ask at all.
  • (LOW) The fixture's origin is app.ovis.sh only. The conventions lock does not catch navigator["onLine"] or destructuring.

Validation

  • src/components/RelayShell.test.tsx: the fix(relay): ask the account service before saying the device is offline #4810 test now runs twice, once with an account service and once without. In the second run the screen asks https://app.ovis.sh/api/health. No answer (the ask's timeout) shows the offline line, Try again's answer takes it away, a tap asks again and opens the PC once it answers, and a later unanswered tap says the device is offline and opens nothing. "Says this device, in a browser, and opens nothing while it is offline" now stubs fetch as a dropped network: every ask fails, the screen asked only its own origin, and nothing opened. Both no-account-service cases fail on main (no ask is made). The account-service case and the two phone-app cases pass unchanged.
  • The new conventions test fails when a navigator?.onLine read is added to src/lib/nativeApp.ts. The first version of its pattern matched a prop named onLine in RepoDiff.tsx, so it is now navigator.onLine only.
  • New in the review round: "holds a tap on a paired PC of a page with no account..." fails on the previous RelayShellScreens.tsx, and the Try-again-during-a-tap step fails without the confirmOffline wait (in both runs of the fix(relay): ask the account service before saying the device is offline #4810 test).
  • bun test src/components/RelayShell.test.tsx src/conventions.test.ts src/lib/ws.test.ts src/components/ConnectStart*: 304 pass, 0 fail. bun run typecheck: ok.
  • bun run check fast: ok (typecheck, build, unit tests: 29428 pass, 0 fail).
  • Browser: relay-offline-reasons-regression, relay-shell-browser-qa, relay-e2e-regression, relay-first-link-regression, add-pc-more-relay-regression, relay-account-pcs-regression: 6/6 pass on bun run check run at 2a6471478c. At 71a4ba7332 all six pass too, two of them only on the second try: on the first, the test herdr answered "server is shutting down" before any page loaded.
  • Skipped: the Android emulator run with CDP forcing onLine=false. Every shipped phone build carries the account service meta, so this change does not run in the app (the app keeps the flag, see above).

…line where no account service is

A hosted shell built with OVIS_ACCOUNT_SERVICE_URL=off has no account service to ask, so it believed navigator.onLine === false alone and refused every open. checkNetwork now asks the page's own origin under /api/ (which the service worker does not answer) with the same one no-cors, no-store ask and 8 s limit. The phone app answers its own origin itself, so there the flag still stands.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Hosted apps without an account service now check their own health endpoint before deciding whether to open a PC, instead of relying only on the browser’s offline status.
    • If the health check fails or times out, the offline message is shown and relay-row navigation is blocked. Navigation proceeds once the check succeeds.

When the browser reports offline, checkNetwork now checks the configured account service or, for hosted apps without one, the page’s /api/health endpoint. Native apps without an account service make no request. Tests cover health-check results and relay navigation.

Changes: Offline network checks

Layer / File(s) Summary
Select and verify the health-check destination
src/lib/useOffline.ts, src/components/RelayShell.test.tsx, src/conventions.test.ts, changelog.d/offline-line-asks-own-origin.md
checkNetwork uses the configured account-service URL or the page-origin /api/health endpoint. A native app without an account service clears the answered state without a request. Tests cover both configurations, timeout behavior, offline messaging, and blocked relay navigation. A convention test restricts navigator.onLine reads in client code.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Merge Risk: Minimal · previous review 2a647

Hosted shells built without an account service now check their own origin before refusing to open a PC while the browser reports offline. Phone app behavior is unchanged. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: when no account service is configured, the relay asks the page's own origin before reporting the device offline. The changeset adds this /api/health check in src/lib/u…
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 follows the template. It has a Change section that explains the problem (a page without an account service trusted navigator.onLine alone), the resulting behavior (checkNetwork asks /a…
Full details: Title check

Explanation

The title names the main change: when no account service is configured, the relay asks the page's own origin before reporting the device offline. The changeset adds this /api/health check in src/lib/useOffline.ts, with matching tests and a convention test. The title is specific and matches the change.

Full details: Description check

Explanation

The description follows the template. It has a Change section that explains the problem (a page without an account service trusted navigator.onLine alone), the resulting behavior (checkNetwork asks /api/health, the phone app keeps the flag), and the files touched. It has a Validation section that lists the commands run (bun test subset, bun run typecheck, bun run check fast, six browser regression checks) and the one skipped check (Android emulator run) with a reason. The Change section does not link an issue, but this is a fix to an earlier PR (#4810) and the template asks for a link only for features, so this is not required here.

Finishing Touches

Generate unit tests (beta)

  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1d88a2d and 2a64714.

Files selected for processing: 4

  • changelog.d/offline-line-asks-own-origin.md
  • src/components/RelayShell.test.tsx
  • src/conventions.test.ts
  • src/lib/useOffline.ts

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

… wait for Try again's answer

Review round: the accountless Your PCs row followed its link without asking, and a tap whose ask Try again replaced read the old answer and stayed shut. The ConnectStart rows' hold moves to followUnlessOffline in useOffline.ts, which the accountless row uses too, and confirmOffline waits for the ask that replaced its own.
@devswha
devswha merged commit f496b06 into main Nov 27, 2026
15 checks passed
@devswha

devswha commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Merged through pr-merge at head 4f25fb665. Seen before the merge was asked for: required checks green, no unresolved thread, no conflict, no hold, main not red, no release in progress. CodeRabbit finished, with no review that names this head.

main had moved since the checks of 71a4ba733: pr-merge --update merged it in (d1c1355e6), and every required check was green at this head.

It waited in the merge queue behind #4896, whose change overlaps it, before it was updated.

omo gate review and one Codex adversarial review (gpt-6.2-sol-fast, xhigh) ran on 2a64714; the one fix round 71a4ba7 addresses the HIGH and both MEDIUMs (see PR body). Merged on the lane lead's go for plan step A1. CodeRabbit did not review this head.

@devswha
devswha deleted the fix/shell-asks-own-origin branch November 27, 2026 16:13
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