Skip to content

fix(desktop): stop the notification-settings query from killing a non-app host - #12687

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
aryanorastar:fix/9029-notification-settings-no-app-bundle
Sep 4, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
aryanorastar:fix/9029-notification-settings-no-app-bundle

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes the process-terminating crash in #9029.

Reproduced first

swift test --package-path Desktop (single combined process) on current main:

started=2652  completed=2650  failed=1
libc++abi: terminating due to uncaught exception of type NSException

The victim moved between my two runs of the same tree (ChatTranscriptGestureHarnessTests, then HomeDailySummaryTests) — the ordering signature the issue describes.

Root cause

One call, ProactiveAssistantsPlugin+NotificationSettings.swift:227:

bundleProxyForCurrentProcess is nil: mainBundle.bundleURL file:///Applications/Xcode.app/Contents/Developer/usr/bin/
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException'

UNUserNotificationCenter.current() does not fail softly off an app bundle. It raises an Objective-C exception, and Swift cannot catch one, so it terminates the whole process. Under swift test the main bundle is the xctest tool, so any suite that reaches the production settings query kills the run.

That explains all three symptoms the issue lists:

  • no assertion failure — it is a process termination, not a test failure
  • victim moves with ordering — the crash lands on whichever suite is executing, not the one that reached the query
  • every suite passes in isolation — per-suite processes contain the blast radius, which is exactly what the test.sh mitigation does

The fix

The injection seam already existed — notificationSettings(query:handler:) takes the query — and only the production default was unsafe. It now answers .notDetermined when the host is not an app bundle, the same answer a fresh install gives, and never constructs UNUserNotificationCenter.

No test suite had to change, because the guard sits where every caller routes through.

Verification

Full combined run, same command, before and after:

crash lines tests completed
before 1 2650 (run died)
after 0 3023

NotificationSettingsHostBundleTests pins both halves in the real xctest host rather than a simulated one: the host is not an app bundle, and the production query answers rather than terminating. Before this change the second test took the process down instead of failing — that is the regression it guards.

Also verified with -strict-concurrency=complete, not just a debug build.

Scope — what this does not do

  • Does not close Swift test suite: shared-singleton contamination causes scheduling-dependent xctest worker crash #9029 by itself. The issue also asks for DI seams across RewindDatabase.shared, MemoryStorage.shared, AuthState.shared, StagedTaskStorage.shared and UserDefaults.standard. This removes the one defect that terminates the process; ordinary shared-state coupling remains.
  • Does not remove the per-suite mitigation in test.sh. That is a separate call once the combined run has been trusted for a while, and it should be its own PR.
  • ChatDiscoverabilityTests.testDesktopCapabilitiesExistInAgentToolDeclarations still fails, before and after, and in isolation on main. Pre-existing and unrelated; left alone rather than folded in.

Failure-Class: none

Review in cubic

…-app host

BasedHardware#9029 reports the desktop Swift suite hard-crashing in a single `swift test` process with
no assertion failure, the victim suite moving with test ordering, and every suite passing
in isolation. Reproduced on current `main` and traced to one call:

    ProactiveAssistantsPlugin+NotificationSettings.swift:227
    bundleProxyForCurrentProcess is nil: mainBundle.bundleURL .../Developer/usr/bin/
    *** Terminating app due to uncaught exception 'NSInternalInconsistencyException'

`UNUserNotificationCenter.current()` does not fail softly off an app bundle — it raises an
Objective-C exception, which Swift cannot catch, so it terminates the process. Under
`swift test` the main bundle is the xctest tool, so any suite reaching the production
settings query kills the run. The crash lands on whichever suite is executing rather than
the one that reached the query, which is exactly why the victim moved and why per-suite
isolation hid it.

The injection seam already existed: `notificationSettings(query:handler:)` takes the query,
and only the production default was unsafe. It now answers `.notDetermined` when the host
is not an app bundle, which is the same answer a fresh install gives, and never constructs
`UNUserNotificationCenter`.

Verification, full combined `swift test --package-path Desktop`, before and after:

    before: 1 "Terminating app due to uncaught exception", run died at 2650 tests
    after:  0 crash lines, run completed 3023 tests

`NotificationSettingsHostBundleTests` pins both halves in the real xctest host rather than a
simulated one: the host is not an app bundle, and the production query answers instead of
terminating. Before this change the second test took the process down rather than failing.

Not fixed here, and pre-existing: `ChatDiscoverabilityTests
.testDesktopCapabilitiesExistInAgentToolDeclarations` fails in isolation on `main` too, so
it is unrelated to this crash and left alone. This also does not remove the per-suite
mitigation in `test.sh`; that is a separate call once the combined run is trusted.

Verified with `-strict-concurrency=complete`, not just a debug build.

Failure-Class: none
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@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.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @aryanorastar — clean, well-scoped fix with an unusually good write-up (repro, root cause, before/after verification, and an honest scope section).

Verified against the head:

desktop/macos/Desktop/Sources/ProactiveAssistants/ProactiveAssistantsPlugin+NotificationSettings.swift

  • The guard sits exactly where every production caller routes: notificationSettings(handler:) defaults to systemNotificationSettingsQuery, and authorizationStatus(handler:) plus the signed-smoke probe flow through it too — one guard covers the whole surface without touching any suite.
  • hostProcessUnavailable answering .notDetermined is the right semantic: callers keep taking their existing unauthorized path, and the synchronous completion still flows through dispatchToMain, so the MainActor handoff contract is preserved.
  • Bundle.main.bundleURL.pathExtension == "app" is a cheap, correct predicate; the shipped app always satisfies it, so user-facing behavior is unchanged — matching the changelog fragment's claim.
  • Dropping private from systemNotificationSettingsQuery so the host-bundle test can exercise the real function is a minimal, reasonable visibility change.

desktop/macos/Desktop/Tests/NotificationSettingsHostBundleTests.swift

  • Good choice pinning the condition in the real xctest host rather than simulating it — and the precondition test fails loudly if the host ever becomes an app bundle, which would otherwise silently un-exercise the guard.
  • SnapshotBox (NSLock-guarded @unchecked Sendable) is the right shape for capturing a callback that answers on an arbitrary queue; the target wiring is correct (Desktop/Tests → Omi ComputerTests, @testable import Omi_Computer).

desktop/macos/changelog/unreleased/20260903-notification-settings-host-guard.json

  • {"kind": "none"} matches the documented pattern for internal-only production edits; the extra reason field is useful for humans and harmless to the checker (Hygiene is green).

Two non-blocking observations for the record:

  1. Other production paths still call UNUserNotificationCenter.current() directly — requestAuthorization and add in this same file, plus call sites in AppState.swift, AppState+Permissions.swift, DeviceProvider.swift, OmiApp.swift, NotificationService.swift, NotificationDeliveryTelemetry.swift, and SBOnboardingModel+Steps.swift. The Swift test suite: shared-singleton contamination causes scheduling-dependent xctest worker crash #9029 crash traced to the settings query, but if any of those other paths is ever reached from a non-app host, the same uncatchable termination applies. A follow-up routing them through the bridge (or the same guard) would retire the hazard class, not just this instance.
  2. Agree with the framing that Swift test suite: shared-singleton contamination causes scheduling-dependent xctest worker crash #9029 stays open — the shared-singleton coupling it describes is untouched, and unwinding the per-suite test.sh mitigation should indeed be its own PR once the combined run has been trusted for a while.

Release compile is green; the Desktop Swift Static & Test Contracts run is still in flight. Leaving merge sign-off to a maintainer once that lands.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Follow-up measurement, now that #12705 is open alongside this.

With both this crash guard and #12705's stale-pin fix applied, the full combined single-process run is green:

swift test --package-path Desktop
started=3065  completed=3065  skipped=1  failed=0  crash lines=0

Progression on the same command:

tree crash lines result
main 1 died at 2650 tests
+ this PR 0 3023 completed, 1 failure (the #12705 pin)
+ both 0 3065/3065, 0 failures

Two things that should not be read into it. The green run needs both PRs — this one alone still leaves the ChatDiscoverabilityTests failure. And it does not mean the singleton coupling in #9029 is resolved: RewindDatabase.shared, MemoryStorage.shared, AuthState.shared and friends are still process-global and still shared across suites. Nothing currently mutates them in a damaging order; that is a weaker statement than "isolated".

So the per-suite mitigation in test.sh should stay for now, and removing it belongs in its own PR once both of these have been on main for a while.

@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.

Root-caused process-killing NSException from UNUserNotificationCenter under xctest (non-app host), fixes with a targeted guard + regression test pinning both halves. Confirmed not already fixed on main. Owner-override desktop bug fix, no abuse signals — merging.

@kodjima33
kodjima33 merged commit a053d92 into BasedHardware:main Sep 4, 2026
37 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

macOS positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swift test suite: shared-singleton contamination causes scheduling-dependent xctest worker crash

3 participants