fix(cli): prevent self-destruction via --all commands#604
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().
When honryu (or any agent) runs `kild stop --all` or `kild destroy --all` from inside its own session, it now skips itself and prints a note. Explicit single-branch commands (`kild stop honryu`) still work but print a warning. Changes: - Add `resolve_self_branch()` helper using $KILD_SESSION_BRANCH + CWD fallback - Filter calling session from stop --all and destroy --all loops - Add self-targeting warnings for explicit stop/destroy commands - Add unit tests for resolve_self_branch() Fixes #600
Sessions created with --main use the project root as worktree_path, causing any CWD inside the project to false-positive match. The env var path ($KILD_SESSION_BRANCH) is authoritative for --main sessions.
Owner
Author
Self-ReviewSummaryFix is clean and addresses the root cause: FindingsStrengths
Post-Review Fix Applied
Design Decision: Warn vs Block on Explicit Self-TargetingThe explicit path ( Checklist
|
Changes warn-only self-targeting to a hard block: explicit `kild stop <self>` and `kild destroy <self>` now require --force. Adds --force flag to `kild stop` command. Addresses review feedback: an agent reading only stdout would silently self-destruct with warn-only behavior.
Owner
Author
PR Review SummaryReviewed by 4 specialized agents: code quality, silent failures, test coverage, docs impact. Critical Issues (3 found)
Important Issues (4 found)
Test Gaps (3 found)
Documentation Updates
Committed as Strengths
Verdict: NEEDS FIXESPriority:
|
- Add warn! logs to resolve_self_branch() CWD and session lookup
fallback failures (prevents silent self-protection bypass)
- Add .conflicts_with("all") to --force on stop_command() so
`kild stop --force --all` is rejected by clap instead of silently
ignoring the flag
- Downgrade error! → warn! on policy block events (cli.stop_failed,
cli.destroy_failed) — these are expected behavior, not errors
- Add structured log events for --force override paths
(cli.stop_self_forced, cli.destroy_self_forced)
- Add mutex to serialize env-var-mutating tests for thread safety
- Add CLI parse tests for stop --force, stop -f, and
stop --force --all conflict
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 honryu (or any agent) runs
kild stop --allorkild destroy --allfrom inside its own session, it includes itself in the operation — killing its own process mid-execution and leaving the fleet unmanaged.Root Cause
The
--alliteration loops inhandle_stop_all()andhandle_destroy_all()had no self-exclusion filter. Self-detection primitives existed ($KILD_SESSION_BRANCHenv var, CWD-based worktree path match) but were only wired intoagent-status.Changes
crates/kild/src/commands/helpers.rsresolve_self_branch()— tries$KILD_SESSION_BRANCHthen CWD fallbackcrates/kild/src/commands/stop.rs--allloop; warn on explicit self-stopcrates/kild/src/commands/destroy.rs--allloop; warn on explicit self-destroyTesting
cargo fmt --checkpassescargo clippy --all -- -D warningspassescargo test --allpasses (3 new tests forresolve_self_branch)cargo build --allcleanValidation
Fixes #600