Skip to content

infra: clean up agent workspace + processes on completion (worktrees, temp, child procs) #11

Description

@jg-noncelogic

HIGH — second root cause of the OOM crash. When an agent finishes (success, failure, OR host death) its resources are not reliably reclaimed: the crashed run left ~7 git worktrees (.claude/worktrees/*, ~/ws/*, /tmp/sf-*) and orphaned processes behind. Accumulated resources contributed to the OOM and left a dirty workspace.

Fix: a per-agent/per-ticket cleanup contract that runs in a finally (so it fires even on error/timeout): git worktree remove --force the ticket worktree, delete temp dirs, kill child processes spawned by the agent. The delivery-train integrator already removes worktrees on merge — extend to the non-merge/left-open/died paths (overlaps with #7) and make it a harness-level guarantee, not engine-specific. Add a startup sweep that prunes stale worktrees/temp from prior crashed runs.


Filed 2026-06-16 after the delivery-train host OOM crash mid-run (CDP/Chrome memory leak + no agent resource cleanup). The run had ~12 orphaned --remote-debugging-port=9222 Chrome procs (~1GB, reparented to systemd-user, 12h old) and ~7 leftover git worktrees that were never reaped — host ran out of memory and stalled, killing the workflow ~16/18 tickets in.

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions