# Research: why agents get lost as the repo grows (and recover when it's structured)

## Metadata

- Author: Fable 5 (Claude Code session, 2026-08-02)
- Purpose: to respond with a scientific/mathematical profile to the user's observation, and to serve as input for **adversarial comparison** against an equivalent research by Codex
- Original question: *"An AI agent with a small project works perfectly; at some indeterminate moment, when the repo grows, it gets lost, takes diverse paths and wants to rewrite everything; when the software is structured in sealed compartments and tests are extensive, it regains its bearings. Is it studied? Can you introspect and give a mathematical profile?"*
- Convention: each claim carries a confidence level — **[HIGH]** published and verified evidence, **[MEDIUM]** published evidence not verified in depth or strong inference, **[SPECULATIVE]** own reasoning or analogy.

## 0. Executive summary

The phenomenon is real, is studied in parts (and since 2025-2026 also as a compound), and the user's key observation — that the curve is **U-shaped, not monotonic** — rules out repo size as a causal variable. The correct variable is the relationship between the **minimum founded context required by the task (K)** and the **agent's effective context capacity (C_eff)**. Structure (information hiding) bounds K; tests convert the open loop into a closed loop and accumulated error goes from quadratic to linear. The impulse to rewrite is a rational decision under biased estimates, amplified by autoregressive bias toward fresh code.

## 1. Claims about the literature

### C1. Collapse by size/complexity is measured and abrupt, not gradual — [MEDIUM]

Recent repo-level benchmarks report a *scaling collapse*: ~91% pass rate in repos <10K LOC, ~67% in 10-50K, **~15% in >50K**, with most repos >100K LOC below 20%. Fine finding: the problem **is not** that code doesn't fit in context (agents read on-demand and compact) — it is maintaining a coherent architectural model across thousands of interdependent files.

