Skip to content

app(local_dev): wait for the dev stack at launch instead of failing behind the Local Network prompt - #26672

Merged
Git-on-my-level merged 4 commits into
mainfrom
dev-stack/local-dev-reachability
Nov 29, 2026
Merged

Git-on-my-level merged 4 commits into
mainfrom
dev-stack/local-dev-reachability

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Summary

On a fresh local-dev install, the iPhone app's first launch failed while iOS showed the "find devices on your local network" prompt. Sometimes "Try again" never recovered. Everything here applies only to builds made with --dart-define=OMI_APP_PROFILE=local_dev, through the new kLocalDevProfileBuild constant. Release, production and normal dev-flavor builds are unchanged.

Cause

The cause was worked out from the code; there is no device log.

  • First launch: a reinstall keeps the Firebase sign-in in the keychain, so the app starts signed in. Its first backend requests run while the prompt is up and fail: the connectivity check's /v1/health, the token refresh against the Auth emulator, and then AccountDeletionGate's account-status request, which shows "Something went wrong".
  • Try Again not recovering: local-dev session recovery ran only from the single startup getIdToken() call. Normal requests refresh tokens on a different path. If Allow was tapped after that one attempt, every later request and every Try Again failed the same way.

Change

  • Startup wait (lib/startup/local_dev_reachability.dart, called from main.dart before the first backend or Auth request):
    • It probes the backend's /v1/health and the Auth emulator.
    • If both answer, nothing is shown. Otherwise a dev-only screen says "Can't reach the local dev stack at host:port…".
    • It retries every 2 s for 60 s, then offers manual Retry, and continues once the stack answers.
    • It is skipped for physical-qualification runs.
  • Auth recovery (auth_service.dart): every failed token refresh now schedules local-dev recovery, one at a time. Recovery keeps the signed-in uid instead of always switching to local-dev-user.

Tests

  • New tests:
    • local_dev_reachability_test.dart: wait screen, retry window, manual Retry, and a plain build without the define.
    • local_dev_reachability_probe_test.dart: loopback 200, 503 and connection refused.
    • local_dev_request_recovery_test.dart: recovery after every failed refresh, serialized; non-local-dev builds never recover this way.
  • A mutation check confirmed the recovery tests fail without the new line.
  • Full flutter test: 11,094 passed, 13 skipped. Format, analyze on changed files, and the UX contract check are clean.
  • Not yet verified on an iPhone. This is the next local phone run.

Failure-Class: none

UI-Evidence: none -- the only new screen is a dev-only wait screen compiled into OMI_APP_PROFILE=local_dev builds; no production UI changes

Product invariants

INV-DATA-1 (production-family data-plane continuity). app/lib/env/environment_profile.dart changed. The only addition is a read-only const bool kLocalDevProfileBuild = String.fromEnvironment('OMI_APP_PROFILE') == 'local_dev'.

  • It does not change which Firebase project, Auth authority or API endpoint any profile resolves to.
  • It does not alter AppEnvironmentProfile resolution.
  • It is false in every production-family artifact (Stable, Beta, TestFlight, Play Internal), none of which is built with that define.
  • The behavior it gates (the startup reachability wait, and local-dev session re-minting that keeps the signed-in uid) talks only to the local stack and the Firebase Auth emulator.

Review

One round. Luna found nothing blocking:

  • Gating requires the explicit local_dev define.
  • Recovery is serialized, keeps the uid, and keeps the original failure visible.
  • The wait has bounded auto-retry plus manual Retry, and leaves the three-boot recovery intact.

DeepSeek found one blocker and two high-severity issues. Commits 913085397d and 1168f50be5 fix them:

  • B1, the blocker: the wait replaced the whole app, so Android Emulator Acceptance (a local_dev release APK on 127.0.0.1, airplane mode) never reached first run. CI confirmed this on 3093f15. Now the gate waits only for non-loopback hosts. Loopback builds never probe and never show the screen; the test "CI's Android acceptance APK … waits for nothing" covers it. The screen also has Continue anyway, and once the stack answers it switches to "Starting Omi".
  • H1: a re-mint could undo a sign-out or an account switch. It now records the uid and session generation when it is scheduled, and checks them again inside the account-mutation queue, right before signInWithCustomToken.
  • H2: a re-mint never wrote tokenExpirationTime, so it kept re-triggering itself. It now writes it from getIdTokenResult(), with at most one attempt every 10 s.

After those fixes, the full hermetic flutter test passes: 11,108 passed, 13 skipped.

🤖 Generated with Claude Code

Git-on-my-level and others added 2 commits November 28, 2026 19:35
…ehind the Local Network prompt

A freshly installed local_dev build on an iPhone makes its first requests to
the Mac (backend health probe, Firebase Auth emulator token refresh, account
deletion status) while iOS is still showing the Local Network prompt. Those
requests fail, and the account check's failure leaves the user on an error
with Try Again.

- Startup (local_dev builds only) now waits for the backend's /v1/health and
  the Auth emulator before the first backend or Auth request. A dev-only
  screen names the unreachable host:port, retries every 2 s for 60 s, keeps a
  manual Retry, and continues on its own once the stack answers. When the
  stack answers at once, nothing is shown.
- Try Again could stay broken because the local-dev session re-mint ran only
  from getIdToken(), which startup calls once. Authenticated requests refresh
  through refreshIdToken() and never re-minted. In a local_dev build, every
  transient refresh failure now schedules the re-mint (one at a time), and the
  re-mint keeps the signed-in uid.

Gated on --dart-define=OMI_APP_PROFILE=local_dev (kLocalDevProfileBuild).
Production, mobile_beta and real-server dev builds are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T01:42:18.152440Z 1168f50 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Git-on-my-level
Git-on-my-level marked this pull request as draft November 29, 2026 00:39
Git-on-my-level and others added 2 commits November 28, 2026 19:42
…xpiry, and backs off

Review findings H1, H2 and L5 on the local-dev reachability change.

- H1: the uid and session generation are captured when the re-mint is
  scheduled. They are re-checked after the harness round trip and again
  inside the account-mutation queue, right before signInWithCustomToken. A
  sign-out or account switch that lands while the request is in flight
  (up to 16 s) now wins, instead of the old uid being signed back in.
- H2: a successful re-mint writes tokenExpirationTime from
  getIdTokenResult(), so the cached token no longer reads as expired and
  re-arms the refresh-then-re-mint cycle. Attempts are at most one per
  10 s, so a stack that is down does not spin.
- signInWithLocalDevToken and the re-mint share one harness step
  (_fetchLocalDevCustomToken). Tests inject that step and the Firebase
  sign-in step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nyway, say when connected

Review findings B1 and M1 on the local-dev reachability change.

- B1: the wait now applies only to stack endpoints on a non-loopback host.
  iOS's Local Network prompt never applies to loopback. CI's Android
  emulator acceptance APK (local_dev, empty API_BASE_URL, so 127.0.0.1:8000
  and emulator host 127.0.0.1) therefore boots straight to first-run as
  before. main.dart calls one guard, localDevEndpointsToAwait, and tests
  cover it with the profile and Env defaults that APK uses.
- A "Continue anyway" action lets a local_dev phone install start with the
  Mac off.
- M1: once the stack answers, or is skipped, the screen says "Starting Omi"
  for the rest of startup instead of "Can't reach".
- Cleanups: the two probes run in parallel, the unused attempts counter is
  gone, and the `!` on Env.apiBaseUrl is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level marked this pull request as ready for review November 29, 2026 01:37
@Git-on-my-level
Git-on-my-level merged commit d6d00bd into main Nov 29, 2026
55 checks passed
@Git-on-my-level
Git-on-my-level deleted the dev-stack/local-dev-reachability branch November 29, 2026 01:37

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1168f50be5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +253 to +255
static String waiting(String hostPort) =>
"Can't reach the local dev stack at $hostPort. Allow Local Network access if iOS asked; "
'this retries automatically.';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Localize the startup reachability screen

On a device configured for a non-English locale, this screen displays its connectivity instructions and recovery actions only in English. app/AGENTS.md requires all user-facing strings to use localization and provides no exception for local-dev builds. Add these messages through the localization tooling and resolve the device locale in this standalone startup surface; BootRecoveryApp already demonstrates localized copy before the main app's localization scope exists.

AGENTS.md reference: app/AGENTS.md:L121-L122

Useful? React with 👍 / 👎.

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