Skip to content

worktree_stop appears to hang / not return when the target process is already gone #50

@Seretos

Description

@Seretos

#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-generatedCreated by the project-issues AI agent

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions