# patch agent failed when agent ran axe re-check too early - how to fix it

## TL;DR

Sequence the re-check after the patch settles: wait for the framework's render commit (or a mutation-settle window) before re-running axe. Re-checking mid-render audits a half-patched DOM and reports phantom failures. One line of why: patches land asynchronously in component frameworks, and axe snapshots whatever exists at call time.

## The error, verbatim

```text
PatchAgentError: re-check ran too early, phantom violations
    patch: applied at t=0ms, axe ran at t=50ms, render committed at t=400ms
    result: reported the violation as still present (false negative on the fix)

```

## Fix it step by step

### Step 1: Reproduce the early re-check

```bash
node agent/remediate.js | rg -i 'too early|phantom|false' | head -5
```

Expected: Re-checks report violations that a later scan shows as fixed.

### Step 2: Measure the render commit delay

```bash
node -e "console.log('patch applied t=0, DOM settled t=400ms, axe ran t=50ms')"
```

Expected: Instrumentation shows the race.

### Step 3: Wait for settle before re-check

```bash
rg -n 'recheck|verify|axe.run' agent/remediate.js | head -10
```

Expected: Add: wait for mutation settle (e.g. 500ms quiet) or framework commit before axe.run.

### Step 4: Re-run remediation

```bash
node agent/remediate.js | tail -4
```

Expected: Re-checks run on settled DOMs and report real results.

### Step 5: Add a regression probe

```bash
node agent/run-audit.js --smoke | tail -3
```

Expected: Smoke run passes; schedule it so the breakdown is caught if it ever regresses.

## When to use this skill

- You run an agent that scans UIs for accessibility and it hits this breakdown
- The agent's scan loop stalls, crashes, or loops on this exact failure
- You are hardening an audit agent's error handling for production scans

## When NOT to use this skill

- A human runs the scan manually and it works, this is agent-harness failure handling
- The scan completes and only reports violations, use the rule-specific skills

## Compatibility

Remediation agent with axe re-scan verification. Settle detection is a MutationObserver quiet window. Pin the tool version in the lockfile so scans stay reproducible across machines.

## Variant phrasings

### agent axe recheck race

Same race, same settle wait.

### verification ran before render committed

Practitioner phrasing.

### the breakdown hits other routes too

Agent failure modes are systemic; apply the hardening to every route the agent covers, not just the one that failed.

## Why it happens

In component frameworks, a patch (state change, DOM edit) does not hit the DOM synchronously; the framework batches and commits later. An agent that re-runs axe immediately audits the pre-patch DOM and concludes the fix failed, then either loops or reports a false negative. The fix is a settle wait: observe DOM mutations and run axe after a quiet window, or hook the framework's commit signal. The wait only needs to cover the render, not network, so it is short. Agent breakdowns are systemic: the same failure mode will hit every route, page, or run the agent touches. Harden the harness once (timeouts, loop detection, verification gates) instead of patching per page, and keep breakdown telemetry separate from violation counts.

## Edge cases

- A 500ms mutation-quiet window is a good default, tune per app if renders are slower.
- Do not use fixed sleeps alone, they are either too short (race persists) or too long (slow runs).
- If the patch triggers async data fetches, wait for those too, or scope the re-check to the patched region.
- Log breakdowns separately from violations in agent telemetry; mixing them hides whether the agent itself is getting more reliable.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_NQjD-omt-0bIAYPEF-irqw
