Skip to content

fix(runtime): prevent Cmd+W close crash during session despawn#247

Merged
forketyfork merged 1 commit intomainfrom
fix/cmdw-close-crash
Feb 25, 2026
Merged

fix(runtime): prevent Cmd+W close crash during session despawn#247
forketyfork merged 1 commit intomainfrom
fix/cmdw-close-crash

Conversation

@forketyfork
Copy link
Owner

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 despawn path that keeps active wait-context memory alive until callback cleanup can happen safely. Final deinit still 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

  • Launch Architect, open multiple terminals, press Cmd+W repeatedly on different sessions, and confirm the app does not crash.
  • In full view, close the focused session with Cmd+W and confirm collapse/reflow behavior still works as before.
  • Trigger the "Delete Terminal?" confirmation by running a foreground process, confirm delete, and verify no crash during/after close.

@forketyfork forketyfork requested a review from Copilot February 25, 2026 10:43
@forketyfork forketyfork marked this pull request as ready for review February 25, 2026 10:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() with despawn() 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.

@forketyfork forketyfork merged commit 5df7e29 into main Feb 25, 2026
8 checks passed
@forketyfork forketyfork deleted the fix/cmdw-close-crash branch February 25, 2026 10:55
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.

2 participants