Skip to content

needle stop --all exits non-zero on a successful shutdown (orphan check races graceful exit) #19

Description

@brianhendry

needle stop --all kills the tmux session; the workers then exit gracefully over the next few seconds. The post-kill check runs before they finish, reports them as orphans, and exits non-zero on what was a successful shutdown.

Reproducible on three consecutive stops (needle 0.6.0, Ubuntu 22.04.5 / WSL2).

$ needle stop --all && sleep 2 && pgrep -af "needle run" || echo clean
Error: 2 needle process(es) still running after kill attempt for session 'needle-claude-alpha':
  PID 5963: ... --identifier alpha
  PID 6006: ... --identifier bravo
can't find session: needle-claude-alpha
Error: needle-claude-alpha - kill attempt reported success but 2 process(es) still running
...
5963 ... --identifier alpha
6006 ... --identifier bravo

$ kill 5963 6006
-bash: kill: (5963) - No such process
-bash: kill: (6006) - No such process

$ pgrep -af "needle run" || echo clean
clean

Both processes had exited by the time kill ran. Nothing leaks — they were mid-shutdown when the check fired.

Impact: a script using needle stop --all as a gate treats a clean shutdown as a failure, and the error text names PIDs that no longer exist.

Suggested: poll for exit with a short grace period (5–10s) before declaring orphans, and distinguish "still running after the grace period" from "still running right now".

Possibly the same underlying behaviour as the ⚠️ Found 1 unregistered needle run process(es) warning I saw on v0.4.2 — a worker observed mid-flight rather than a genuine orphan.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions