Skip to content

macOS window-restoration relaunch dialog blocks automated runs after a crashing test #25922

Description

@rolfbjarne

Context

When a macOS/Mac Catalyst app crashes, the next launch of the same app can show a blocking window-restoration dialog:

The application "…" quit unexpectedly while trying to restore its windows. Do you want to try to reopen its windows again?

Until someone clicks a button, the app doesn't start — which stalls automated/unattended test runs (locally and potentially on CI bots) after a crashing test.

This is driven by macOS's saved application state (window restoration) mechanism, and is separate from the crash-reporter ("… quit unexpectedly") panel.

Ways to avoid it

  • Delete the app's saved state before launching:
    rm -rf ~/Library/Saved\ Application\ State/<bundle-id>.savedState
  • Disable window keeping / state restore per app:
    defaults write <bundle-id> NSQuitAlwaysKeepsWindows -bool false
    defaults write <bundle-id> ApplePersistenceIgnoreState -bool YES
  • Suppress the crash-reporter panel as well:
    defaults write com.apple.CrashReporter DialogType none

For a robust test wrapper, combine deleting the .savedState directory before launch with CrashReporter DialogType none.

Prior art in this repo

We already do exactly this for the simulator:

https://github.com/dotnet/macios/blob/main/tests/dotnet/UnitTests/ProjectTest.cs#L1840

var dirsToBeDeleted = new [] {
    Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.UserProfile), "Library", "Saved Application State", "com.apple.iphonesimulator.savedState"),
};

Suggested action

Apply the same "delete .savedState before launch" approach (and/or the defaults above) to the macOS/Mac Catalyst test launch paths, so a crashing test doesn't block subsequent runs on an interactive dialog.


🤖 Issue filed by Copilot

Metadata

Metadata

Assignees

No one assigned

    Labels

    copilottestsAnything related to tests

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions