Repository navigation
windows/macos: orderly embedded-backend shutdown on session end - #171
Merged
Merged
Conversation
added 5 commits
October 9, 2026 23:29
The Linux adapter has shipped InstallShutdownHook since #128 and the scaffold wires it since #168; Windows and macOS scaffolds had no signal or session-end path, so logoff/shutdown killed the process with the backend mid-flight. - Windows system adapter: InstallShutdownHook over SetConsoleCtrlHandler (CTRL_C_EVENT, CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, CTRL_SHUTDOWN_ EVENT — session logoff and OS shutdown reach GUI processes through the last two). Registration failure throws; the callback contract stays synchronous and allocation-light like the Linux hook. - Windows scaffold: MainWindow funnels window close (Window.Closed) and the console-control callback into StopBackendOrderly, which reads the shared backend through std::atomic_load and calls the thread-safe stop() — the control callback runs on its own thread and never touches XAML state. - macOS scaffold: NSApplicationDelegateAdaptor with applicationShouldTerminate runs the registered backend stop for every termination path (Cmd-Q, window close, logout, shutdown). Fixes #120.
Swift strict concurrency rejects a nonisolated static var; AppKit delivers applicationShouldTerminate on the main thread, so MainActor plus assumeIsolated keeps registration (from the MainActor AppModel) and the callback on one isolation domain.
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
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.
Fixes #120 (completes the Windows/macOS half; Linux landed via #128 + #168).
Change
InstallShutdownHook(std::function<void()>)overSetConsoleCtrlHandler— CTRL_C/CTRL_CLOSE/CTRL_LOGOFF/CTRL_SHUTDOWN (session logoff and OS shutdown reach GUI processes through the logoff/shutdown events even without a console). Mirrors the Linux adapter's name and synchronous, allocation-light callback contract.Window.Closedand the hook both funnel intoStopBackendOrderly()—std::atomic_loadof the backend shared_ptr + thread-safestop(); the control thread never touches XAML state. Hook installation failure degrades to the window-close path only.@NSApplicationDelegateAdaptor+applicationShouldTerminate→ registered backendstop(), covering Cmd-Q, window close, logout, and OS shutdown.Verification
tests/codegen.rktpins the scaffold contract (hook present in the Windows template source,StopBackendOrderlydeclared,applicationShouldTerminate/orderlyShutdownin the macOS template).