Skip to content

Stop winapp run hanging when several packaged launches deploy at once - #1058

Merged
Nikola Metulev (nmetulev) merged 4 commits into
mainfrom
zateutsch-fix-run-activation-hang
Oct 12, 2026
Merged

Nikola Metulev (nmetulev) merged 4 commits into
mainfrom
zateutsch-fix-run-activation-hang

Conversation

@zateutsch

Copy link
Copy Markdown
Contributor

Description

winapp run could hang forever in IApplicationActivationManager.ActivateApplication when several packaged-app launches ran at once (#1035).

Likely cause: the CLI has no synchronization context. When a PackageManager deploy/remove/add operation finishes, the code after await runs inline on the WinRT completion-callback thread. So after a fresh registration, the whole rest of winapp run, including app activation, ran inside the deployment callback. Stack traces confirm ActivateApplication was called beneath AsyncInfoToTaskBridge.Complete. With several deployments in flight, activation from inside that callback can plausibly wait on deployment work that is waiting on the callback.

Changes:

  • PackageRegistrationService: every PackageManager await now yields to the thread pool after it completes, so later work never runs on the deployment callback thread. ConfigureAwaitOptions.ForceYielding is not enough here, because it only affects tasks that are already complete.

  • AppLauncherService.LaunchByAumid: activation runs on a pool thread with a 2-minute timeout. If Windows never answers, the user gets an actionable error instead of a hang:

    Windows did not finish activating '' within 120 seconds. The package is registered; try launching it again, or check Event Viewer > Applications and Services Logs > Microsoft > Windows > AppModel-Runtime for activation errors.

    Activation failures keep their original exception type, so existing error messages are unchanged.

Usage Example

No command changes. Concurrent winapp run <folder> --detach invocations should all return.

Related Issue

Fixes #1035

Type of Change

  • 🐛 Bug fix

Checklist

  • New tests added for new functionality (if applicable)
  • Tested locally on Windows

Screenshots / Demo

N/A

Additional Notes

I couldn't reproduce the hang, so this is a best-guess fix. Tested on Windows 10.0.26310 ARM64; the reporter used 28000 ARM64.

  • 6 minimal full-trust packaged apps launched concurrently with --detach --without-alias: many rounds, fresh and existing registrations. No hang.
  • 4 dotnet new winui projects launched concurrently: 15 rounds, with and without --no-build. No hang.

What was confirmed: before the fix, ActivateApplication runs inside the deployment completion callback (AsyncInfoToTaskBridge.Complete is on the stack). After the fix, that frame is gone, and 3 concurrent rounds still pass. Repeated runs skip re-registration when the manifest hasn't changed, which hides this path.

Validation:

  • dotnet test --project src/winapp-CLI/WinApp.Cli.Tests/WinApp.Cli.Tests.csproj -c Debug --filter "...AppLauncherServiceTests|PackageRegistrationService|GuestLaunchCommandTests|RunCommandTests|MsixService": 568 passed, 0 failed, on the rebased head.
  • New OffDeploymentCallback_ContinuationDoesNotRunOnCompletingThread: fails when the yield is removed (negative control) and passes with it.
  • New LaunchByAumid_ActivationNeverReturns_ThrowsTimeoutException and LaunchByAumid_ActivatorThrows_PropagatesOriginalException: pass.

Package deployment awaits now leave the WinRT completion callback before
continuing, so app activation no longer runs inside that callback. App
activation is also bounded by a 2-minute timeout with a clear error.

Fixes #1035

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0f5f2312-a548-4c59-a784-016bc0a48ebe
Copilot AI balanced review requested due to automatic review settings October 9, 2026 21:57
@zateutsch

Copy link
Copy Markdown
Contributor Author

Nikola Metulev (@nmetulev) I couldn't reproduce the #1035 hang locally, so this is a best-guess fix.

What I tried on Windows 10.0.26310 ARM64 (the issue was on 28000 ARM64):

  • 6 minimal packaged apps launched concurrently with winapp run --detach, many rounds. No hang.
  • 4 WinUI 3 projects launched concurrently, 15 rounds. No hang.

What I did confirm: after a fresh registration, ActivateApplication was running inside PackageManager's WinRT completion callback. This PR moves activation off that callback, which is the most plausible deadlock source. It also adds a 2-minute activation timeout, so even if the cause is something else, winapp run fails with a clear error instead of hanging.

Could you run this branch against your repro on 28000 to confirm it fixes the hang?

@zateutsch Zach Teutsch (zateutsch) added the agent-preparing Agent is addressing feedback or completing required validation and CI label Oct 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Release build and 88 targeted tests pass, but the low-level WinRT concurrency failure was not reproducible, so the mitigation needs final human review.

0 open findings

What changed in this PR

Prevents concurrent packaged-app launches from hanging during Windows deployment callbacks and adds a bounded activation timeout.

Changes:

  • Resumes package operations off WinRT completion threads.
  • Runs application activation asynchronously with a two-minute timeout.
  • Adds regression tests for callback threading, timeouts, and exception propagation.
File Description
PackageRegistrationService.cs Moves post-deployment continuations to the thread pool.
AppLauncherService.cs Adds bounded off-thread activation.
PackageRegistrationServiceTests.cs Tests callback-thread separation.
AppLauncherServiceTests.cs Tests timeout and exception behavior.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0f5f2312-a548-4c59-a784-016bc0a48ebe
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

⏳ Build in progress — metrics below are from a previous commit and will update when the current build finishes.

Build Metrics Report

Validation passed. All required build and validation jobs succeeded.

Binary Sizes

Artifact Baseline Current Delta
CLI (ARM64) 57.77 MB 57.78 MB 📈 +11.0 KB (+0.02%)
CLI (x64) 57.79 MB 57.80 MB 📈 +10.0 KB (+0.02%)
MSIX (ARM64) 24.02 MB 24.03 MB 📈 +6.6 KB (+0.03%)
MSIX (x64) 25.49 MB 25.50 MB 📈 +4.2 KB (+0.02%)
NPM Package 50.08 MB 50.09 MB 📈 +9.2 KB (+0.02%)
NuGet Package 50.19 MB 50.20 MB 📈 +4.9 KB (+0.01%)

.NET Test Results (TRX reports)

Other suites are reflected in the overall validation status above.

✅ 8335 passed, 37 skipped out of 8372 tests in 1266.1s (+4 tests, +94.2s vs. baseline)

Test Coverage

✅ 87.5% line coverage, 82.2% branch coverage · ✅ no change vs. baseline

CLI Startup Time

64ms median (x64, winapp --version) · ✅ no change vs. baseline

Try This Build

Installs the MSIX for your architecture, replacing any previously installed build. Needs the GitHub CLI — the command offers to install it and sign you in if it is missing.

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) 1058
Switching between builds often?

Put the tool on your PATH once:

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) -AddToPath

Then this build is just:

winapp-pr 1058

Run winapp-pr with no arguments to pick from a list of open PRs.


Updated 2026-10-10 19:25:21 UTC · commit 4090633 · workflow run

@nmetulev
Nikola Metulev (nmetulev) merged commit c4d221b into main Oct 12, 2026
14 checks passed
@nmetulev
Nikola Metulev (nmetulev) deleted the zateutsch-fix-run-activation-hang branch October 12, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-preparing Agent is addressing feedback or completing required validation and CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: winapp run can hang forever while launching a packaged app when several launches run at once

3 participants