agh-cleanup-failure-paths

Installation
SKILL.md

Cleanup Failure Paths

Hermes review issue #001 cost a real PR round because a procCtx leaked when registry registration failed. The happy path was clean; the partial-failure path leaked. This pattern recurs in every AGH PR that adds multi-step setup. Activate this skill before editing any function that creates/extends a context, registers a resource, opens a connection, or spawns a subprocess.

Procedures

Step 1: Identify Setup-Step Boundaries

  1. Read the target function and enumerate every "step" that allocates a resource: context creation, file open, listener bind, registry register, lease claim, goroutine spawn, subprocess start, HTTP request, mutex lock, transaction begin.
  2. For each step, identify the cleanup action that pairs with it: cancel(), Close(), Unregister(), Release(), Stop(), defer cancel(), tx.Rollback().
  3. Read references/cleanup-table.md for the canonical pairing table.

Step 2: Walk Every Error Return

  1. List every return ... err statement in the function.
  2. For each one, walk backward through the function body and confirm every resource allocated above the return point is cleaned up — either by an immediate defer adjacent to its allocation OR by an explicit cleanup call before the return.
  3. If a resource is allocated and the only cleanup is on the success path, that's a leak. Add cleanup on the error path.
  4. Treat panic recovery and runtime.Goexit as additional exit paths — defer covers both.
Installs
1
Repository
compozy/agh
GitHub Stars
139
First Seen
Jun 16, 2026
agh-cleanup-failure-paths — compozy/agh