The Agent That Trapped Itself: How Context Eviction and Deduplication Broke on a Go Project
Description and use
Context eviction and deduplication in Legion caused an agent to lose file access, resulting in an hour of no code. Switching to on‑demand eviction, session‑based retention, and ledger sync fixed the issue, cutting tokens by 46% and improving code quality.
Problem
Context eviction and deduplication mechanisms in Legion’s multi‑agent hub caused an agent to lose access to file contents, leading to an hour of work with zero code output.
Outcome
The new architecture cut prompt size by 46%, reduced completion verbosity by 42%, eliminated extreme outliers, and enabled agents to write correct Go code.
Workflow
- 1. Implemented on‑demand eviction instead of eager.
- 2. Tied content retention to current session, resetting seen status each new attempt.
- 3. Rewrote receipt stubs to allow re‑reading of files.
- 4. Synchronized assembler with read ledger to reset deleted chunk status.
Evidence
The default policy (eager) left only the three most recent tool results "raw" within a limit of 6,000 tokens.
The investigation revealed a classic deadlock of two independent, yet inconsistent, logic flows: "Always" (Eager) Eviction, Not On‑Demand.
After the post‑mortem, the gateway architecture underwent four key changes: on_demand Eviction Mode, Content Retention Tied to Session, Honest Manifest, Synchronization with Compaction.
- Record date: 2026-10-12T22:40:53.320Z