Skip to content

fix(autofix): Safe sweep pattern bug + auto-dispatch Codex for partial fixes #266

Description

@stranske

Why

Testing the autofix system on PR stranske/Manager-Database#84 revealed two issues preventing the system from fully resolving CI failures:

  1. Bug: Safe sweep pattern matching fails when repo has Python at root
  2. Gap: Non-agent PRs never get Codex fallback, even when quick autofix partially succeeds

Scope

Bug #1: Safe Sweep Pattern Matching

Location: .github/workflows/reusable-18-autofix.yml - "Summarise safe sweep results" step

Problem: When a repo has Python files at the root directory:

  • find . -name "*.py" returns . as a directory
  • clean_dir="${dir#./}" transforms .. (not empty)
  • Pattern becomes ./** which does NOT match paths like tests/file.py
  • Git diff outputs paths without leading ./, so ./** never matches

Evidence:

[autofix] Target directories: .
Found 22 errors (16 fixed, 6 remaining).
[autofix] ERROR: safe sweep produced changes outside allowed globs:
  - tests/test_autofix_validation.py

Fix:

clean_dir="${dir#./}"
if [[ "$clean_dir" == "." || -z "$clean_dir" ]]; then
  allowed_patterns+=("**")  # Match all files at root
elif [[ -n "$clean_dir" ]]; then
  allowed_patterns+=("${clean_dir}/**")
fi

Gap #2: Auto-Dispatch Codex for Partial Fixes

Location: .github/workflows/agents-autofix-loop.yml - "Evaluate workflow_run" step

Current behavior:

const autofixEnabled = configMatch ? configMatch[1] === 'true' : hasAgentLabel;
if (!autofixEnabled) {
  return stop('autofix disabled for this pull request');
}

Problem: Human-created PRs that:

  • Get quick autofix (lint/black) ✅
  • Have remaining unfixable issues (mypy, test failures) ❌
  • Never get Codex dispatch because no agent:codex label

Proposed Design (Option C): Auto-dispatch Codex when quick autofix partially succeeded:

  1. Quick autofix runs on all PRs
  2. If autofix fixed some issues but Gate still fails...
  3. Automatically enable Codex dispatch for that PR
  4. Add autofix:escalated label to track

Implementation approach:

  • Check autofix workflow outputs for changed=true AND remaining > 0
  • OR check if Gate failed after autofix commit was pushed
  • Enable Codex dispatch with limited attempts (e.g., 1-2 vs 3 for agent PRs)

Non-Goals

  • Changing behavior for PRs with explicit autofix: false in body
  • Unlimited Codex retries on non-agent PRs
  • Dispatching Codex for PRs where quick autofix made no changes

Tasks

  • Fix safe sweep pattern for root directory Python projects
  • Add unit test for ./** vs ** pattern matching
  • Modify agents-autofix-loop to check for partial autofix success
  • Add autofix:escalated label definition
  • Limit Codex attempts for auto-escalated PRs (1-2 max)
  • Update documentation on autofix behavior

Acceptance Criteria

  • Autofix can push fixes when repo has Python at root
  • Human PRs with partial autofix success get Codex dispatch
  • Auto-escalated PRs have limited retry count
  • autofix:escalated label applied when Codex auto-dispatched
  • PRs with autofix: false still opt out completely

Test PR

stranske/Manager-Database#84 - Contains intentional lint, mypy, and test failures for validation

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:codexAgent-created issues from Codex

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions