Skip to content

fix: keep blocking work off Swift's shared thread pool - #619

Merged
M4n0x merged 2 commits into
mainfrom
fix/618-blocking-work-off-pool
Nov 13, 2026
Merged

M4n0x merged 2 commits into
mainfrom
fix/618-blocking-work-off-pool

Conversation

@M4n0x

@M4n0x M4n0x commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Problem

Since 11 November, six CI Test jobs have hung until the 20-minute limit, two of them on main, where the beta was skipped. Two tests block slow work on purpose, and the app ran that work on Swift's shared thread pool, which has one thread per core and never replaces a blocked one. On the 3-core runner, the three blocked test cases could take every pool thread while waiting for work that needed one. #618 has the stack samples and the diagnosis.

Fixes #618

Changes

  • BlockingWork.run (new) runs blocking work on a GCD queue and awaits it. GCD adds a thread when one blocks.
  • ApplicationMover copies, verifies and un-quarantines the new copy through it.
  • SetupWorkspaceChecker looks up yabai's or OmniWM's executable through it, so a lookup stuck on a network volume no longer holds a pool thread after setup's check has given up at its deadline.
  • applicationMoveCapturesSessionEditsAfterCopying and theDeadlineReturnsEvenWhileExecutableLookupIsStuck check that their blocking stub runs off the pool, so a regression fails at once on any Mac instead of hanging CI now and then. blockingWorkRunsOffSwiftsPool checks that the pool check itself tells the two apart.
  • AGENTS.md (test rules) and DECISIONS.md get the rule.

Testing

  • Reproduced the hang: on main (9d60793), both tests hang every time with Swift's pool narrowed to one thread (LIBDISPATCH_COOPERATIVE_POOL_STRICT=1), stopped after 60 s, while other tests from the same suites pass.
  • New checks catch it: with the app changes reverted, they fail in 0.2 s on a 10-core Mac.
  • With the fix: the three tests pass normally and on a one-thread pool (1.3 s).
  • Whole Swift Testing suite on a one-thread pool: finishes in 42 s, so no other test blocks the pool this way.
  • Full suite (swift test): XCTest 308 tests, 0 failures. Swift Testing: 924 tests with 6 issues, all in pinnedPopupsStayOnScreenAndReturnUnderTheirWidget and shiftReturnStartsANewLineInAnInputThatWrapsAndReturnSends. My screen was locked with the display asleep. Both tests fail the same way without these changes, and they pass on CI.
  • swift test --filter 'ApplicationMove|applicationMove|SetupWorkspace|BlockingWork': 90 tests pass.
  • scripts/check.sh --quick and commitlint pass.
  • Not checked: moving a real StableBar to Applications by hand. The copy now runs on a GCD thread, and the steps around it are unchanged.

No visible change, so no screenshots.

Merging

Merge commit: one fix commit for the app and tests and one docs commit for the rule. The fix changes app code, so it ships in the next beta.

Claude Opus 5.5 via Claude Code

Copying StableBar to Applications and looking up yabai's or OmniWM's executable blocked a
thread of Swift's shared pool, which has one thread per core and never replaces a blocked
one. Their tests block that work on purpose. On CI's 3-core runner, the three blocked cases
could take every pool thread while waiting for work that needed one, and the test run hung
until the job's 20-minute limit.

BlockingWork.run now runs that work on a GCD queue, which adds a thread when one blocks.
Both tests check that their blocking stub runs off the pool, so a regression fails at once
on any Mac instead of hanging CI now and then.

Fixes #618
Add the rule to the test rules in AGENTS.md and to DECISIONS.md.

Refs #618
@M4n0x
M4n0x requested a review from Seb-GRAF as a code owner November 13, 2026 12:19
@coderabbitai

coderabbitai Bot commented Nov 13, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Adds BlockingWork.run to execute blocking work on a GCD queue. Application copying, validation, quarantine removal, and executable lookup now use it. Tests check that these operations run outside Swift’s cooperative pool.

Changes: Blocking Work Routing

