CAPYBALA: Context-Aware Pruning for Yielding and Backtrack-Aligned Loop Avoidance in Autonomous Software Engineering Agents
Abstract Autonomous software engineering agents frequently become entrapped in catastrophic error loops and cognitive deadlocks, burning millions of tokens while executing repetitive failing tool invocations. Existing self-reflection frameworks exacerbate token exhaustion by appending redundant verbal history to the context window, while naive context truncation routinely violates protocol invariants between tool calls and execution responses. We introduce CAPYBALA (Context-Aware Pruning for Yielding and Backtrack-Aligned Loop Avoidance), an in-memory runtime supervisor that tracks agent trajectory dynamics via a signed feature-hashed phase-space manifold (O(1) space complexity, sub-millisecond execution latency) and performs atomic context pruning with formal protocol pairing guarantees (N_tool_call = N_tool_response). Evaluated across an offline trajectory replay benchmark of 200 real-world SWE-bench agent runs and 3,209 execution turns from the open Nebius SWE-agent trajectory corpus, alongside live head-to-head coding duels on active commercial foundation models, CAPYBALA captures deadlocks with 86.00% to 97.86% recall, 95.56% to 98.56% precision (with 96.00% to 96.67% clean specificity), eliminates an aggregate 42.8% of wasted tokens (1,017,250 tokens across 200 trajectories, saving 59.74% of non-productive turns across stuck trajectories and 40.3% to 47.1% in live coding duels), and maintains a sub-millisecond mean decision latency (0.641 ms mean supervisor turn, p50 = 0.546 ms; 53 μs raw feature extraction, p50 = 38 μs; p99 = 5.84 ms tail) without requiring model fine-tuning or secondary embedding inference.
Authors
- Khairan Noor Fadhlillah (ORCID: https://orcid.org/0009-0001-8967-3425)
Publication Details
- Journal
- Research Square
- Published
- 2026-11-03
- DOI
- https://doi.org/10.21203/rs.3.rs-11597011/v1
- Primary Topic
- Software Engineering Research
- Type
- preprint