Defer backend client setup until after first paint (fixes #75)#76
Open
techut30 wants to merge 1 commit into
Open
Defer backend client setup until after first paint (fixes #75)#76techut30 wants to merge 1 commit into
techut30 wants to merge 1 commit into
Conversation
AccountService and ModelCatalog were configured in main.swift before NSApplication.run(), so constructing the Convex/Clerk network clients ran on the main thread before the run loop started. If that construction blocks, app.run() is never reached and the window is never created — the process sits alive at 0% CPU, never connects to the window server, and is eventually flagged "not responding", with no crash and no window. Move both configure() calls into applicationDidFinishLaunching, after the home window is shown, on a deferred main-actor Task so a slow or unreachable backend can no longer block first paint. Order is preserved (ModelCatalog reads AccountService.shared.convex); neither the home window nor MCPService.start() depends on these being configured beforehand. Co-Authored-By: Claude Opus 4.8 (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.
Problem
Fixes #75 — app hangs on launch (0% CPU, never draws a window) on macOS 26.2.
main.swiftconfigures the backend clients beforeNSApplication.run():AccountService.configure()synchronously constructs the Convex (Rust-FFI) / Clerk network clients on the main thread, before the run loop starts. If that construction blocks,app.run()is never reached, so AppKit never connects to the window server and no window is ever created. The process stays alive at 0% CPU (a blocked synchronous wait), never signals launch, and is eventually flagged "not responding" — with no crash report and no window. That matches the issue exactly (lsappinfoshows!cgsConnection !signalled).None of this work is needed to draw the home window.
Change
Move both
configure()calls out of the pre-run()path and intoapplicationDidFinishLaunching, after the window is shown, on a deferred main-actorTaskso first paint can't be blocked by backend-client construction:ModelCatalog.configure()readsAccountService.shared.convex, andconfigure()setsconvexsynchronously before returning, so calling them sequentially in the same task keeps the dependency intact.HomeViewbindsAccountService.sharedvia@Observableand already tolerates the pre-load / signed-out state) norMCPService.start()readsconvex/ModelCatalog, so moving config a beat later is safe.Testing
I was not able to build/run locally (only have Swift 5.10 / Command Line Tools here, not the Swift 6.2 + Xcode 16 toolchain), and I couldn't reproduce the hang deterministically — the app is hardened-runtime signed, which blocks
sample/spindump/lldbintrospection, so I diagnosed from the launch architecture rather than a captured stack. The change is small and ordering-preserving; a maintainer build/run on macOS 26.x would be the real confirmation. Happy to adjust (e.g. also deferTelemetry.start()/MCPService.start(), or bracket each startup step with an os_log marker so a future launch hang is immediately attributable) if you'd prefer a different shape.