Layer / File(s) Summary
Blocking-work wrapper and convention
Sources/StableBar/BlockingWork.swift, DECISIONS.md, AGENTS.md
BlockingWork.run dispatches throwing work to a global .userInitiated queue and returns or throws its result through a checked continuation. The decision and testing guidance describe its use.
Application operation routing
Sources/StableBar/ApplicationMover.swift, Sources/StableBar/SetupWorkspaceConnection.swift
ApplicationMover.transfer runs copying, identity verification, signature validation, and quarantine removal through BlockingWork.run. SetupWorkspaceChecker.inspect uses it for executable lookup.
Thread-pool regression checks
Tests/StableBarTests/BlockingWorkTests.swift, Tests/StableBarTests/ApplicationMoverTests.swift, Tests/StableBarTests/SetupWorkspaceConnectionTests.swift
Tests check that the wrapper, copy callback, and executable lookup do not run on Swift’s cooperative pool.

Severity of issue fixed: High

Merge Risk: Minimal · up to d6257

The change moves blocking app-copy and executable-lookup work off Swift's shared thread pool, which should stop the reported test hangs. No actionable merge-blocking risk remains. The author did not manually check moving a real app to Applications.

Security architecture risk: Minimal · up to d6257

The change moves blocking work onto background dispatch threads without changing application identity checks, installation permissions, executable selection, or rollback ownership. No material security risk introduced or worsened by this change was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed execution paths remain within the desktop application's existing authority: copying its bundle into a writable Applications location and checking workspace managers selected through the existing login environment. Dispatching these operations does not itself grant additional filesystem or command authority.

Trust Boundaries and Controls

  • observed — Executable lookup still receives PATH from the same environment provider. After lookup, a cancellation check precedes workspace reads and commands. Deadline and cancellation paths finish the result stream, while the UI checks cancellation before publishing a result.

Resilience and Maintainability Implications

  • observed — Cancellation does not interrupt an already dispatched blocking closure. Setup can nevertheless return at its deadline without awaiting lookup completion. Installation retains its controller-level single-flight guard and waits for copying to complete before proceeding or cleaning staging; these preserve the inspected failure-containment boundaries.
Pre-merge checks: Passed 3

