#ai-generated
Summary
worktree_stop (exposed via the agent-worktree MCP, backed by core/process_lifecycle.py) appeared to hang / not return in a session where the tracked Unity process had already exited externally (closed/Stop-Process), leaving a stale running record with a dead PID.
Context / observations
- The worktree record still showed
status: running with an old PID (e.g. pids.main = 41020) while no Unity.exe was actually running.
- Calling
worktree_stop (with kill_orphans=true) in this state did not return promptly; it had to be interrupted repeatedly.
- This surfaced during the cache-server investigation (see the companion ticket about
worktree_start + Cache Server). It may share the same area of the codebase (process_lifecycle.py).
Hypotheses to check
- Graceful-shutdown wait (SIGTERM/CtrlBreak → timeout → kill) blocking when the PID is already dead/reparented.
kill_orphans cwd/open-file scan blocking or iterating over a large/locked set.
- Reconciliation of a stale
running record not short-circuiting when the recorded PID no longer exists.
Suggested next step
Add a fast path: if the recorded PID is not alive, mark the record stopped and return immediately (idempotent), and bound/parallelise the orphan scan with a hard timeout so worktree_stop always returns within the documented timeout.
Relevant code
src/lib_python_worktree/core/process_lifecycle.py (stop / graceful-shutdown / orphan-scan logic).
Note: observed on Windows; not yet confirmed on POSIX.
#ai-generated
Summary
worktree_stop(exposed via the agent-worktree MCP, backed bycore/process_lifecycle.py) appeared to hang / not return in a session where the tracked Unity process had already exited externally (closed/Stop-Process), leaving a stalerunningrecord with a dead PID.Context / observations
status: runningwith an old PID (e.g.pids.main = 41020) while noUnity.exewas actually running.worktree_stop(withkill_orphans=true) in this state did not return promptly; it had to be interrupted repeatedly.worktree_start+ Cache Server). It may share the same area of the codebase (process_lifecycle.py).Hypotheses to check
kill_orphanscwd/open-file scan blocking or iterating over a large/locked set.runningrecord not short-circuiting when the recorded PID no longer exists.Suggested next step
Add a fast path: if the recorded PID is not alive, mark the record
stoppedand return immediately (idempotent), and bound/parallelise the orphan scan with a hard timeout soworktree_stopalways returns within the documentedtimeout.Relevant code
src/lib_python_worktree/core/process_lifecycle.py(stop / graceful-shutdown / orphan-scan logic).Note: observed on Windows; not yet confirmed on POSIX.