StateHarness: Maintaining Evolving Project State for Long-Horizon Coding Agents

Chuan Zou, Yujun Zhou, Xiaonan Luo, Xiangliang ZhangarXiv 2026

TL;DR

StateHarness is a runtime framework that helps AI coding agents maintain a structured, evolving "mental model" of a software project during long, complex tasks. By persistently tracking findings, decisions, and code relationships outside the model's context window, it significantly boosts task completion and ensures that secondary artifacts like documentation and imports aren't left in a broken state.

What Problem Does This Paper Address?

As AI coding agents move from fixing single-line bugs to handling "long-horizon" tasks—like refactoring entire modules or implementing complex features—they run into a context problem. A typical software project is a web of interconnected files. When an agent makes a change in one file, it often forgets to update the callers, tests, or documentation scattered elsewhere.

The core issue is that agents experience tasks as a linear stream of events. Important insights or "unfinished business" from step 5 can easily get buried by the time the agent reaches step 50. Without a persistent, structured view of the project state, agents often "spin their wheels," repeatedly reconstructing the same understanding from raw code or losing track of the wider consequences of their edits.

Methods

The authors introduce StateHarness, a training-free runtime framework that augments existing agents (like Claude Code) with four key components:

  1. Persistent Project Records: Instead of relying solely on conversation history, the agent maintains four editable files:
  2. Task State: Tracks the current sub-problem and working hypothesis.
  3. Event Log: A history of important findings, test outcomes, and reasons for changing direction.
  4. Relation Notes: A map of discovered cross-file dependencies (e.g., "this function is called by api.py").
  5. Procedure Guidance: Records which tools or approaches have failed previously to avoid repeating mistakes.
  6. Working Brief: A compact, auto-refreshed summary of these records that is injected into every model request, keeping the most relevant context "top of mind."
  7. Change-Impact Retrieval: When the agent proposes a major change (like a function signature update), the framework automatically searches the repository for affected files and prompts the agent to inspect them.
  8. On-Demand Diagnostic Session: If the framework detects "behavioral signals" of failure—like the agent reading the same file three times or ignoring the working brief—it triggers a separate LLM session to review the full history and surface overlooked evidence.
Figure 2: StateHarness overview. The working agent maintains persistent project records, from which fixed rules refresh a compact working brief. Change-impact retrieval identifies candidate files for inspection when supported edits may have non-local consequences. Accumulated behavioral signals can trigger a separate diagnostic session that revisits older recorded evidence and returns concise suggestions through the brief.

Datasets

The framework was evaluated across three repository-level benchmarks:

  • RefactorBench: Focuses on cross-file consistency during sequential refactoring tasks.
  • Long-Horizon Terminal-Bench (LHTB): Tests sustained execution over dependent terminal actions (e.g., complex environment setup and multi-step coding).
  • ChainSWE: A benchmark where agents must resolve a chronological chain of related software issues within a single repository.

Key Insights and Ideas

  • State vs. History: Simply giving an agent a larger context window isn't enough. Information needs to be structured and editable. By allowing the agent to update its own "notes," StateHarness prevents progress from being lost in the noise of a long trajectory.
  • The "Cleanup" Gap: Agents are generally good at the primary task (fixing the bug) but terrible at the "cleanup" (updating imports and docs). StateHarness specifically targets this by keeping "Relation Notes" that persist even after the main edit is done.
  • Behavioral Triggers: The idea of using "spinning wheels" (repeated actions) as a signal to trigger a deeper diagnostic review is a clever way to handle agentic failure without constant, expensive oversight.

Key Results

Across all benchmarks, StateHarness outperformed the baseline "naked" agent and even more complex, multi-role frameworks.

  • RefactorBench: Full-chain completion rose from 29.4% to 35.3%. Most impressively, "cleanup" accuracy (fixing imports and docs) jumped from 87.0% to 95.4%.
  • LHTB: The mean reward improved from 0.427 to 0.576, exceeding the performance of the more heavily orchestrated LongHorizon-Harness while using significantly fewer resources.
  • ChainSWE: The bug-fix rate increased from 35.1% to 39.5%, and "residual debt" (unresolved inconsistencies left behind) dropped from 60 items to 43.
Figure 3: RefactorBench consistency breakdown. StateHarness produces a modest improvement on checks for the requested refactoring itself, while larger gains appear in cleanup checks for related artifacts. The largest improvements occur for import and documentation updates; call-site perfor- mance is unchanged.
Summary of performance across RefactorBench, LHTB, and ChainSWE.

Limitations and Future Work

  • Execution Cost: Maintaining state isn't free. StateHarness increases token usage and wall-clock time compared to a standard agent.
  • Regression Trade-offs: Interestingly, on ChainSWE, while the agent fixed more bugs overall, it also introduced more "pass-to-pass" regressions (breaking things that previously worked). This suggests that while state helps with progress, it doesn't perfectly solve the problem of unintended side effects.
  • Memory $\neq$ Action: The authors noted that just because an agent remembers a problem (it's in the records) doesn't mean it will always act on it. Future work could explore more "forceful" ways to ensure agents resolve known shortfalls before terminating.

Summary updated

BibTeX
@misc{zou2026stateharness,
  author = {Chuan Zou and Yujun Zhou and Xiaonan Luo and Xiangliang Zhang},
  title = {{StateHarness: Maintaining Evolving Project State for Long-Horizon Coding Agents}},
  year = {2026},
  eprint = {2610.17616},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.17616},
}
Figure