Skip to content

fix(macos): capture weak self in network-monitor Task#19

Merged
MegaManSec merged 2 commits into
mainfrom
fix/network-monitor-task-weak-self
Jun 8, 2026
Merged

fix(macos): capture weak self in network-monitor Task#19
MegaManSec merged 2 commits into
mainfrom
fix/network-monitor-task-weak-self

Conversation

@MegaManSec

Copy link
Copy Markdown
Owner

Why

The release build's Build (Swift) step started failing with a hard compile error:

apps/macos/Sources/WizApp/AppState.swift:757:28: error: reference to captured var 'self' in concurrently-executing code

In startNetworkMonitor(), the NWPathMonitor update handler captures [weak self], which makes self a mutable weak var. Referencing it from the nested Task { @MainActor } trips strict-concurrency checking. A newer Swift toolchain on the CI runner image (macos-14-arm64 20260525.0091) promoted this from a warning to a hard error, breaking the release build. (The same pattern in the DispatchQueue.async closures elsewhere in the file stays a warning for now.)

Fix

Give the Task its own [weak self] capture so it holds an immutable copy instead of referencing the outer closure's captured var self:

Task { @MainActor [weak self] in self?.handlePathChange(path) }

Verification

  • swift build --package-path apps/macos — completes cleanly
  • swift test --package-path apps/macos — all 15 tests pass

The NWPathMonitor update handler captures [weak self], making self a
mutable weak var. Referencing it from the nested Task { @mainactor }
trips strict-concurrency checking ('reference to captured var self in
concurrently-executing code'), which a newer Swift toolchain on the CI
runner image promoted from a warning to a hard error, breaking the
release build.

Give the Task its own [weak self] capture so it holds an immutable copy
instead of the outer closure's captured var.
Bump the single source of truth (root package.json) and the three
lockstep sources the release workflow validates — core and cli
package.json versions and the macOS app's CFBundleShortVersionString —
to 5.0.1.
@MegaManSec MegaManSec merged commit f066a2a into main Jun 8, 2026
2 checks passed
@MegaManSec MegaManSec deleted the fix/network-monitor-task-weak-self branch June 8, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant