fix(session): reject kild open on active sessions#603
Merged
Conversation
…agent Root cause: open_session() has no guard checking session status before spawning. Fix: add AlreadyActive error + active-session guard with daemon liveness check, mirroring the AlreadyExists guard in create_session().
`kild open` on an already-active session unconditionally spawned a second agent process and overwrote `agent_session_id`, breaking `--resume` for the original conversation with no recovery path. Changes: - Add `AlreadyActive` error variant with actionable alternatives (attach, inject, stop+reopen) - Add active-session guard in `open_session()` before agent spawn - Daemon sessions get a liveness check via `sync_daemon_session_status()` so stale-active sessions (dead PTY) can still be reopened - Non-daemon sessions trust stored status (no reliable liveness check) Fixes #599
Owner
Author
PR Review SummaryReviewed by 5 specialized agents: code-reviewer, pr-test-analyzer, silent-failure-hunter, comment-analyzer, and self-reviewer. Critical Issues (3 found)
Important Issues (3 found)
Suggestions (5 found)
Strengths
VerdictNEEDS FIXES — 3 critical issues require changes before merge. The core approach is sound; the guard logic, error variant, and daemon liveness integration are correct. The critical fixes are:
Recommended Action Order
|
Critical fixes: - Remove redundant save_session_to_file in stale-active path — sync_daemon_session_status already persists via patch_session_json_fields which preserves unknown fields from newer binary versions - Gate guard on !BareShell — bare shell opens don't spawn agents and should not be blocked by the active-session guard - Update open_session docstring to reflect the new guard behavior Important fixes: - Add terminal liveness-skip log event for debuggability - Rename tests to follow <subject>_<expected_behavior> convention - Add BareShell bypass test to verify bare shells are not blocked - Stopped session test now adds an agent to prove status check, not just empty agents vec - Add kild stop assertion to error message test - Add comment explaining sync_daemon_session_status negation - Log resume field in open_started event - Log session_id in open_stale_active_synced event
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
kild openon an already-active session unconditionally spawned a second agent process and overwroteagent_session_idwith a new UUID. This created competing agents in the same worktree and permanently broke--resumefor the original conversation.Root Cause
open_session()had no guard checking session status before spawning — unlikecreate_session()which checks forAlreadyExists. The agents vec got a duplicate push androtate_agent_session_id()silently discarded the live session ID.Changes
crates/kild-core/src/sessions/errors.rsAlreadyActiveerror variant with actionable alternatives (attach, inject, stop+reopen)crates/kild-core/src/sessions/open.rscrates/kild-core/src/sessions/errors.rsAlreadyActiveerrorcrates/kild-core/src/sessions/open.rsDesign Decisions
sync_daemon_session_status()verifies the PTY is truly running. Stale-active sessions (daemon PTY died withoutkild stop) get synced to Stopped and can reopen normally.kild stopthenkild open.--allunaffected: Theopen --allCLI path already filters forStoppedsessions only.Testing
cargo fmt --checkpassescargo clippy --all -- -D warningspassescargo test --allpasses (all existing + 3 new tests)Validation
Issue
Fixes #599