eng-cleanup-failure-paths

Audit Go functions for resource leaks across every error and cancellation exit path.

2.7k|171|Updated Mar 28, 2026
One-click install
npx skills add https://github.com/compozy/compozy --skill eng-cleanup-failure-paths
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: eng-cleanup-failure-paths
Source: https://github.com/compozy/compozy/tree/main/.agents/skills/eng/eng-cleanup-failure-paths
Command: npx skills add https://github.com/compozy/compozy --skill eng-cleanup-failure-paths

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go functions that acquire multiple fallible resources (contexts, files, transactions, leases, subprocesses, HTTP responses) often leak them on error, cancellation, or panic paths, causing deadlocks, leaked ports, and poisoned connections that are hard to detect in review.

Core Features & Use Cases

  • Acquisition Matrix Audit: Enumerates every resource acquisition in a changed function and maps each to its owner, cleanup action, error policy, and shutdown order using a canonical pairing table.
  • Exit-Path Verification: Walks success, error, cancellation, panic-recovery, and runtime.Goexit exits backward to prove every live resource is released or ownership is transferred.
  • Canonical Failure Testing: Provides test patterns that inject failing dependencies, cancel mid-flight, force HTTP body failures, and restart components to prove resources are actually released rather than merely called.
  • Use Case: After modifying a daemon function that claims a task lease, registers with a registry, and spawns an ACP subprocess, run this audit to confirm the lease is released when registration fails and the process group is killed on context cancellation.

Quick Start

Audit the function I just changed for cleanup gaps on every error and cancellation path, and add tests proving each resource is released.

Frequently Asked Questions about eng-cleanup-failure-paths

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find resource leaks in Go error handling paths?

Build an acquisition matrix listing every fallible resource the function acquires, then walk backward from every exit (success, error, cancellation, panic) to confirm each resource is released or ownership is transferred. Pair each acquisition with its canonical cleanup, such as defer cancel() after context.WithTimeout.

How to test cleanup failure paths in Go?

Inject a failing dependency through an interface, then assert the resource is actually released, not just that a cleanup method was called. For subprocesses, cancel the parent context mid-flight and assert the process group exits within a timeout; for HTTP, force a 5xx and verify the body is drained and closed.

Should I drain HTTP response bodies on error responses in Go?

Yes, always drain the body even on non-2xx responses, otherwise the connection is poisoned for keep-alive reuse. Account for both the io.Copy drain error and the Close error, and do not double-drain when an SSE reader already handles it.

When should I not use a cleanup failure-path audit?

Skip it for pure transformations, read-only helpers, and test-only code that acquire no fallible resources. The audit targets functions that acquire, register, start, claim, lease, or open more than one resource before returning.

Why does deferring too many cleanups in one Go function cause problems?

More than roughly six defers signals the function owns too many resources and cannot prove cleanup on every exit. Split ownership into smaller helpers, push cleanup to the caller via an opener-closer pair, or return a cleanup func() callback before adding more defers.