Skip to content

Route macOS beta to development backends - #7014

Merged
kodjima33 merged 1 commit into
mainfrom
macos-beta-dev-backend
Apr 26, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
macos-beta-dev-backend

Conversation

@kodjima33

Copy link
Copy Markdown
Collaborator

Summary

  • route production-bundle macOS beta/staging channel to dev Python and Rust backends
  • preserve stable production routing and local/dev env override behavior
  • make Chat Lab ratings use APIClient baseURL instead of hardcoded prod URL
  • add routing coverage for beta/stable backend selection and request body capture

Verification

  • Mac mini: swift test --filter APIClientRoutingTests (43 tests, 0 failures)
  • git diff --check
  • swift format lint desktop/Desktop/Sources/DesktopBackendEnvironment.swift

Data stores

Dev backend deployments already point at production data stores: GOOGLE_CLOUD_PROJECT=based-hardware for Python and FIREBASE_PROJECT_ID=based-hardware for Rust.

@greptile-apps

greptile-apps Bot commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces DesktopBackendEnvironment, a new routing layer that directs production-bundle macOS beta/staging builds to development Python and Rust backends while keeping stable builds on production. It also fixes ChatLabView to use APIClient.shared.baseURL instead of a hardcoded production URL, and adds 5 new unit tests covering the beta/stable selection logic.

All findings are P2. The most actionable is testBaseURLDefaultsToPythonBackend — it creates a real APIClient and asserts the production URL after unsetting the env var, but the new routing layer will return the dev URL if the test binary resolves to the production bundle ID with a beta channel in UserDefaults. The new overloaded test helpers in the same file are the right pattern to use here.

Confidence Score: 4/5

Safe to merge; all findings are non-blocking P2 style/quality concerns with no runtime breakage on the happy path

No P0 or P1 issues found. The routing logic is correct, well-tested, and the initialization ordering in AppState.init guarantees UserDefaults is seeded before any backend URL is resolved at runtime. Score is 4 rather than 5 due to the environment-sensitive test and the static-let divergence in TranscriptionService.

desktop/Desktop/Tests/APIClientRoutingTests.swift (environment-sensitive test) and desktop/Desktop/Sources/TranscriptionService.swift (static-let URL capture)

Important Files Changed

Filename Overview
desktop/Desktop/Sources/DesktopBackendEnvironment.swift New file centralising beta/stable backend routing logic; well-structured with testable overloads, but silently ignores env-var overrides on beta builds
desktop/Desktop/Sources/APIClient.swift Simplified to delegate URL resolution to DesktopBackendEnvironment; computed properties re-evaluate on every call correctly
desktop/Desktop/Sources/AppBuild.swift Adds isProductionBundle and prepareUpdateChannelForBackendRouting() to seed UserDefaults before backend URL resolution runs
desktop/Desktop/Sources/AppState.swift Correctly calls prepareUpdateChannelForBackendRouting() before loadEnvironment(), and applyReleaseChannelDefaults() at the end of loadEnvironment()
desktop/Desktop/Sources/TranscriptionService.swift static let pythonBackendBaseURL is permanently cached on first access; diverges from APIClient's computed-property approach and may resolve before channel is seeded
desktop/Desktop/Sources/MainWindow/Pages/ChatLabView.swift Replaces hardcoded production URL with APIClient.shared.baseURL; correctly awaits the actor-isolated property
desktop/Desktop/Sources/ProactiveAssistants/ProactiveAssistantsPlugin.swift Adds applyReleaseChannelDefaults() after .env file loading so dev URLs override any file-sourced values on beta builds; idempotent
desktop/Desktop/Tests/APIClientRoutingTests.swift Adds good beta/stable routing unit tests, but testBaseURLDefaultsToPythonBackend can return dev URL when run with production bundle + beta UserDefaults state

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[AppState.init] --> B[prepareUpdateChannelForBackendRouting]
    B --> C{isProductionBundle?}
    C -- No --> D[Skip — non-prod bundle]
    C -- Yes --> E[migrateBetaChannelOverwrite]
    E --> F[syncUpdateChannelOnFirstLaunch if nil]
    F --> G[loadEnvironment]
    G --> H[Load .env files via setenv]
    H --> I[applyReleaseChannelDefaults]
    I --> J{shouldUseDevelopmentBackends?}
    J -- bundleId==prod AND channel==beta/staging --> K[setenv OMI_PYTHON_API_URL = api.omiapi.com]
    J -- stable OR non-prod bundle --> L[No override — keep existing env vars]
    K --> M[APIClient.baseURL computed each call]
    L --> M
    M --> N{shouldUseDevelopmentBackends?}
    N -- Yes --> O[https://api.omiapi.com/]
    N -- No --> P{OMI_PYTHON_API_URL set?}
    P -- Yes --> Q[Use env var URL]
    P -- No --> R[https://api.omi.me/]
    TS[TranscriptionService] --> S[pythonBackendBaseURL static let captured ONCE]
    S --> N
Loading

Comments Outside Diff (1)

  1. desktop/Desktop/Tests/APIClientRoutingTests.swift, line 116-121 (link)

    P2 Test is environment-sensitive after routing change

    testBaseURLDefaultsToPythonBackend unsets OMI_PYTHON_API_URL then asserts production URL, but APIClient.baseURL now calls DesktopBackendEnvironment.pythonBaseURL() which checks shouldUseDevelopmentBackends. If the test binary resolves to com.omi.computer-macos (the bundleIdentifier fallback when Bundle.main.bundleIdentifier is nil) and UserDefaults contains update_channel = "beta", the call returns "https://api.omiapi.com/" instead, failing the assertion. The companion tests for beta/stable correctly use the overloaded pythonBaseURL(useDevelopmentBackends:environmentValue:) to avoid this — this one should too.

Reviews (1): Last reviewed commit: "Route macOS beta to development backends" | Re-trigger Greptile

}
return "https://api.omi.me/"
}()
private static let pythonBackendBaseURL: String = DesktopBackendEnvironment.pythonBaseURL()

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.

P2 Static-let URL is captured once and never refreshes

pythonBackendBaseURL is a static let, so it is evaluated lazily on first access and permanently cached for the process lifetime. APIClient.baseURL is a computed var that re-evaluates DesktopBackendEnvironment.pythonBaseURL() on every call, but TranscriptionService will silently keep whatever URL was resolved at first use. If anything accesses this property before AppBuild.prepareUpdateChannelForBackendRouting() writes to UserDefaults, the wrong backend URL is permanently baked in for the session. Consider making this a computed property to mirror APIClient.

Comment on lines +23 to +35
static func pythonBaseURL(
environmentValue: String? = currentEnvironmentValue("OMI_PYTHON_API_URL")
) -> String {
pythonBaseURL(
useDevelopmentBackends: shouldUseDevelopmentBackends,
environmentValue: environmentValue
)
}

static func pythonBaseURL(useDevelopmentBackends: Bool, environmentValue: String?) -> String {
if useDevelopmentBackends {
return developmentPythonAPIURL
}

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.

P2 Env-var override is silently ignored on beta builds

When useDevelopmentBackends == true, the environmentValue parameter is discarded before it is inspected. A developer running a production beta bundle who sets OMI_PYTHON_API_URL=http://localhost:8080 in .env will be silently routed to api.omiapi.com instead. The PR description says it "preserves local/dev env override behavior" but that only applies to stable builds. A log message when a non-empty env var is overridden would make this easier to diagnose.

@kodjima33
kodjima33 merged commit 60046c1 into main Apr 26, 2026
3 checks passed
@kodjima33
kodjima33 deleted the macos-beta-dev-backend branch April 26, 2026 00:20
beastoin added a commit that referenced this pull request Apr 26, 2026
## Summary
- Add 5 env vars present in prod but missing from dev backend-listen
- Variables: `GROQ_API_KEY`, `OPENROUTER_API_KEY`, `RAPID_API_HOST`,
`RAPID_API_KEY`, `CONVERSATION_SUMMARIZED_APP_IDS`
- Add secret key mappings to ExternalSecret values (backend-secrets
chart) for GCP SM → K8s sync
- Use `secretKeyRef` pattern in backend-listen chart (consistent with
existing secret refs)

## GCP Secret Manager status (based-hardware-dev)
| Secret | Status |
|--------|--------|
| GROQ_API_KEY | Created with `PLACEHOLDER_GROQ_API_KEY` value |
| OPENROUTER_API_KEY | Already existed (real value, 73 chars) |
| RAPID_API_HOST | Already existed (real value, 28 chars) |
| RAPID_API_KEY | Already existed (real value, 50 chars) |
| CONVERSATION_SUMMARIZED_APP_IDS | Created with
`PLACEHOLDER_CONVERSATION_SUMMARIZED_APP_IDS` value |

## Context
Beta users are routed to dev backends (PR #7014). Env var audit found
these 5 vars exist in prod backend-listen but are absent in dev GKE
deployment.

## Test plan
- [ ] Deploy backend-secrets chart first (syncs new keys to K8s secret)
- [ ] Deploy backend-listen chart (pods pick up new env vars)
- [ ] Verify pods start without CrashLoopBackOff
- [ ] Replace 2 placeholder values (GROQ_API_KEY,
CONVERSATION_SUMMARIZED_APP_IDS) with real values when available

🤖 Generated with [Claude Code](https://claude.com/claude-code)
kodjima33 added a commit that referenced this pull request Apr 26, 2026
…ase accounts (#7040)

## Problem

Production-bundle macOS users on the `beta` update channel are landing
in **fresh empty Firebase accounts** after sign-in. Concrete repro:
signing in as `[email protected]` on build `0.11.365` creates new
Firebase user `caLCFj7IisV85UX9XrrV1aVf3pk1` (no email, no providers,
created today) instead of returning the existing
`viUv7GtdoHXbK1UBCDlPuTDuPgJ2` that owns all of kodjima33's data.
Reported as widespread across beta users.

Both UIDs are in the same `based-hardware` Firebase project (`aud:
based-hardware`, `iss: https://securetoken.google.com/based-hardware`),
so it's not a project mismatch — the dev auth flow is minting tokens for
new UIDs instead of linking to existing ones.

## Cause

PR #7014 (`60046c19f`) routed `com.omi.computer-macos` clients on the
`beta` channel to:
- Python: `https://api.omiapi.com/`
- Rust: `https://desktop-backend-dt5lrfkkoa-uc.a.run.app/`

The `OMI_AUTH_URL` is unchanged (still prod `omi-desktop-auth`), but
downstream calls through the dev Python backend during sign-in result in
a different uid being returned to the client. The empty user record on
the new uid (no email, no providers) indicates the path goes through
`signInWithCustomToken` for a freshly-generated uid rather than
`signInWithIdp` linking by email.

## Fix

Surgical: `shouldUseDevelopmentBackends` now always returns `false`, so
prod-beta clients keep talking to prod backends. The routing scaffolding
(`DesktopBackendEnvironment`, env-var override paths,
`applyReleaseChannelDefaults`) is left in place for when the auth-side
issue is properly diagnosed and fixed — at that point this can be
reverted.

A full `git revert` of #7014 conflicts with newer changes to
`TranscriptionService.swift` and others; this 1-line approach gets the
same effect with no merge surgery.

## Verification

- [ ] Codemagic build succeeds
- [ ] Mac mini smoke test: sign in as kodjima33 on the new build,
confirm uid = `viUv7GtdoHXbK1UBCDlPuTDuPgJ2` and data loads
- [ ] Confirm `APIClient.baseURL` resolves to `https://api.omi.me/` for
prod-beta
- [ ] Confirm `rustBackendURL` resolves to the prod
`desktop-backend-hhibjajaja-uc.a.run.app` (or the env-var override)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
pull Bot pushed a commit to Mu-L/omi that referenced this pull request Apr 26, 2026
…irebase accounts

PR BasedHardware#7014 routed prod-bundle beta-channel users to api.omiapi.com + the dev
desktop-backend, with the assumption that both would still read prod
Firestore. In practice, signing in via the dev path lands users in fresh
empty Firebase accounts (e.g. caLCFj7… instead of viUv7Gtdo… for
[email protected]) — so they sign in successfully but see zero data.

Surgical fix: make `shouldUseDevelopmentBackends` always return false so
prod-beta clients keep using prod backends. Routing scaffolding is left in
place for when the auth-side issue is fixed.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
…rdware#7029)

## Summary
- Add 5 env vars present in prod but missing from dev backend-listen
- Variables: `GROQ_API_KEY`, `OPENROUTER_API_KEY`, `RAPID_API_HOST`,
`RAPID_API_KEY`, `CONVERSATION_SUMMARIZED_APP_IDS`
- Add secret key mappings to ExternalSecret values (backend-secrets
chart) for GCP SM → K8s sync
- Use `secretKeyRef` pattern in backend-listen chart (consistent with
existing secret refs)

## GCP Secret Manager status (based-hardware-dev)
| Secret | Status |
|--------|--------|
| GROQ_API_KEY | Created with `PLACEHOLDER_GROQ_API_KEY` value |
| OPENROUTER_API_KEY | Already existed (real value, 73 chars) |
| RAPID_API_HOST | Already existed (real value, 28 chars) |
| RAPID_API_KEY | Already existed (real value, 50 chars) |
| CONVERSATION_SUMMARIZED_APP_IDS | Created with
`PLACEHOLDER_CONVERSATION_SUMMARIZED_APP_IDS` value |

## Context
Beta users are routed to dev backends (PR BasedHardware#7014). Env var audit found
these 5 vars exist in prod backend-listen but are absent in dev GKE
deployment.

## Test plan
- [ ] Deploy backend-secrets chart first (syncs new keys to K8s secret)
- [ ] Deploy backend-listen chart (pods pick up new env vars)
- [ ] Verify pods start without CrashLoopBackOff
- [ ] Replace 2 placeholder values (GROQ_API_KEY,
CONVERSATION_SUMMARIZED_APP_IDS) with real values when available

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
…irebase accounts

PR BasedHardware#7014 routed prod-bundle beta-channel users to api.omiapi.com + the dev
desktop-backend, with the assumption that both would still read prod
Firestore. In practice, signing in via the dev path lands users in fresh
empty Firebase accounts (e.g. caLCFj7… instead of viUv7Gtdo… for
[email protected]) — so they sign in successfully but see zero data.

Surgical fix: make `shouldUseDevelopmentBackends` always return false so
prod-beta clients keep using prod backends. Routing scaffolding is left in
place for when the auth-side issue is fixed.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
…ase accounts (BasedHardware#7040)

## Problem

Production-bundle macOS users on the `beta` update channel are landing
in **fresh empty Firebase accounts** after sign-in. Concrete repro:
signing in as `[email protected]` on build `0.11.365` creates new
Firebase user `caLCFj7IisV85UX9XrrV1aVf3pk1` (no email, no providers,
created today) instead of returning the existing
`viUv7GtdoHXbK1UBCDlPuTDuPgJ2` that owns all of kodjima33's data.
Reported as widespread across beta users.

Both UIDs are in the same `based-hardware` Firebase project (`aud:
based-hardware`, `iss: https://securetoken.google.com/based-hardware`),
so it's not a project mismatch — the dev auth flow is minting tokens for
new UIDs instead of linking to existing ones.

## Cause

PR BasedHardware#7014 (`60046c19f`) routed `com.omi.computer-macos` clients on the
`beta` channel to:
- Python: `https://api.omiapi.com/`
- Rust: `https://desktop-backend-dt5lrfkkoa-uc.a.run.app/`

The `OMI_AUTH_URL` is unchanged (still prod `omi-desktop-auth`), but
downstream calls through the dev Python backend during sign-in result in
a different uid being returned to the client. The empty user record on
the new uid (no email, no providers) indicates the path goes through
`signInWithCustomToken` for a freshly-generated uid rather than
`signInWithIdp` linking by email.

## Fix

Surgical: `shouldUseDevelopmentBackends` now always returns `false`, so
prod-beta clients keep talking to prod backends. The routing scaffolding
(`DesktopBackendEnvironment`, env-var override paths,
`applyReleaseChannelDefaults`) is left in place for when the auth-side
issue is properly diagnosed and fixed — at that point this can be
reverted.

A full `git revert` of BasedHardware#7014 conflicts with newer changes to
`TranscriptionService.swift` and others; this 1-line approach gets the
same effect with no merge surgery.

## Verification

- [ ] Codemagic build succeeds
- [ ] Mac mini smoke test: sign in as kodjima33 on the new build,
confirm uid = `viUv7GtdoHXbK1UBCDlPuTDuPgJ2` and data loads
- [ ] Confirm `APIClient.baseURL` resolves to `https://api.omi.me/` for
prod-beta
- [ ] Confirm `rustBackendURL` resolves to the prod
`desktop-backend-hhibjajaja-uc.a.run.app` (or the env-var override)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
kodjima33 added a commit that referenced this pull request May 10, 2026
## Summary

- Beta channel of the production bundle (`com.omi.computer-macos`) now
routes to the dev backend (`api.omiapi.com` Python + dev Cloud Run
desktop-backend), matching mobile's TestFlight → staging pattern.
- Stable channel and non-prod bundles are unchanged.
- New `OMI_FORCE_DEV_BACKENDS=1` env override lets a named test bundle
opt into dev backends without flipping its channel — handy for
side-by-side validation.

## Why this won't repeat the PR #7014 outage

PR #7014 (April 2026) was reverted because the dev backend was wired to
the `based-hardware-dev` Firebase project, so beta users signed in as
fresh empty UIDs (e.g. `caLCFj7…` instead of prod's `viUv7Gtdo…`). The
dev backend infra has since been moved onto prod Firebase. Verified
against the live deployments:

```
$ gcloud run services describe backend --project=based-hardware-dev …
  FIREBASE_PROJECT_ID = based-hardware
  FIREBASE_AUTH_DOMAIN = based-hardware.firebaseapp.com
  GOOGLE_CLOUD_PROJECT = based-hardware
  FIREBASE_API_KEY = AIzaSyA88g…   (matches prod)
  SERVICE_ACCOUNT_JSON.project_id = based-hardware
  client_email = [email protected]

$ gcloud run services describe desktop-backend --project=based-hardware-dev …
  FIREBASE_PROJECT_ID = based-hardware
  FIREBASE_API_KEY = AIzaSyA88g…   (matches prod)
```

So custom tokens minted by the dev backend resolve to the **same UID**
the user has on prod, and reads/writes hit prod Firestore.

## Test plan

- [x] `swift test --filter APIClientRoutingTests` (46/46 passing)
- [ ] Codemagic builds Beta DMG from this branch on merge
- [ ] Install Beta DMG on Mac mini, sign in with [email protected]
- [ ] Confirm `auth_userId` defaults shows the prod UID (`viUv7Gtdo…`),
not a fresh one
- [ ] Confirm existing conversations + memories load
- [ ] Record a new conversation; confirm it appears in prod Firestore
for the prod UID
- [ ] Confirm stable channel of the same prod bundle keeps using
`api.omi.me`

🤖 Generated with [Claude Code](https://claude.com/claude-code)
pull Bot pushed a commit to codingwatching/omi that referenced this pull request May 11, 2026
Beta channel of the production bundle now routes to the development
backend (api.omiapi.com + the dev Cloud Run desktop-backend). The dev
backend is configured to use prod Firebase (project_id=based-hardware,
prod service account, FIREBASE_API_KEY=AIzaSyA88g...), so custom tokens
it mints resolve to the same UID users have on prod — reads/writes hit
prod Firestore. Same pattern mobile TestFlight uses for staging.

This redoes PR BasedHardware#7014, which was reverted in April because dev backend
was on the based-hardware-dev Firebase project at the time, so beta
users landed in fresh empty Firebase accounts. The dev backend's
SERVICE_ACCOUNT_JSON, FIREBASE_API_KEY, FIREBASE_PROJECT_ID, and
FIREBASE_AUTH_DOMAIN have all since been moved onto prod Firebase —
verified via `gcloud run services describe backend
--project=based-hardware-dev`. The Rust desktop-backend in the dev GCP
project has the matching FIREBASE_PROJECT_ID=based-hardware and the
same FIREBASE_API_KEY as prod.

Also adds an OMI_FORCE_DEV_BACKENDS env override so a named test bundle
(com.omi.omi-*) can opt into dev backends without flipping its channel
or bundle ID — useful for validating routing on a side-by-side build
before shipping to actual beta users.

Stable channel and non-prod bundles still default to prod backends or
their configured OMI_PYTHON_API_URL / OMI_DESKTOP_API_URL.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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