Repository navigation
fix(desktop): count a failed update check once, not once per Sparkle callback - #12269
Conversation
Every desktop CI lane (Static & Test Contracts, Release Compile, Build & Tests aggregate) has been red since main's d49f978 landed `var alertPresenter: any DesktopAlertPresenting = AppKitSheetAlertPresenter()`: the pinned Xcode 16.4 toolchain segfaults (signal 11) in silgen emitStoredPropertyInitialization while lowering that existential-erasure default initializer. Reproduced on main itself (d49f978, fb67ca9, 50cf064 all failed; d06e220 passed only because its desktop jobs were path-filter skipped) and on unrelated PRs (#12269, #12272), so this is not specific to this branch. Move the initializer from the stored-property default position into init(). Identical semantics on both toolchains - AppState is @mainactor with a single designated init, and the alert tests overwrite the presenter immediately after construction. Xcode 26.6 parses, swift-format lint passes, changelog gate passes. Failure-Class: none
|
CI unblocked: fixed the Xcode 16.4 compiler crash blocking every desktop PR (commit
Fix: declare the property without a default-value expression and assign Results on the new head:
Local verification: |
Every desktop CI lane (Static & Test Contracts, Release Compile, Build & Tests aggregate) has been red since main's d49f978 landed `var alertPresenter: any DesktopAlertPresenting = AppKitSheetAlertPresenter()`: the pinned Xcode 16.4 toolchain segfaults (signal 11) in silgen emitStoredPropertyInitialization while lowering that existential-erasure default initializer. Reproduced on main itself (d49f978, fb67ca9, 50cf064 all failed; d06e220 passed only because its desktop jobs were path-filter skipped) and on unrelated PRs (#12269, #12272), so this is not specific to this branch. Move the initializer from the stored-property default position into init(). Identical semantics on both toolchains - AppState is @mainactor with a single designated init, and the alert tests overwrite the presenter immediately after construction. Xcode 26.6 parses, swift-format lint passes, changelog gate passes. Failure-Class: none
Every desktop CI lane (Static & Test Contracts, Release Compile, Build & Tests aggregate) has been red since main's d49f978 landed `var alertPresenter: any DesktopAlertPresenting = AppKitSheetAlertPresenter()`: the pinned Xcode 16.4 toolchain segfaults (signal 11) in silgen emitStoredPropertyInitialization while lowering that existential-erasure default initializer. Reproduced on main itself (d49f978, fb67ca9, 50cf064 all failed; d06e220 passed only because its desktop jobs were path-filter skipped) and on unrelated PRs (#12269, #12272), so this is not specific to this branch. Move the initializer from the stored-property default position into init(). Identical semantics on both toolchains - AppState is @mainactor with a single designated init, and the alert tests overwrite the presenter immediately after construction. Xcode 26.6 parses, swift-format lint passes, changelog gate passes. Failure-Class: none
deda01a to
a0a8f72
Compare
…11454's contract (#12277) * chore(desktop): unbreak the local Swift build and formatter gate on Xcode 26 Two pre-existing blockers on `main` that fail the pre-push gate for any desktop PR when the local toolchain is newer than the pinned Xcode 16.4: - `AppState+Permissions.swift` has swift-format drift, and `desktop-swift-format-lint` runs `lint-scope` over every first-party Swift file. Formatter output only. - `AppState+Transcription.swift:848` captures `alertPresenter` implicitly in an escaping closure. Swift 6.2 (Xcode 26.x) rejects this; Xcode 16.4 accepts it. Writing `self.` is what the diagnostic asks for and is the same strong capture the implicit form already produced, so behavior is unchanged on both toolchains. Failure-Class: none * chore(desktop): dodge the Xcode 16.4 SILGen segfault on alertPresenter Every desktop CI lane (Static & Test Contracts, Release Compile, Build & Tests aggregate) has been red since main's d49f978 landed `var alertPresenter: any DesktopAlertPresenting = AppKitSheetAlertPresenter()`: the pinned Xcode 16.4 toolchain segfaults (signal 11) in silgen emitStoredPropertyInitialization while lowering that existential-erasure default initializer. Reproduced on main itself (d49f978, fb67ca9, 50cf064 all failed; d06e220 passed only because its desktop jobs were path-filter skipped) and on unrelated PRs (#12269, #12272), so this is not specific to this branch. Move the initializer from the stored-property default position into init(). Identical semantics on both toolchains - AppState is @mainactor with a single designated init, and the alert tests overwrite the presenter immediately after construction. Xcode 26.6 parses, swift-format lint passes, changelog gate passes. Failure-Class: none * test(desktop): enroll BYOK fingerprints so paywall/agent tests match #11454's contract #11454 replaced the old "all keys present in UserDefaults" check for isByokActive with a stricter one: the selected provider's *current* key must match a fingerprint already persisted via APIKeyService.persistEnrolledFingerprints (set by activateBYOK reconciliation after BYOKValidator confirms the key). Seven tests across BYOKPaywallTests and AgentRuntimeProcessTests still set up state the old way — raw UserDefaults keys, no enrollment — and started failing the moment CI could actually reach them (#12276): main's own contract job caught this on #11454 before merge, but a compiler crash landed 8 minutes earlier (tracked separately in #12275) blocked every real desktop Swift test run afterward, so it went unnoticed. This is a test-only fix that transcribes #11454's already-stated and already-tested enrollment contract into the tests that never learned about it; no Sources change. - BYOKPaywallTests: add `enroll(_:)`, calling `persistEnrolledFingerprints` with the SHA-256 fingerprint of the provider's current key, exactly as `activateBYOK` reconciliation would after successful validation. Five tests were asserting on raw key presence: testByokActiveRequiresSelectedLLMKey (needs a *second* enrollment after setAllBYOKKeys() rewrites openrouter's key and invalidates the first fingerprint), testBuildHeadersAttachSelectedLLMByokKey, testBuildHeadersSuppressesOnlyInvalidByokHeader, testPaywallFlagSuppressedWhenByokActive, and testRemovingDeepgramKeyLeavesSelectedLLMByokActive (both of the last two now select the provider explicitly rather than relying on legacy first-match inference, since every provider's key is set and the test must enroll the same provider it selects). - AgentRuntimeProcessTests: enroll the selected provider in testUsableByokEnvironmentIncludesAllKeysWhenAllProvidersAreUsable and testUsableByokEnvironmentSuppressesAllKeysWhenOneProviderIsKnownBad — usableBYOKEnvironment() gates on isByokActive before the CredentialHealthManager suppression these tests exercise. Both existing `defer` blocks now also save/restore the enrollment map. Not touched: testBuildHeadersCanExplicitlyExcludeByokKeys and testLowLevelTransportDefaultsToExcludingByokKeys currently pass vacuously — neither enrolls a provider, so isByokActive is false and headers come back nil regardless of includeBYOK. Flagging for whoever owns BYOK rather than fixing here, since giving them real coverage means deciding what "excluded despite being active" should assert, and that's a product call, not a mechanical transcription of #11454. No assertions were weakened or removed — every fix completes test setup to match the stated contract. testPaywallFlagSuppressedWhenByokActive is the only coverage that an enrolled BYOK user is never paywalled; it was made to pass by enrolling correctly, not by loosening what it checks. Fixes: #12276 Failure-Class: none --------- Co-authored-by: David Zhang <[email protected]>
…callback ## Why The 2026-08 macOS churn cohort analysis flagged `Update Check Failed` as ambient noise that dwarfs real updater failures (~42% of cohort users, ~17.5 events/user in three weeks), and adopted a standing guardrail to hand-exclude Sparkle code 2001 from every reliability analysis. The recorded cause was wrong, and the real one is a defect in this file. Code 2001 is `SUDownloadError`, not "no update available" (that is 1001, and `UpdateFailureDiagnostics.reason` already maps it to `.noUpdate` and suppresses the event). What actually inflates the event is that Sparkle re-delivers `didAbortWithError` for a single check — the tracker's own doc comment says so — and the legacy event has no guard against it. `Update Check Completed` is protected: `finishFailure` consumes the attempt identity, so a second callback returns nil and emits nothing. `Update Check Failed` fires straight from the delegate with no identity of its own, so one failed check is counted once per callback. PostHog, production namespace, 2026-08-18 → 2026-08-25: | build | `Update Check Failed` | `Update Check Completed` result=failed | | --- | --- | --- | | 0.12.187 | 1590 / 307 users | 506 / 160 users | | 0.12.208 | 141 / 36 users | 3 / 2 users | | 0.12.212 | 233 / 62 users | 11 / 6 users | | 0.12.213 | 52 / 27 users | 52 / 27 users | ## What changed `UpdateCheckAttemptTracker.isDuplicateOfLastTerminal(_:)` reports whether an abort is Sparkle re-delivering a terminal already closed for the same check (no active attempt, and the closed terminal's reason/domain/code/ NSURL code all match). `didAbortWithError` skips only the legacy analytics call in that case; the local log and the view-model state are untouched. The guard keys on the closed terminal rather than on "no active attempt", so an abort with nothing closed yet is still reported instead of being swallowed. No failure code is reclassified: 1003, 2001, 3000, 4005, 4007 and everything else still emit exactly as before, once. `Update Check Completed`, the authoritative metric, is unchanged. ## Proof `UpdaterViewModelTests` (12 tests pass locally): - `testRepeatedAbortForOneCheckIsRecognizedAsADuplicate` - `testDistinctAndUntrackedFailuresAreStillReported` — a different failure after a closed check, and a first-ever abort with nothing tracked, are both still reported - `testActiveCheckIsNeverTreatedAsADuplicate` `docs/release-health-metrics.md` records that pre-fix `Update Check Failed` volume is inflated and must not be compared across the boundary. Failure-Class: FC-same-subject-counted-once-per-evidence-source
a0a8f72 to
34c0c20
Compare
kodjima33
left a comment
There was a problem hiding this comment.
Desktop bug fix (owner-override): fixes duplicate Sparkle abort-callback analytics counting for Update Check Failed with a targeted dedupe guard, tests included, CI green. Merging.
## Defect
The 2026-08 macOS churn cohort analysis
(`omi-knowledge-base/projects/macos-churn-analysis/evidence/2026-08-26-macos-churn-cohort-analysis.md`)
records under "Methodology guardrails":
> Instrumentation known-broken: `App Startup Timing` (11 samples/7 users
cohort-wide; `had_unclean_shutdown` ~always true; implausible TTI
values)
and under "Engineering leads": *"no usable macOS startup-performance
signal exists."*
That is three separate defects, and the first one changes how the other
two should be read.
### 1. The event does not reach PostHog at all
`AnalyticsManager.trackStartupTiming` writes only a Sentry breadcrumb:
```swift
// Routed to Sentry as a breadcrumb (perf telemetry, not product analytics) so the data
// is attached to any same-session crash report without creating a per-launch analytics
// event.
```
PostHog, `$os = macOS`, 2026-08-18 → 2026-08-25:
| build | `App Startup Timing` samples | `App Launched` |
| --- | --- | --- |
| 0.12.187 | **0** | 4,380 |
| 0.12.213 | **0** | 1,188 |
| 0.12.144 | **0** | 667 |
| 0.11.420 | 7 | 64 |
| 0.11.360 | 6 | 26 |
Every 0.12.x build emits zero. The cohort's 11 samples are not a
sampling defect — they are the last stragglers of an event that was
retired from product analytics. So "the event rarely fires" is not the
finding; "the event was deliberately moved to Sentry and nobody noticed
the fleet metric died" is.
### 2. `had_unclean_shutdown` was a race, not a crash rate
`.omi_running` is created at the *end* of
`RewindDatabase.performInitialization()`. Seventeen storage actors call
`RewindDatabase.shared.initialize()` lazily, and any of them can beat
`ViewModelContainer.loadAllData()` to it — the code even documents this
("TierManager triggers init early"). Once the database is open,
`hadUncleanShutdown()` reads **this** session's flag and reports every
clean launch as a crash.
### 3. TTI measured the wrong interval
`timeToInteractive` started at `CFAbsoluteTimeGetCurrent()` on the first
line of `loadAllData()`, which runs long after `main()`. 11–131ms is a
correct measurement of the wrong thing.
## Fix
- **`AnalyticsManager.trackStartupTiming`** emits `App Startup Timing`
to PostHog again, **once per process** (`loadAllData` re-runs on an
owner switch, and that is not a launch). The Sentry breadcrumb stays, so
the numbers remain attached to a same-session crash report — Sentry
answers "what did this crash look like", PostHog answers "is startup
getting slower across the fleet", and only the second one was lost.
- **`RewindDatabase`** latches the unclean-shutdown verdict at the first
observation in the process, and `performInitialization()` latches it
from `previousCrashed` *before* writing this session's flag. The verdict
becomes a property of the process rather than of call order. `close()`
clears the latch so a user retarget re-observes for the user it opens.
- **`AppStartupTiming.processStartDate()`** reads
`kinfo_proc.kp_proc.p_starttime` — the kernel's exec stamp, before dyld
and before `main`. `time_to_interactive_ms` is measured from there, and
is **omitted rather than faked** when the lookup fails.
- The old measurement is kept under the name it deserves:
**`data_load_ms`**.
### Event shape change
```
db_init_ms unchanged
data_load_ms new — what time_to_interactive_ms used to measure
time_to_interactive_ms same name, now measured from kernel process start
had_unclean_shutdown unchanged name, now actually about the previous session
database_init_failed unchanged
```
**`time_to_interactive_ms` keeps its name and changes meaning.**
Historical values are not comparable — but there are 11 of them and they
were wrong. Anything reading this property (the `omi-posthog-macos`
skill documents it) should treat 0.12.x-and-later as a new series.
This adds a per-launch PostHog event, which moves the legacy all-events
DAU insight (already labelled `[Legacy] DAU — all events
(instrumentation-sensitive)`). `Core Product DAU v1 — clean by platform`
is an explicit allowlist and is unaffected.
## Proof
`xcrun swift test --filter
"AppStartupTimingTests|RewindDatabaseLifecycleTests"` — 14 tests pass
locally.
- `testUncleanShutdownVerdictSurvivesTheDatabaseOpeningFirst` — opens
the database first, asserts this session's flag exists (so the test
cannot pass vacuously), then asserts the verdict is false.
**Mutation-checked: deleting the latch read makes this test fail with
the exact production symptom.**
- `testPreviousSessionCrashIsStillReportedAfterTheDatabaseOpens` — a
stale flag from a previous session still reports unclean, so the latch
cannot swallow a real crash.
- `AppStartupTimingTests` — the kernel stamp is read and precedes any
`Date()` our own code can take; conversion floors at zero across a
wall-clock adjustment; a failed lookup yields no measurement rather than
a fabricated one.
Local `make preflight` passes. Full Swift contract CI (~42 min) runs
after push; not claimed green here.
## Invariants
- INV-AUTH-1 — touched by path only (`RewindDatabase.swift` is in the
desktop session-truth glob). This PR adds a latched boolean about the
*previous* process's shutdown; it does not touch session death,
`invalidateSession`, `signOut()`, Firebase credentials, or owner
identity. `close()`/`configure()` semantics are unchanged apart from
clearing that boolean.
Failure-Class: FC-alert-never-provably-fired
Line-Count-Exception:
desktop/macos/Desktop/Sources/Rewind/Core/RewindDatabase.swift | 3481 ->
3508 | +27 lines: one optional `Bool` field, a latch read in
`hadUncleanShutdown()`, a latch write in `performInitialization()`, a
clear in `close()`, and the comments that explain the race. Splitting a
3.5k-line database class is the right cleanup but is not this telemetry
fix's job, and folding it in would bury a 4-line behavior change in a
move diff.
---
*First commit is unrelated housekeeping needed to get any desktop PR
past the local pre-push gate on Xcode 26.x (also in #12267 and #12269):
a swift-format drift already on `main` and one implicit `self` capture
that Swift 6.2 rejects and Xcode 16.4 accepts. It drops out on rebase
once any of the three lands.*
<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/12271?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. -->
Defect
The 2026-08 macOS churn cohort analysis (
omi-knowledge-base/projects/macos-churn-analysis/evidence/2026-08-26-macos-churn-cohort-analysis.md, "Methodology guardrails") records:The recorded cause is wrong, and correcting it changes what the fix should be.
Sparkle code 2001 is
SUDownloadError, not "no update available" — that isSUNoUpdateError(1001), whichUpdateFailureDiagnostics.reasonalready maps to.noUpdateand whichdidAbortWithErroralready suppresses. In PostHog (project 302298, production namespace) the 2001 corpus is dominated by anNSURLErrorDomainchain:-1009not-connected (28,802 events / 1,295 users, Aug 1–25), then-1005,-1001,-1003,-1004. Those are genuine "the check never reached the appcast" events, and the-1009half of them was already fixed on current builds by98f1ee7c7f/f34be3b3c1(2026-08-11):Update Check Completedreports them asresult = network_unavailableand the legacy event is suppressed.What is still broken is the volume itself. Sparkle re-delivers
didAbortWithErrorfor a single check — the tracker's own doc comment says so — and only the authoritative event is protected.UpdateCheckAttemptTracker.finishFailureconsumes the attempt identity, so a second callback returns nil and emits nothing.AnalyticsManager.shared.updateCheckFailed(diagnostics:)fires straight from the delegate with no identity of its own, so one failed check is counted once per callback.PostHog,
$app_namespace = com.omi.computer-macos, 2026-08-18 → 2026-08-25:Update Check FailedUpdate Check Completedresult=failedFix
UpdateCheckAttemptTracker.isDuplicateOfLastTerminal(_:)reports whether an abort is Sparkle re-delivering a terminal already closed for the same check: no active attempt, and the closed terminal'sreason,domain,codeandnsurlErrorCodeall match.didAbortWithErrorthen skips only the legacy analytics call; the local diagnostic log and the view-model state are untouched.The guard keys on the closed terminal rather than on "no active attempt", so an abort with nothing closed yet is still reported instead of being swallowed.
No failure code is reclassified. 1003, 2001, 3000, 4005, 4007 and everything else still emit exactly as before — once.
Update Check Completed, the authoritative metric defined indocs/release-health-metrics.md, is unchanged.Proof
UpdaterViewModelTests— 12 tests pass locally (xcrun swift test --filter UpdaterViewModelTests):testRepeatedAbortForOneCheckIsRecognizedAsADuplicate— the second abort for one closed check is a duplicate. This is the automatic-or-dead check: remove the guard and it fails.testDistinctAndUntrackedFailuresAreStillReported— a different failure after a closed check, and a first-ever abort with nothing tracked, are both still reported. This is the check that stops the fix from over-suppressing.testActiveCheckIsNeverTreatedAsADuplicate— a new admitted check owns its own terminal even when the failure repeats.docs/release-health-metrics.mdnow records that pre-fixUpdate Check Failedvolume is inflated and must not be compared across the boundary.Local
make preflightpasses. Full Swift contract CI (~42 min) runs after push; not claimed green here.Deliberately not in this PR
The remaining
Update Check Failedvolume on current builds is transient network (-1005,-1001,-1003,-1004: 1,824 of 2,016 events on 0.12.187+ over 7 days). Reclassifying those asnetwork_unavailablewould be a change to the metric definition —docs/release-health-metrics.mddeliberately keeps "timeouts, DNS, and server reachability errors" as failures so a real update-service outage is not masked. That is a decision for the metric owner, not a drive-by change, so it is written up as a separate shaped issue rather than folded in here.Invariants
desktop/macos/Desktop/Sources/UpdaterViewModel.swiftis in the updater/beta-identity glob). This PR changes only whether a duplicate Sparkle abort callback re-emits a legacy analytics event. Channel selection,allowedChannels(for:), bundle identity, and the Omi Beta side-by-side app are untouched.Failure-Class: FC-same-subject-counted-once-per-evidence-source
First commit is unrelated housekeeping needed to get any desktop PR past the local pre-push gate on Xcode 26.x (also in #12267): a swift-format drift already on
mainand one implicitselfcapture that Swift 6.2 rejects and Xcode 16.4 accepts. It drops out on rebase once either PR lands.