context limit error mid large-file remediation agent run
Fixes remediation agent context limits on large files with slice-based patching and generated-file exclusion. Use it when giant files blow the context budget. Not for normal source files, which fit comfortably.
context limit error mid large-file remediation agent run - how to fix it
TL;DR
Exclude the large files from the working set and patch by slice: skip bundles and generated files entirely, load only the code around each violation, and process violations one at a time with progress on disk. One line of why: a single 2MB file can eat the whole context, and the agent never needed the whole file.
The error, verbatim
RemediationAgentError: context limit exceeded
file: generated/api-client.js (2.1MB, 41000 lines)
violations_in_file: 3 (all in the header comment block)
Fix it step by step
Step 1: Reproduce the overflow
node agent/remediate.js --file generated/api-client.js | rg -i 'context|limit' | head -3Expected: The run dies loading the giant file.
Step 2: Confirm the violations are local
npx @axe-core/cli https://example.com/ --save axe-big.json | tail -2Expected: The violations are in a small region of the file.
Step 3: Add slice-based patching
rg -n 'slice|window|chunk' agent/remediate.js | head -10Expected: Add: load 200-line windows around each violation, exclude generated files by pattern.
Step 4: Re-run remediation
node agent/remediate.js | tail -4Expected: Agent patches the slices and completes within budget.
Step 5: Add a regression probe
node agent/run-audit.js --smoke | tail -3Expected: 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 on any LLM backend. Slicing is harness logic around the violation locations. Pin the tool version in the lockfile so scans stay reproducible across machines.
Variant phrasings
agent context limit large file
Same overflow, same slicing.
remediation OOM generated file
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
Generated files (API clients, bundles, vendored code) are huge and occasionally contain violations, and agents that load whole files into context die on them. The violations are always localizable: axe reports selectors or line hints, and the patch needs only the surrounding slice. The harness should exclude generated files by pattern by default (they should be fixed at the generator, not patched), and for legitimately large source files, window the context around each violation. 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
- Generated files get fixed at the generator or config, not by patching the output.
- 200-line windows cover nearly every violation's context, tune only if patches keep missing.
- Track context usage per file and skip-with-report above a threshold, never crash the run.
- 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_kR05f1zz4rHrVZBTwt5IsQ