fix: detect early PTY exit in daemon sessions (#320)#341
Merged
Conversation
When a daemon PTY process exits immediately after spawn (bad resume session, missing binary, env issue), kild now detects it within 200ms instead of letting the user discover it later via `kild attach`. Changes: - Add exit_code field to DaemonSession and SessionInfo wire type - Store exit_code in handle_pty_exit before transitioning to Stopped - Add get_session_info() and read_scrollback() daemon client functions - Add DaemonPtyExitedEarly error variant with exit code and scrollback - Add post-creation health check in both create_session and open_session daemon paths (200ms grace period + daemon status poll) - Clean up stopped daemon session on early exit detection Fixes #320
Owner
Author
Self Code ReviewSummaryClean implementation that directly addresses the root cause. No critical issues found. FindingsStrengths
Edge Cases Handled
SecurityNo security concerns identified. Checklist
|
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.
Summary
When using
kild open --daemonorkild open --resume --daemon, the daemon PTY session sometimes exits immediately after spawning. Thekild opencommand reported success (session set to Active), butkild attachfailed with the confusing error "session not running" — with no diagnostic info about why.exit_codefield toDaemonSessionandSessionInfoso the exit code is stored and surfaced via IPCget_session_info()andread_scrollback()daemon client functions for the health checkcreate_sessionandopen_sessiondaemon pathsRoot Cause
No post-creation health check existed in the daemon code path.
create_pty_session()returned as soon as the daemon spawned the PTY, and the exit code was logged but discarded. Fast-failing processes (bad resume session, missing binary, env issues) would exit within milliseconds, but kild-core saved the session as Active and returned success.Changes
crates/kild-daemon/src/session/state.rsexit_codefield, getter, setter toDaemonSessioncrates/kild-daemon/src/types.rsexit_codetoSessionInfowire typecrates/kild-daemon/src/session/manager.rshandle_pty_exitbeforeset_stoppedcrates/kild-core/src/daemon/client.rsget_session_info()andread_scrollback()functionscrates/kild-core/src/sessions/errors.rsDaemonPtyExitedEarlyerror variant with diagnosticscrates/kild-core/src/sessions/handler.rsTesting
cargo fmt --check— cleancargo clippy --all -- -D warnings— 0 warningscargo test --all— all tests passcargo build --all— clean buildValidation
Issue
Fixes #320