fix(runtime): prevent Cmd+W close crash during session despawn#247
Merged
forketyfork merged 1 commit intomainfrom Feb 25, 2026
Merged
fix(runtime): prevent Cmd+W close crash during session despawn#247forketyfork merged 1 commit intomainfrom
forketyfork merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an intermittent crash when closing a terminal with Cmd+W by introducing a safe session teardown path for runtime closes. The crash occurred because session close used full teardown (deinit) while the event loop could still deliver pending process-watcher callbacks, creating a window where callback context could be freed prematurely.
Changes:
- Added
despawn()method for runtime session closes that defers destruction of active wait contexts until callbacks can reclaim them - Replaced
deinit()withdespawn()in Cmd+W close handlers - Added regression test for callback safety during session despawn
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/session/state.zig |
Introduced WaitContextCleanup enum, new despawn() method, refactored deinit() to use shared teardown() with conditional wait context cleanup, added regression test |
src/app/runtime.zig |
Updated Cmd+W close handlers and UI despawn action to use despawn() instead of deinit() |
docs/ARCHITECTURE.md |
Added despawn() to session lifecycle API documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Issue
Hotfix fast-path: no GitHub issue exists yet.
Issue linkage is intentionally omitted for now and will be added during mandatory cleanup.
Solution
This change fixes an intermittent crash when closing a terminal with
Cmd+W.The close path was using full session teardown while the event loop could still deliver a pending process-watcher callback. That left a small window where callback context could be freed too early.
To close that gap, runtime close now uses a dedicated
despawnpath that keeps active wait-context memory alive until callback cleanup can happen safely. Finaldeinitstill does immediate teardown when the app is shutting down.I also added a regression test that exercises this callback-safety behavior, and updated architecture docs to include the new session lifecycle API.
Test plan
Cmd+Wrepeatedly on different sessions, and confirm the app does not crash.Cmd+Wand confirm collapse/reflow behavior still works as before.