Skip to content

fix(desktop): count a failed update check once, not once per Sparkle callback - #12269

Merged
kodjima33 merged 1 commit into
mainfrom
telemetry/updater-ambient-network
Aug 27, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
telemetry/updater-ambient-network

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

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:

Update Check Failed code 2001 is ambient noise (Sparkle "no update" mis-logged; ~42% of cohort, ~17.5 events/user) — exclude it.

The recorded cause is wrong, and correcting it changes what the fix should be.

Sparkle code 2001 is SUDownloadError, not "no update available" — that is SUNoUpdateError (1001), which UpdateFailureDiagnostics.reason already maps to .noUpdate and which didAbortWithError already suppresses. In PostHog (project 302298, production namespace) the 2001 corpus is dominated by an NSURLErrorDomain chain: -1009 not-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 -1009 half of them was already fixed on current builds by 98f1ee7c7f / f34be3b3c1 (2026-08-11): Update Check Completed reports them as result = network_unavailable and the legacy event is suppressed.

What is still broken is the volume itself. Sparkle re-delivers didAbortWithError for a single check — the tracker's own doc comment says so — and only the authoritative event is protected. UpdateCheckAttemptTracker.finishFailure consumes 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:

build Update Check Failed Update Check Completed result=failed ratio
0.12.187 1,590 events / 307 users 506 / 160 3.1x
0.12.208 141 / 36 3 / 2 47x
0.12.212 233 / 62 11 / 6 21x
0.12.213 52 / 27 52 / 27 1.0x

Fix

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 and nsurlErrorCode all match. didAbortWithError then 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 in docs/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.md now records that pre-fix Update Check Failed volume is inflated and must not be compared across the boundary.

Local make preflight passes. Full Swift contract CI (~42 min) runs after push; not claimed green here.

Deliberately not in this PR

The remaining Update Check Failed volume 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 as network_unavailable would be a change to the metric definition — docs/release-health-metrics.md deliberately 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

  • INV-BETA-1 — touched by path only (desktop/macos/Desktop/Sources/UpdaterViewModel.swift is 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 main and one implicit self capture that Swift 6.2 rejects and Xcode 16.4 accepts. It drops out on rebase once either PR lands.

Review in cubic

Git-on-my-level added a commit that referenced this pull request Aug 27, 2026
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
@Git-on-my-level

Copy link
Copy Markdown
Member Author

CI unblocked: fixed the Xcode 16.4 compiler crash blocking every desktop PR (commit deda01affd)

Desktop Swift Release Compile / Static & Test Contracts / Build & Tests were all failing — but not on this PR's diff. Since d49f978512 (#11453), the pinned CI toolchain (Xcode 16.4 / Swift 6.1.2) crashed with signal 11 in SILGen emitStoredPropertyInitialization while lowering the stored-property default var alertPresenter: any DesktopAlertPresenting = AppKitSheetAlertPresenter() (AppState.swift:322). Xcode 26 compiles it fine, which is how it landed; main's own push runs have been failing on it since 18:14Z (the latest "success" is path-filter-skipped).

Fix: declare the property without a default-value expression and assign AppKitSheetAlertPresenter() as the first statement of AppState.init() — same initializer, same isolation, no behavior change on either toolchain; the crashing vpfi lowering path is simply never emitted.

Results on the new head:

  • Desktop Swift Release Compile ✓ passes (was the crash site at ~7 min; now completes the full release compile)
  • Desktop Swift Static & Test Contracts ✗ still fails — now on pre-existing BYOK test regressions from feat: simplify BYOK LLM provider setup #11454 (testUsableByokEnvironment…, BYOKPaywallTests), which fail identically on feat: simplify BYOK LLM provider setup #11454's own pre-merge head run (d0e3a4e, merged red at 18:22Z). That regression is out of scope for this telemetry PR and needs its own fix.
  • Desktop Swift Build & Tests ✗ fails only as the downstream gate of Contracts.

Local verification: git diff --check clean, xcrun swiftc -parse AppState.swift clean, swift-format lint-scope clean. No code from this PR's telemetry change was touched.

Git-on-my-level added a commit that referenced this pull request Aug 27, 2026
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
Git-on-my-level added a commit that referenced this pull request Aug 27, 2026
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
@Git-on-my-level
Git-on-my-level force-pushed the telemetry/updater-ambient-network branch from deda01a to a0a8f72 Compare August 27, 2026 02:08
Git-on-my-level added a commit that referenced this pull request Aug 27, 2026
…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
@Git-on-my-level
Git-on-my-level force-pushed the telemetry/updater-ambient-network branch from a0a8f72 to 34c0c20 Compare August 27, 2026 03:52

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@kodjima33
kodjima33 merged commit 994bc3b into main Aug 27, 2026
26 checks passed
@kodjima33
kodjima33 deleted the telemetry/updater-ambient-network branch August 27, 2026 14:40
Git-on-my-level added a commit that referenced this pull request Aug 29, 2026
## 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. -->
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.

2 participants