- Provenance note for adversarial comparison: figures taken from search results on 2026 benchmarks ([ProjDevBench](https://arxiv.org/html/2602.01655v1), [Rust repo-level issue resolution](https://arxiv.org/html/2602.22764v1)); the exact attribution of the LOC table requires direct verification of the source paper.

### C2. Degradation by iteration is measured: the agent extends its own anti-patterns — [MEDIUM]

Under repeated editing, each turn preserves and amplifies anti-patterns from previous turns ([SlopCodeBench](https://arxiv.org/html/2603.24755v1)). Constraints declared at the beginning are progressively lost — the literature calls this *constraint decay* ([paper](https://arxiv.org/html/2605.06445)) — which is exactly the "objective drift" observed.

### C3. The mathematics of horizon: geometric decay with increasing ε — [HIGH in form, MEDIUM in constants]

With failure probability per step ε, success at T steps decays as **(1−ε)^T**. Moreover ε is not constant: it grows with context length, approximately **ε(t) ≈ ε₀ + α·log t** (attention dilution). Reported consequences: with ε > ~0.014 you don't reach 50% in long horizons; empirical phase transition around ~50 steps. METR measured that the horizon-to-50% of frontier models doubles every ~7 months — improves the crossing point, not the functional form ([Illusion of Diminishing Returns](https://arxiv.org/pdf/2509.09677), [Reliability Science](https://arxiv.org/pdf/2603.29231), [Long-Horizon Task Mirage](https://arxiv.org/html/2604.11978v1)).

### C4. The foundations are pre-LLM and human — [HIGH]

Parnas 1972 (*information hiding*), Baldwin & Clark (*Design Rules*, modularity as options theory), MacCormack et al. (*propagation cost* on Design Structure Matrices) predict the same phenomenon for human teams: the cost of change scales with coupling, not size. The agent exhibits the human phenomenon **amplified**, because its working memory is more rigid.

### C5. There exists (that we know) no paper naming the compound U-curve as such — [MEDIUM]

The components are studied separately (long-context degradation, error compounding, modularity, verifiable rewards). The compound curve *small-good / medium-chaotic / large-structured-good* seems to have no canonical name. Explicitly attackable point for rival research: if such a paper exists, this document loses an originality it claims.

## 2. The proposed mathematical profile

### M1. The causal variable: K vs C_eff — [SPECULATIVE as formalization, consistent with C1-C3]

For each task, let:

- **K** = minimum *founded* context (read, not assumed) necessary to act correctly;
- **C_eff** = effective context capacity (< nominal window, due to attention dilution).

The agent operates well while **K < C_eff**. The three regimes of the U-curve:

| Regime | K | Result |
| --- | --- | --- |
| Small repo | K ≈ entire repo < C_eff | Total observability; knowledge, not assumption |
| Medium without structure | coupling ⇒ K ~ O(repo) > C_eff | Decisions on unfounded priors; divergent paths = prior sampling |
| Large structured | information hiding ⇒ K ≈ module + interfaces, **independent of total** | K < C_eff again; regains bearings |

Alternative equivalent formalization: error rate grows with **H(I | G)** — the conditional entropy of necessary information given founded information in context.

### M2. Why the moment is "indeterminate" and feels sudden — [SPECULATIVE, with empirical anchors]

Two superimposed threshold mechanisms:

1. **Stochastic crossing per task**: K > C_eff doesn't occur for all tasks at once; collapse appears erratic before becoming systematic.
2. **Percolation of dependency graph** (formal analogy, not measurement): without boundaries, the graph densifies like a random graph; in Erdős–Rényi the giant component emerges discontinuously when mean degree crosses 1. The radius of impact of a change jumps from local to global at once. Phase transitions *feel* like "an indeterminate moment when everything broke". Empirically compatible anchor: the phase transition at ~50 steps reported in C3.

### M3. The impulse to rewrite: rational under biased estimates — [SPECULATIVE, with partial support]

The agent compares cost of understanding (U) vs cost of regenerating (R) and chooses to rewrite when U > R. In the valley:

- **U explodes for real** (K > C_eff makes understanding genuinely expensive);
- **R is systematically underestimated**: the invisible specification embedded in mature code — edge cases, bugfix history, everything Hyrum's law says someone already depends on — doesn't enter the estimate;
- **Autoregressive bias**: generating fresh code is "downhill" (high-probability trajectories from the training distribution); editing foreign code requires conditioning on idiosyncratic low-probability context. With weak conditioning signal, the fresh-code attractor wins.
- Entropic reading: rewriting is how the agent **reduces its own uncertainty** — its code is self-consistent within its window. Locally rational, globally destructive.

### M4. Why tests return the bearings — the part with theorem-like form — [HIGH]

Classic result from imitation learning (DAgger; Ross, Gordon & Bagnell, AISTATS 2011): an agent in **open loop** accumulates error as **O(εT²)** — each step out of distribution takes it to states where it errs more severely (covariate shift). With **dense corrective feedback**, error returns to **O(εT)**, linear.

- Extensive tests = dense reward: they convert "does the whole system work?" (sparse) into "this step broke that" (dense), and close the loop.
- Interfaces = **founded summaries**: reading a module boundary gives valid belief about what's behind without reading it. Structure = compression with guarantees.

## 3. Introspection (with epistemic caveat)

**[SPECULATIVE by construction]** — without access to weights or attention patterns; this is phenomenological reconstruction, not measurement, and interpretability research shows model self-reports are unreliable. Included because it is consistent with what is measurable from the outside:

1. I don't "have" the repo; I have my context. About unread code I don't have conscious ignorance — I have **interpolation that feels like knowledge**. The difference between read and assumed doesn't arrive labeled.
2. In a small repo interpolation is ~0. In the valley, an increasing fraction of decisions rest on plausible unfounded priors; when two priors compete, one is sampled → divergent paths between sessions.
3. A failing test is qualitatively different from an instruction: **collapses** belief and displaces the prior. An instruction is text competing for attention with a thousand others, and decays with distance (*constraint decay*).
4. Sealed compartments don't make the agent smarter — they make its ignorance **irrelevant**, which is better.

## 4. Design implication (link with this repo)

The valley of the U-curve is the phase where intrinsic structure (modules, tests) doesn't yet exist — the loop must be closed **from outside**:

- Contracts (`prd-objective-guard.md`, layer 2 of `prd-vigia.md`) = artificial module boundaries for repos that don't yet have them.
- The deterministic eye (Vigia) = dense feedback that converts O(εT²) to O(εT) before the suite exists.
- Natural market of the tool: neither the prototype nor the mature repo — **the valley**.

## 5. Attackable points (pre-registered for adversarial comparison)

1. **Provenance of C1's figures**: taken from search summaries; the exact paper of the LOC→pass-rate table was not read in depth. If the rival verifies it better (or refutes it), wins that point.
2. **Percolation (M2.2) is analogy, not measurement**: no one measured a giant component in dependency graphs correlated with agent collapse. It's falsifiable and hasn't been done yet.
3. **K and C_eff are not directly measurable** as defined; the formalization is useful as a model, not as an instrument. A rival can propose better operationalization.
4. **Introspection (§3) is not evidence** and is marked as such; any use of it to support a claim would be an error in this document.
5. **C5 may be outdated**: there may be a paper naming the compound curve.
6. The 26xx arXiv IDs cited come from August 2026 search and were not all read in full.

## 6. Sources

- [ProjDevBench: Benchmarking AI Coding Agents on End-to-End Project Development](https://arxiv.org/html/2602.01655v1)
- [Evaluating and Improving Automated Repository-Level Rust Issue Resolution with LLM-based Agents](https://arxiv.org/html/2602.22764v1)
- [SlopCodeBench: Benchmarking How Coding Agents Degrade Over Long-Horizon Iterative Tasks](https://arxiv.org/html/2603.24755v1)
- [Constraint Decay: The Fragility of LLM Agents in Backend Code Generation](https://arxiv.org/html/2605.06445)
- [ContextBench: A Benchmark for Context Retrieval in Coding Agents](https://arxiv.org/html/2602.05892v3)
- [The Illusion of Diminishing Returns: Measuring Long Horizon Execution in LLMs](https://arxiv.org/pdf/2509.09677)
- [Beyond pass@1: A Reliability Science Framework for Long-Horizon LLM Agents](https://arxiv.org/pdf/2603.29231)
- [The Long-Horizon Task Mirage: Diagnosing Where and Why Agentic Systems Break](https://arxiv.org/html/2604.11978v1)
- [Solving a Million-Step LLM Task with Zero Errors (MAKER)](https://arxiv.org/pdf/2511.09030)
- [Survey: Navigating the Long Horizon](https://victorchen96.github.io/auto_research/long_horizon_survey.pdf)
- Classics: Parnas (1972), *On the Criteria to Be Used in Decomposing Systems into Modules*; Baldwin & Clark (2000), *Design Rules*; MacCormack, Rusnak & Baldwin, propagation cost / DSM; Ross, Gordon & Bagnell (2011), *DAgger*; Hyrum's law.
