Skip to content

feat(desktop): remote-triggered onboarding rerun for users who never got going - #12597

Merged
kodjima33 merged 1 commit into
mainfrom
kodjima33/onboarding-rerun-flag
Sep 2, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
kodjima33/onboarding-rerun-flag

Conversation

@kodjima33

@kodjima33 kodjima33 commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Remote-triggered onboarding rerun for users who never got going. The PostHog flag desktop-onboarding-rerun carries a rule payload:

{"generation":1,"min_account_age_days":7,"active_questions_30d":8}

Each client evaluates the rule locally when flags arrive and again when the session becomes authenticated (flags usually land before the stored session is restored). Eligible = signed in, onboarding completed, account older than min_account_age_days, and NOT active, where active = at least active_questions_30d questions in the last 30 days (backend chat history; local lifetime counter as fallback) with both Screen Recording and Microphone granted. Eligible clients rerun onboarding in place (same steps as Reset Onboarding, no relaunch), once per generation; the generation is recorded before the reset so a flag left on never loops. Account age comes from Firebase auth metadata, then the backend profile created_at, then the local data folder's creation date (a lower bound). Because the rule lives on the client, every install that launches again after updating is covered (39k macOS users all-time), not only the ~4k PostHog saw this month.

DEBUG builds accept OMI_ONBOARDING_RERUN_PAYLOAD (the JSON the flag would carry) so the path can be exercised on a dev bundle without a live flag; release builds only read PostHog.

Verification

omi-doors dev bundle (previously onboarded, signed in as Nik) with the payload in the bundle .env:

  • First attempt exposed a real race: flags arrived before auth restored → "recorded without rerun (not onboarded)" burned the generation. Fixed: signed-out evaluations record nothing, and a session observer re-evaluates on authentication.
  • After the fix: log shows OnboardingRerun: generation 2 — rerunning onboarding, profile=Profile(accountAgeDays: 0, questionsLast30Days: 26, screenRecordingGranted: true, microphoneGranted: true) followed by DesktopHomeView: resetOnboardingRequested; hasCompletedOnboarding cleared; omi-ctl state reports appState: onboarding; the window shows the first onboarding step (screenshot attached to the review).
  • Relaunched the bundle: no second rerun (generation already applied), app stays in onboarding.
  • Unit tests: OnboardingRerunPolicyTests (low-usage reruns; active with both permissions skipped; heavy user missing a permission reruns; young/unknown age skipped unless the rule has no minimum; once per generation; payload parsing).

Invariants: none matched.
Failure-Class: none

Review in cubic

…got going

PostHog flag desktop-onboarding-rerun carries {generation, min_account_age_days,
active_questions_30d}. Each client evaluates it locally at flag delivery: signed in,
onboarding completed, account older than the minimum, and not active (fewer than the
threshold of questions in 30 days, or Screen Recording / Microphone not granted) reruns
onboarding once per generation via the same steps as Reset Onboarding, without a relaunch.

Failure-Class: none

@cubic-dev-ai cubic-dev-ai 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.

3 issues found across 5 files

Confidence score: 2/5

  • OnboardingRerunPolicy.swift can apply the previous session’s profile to a newly signed-in account when currentProfile() is awaiting network results, potentially resetting onboarding for the wrong user — capture the owner before awaiting and verify it is unchanged before applying the result.
  • OnboardingRerunPolicy.swift does not clear the setup-owned onboarding kernel journal, although resetOnboardingAndRestart in AppState+SystemActions.swift does, so remote reruns may leave stale onboarding state behind — make the remote path mirror the manual reset cleanup.
  • OnboardingRerunPolicy.swift limits questionsInLast30Days to the newest 200 messages, which can miss qualifying older questions within the 30-day window for active users — paginate the message query or use a server-side time-bounded count.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="desktop/macos/Desktop/Sources/Onboarding/OnboardingRerunPolicy.swift">

<violation number="1" location="desktop/macos/Desktop/Sources/Onboarding/OnboardingRerunPolicy.swift:144">
P1: When the account changes while `currentProfile()` is awaiting network results, this evaluation can reset onboarding for the newly signed-in account using the previous session's profile. Capture the owner before the await, pass it through the profile requests, and re-check it before applying the generation; otherwise the suppressed follow-up evaluation cannot reliably recover.</violation>

<violation number="2" location="desktop/macos/Desktop/Sources/Onboarding/OnboardingRerunPolicy.swift:180">
P2: The remote rerun does not clear the setup-owned onboarding kernel journal, unlike the manual Reset Onboarding it claims to mirror. `resetOnboardingAndRestart` (AppState+SystemActions.swift) clears `ChatProvider.clearOnboardingJournal()` (with the comment "A re-walkthrough must never mutate the user's normal local or backend chat history") before relaunching. This path posts `.resetOnboardingRequested`, clears persisted keys, and clears `OnboardingChatPersistence`, but never clears the journal, and because it does not relaunch, the in-memory `ChatProvider` stays in its completed state. The re-walkthrough's setup-owned conversation state can therefore be left in place / not isolated the way the manual reset's is.</violation>

<violation number="3" location="desktop/macos/Desktop/Sources/Onboarding/OnboardingRerunPolicy.swift:212">
P2: `questionsInLast30Days` counts only within the newest 200 messages returned by `getMessages(limit: 200)`. For a user with more than 200 total messages, questions older than the 200-message window but still inside the 30-day cutoff are silently dropped, which can undercount 30-day activity and wrongly mark an actually-active user as inactive (skipping the active exemption and forcing a rerun). The 30-day count should come from the full 30-day window (e.g. use the backend's created-at query or paginate) rather than a fixed 200-row slice.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

}
evaluating = true
defer { evaluating = false }
let profile = await currentProfile()

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: When the account changes while currentProfile() is awaiting network results, this evaluation can reset onboarding for the newly signed-in account using the previous session's profile. Capture the owner before the await, pass it through the profile requests, and re-check it before applying the generation; otherwise the suppressed follow-up evaluation cannot reliably recover.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/Onboarding/OnboardingRerunPolicy.swift, line 144:

<comment>When the account changes while `currentProfile()` is awaiting network results, this evaluation can reset onboarding for the newly signed-in account using the previous session's profile. Capture the owner before the await, pass it through the profile requests, and re-check it before applying the generation; otherwise the suppressed follow-up evaluation cannot reliably recover.</comment>

<file context>
@@ -0,0 +1,224 @@
+    }
+    evaluating = true
+    defer { evaluating = false }
+    let profile = await currentProfile()
+    guard
+      let generation = OnboardingRerunPolicy.generationToApply(
</file context>

log("OnboardingRerun: account age from local data folder (\(ageDays ?? -1)d)")
}
var questions = 0
if let messages = try? await APIClient.shared.getMessages(limit: 200) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: questionsInLast30Days counts only within the newest 200 messages returned by getMessages(limit: 200). For a user with more than 200 total messages, questions older than the 200-message window but still inside the 30-day cutoff are silently dropped, which can undercount 30-day activity and wrongly mark an actually-active user as inactive (skipping the active exemption and forcing a rerun). The 30-day count should come from the full 30-day window (e.g. use the backend's created-at query or paginate) rather than a fixed 200-row slice.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/Onboarding/OnboardingRerunPolicy.swift, line 212:

<comment>`questionsInLast30Days` counts only within the newest 200 messages returned by `getMessages(limit: 200)`. For a user with more than 200 total messages, questions older than the 200-message window but still inside the 30-day cutoff are silently dropped, which can undercount 30-day activity and wrongly mark an actually-active user as inactive (skipping the active exemption and forcing a rerun). The 30-day count should come from the full 30-day window (e.g. use the backend's created-at query or paginate) rather than a fixed 200-row slice.</comment>

<file context>
@@ -0,0 +1,224 @@
+      log("OnboardingRerun: account age from local data folder (\(ageDays ?? -1)d)")
+    }
+    var questions = 0
+    if let messages = try? await APIClient.shared.getMessages(limit: 200) {
+      questions = OnboardingRerunPolicy.questionsInLast30Days(messages)
+    } else {
</file context>

NotificationCenter.default.post(name: .resetOnboardingRequested, object: nil)
OnboardingFlow.clearPersistedState(in: defaults)
defaults.removeObject(forKey: .hasCompletedOnboarding)
OnboardingChatPersistence.clear()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: The remote rerun does not clear the setup-owned onboarding kernel journal, unlike the manual Reset Onboarding it claims to mirror. resetOnboardingAndRestart (AppState+SystemActions.swift) clears ChatProvider.clearOnboardingJournal() (with the comment "A re-walkthrough must never mutate the user's normal local or backend chat history") before relaunching. This path posts .resetOnboardingRequested, clears persisted keys, and clears OnboardingChatPersistence, but never clears the journal, and because it does not relaunch, the in-memory ChatProvider stays in its completed state. The re-walkthrough's setup-owned conversation state can therefore be left in place / not isolated the way the manual reset's is.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/Onboarding/OnboardingRerunPolicy.swift, line 180:

<comment>The remote rerun does not clear the setup-owned onboarding kernel journal, unlike the manual Reset Onboarding it claims to mirror. `resetOnboardingAndRestart` (AppState+SystemActions.swift) clears `ChatProvider.clearOnboardingJournal()` (with the comment "A re-walkthrough must never mutate the user's normal local or backend chat history") before relaunching. This path posts `.resetOnboardingRequested`, clears persisted keys, and clears `OnboardingChatPersistence`, but never clears the journal, and because it does not relaunch, the in-memory `ChatProvider` stays in its completed state. The re-walkthrough's setup-owned conversation state can therefore be left in place / not isolated the way the manual reset's is.</comment>

<file context>
@@ -0,0 +1,224 @@
+    NotificationCenter.default.post(name: .resetOnboardingRequested, object: nil)
+    OnboardingFlow.clearPersistedState(in: defaults)
+    defaults.removeObject(forKey: .hasCompletedOnboarding)
+    OnboardingChatPersistence.clear()
+  }
+
</file context>

@kodjima33
kodjima33 merged commit b97e7ce into main Sep 2, 2026
26 of 29 checks passed
@kodjima33
kodjima33 deleted the kodjima33/onboarding-rerun-flag branch September 2, 2026 06:11
Git-on-my-level added a commit that referenced this pull request Sep 3, 2026
…io NSException (#12656)

## What changed and why

Two independent production reliability fixes.

**Mobile — false `Recording Start Failed` telemetry.** The `Recording
Start Failed` / `Recording Started` events shipped 2026-08-31 in #11539.
On 2026-09-02 PostHog showed 247 `Recording Start Failed` events (93
users, all `failure_class=capture_unavailable`) against 157 `Recording
Started` (58 users). Failures outnumbering starts is impossible for a
real failure rate.

Cause: `streamDeviceRecording` called `_recordingTelemetry.prepare(...)`
unconditionally, then emitted `capture_unavailable` whenever the start
did not reach `deviceRecord`. HomePage calls this with `device == null`
on every entry as a check-only path, so every home-page entry with no
pendant connected was counted as a failed start.

A no-device / check-only call now skips `prepare()` and does not emit
start-failed. A real device start (a device was passed, or a recording
device is already set) that does not reach `deviceRecord` still emits
`capture_unavailable`.

**macOS — onboarding sound engine crash.** Sentry `OMI-DESKTOP-4EK`,
title `com.apple.coreaudio.avfaudio: player did not see an IO cycle.`,
level fatal, `mechanism=nsexception`, `handled=no`. 25 distinct users
since 2026-08-24; 8 of them on 2026-09-02 while the flag-driven
onboarding rerun (#12597) pushed ~218 dormant users back through
onboarding. This is the only `AVAudioPlayerNode` usage in the onboarding
path.

`AVAudioPlayerNode.play()` raises that NSException when the engine is
not running or has not completed an IO cycle. Every
`scheduleBuffer`/`play()` now re-checks `engine.isRunning` on the audio
queue, is wrapped in the existing `ObjCExceptionCatcher`, and a caught
exception logs once then sets `isSilenced` so onboarding continues
without retrying in a loop. `rebuildAfterConfigurationChange` does not
play until the rebuilt engine is running.

## Product invariants affected

none

## How it was verified

### Mobile
```
cd app
flutter analyze lib/services/capture/capture_controller.dart lib/providers/capture_provider.dart
```
No issues found! (ran in 32.2s)

```
cd app
flutter analyze lib/services/capture/capture_controller.dart lib/providers/capture_provider.dart test/unit/recording_lifecycle_telemetry_test.dart test/providers/capture_provider_test.dart
```
3 pre-existing infos in `capture_provider_test.dart`
(`depend_on_referenced_packages`, two
`no_leading_underscores_for_local_identifiers`); 0 issues in the
production files.

```
cd app
flutter test test/unit/recording_lifecycle_telemetry_test.dart test/providers/capture_provider_test.dart
```
All 93 tests passed.

### macOS
```
cd desktop/macos
python3 scripts/dev-feedback.py --once swift 'OmiOnboardingSoundTests'
```
`OmiOnboardingSoundTests`: 17 tests, 0 failures. Iteration 1: PASS.

```
cd desktop/macos
python3 scripts/check_desktop_test_quality.py
./scripts/swiftlint-wrapper.sh lint
```
`check_desktop_test_quality.py`: OK (debt at or below baseline).
SwiftLint: 0 violations, 0 serious in 3052 files.

Did not exercise the onboarding cinematic in a named bundle: the crash
is an ObjC exception from `AVAudioPlayerNode.play()` when the engine has
no IO cycle, which the unit tests cannot drive. The decision guard is
covered by `OmiAVSoundPlayback.mayPlay`.

## Tests

- `app/test/unit/recording_lifecycle_telemetry_test.dart`: `failStart`
without `prepare` emits nothing; a prepared device start still emits
`capture_unavailable`.
- `app/test/providers/capture_provider_test.dart`: homepage no-device
`streamDeviceRecording` emits no events; a requested device that cannot
reach `deviceRecord` emits `capture_unavailable`.
- `desktop/macos/Desktop/Tests/OmiOnboardingSoundTests.swift`: `mayPlay`
is false when the engine is not running or the output is silenced.

## Failure class (fixes)

Failure-Class: none

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/12656?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
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