Skip to content

Add 'stale state on failure' check to code-reviewer and silent-failure-hunter agents #294

@N3SSQwiK

Description

@N3SSQwiK

Summary

The feature-dev:code-reviewer and pr-review-toolkit:silent-failure-hunter agents currently miss a class of bugs where methods return a failure status but leave the object in a stale/invalid state.

Example Bug Missed

In a recent PR review, both agents missed this issue (caught by Codex):

spawn(excludePositions, currentTick) {
    // Try random positions...
    // Fallback to exhaustive search...
    
    if (validCells.length > 0) {
        this.position = validCells[randomIndex];
        this.spawnTick = currentTick;
        return true;
    }

    // Bug: returns false but doesn't clear existing state
    return false;  // ← position and spawnTick still have old values!
}

Impact: When spawn() fails (grid full), the old position/spawnTick persist, causing stale data to be rendered and collected.

Fix was:

// No valid position available (grid is full)
// Clear food state to prevent stale data
this.position = null;
this.spawnTick = null;
return false;

Current Agent Coverage

code-reviewer checks:

  • Logic errors, null handling, race conditions
  • Security vulnerabilities, performance problems
  • Project guideline compliance

silent-failure-hunter checks:

  • Empty catch blocks
  • Swallowed exceptions
  • Fallback behavior without user awareness
  • Missing error logging

Neither specifically checks: "When a method fails, is the object left in a valid/clean state?"

Suggested Enhancement

Add to code-reviewer.md Bug Detection section:

**State Consistency on Failure**: When methods can fail (return false, throw, etc.), 
verify that partial state changes are reverted or cleaned up. Look for:
- Methods that modify `this.*` properties before a potential failure point
- Return statements that don't reset modified state
- Objects left in inconsistent states after errors

And/or add to silent-failure-hunter.md Hidden Failures section:

**Stale State on Failure**: Look for methods that:
- Return failure status without clearing previously-set properties
- Leave objects in partially-modified states after errors
- Could cause subsequent operations to use stale/invalid data

Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions