Repository navigation
fix(desktop): stop the notification-settings query from killing a non-app host - #12687
Conversation
…-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
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
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:
Two non-blocking observations for the record:
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 |
|
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: Progression on the same command:
Two things that should not be read into it. The green run needs both PRs — this one alone still leaves the So the per-suite mitigation in |
kodjima33
left a comment
There was a problem hiding this comment.
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.
Fixes the process-terminating crash in #9029.
Reproduced first
swift test --package-path Desktop(single combined process) on currentmain:The victim moved between my two runs of the same tree (
ChatTranscriptGestureHarnessTests, thenHomeDailySummaryTests) — the ordering signature the issue describes.Root cause
One call,
ProactiveAssistantsPlugin+NotificationSettings.swift:227: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. Underswift testthe 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:
test.shmitigation doesThe fix
The injection seam already existed —
notificationSettings(query:handler:)takes the query — and only the production default was unsafe. It now answers.notDeterminedwhen the host is not an app bundle, the same answer a fresh install gives, and never constructsUNUserNotificationCenter.No test suite had to change, because the guard sits where every caller routes through.
Verification
Full combined run, same command, before and after:
NotificationSettingsHostBundleTestspins 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
RewindDatabase.shared,MemoryStorage.shared,AuthState.shared,StagedTaskStorage.sharedandUserDefaults.standard. This removes the one defect that terminates the process; ordinary shared-state coupling remains.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.testDesktopCapabilitiesExistInAgentToolDeclarationsstill fails, before and after, and in isolation onmain. Pre-existing and unrelated; left alone rather than folded in.Failure-Class: none