Check name Status Explanation
Description check Passed The description follows the repository template closely. It has Problem, Changes, Testing, and Merging sections, and it links the issue (Fixes #618). It explains the cause: blocking work ran on Swift'…
Linked Issues check Passed Issue #618 is the only directly linked issue. Its coding requirement is that no test or app path blocks a thread of Swift's shared pool while waiting for work that needs one, with the app's slow work …
Out of Scope Changes check Passed All changed areas map to #618 or to its supporting rule:
- Sources/StableBar/BlockingWork.swift (new): the wrapper that implements the fix.
- Sources/StableBar/ApplicationMover.swift and SetupWorkspac…
Full details: Description check

Explanation

The description follows the repository template closely. It has Problem, Changes, Testing, and Merging sections, and it links the issue (Fixes #618). It explains the cause: blocking work ran on Swift's shared pool, which has one thread per core. It lists the changed files and the reason for each. The Testing section gives reproduction steps, before and after results, and full-suite counts. It names the six Swift Testing issues, which are UI tests that failed while the display was asleep, and it states that these also fail without the changes. It says what was not checked: a manual move of a real app. It also notes that no screenshots apply. The Merging section states the commit strategy: a merge commit with one fix commit and one docs commit. It ends with the model and harness line, as the template requires. The description is complete. The only gap is that the six Swift Testing issues are attributed to display sleep without a fresh run on a awake display, which the author partly acknowledges.

Full details: Linked Issues check

Explanation

Issue #618 is the only directly linked issue. Its coding requirement is that no test or app path blocks a thread of Swift's shared pool while waiting for work that needs one, with the app's slow work moved to a GCD queue. Evidence at head d625734:

  • BlockingWork.run (Sources/StableBar/BlockingWork.swift) dispatches the closure to DispatchQueue.global(qos: .userInitiated) and resumes a checked throwing continuation. This matches the issue's proposed fix.
  • ApplicationMover.transfer runs the copy, identity verification, copy signature validation and quarantine removal inside BlockingWork.run, which covers the copy and signature-check work named in #618.
  • SetupWorkspaceChecker.inspect obtains the yabai or OmniWM executable through BlockingWork.run. A stalled lookup therefore holds a GCD thread, not a pool thread, after the deadline in check returns. This covers the executable-lookup scope in #618.
  • The PR summary reports that the two targeted tests now check that their blocking stubs run off the pool, and that the three tests pass on a one-thread pool. I did not read the test hunks directly, so this part rests on the summary and the PR's reported runs.
    No coding requirement in #618 is left unmet. The #364 lock-cycle hang is not requested, and the PR does not claim to address it.
Full details: Out of Scope Changes check

Explanation

All changed areas map to #618 or to its supporting rule:

  • Sources/StableBar/BlockingWork.swift (new): the wrapper that implements the fix.
  • Sources/StableBar/ApplicationMover.swift and SetupWorkspaceConnection.swift: the call sites named in #618.
  • Tests/StableBarTests/ApplicationMoverTests.swift, SetupWorkspaceConnectionTests.swift and BlockingWorkTests.swift: checks that the two hanging tests run off the pool and that the pool check distinguishes the two cases. These support the issue's regression requirement.
  • AGENTS.md and DECISIONS.md: a testing rule and a code decision that record the same blocking-work practice. This is documentation for the fix, not an unrelated change.
    No change is unrelated to #618. The six Swift Testing UI failures in the full-suite run are reported as present without these changes, so they are not PR changes. I did not read the test or documentation hunks directly; this conclusion relies on the PR summary for those files.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9d60793 and d625734.

Files selected for processing: 8

  • AGENTS.md
  • DECISIONS.md
  • Sources/StableBar/ApplicationMover.swift
  • Sources/StableBar/BlockingWork.swift
  • Sources/StableBar/SetupWorkspaceConnection.swift
  • Tests/StableBarTests/ApplicationMoverTests.swift
  • Tests/StableBarTests/BlockingWorkTests.swift
  • Tests/StableBarTests/SetupWorkspaceConnectionTests.swift

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Before and after

main at 9d60793 → this pull request at d625734 · 148 screens drawn in one CI job · 2 changed

Screen Change Where (image pixels)
scenes/accessibility-guide-dark 1,065 pixels 96,150 · 40×41
scenes/accessibility-guide-light 1,088 pixels 95,150 · 42×42

scenes/accessibility-guide-dark

Before After
Before After

Difference, changed pixels in red:

Difference

scenes/accessibility-guide-light

Before After
Before After

Difference, changed pixels in red:

Difference

146 unchanged screens

docs/essentials-clock-settings-dark, docs/essentials-clock-settings-light, docs/essentials-dark, docs/essentials-light, docs/essentials-settings-dark, docs/essentials-settings-light, docs/hero-dark, docs/hero-light, docs/popups-dark, docs/popups-light, docs/settings-dark, docs/settings-light, docs/themes-dark, docs/themes-light, scenes/app-menu-popup-dark, scenes/app-menu-popup-light, scenes/apple-menu-settings-dark, scenes/apple-menu-settings-light, scenes/bottom-bar-popup-dark, scenes/bottom-bar-popup-light, scenes/chat-popup-dark, scenes/chat-popup-light, scenes/crowded-edit-bar-dark, scenes/crowded-edit-bar-light, scenes/dock-badges-bar-dark, scenes/dock-badges-bar-light, scenes/edit-bar-wide-group-dark, scenes/edit-bar-wide-group-light, scenes/essentials-clock-popup-dark, scenes/essentials-clock-popup-light, scenes/gruvbox-bar-dark, scenes/gruvbox-bar-light, scenes/horizontal-list-popup-dark, scenes/horizontal-list-popup-light, scenes/increase-contrast-bar-dark, scenes/increase-contrast-bar-light, scenes/increase-contrast-popup-dark, scenes/increase-contrast-popup-light, scenes/input-source-popup-dark, scenes/input-source-popup-light, scenes/notch-flare-bar-dark, scenes/notch-flare-bar-light, scenes/privacy-both-bar-dark, scenes/privacy-both-bar-light, scenes/privacy-hide-when-idle-bar-dark, scenes/privacy-hide-when-idle-bar-light, scenes/privacy-idle-bar-dark, scenes/privacy-idle-bar-light, scenes/privacy-microphone-bar-dark, scenes/privacy-microphone-bar-light, scenes/privacy-settings-dark, scenes/privacy-settings-light, scenes/reduce-transparency-bar-dark, scenes/reduce-transparency-bar-light, scenes/reduce-transparency-glass-bar-dark, scenes/reduce-transparency-glass-bar-light, scenes/settings-bar-dark, scenes/settings-bar-light, scenes/settings-bar-placement-bottom-dark, scenes/settings-bar-placement-bottom-light, scenes/settings-bar-placement-dark, scenes/settings-bar-placement-light, scenes/settings-crashes-dark, scenes/settings-crashes-light, scenes/settings-feedback-dark, scenes/settings-feedback-light, scenes/settings-general-dark, scenes/settings-general-light, scenes/settings-general-macos15-dark, scenes/settings-general-macos15-light, scenes/settings-general-move-dark, scenes/settings-general-move-failed-dark, scenes/settings-general-move-failed-light, scenes/settings-general-move-light, scenes/settings-general-move-moving-dark, scenes/settings-general-move-moving-light, scenes/settings-general-move-replace-dark, scenes/settings-general-move-replace-light, scenes/settings-general-setup-open-dark, scenes/settings-general-setup-open-light, scenes/settings-general-spaces-dark, scenes/settings-general-spaces-light, scenes/settings-help-dark, scenes/settings-help-light, scenes/settings-help-starred-dark, scenes/settings-help-starred-light, scenes/settings-narrow-dark, scenes/settings-narrow-light, scenes/settings-package-dark, scenes/settings-package-light, scenes/settings-package-widget-dark, scenes/settings-package-widget-light, scenes/settings-theme-dark, scenes/settings-theme-light, scenes/settings-uninstall-dark, scenes/settings-uninstall-failed-dark, scenes/settings-uninstall-failed-light, scenes/settings-uninstall-light, scenes/settings-widget-backgrounds-dark, scenes/settings-widget-backgrounds-light, scenes/settings-workspace-hidden-dark, scenes/settings-workspace-hidden-light, scenes/setup-look-below-menu-bar-dark, scenes/setup-look-dark, scenes/setup-look-no-notch-dark, scenes/setup-move-existing-dark, scenes/setup-move-failed-dark, scenes/setup-move-ready-dark, scenes/setup-move-replace-dark, scenes/setup-omniwm-connection-dark, scenes/setup-permissions-dark, scenes/setup-permissions-spaces-dark, scenes/setup-permissions-spaces-ready-dark, scenes/setup-placement-bottom-dark, scenes/setup-placement-dark, scenes/setup-touches-dark, scenes/setup-touches-macos15-dark, scenes/setup-touches-spaces-dark, scenes/setup-try-dark, scenes/setup-yabai-connection-dark, scenes/slider-end-stop-popup-dark, scenes/slider-end-stop-popup-light, scenes/stablebar-widget-bar-dark, scenes/stablebar-widget-bar-light, scenes/stablebar-widget-settings-dark, scenes/stablebar-widget-settings-light, scenes/starter-bar-dark, scenes/starter-bar-light, scenes/starter-edit-bar-dark, scenes/starter-edit-bar-light, scenes/system-monitor-memory-bar-dark, scenes/system-monitor-memory-bar-light, scenes/system-monitor-shows-settings-dark, scenes/system-monitor-shows-settings-light, scenes/update-popup-dark, scenes/update-popup-light, scenes/update-popup-star-github-cli-dark, scenes/update-popup-star-github-cli-light, scenes/update-popup-star-thanks-dark, scenes/update-popup-star-thanks-light, scenes/workspace-badges-bar-dark, scenes/workspace-badges-bar-light, scenes/workspace-focused-window-bar-dark, scenes/workspace-focused-window-bar-light, scenes/workspace-hidden-apps-bar-dark, scenes/workspace-hidden-apps-bar-light

Visual review: 2 changed screens approved.

@M4n0x M4n0x added the visual-ok A maintainer looked at the changed screens and approves them label Nov 13, 2026
@M4n0x
M4n0x merged commit 2777713 into main Nov 13, 2026
16 checks passed
@M4n0x
M4n0x deleted the fix/618-blocking-work-off-pool branch November 13, 2026 13:01
@stablebar-releases

Copy link
Copy Markdown

🎉 This PR is included in version 0.15.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

M4n0x added a commit that referenced this pull request Nov 14, 2026
…656)

Swift Testing runs about 900 tests at once on CI, nearly all on the main actor, so a test can wait
seconds for its next turn. Three tests bounded such a wait with the clock:

- Scenes gave their views 60 seconds to get ready. The package scene's views need many main-actor
  turns; it took 46 to 70 seconds in passing runs and failed three runs since #619. The wait now
  counts 600 checks a tenth of a second apart, still about a minute when nothing else runs.
- The event burst test timed out its startup command after 4 seconds, before the test released
  it. A later command cleared the error and left a log without end:startup.
- The widget actions test's first action had 60 seconds, which a 61-second hold also beat.

Both held commands now get 120 seconds, like the cancellation test's command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released visual-ok A maintainer looked at the changed screens and approves them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI's test run hangs until its 20-minute limit when blocked work fills Swift's thread pool

1 participant