Repository navigation
Agent processes outlive their closed tab: task-recreate-worker and task-done should see processes running in the worktree: scan the worktree for agent processes, refuse or --kill-stale on recreate, warn on task-done (#305) - #313
Merged
Conversation
…sk-done should see processes running in the worktree: scan the worktree for agent processes, refuse or --kill-stale on recreate, warn on task-done (#305) A new `lib/worktree-procs.sh` lists agent processes (`claude`, `kiro-cli*`, bun/node running kiro-cli, and their children) whose cwd is inside a worktree: one `ps` pass, then `/proc/<pid>/cwd` or one batched `lsof` for the candidates only. The caller's own agent tree is excluded. `task-recreate-worker` refuses while any run, listing them; `--force` does not bypass it. `--kill-stale` sends TERM then KILL after a TTY confirmation (or `--yes`), re-checking pid start times before signalling. `task-done` warns, lists and logs `stray-procs:`, and never signals. Tests stub ps, lsof and the signal sender with pids above every kernel's pid ceiling; the suite sets TASK_FORCE_NO_PROC_SCAN=1 elsewhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
Spec compliance (#305)
The PR body opens with What I verified
FindingsNo blockers. Nits, worth fixing in this PR since each is small:
Verdictclean-with-nits. The spec is fully delivered, the tests are green, and the real- |
Owner
Author
PM: one round before mergeCI is green. Please take all four of the reviewer's nits in this PR (tight-PR norm), plus one test gap from my mutation check:
Mutation-check 1, 4 and 5 yourself before |
…sk-done should see processes running in the worktree: review round on #313 - Liveness after TERM/KILL is a re-scan of the worktree, not `kill -0`, which fails alike for a gone process and one we may not signal (EPERM). A process that refuses the signal now stops the recovery. - An agent is judged by what runs: the `claude` / `kiro-cli*` binary, a bun or node launcher whose script is one, or a shell `-c` wrapper that runs one. `less docs/claude` no longer counts. - Self-exclusion fixture now has task-work's `bash -ic` wrapper above claude, so keeping the innermost agent as root goes red. - pty tests for the `[y/N]` prompt: y signals, n and EOF signal nothing. - Docs: from the worker's own tab the worker is not listed; from the PM's tab a live worker is, and is not necessarily stray. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
task-recreate-workerandtask-donenow look for agent processes still running inside the worktree, so a kiro or claude agent whose tab closed without taking it along is no longer invisible. Recovery refuses while one runs (or stops it with--kill-stale), andtask-donewarns and lists it instead of leaving it behind silently.Closes #305
What changed
lib/worktree-procs.sh(new):aw_worktree_agent_procs <dir>printspid\tstart\tcommandfor agent processes (claude,kiro-cli*, bun/node running kiro-cli) and their descendants whose cwd is in the worktree. Cost is oneps -Aplus a cwd lookup for candidates only:/proc/<pid>/cwdon Linux, one batchedlsof -a -d cwd -Fpnelsewhere. The outermost agent among the caller's ancestors is excluded with its whole tree, sincetask-doneruns under the finishing worker's own agent. Bash 3.2 safe.TASK_FORCE_NO_PROC_SCAN=1disables it.task-recreate-worker: refuses and lists the pids, after all other refusals.--forcekeeps its meaning and does not get past this.--kill-stalesends TERM, then KILL after 5s, after a[y/N]on the terminal;--yesskips it, and with no TTY and no--yesit refuses without signalling. It rescans right before signalling and signals only pids still listed with the same start time (recycled pid guard). A survivor of KILL stops the recovery. Logged asstray-procs:.task-done: warns, lists, prints thekillline and logsstray-procs:(its tab closes right after). It never signals. I left out a--kill-stalethere: the PM decides.task-monitor-snapshot: unchanged. The optional flag would cost a process scan on every refresh.Tests
tests/worktree_procs.bats(17), with stubbedps/lsof/signal sender and pids above both kernels' pid ceilings, so no real process can be reached. It covers: scan scope (other worktree, path prefix, non-agent, caller's own tree, non-agent children),/procmode with a deleted cwd, the kill switch, refusal with and without--force,--kill-stalesignalling exactly the worktree's pids, KILL for a survivor only, a recycled pid skipped, a process that will not die, the no-TTY refusal, no-processes leaving recovery unchanged, andtask-done's warning, log line and no-warning case.Mutation-checked: 18 deliberate breaks of the helper, recreate and task-done each turned at least one test red. Two first-round survivors were fixed: a redundant ancestor-drop line was removed, and a non-agent-child test was added.
tests/setup_suite.bashsetsTASK_FORCE_NO_PROC_SCAN=1for every other suite, so the suite never reads this machine's process table.loadout_modules.bats's fakeroot now copies the new lib.Full suite: 1612/1615 on the first run, with the 3 failures in
loadout_modules(the missing fakeroot lib). After the fix that file passes 23/23. The full suite was not re-run end to end after the fix.tools/check-drift.shandshellcheck -xare clean.Not covered
Not verified against a live process table, by design (PM guardrail). The agent-command pattern and the ancestor exclusion are calibrated on fixtures only, not on real
psoutput from a running kiro or claude. The[y/N]prompt path has no pty test; the no-TTY and--yespaths are tested.Docs: README (recreate section + troubleshooting row), the 7 steering templates,
.claude/gh-workflow.md, CHANGELOG.🤖 Generated with Claude Code