PluginWidgetManifest.write: move blocking I/O off the main thread#2
Open
imaznation wants to merge 1 commit into
Open
PluginWidgetManifest.write: move blocking I/O off the main thread#2imaznation wants to merge 1 commit into
imaznation wants to merge 1 commit into
Conversation
Reproducible startup hang: EdgeControl.main() blocks on PluginWidgetManifest.write() → Data.write(.atomic) → __open syscall inside the app-group container. App never reaches app.run(), no window ever appears. Cause is environmental (sandbox / container-manager state we don't control) — the .write() syscall just never completes for some users. Even with no plugin desktop widgets installed, the empty-manifest write happens on every launch and was the gating call. Fix: - Move the entire write dance (mkdir + freshness check + atomic write) onto DispatchQueue.global(qos: .utility). Fire-and-forget. Main thread proceeds to app.run() instantly. - Skip the write entirely if the on-disk file already matches the new content (avoids a no-op write on every launch). The widget extension polls plugins.json, so a one-tick stale manifest is fine. Plugin renderer also self-corrects on first periodic refresh. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PluginWidgetManifest.write()does file I/O (JSON encoding + atomic write) synchronously, and was being called from main-actor code paths during startup and on widget config changes. On slow disks or under contention the write can stall the main runloop long enough to be perceptible.Fix
Hop the disk I/O onto a background queue. The encode step (Sendable JSON) runs there, and the manifest update closure on the main actor only flips a published flag once the write completes. No behavior change for callers — the function signature stays the same; what changes is which thread the bytes hit disk on.
Notes
Pure plumbing fix, no API surface change. Companion to the BluetoothService off-main fix (#1) — same flavor of "main-thread I/O kept causing UI hitches."