Skip to content

Correctness sub-agent should check Go resource lifecycle patterns (defer Close, http.Response.Body) #4053

Description

@fullsend-ai-retro

What happened

On PR #3194, the review agent's correctness sub-agent analyzed IsProtectedBranch across 12 review runs (Jul 7-10). Every run praised its URL escaping and error handling. But the success path (HTTP 200 response) discarded the *http.Response without closing its body — a textbook Go resource leak. Every other c.get() call site in the same file passes the response to decodeJSON (which defers Body.Close) or closes it explicitly.

The human reviewer flagged this as high severity, noting it was 'flagged independently by 4/8 review-squad agents.' Qodo's initial review also found 4 bugs (unescaped URL, nil maps, state mismatch, wrong error type) that the review agent missed in its first pass. The resource leak was fixed by the author after round 1 of human review.

Related but distinct from #3966 (resource cleanup symmetry in multi-phase operations). That issue addresses cross-phase rollback in orchestration flows; this addresses single-function resource lifecycle in Go HTTP client code.

What could go better

The correctness sub-agent's runtime mechanism checklist covers guard mechanisms and failure paths but has no guidance on resource lifecycle patterns. In Go, every *http.Response must have Body.Close() called on all paths — this is one of the most common Go code review items. The sub-agent demonstrably analyzed the function in detail (commenting on PathEscape, EqualFold) but didn't apply the resource lifecycle lens. Confidence: high — 12 runs all missing the same well-known pattern, while 4/8 human review-squad agents caught it independently, indicates this is a prompting gap rather than a model capability gap.

Proposed change

Add a 'Resource lifecycle checklist' section to the correctness sub-agent (internal/scaffold/fullsend-repo/skills/pr-review/sub-agents/correctness.md) alongside the existing 'Runtime mechanism checklist.' The new section should instruct:

  1. Every acquired resource (http.Response, file handle, database connection, mutex lock) must have a corresponding release on all code paths — success, error, and early-return.
  2. For Go HTTP calls specifically: any call that returns *http.Response must have resp.Body.Close() on all paths, including the success path when the body is not decoded. Pattern to flag: _, err := httpCall(...) discarding the response without verifying the callee closes it internally.
  3. When reviewing a function that manipulates resources, trace the lifecycle: acquire → use → release. If any path skips release, flag it as a medium+ finding.

This fits the existing checklist structure and should trigger on the same class of bug.

Validation criteria

Run the correctness sub-agent on PR #3194's original diff (or a synthetic PR introducing an HTTP call that discards a successful response body). The sub-agent should flag the unclosed resp.Body as a medium+ finding. Success metric: the sub-agent catches Go resource lifecycle bugs that Qodo and the human review-squad caught on this PR.


Generated by retro agent from #3194

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

    agent/reviewReview agentfeatureFeature-category issue awaiting human prioritizationpriority/mediumNormal priority, plan for next cycletriagedTriaged but awaiting human prioritizationtype/featureNew capability request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions