Skip to content

fix(session): make teardown idempotent with handle-based cleanup#245

Merged
forketyfork merged 2 commits intomainfrom
fix/session-deinit-idempotent-teardown
Feb 25, 2026
Merged

fix(session): make teardown idempotent with handle-based cleanup#245
forketyfork merged 2 commits intomainfrom
fix/session-deinit-idempotent-teardown

Conversation

@forketyfork
Copy link
Owner

@forketyfork forketyfork commented Feb 25, 2026

Summary

  • make SessionState.deinit clean up shell, stream, and terminal based on handle presence instead of the spawned flag
  • keep SIGTERM guarded by spawned and !dead, but always deinit and null out owned handles
  • apply the same handle-based cleanup pattern in resetForRespawn

Why

This makes teardown idempotent when lifecycle flags and handles drift out of sync, avoiding stale-resource deinit crashes during close/relaunch paths.

Validation

  • zig build
  • zig build test
  • just lint

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 refactors the SessionState cleanup logic in deinit and resetForRespawn to make teardown idempotent by cleaning up resources based on handle presence rather than the spawned lifecycle flag. The SIGTERM signal is still guarded by spawned and !dead, but resource deinitialization now happens unconditionally when handles exist.

Changes:

  • Modified deinit to clean up shell, stream, and terminal based on handle presence rather than spawned flag
  • Modified resetForRespawn to use the same handle-based cleanup pattern
  • Lifecycle flags (spawned, dead, cwd_settled) are now reset unconditionally outside handle checks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@forketyfork forketyfork merged commit 8c14b0b into main Feb 25, 2026
8 checks passed
@forketyfork forketyfork deleted the fix/session-deinit-idempotent-teardown branch February 25, 2026 09:50
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