
Essay Code and Repo Agents
Long-Running Codebase Analysis Agent With Checkpoint State
Durable checkpoint state lets a replaceable worker resume repository scans after failure.
A long-running codebase analysis agent needs more than a model that can read code. It needs checkpoint state designed into its architecture, so repository traversal, semantic models, and findings survive interruption. The central design choice is to make the worker replaceable while keeping its progress durable. Without that separation, a large scan remains an expensive script that can forget everything before it finishes.
Why codebase analysis breaks the request-response model
A repository scan stops halfway through, with no recoverable map and no usable findings. The model may have done useful work. But if that work lived only inside the request handling it, a timeout has erased the path back to it. API gateways, function runtimes, and HTTP handlers impose time limits well before a multi-hour traversal can finish. Synchronous, stateless execution therefore fails at the point where repository analysis needs continuity.
The loss extends beyond elapsed time. A 12-step workflow that crashes at step 8 may already have consumed model calls, written records, and called external APIs. Starting again from step 1 repeats work that was expensive the first time and may be impractical across a large repository. A better prompt cannot bring back state that the system never saved. The engineering response must begin below the model, in the infrastructure that preserves and resumes its work.
What "long-running" actually means for an analysis agent, and why it matters for design
Long reasoning, long execution, and persistent memory each bring their own problems. A hard planning task may depend mostly on how good the model is, while an agent that remembers earlier tasks needs memory across sessions. Repository analysis combines hours of execution with ordered dependencies and growing context. Thousands of model invocations can contribute to intermediate state that cannot be regenerated cheaply, making recovery an execution-design problem.
What exactly has the agent built halfway through? File paths locate source text, but they do not supply the semantic map of relationships that the agent needs. The agent must construct that map as it discovers symbols, dependencies, and service boundaries.
For this kind of agent, the recoverable unit should be a file, a module, or a meaningful pipeline stage. A model call alone is too narrow. It may finish without completing the traversal work that gives its result meaning, so checkpoint boundaries must follow the structure of the analysis.
The session must live outside the worker process
The foundational rule is simple and prescriptive. All execution state needed to continue the run must live in durable storage outside the worker process. That includes model calls, tool results, approvals, traversal position, and intermediate findings. A worker can then disappear without taking the session with it. Another worker resumes from the last safe point.
This separation also handles a different interruption. When the context window fills, the runtime can start a fresh model session and load the checkpoint state. The execution session outlives any individual model session. Traversal progress can also survive a switch to a different model, provided that progress remains outside it.
The distinction changes what the worker is responsible for. It performs the current piece of work, while durable state records what has happened and what remains. Permissions, retrieval, memory management, and review interfaces still affect reliability, but they no longer depend on one process staying alive.
What to checkpoint, how often, and where to store it
A checkpoint should hold only the state needed to pick up where the work stopped. For repository analysis, that means processed files or modules, the current traversal position, intermediate results, and the context needed for the next decision. The semantic index, dependency map, and findings already surfaced must also remain durable. They need not become a full conversation transcript. Saving that transcript as the resumption record makes checkpoints grow and recovery slower.
A checkpoint should be saved when a meaningful piece of work is done. During a scan, that can mean each file or document processed, while a pipeline also needs checkpoints at stage boundaries. Saving more often uses resources to write state, but saving less often leaves more work to be lost if the run fails. The chosen unit should be idempotent, so replaying it produces the same output. Side effects and non-deterministic operations need to sit inside tasks that can be safely replayed.
Storage should match both deployment and access patterns. An agent on a single machine can use local files if they outlive the worker, while production workers that work together need a persistent store they can share. S3 or GCS offers cheap, durable storage, but a bucket alone is not a shared workspace for inspecting progress. A layered design can use in-memory or key-value storage for active context, a vector store for semantic similarity search, and durable SQL or object storage for audit records and completed findings. Fast working memory must not become the only home of recoverable state.
Designing traversal and pipeline stages to be resumable by default
Even with storage, a traversal needs a clear point from which to restart. The work itself needs ordered, bounded, idempotent stages, each with an output that the next stage can use. A checkpoint then marks completed work. Given the same saved state, a new worker should make the same choices about the traversal. Otherwise, resumption may quietly become a different analysis.
Discovery enumerates files, maps directories, and identifies entry points and service boundaries before saving the map. Indexing extracts symbols, dependencies, and call graphs, with incremental checkpoints per file or module. Analysis uses that index to run the configured checks for dead code, coupling, or security patterns and saves the findings for each rule. Reporting aggregates the findings and saves a report draft before finalizing it.
These are illustrative boundaries. Their value is that a worker resuming analysis does not need to repeat completed indexing. Message queues support the same separation by keeping “decide what to do next” apart from “do the work.” The orchestrator and workers can restart independently without losing queued tasks.
A 12-step workflow that crashes at step 8 may already have consumed model calls, written records, and called external APIs.
Managing context across a repository that won't fit in a window
A scan can resume correctly and still overwhelm the model with more repository detail than its active window can use. Context management addresses the memory side of the same problem. The checkpoint preserves what the run has accomplished, while a context map controls what the model sees now.
The root context should be a map. It loads on each request, stays small, and points to payload files such as dependency maps, error catalogs, and integration records. Those details enter the active window only when the current task needs them. A larger window does not remove the need for this selection, because irrelevant context can degrade the model’s work. Structural pruning is the more direct response.
The map also needs a life beyond one thread. In multi-service analysis, preserved indexes and dependency maps let later sessions use relationships found earlier without traversing the same services again. Context files such as AGENTS.md should describe minimal requirements rather than accumulate unnecessary instructions that make tasks harder. This keeps navigation separate from payload and requirements separate from background.
Coherence drift: the failure mode checkpointing cannot prevent
A recovered run can still reason badly. Checkpointing preserves progress, but it does not guarantee that the model remains consistent as its working set of repository facts grows. Long-horizon failure patterns include “Coherence Collapse,” in which an agent discards already-correct code or conclusions, and “Strained Coherence,” which appears as verbalized conflict in reasoning traces. Neither is a timeout or a crashed worker. Durable storage can preserve the results of poor reasoning just as faithfully as sound reasoning.
The mitigation is to limit and test reasoning between stages. Tight boundaries allow a fresh model session to begin from a clean checkpoint with only the relevant context. Execution-based verification should then test the output before the next stage uses it as input. Before analysis, the index should be checked for internal consistency. Before reporting, findings should be checked against files that were actually visited.
Sensitive work also needs a human review option. For critical or security-sensitive codebases, a pause at a stage boundary is preferable to discovering a coherence failure after the full run. Checkpointing solves recoverability, context management reduces exposure to drift, and verification gates test whether preserved progress deserves to advance.
The runtime layer the agent needs beneath it
These requirements need support below the analysis code. A runtime for durable, long-running execution should have persistence, scheduling, and resumption built in so that each agent does not have to implement them on its own. Saving now and then in a general-purpose function runner falls short of that contract. The platform must guarantee that an interrupted run resumes from its last checkpoint. Otherwise, application code still has to handle the hardest parts of recovery.
The operating-system analogy is useful for this reason. Applications use a lower layer to schedule work, manage memory, and enforce policy, and long-running agents need to share those duties in much the same way. For repository analysis, that layer should support nightly or post-merge runs and repository-event triggers without manual invocation. Scheduling must operate with durable session state so that launching work and preserving it are not separate concerns.
The runtime must also bound what a run can do. It should broker scoped repository-read and findings-write credentials. Cost and resource limits should constrain a traversal that encounters unexpected directory depth or a pathological dependency graph. Those limits cannot depend on the agent choosing to stop. Recovery is useful only within an execution environment that also controls access and resource use.
Surfacing findings without coupling the agent to a delivery channel
Findings trapped inside the analysis session have limited operational value. Yet when the analysis pipeline has to handle every delivery channel, work that already needs careful recovery has one more dependency. The cleaner design writes findings durably and routes them through a separate integration layer. Analysis can then run through a CLI or durable backend while teams receive results where they work. Delivery becomes independent of traversal.
Model Context Protocol (MCP) is one way to connect these systems. Anthropic created MCP and donated it in December 2025 to the Agentic AI Foundation (AAIF), a directed fund under the Linux Foundation co-founded by Anthropic, Block, and OpenAI. Slack’s MCP Server became generally available on February 17, 2026. A deployment can use it to surface findings and escalations in Slack, with an identity and credential layer using MCP’s OAuth 2.1 support. In that design, credential brokering keeps secrets out of the agent session.
The permission split is as important as the connector. Repository-read credentials belong to the analysis side, while communication credentials belong to delivery. Broad credentials, especially production-write access, increase the damage a single mistake can cause. Scoped access limits that exposure, and durable findings make the destination replaceable. Slack, a ticket system, or a dashboard can receive the same output without changing how the analysis produces it.
Putting the architecture together: the design decisions that actually separate a working agent from a fragile one
The practical design review should begin with a recovery question. If the worker goes away before its next step, what saved state lets another worker carry on? Model calls, tool results, traversal position, and findings must already be outside the process. The next question concerns replay. A finished traversal unit needs an output that stays the same, while unfinished work needs a safe way through the same stage without doing the whole scan again.
The review should then follow the saved state into a fresh session. That session should receive a thin navigation map and the payload for its current stage. Verification gates should decide whether the stage’s output can move on, and human review should be an option for sensitive code. Runtime-brokered credentials and resource limits should set bounds on what can run, while findings go through a delivery layer that has no control over analysis. These choices need to be made when the design begins because each one sets boundaries that the others depend on.
The final test is the half-finished scan. After an interruption, the directory map, completed index work, and accumulated findings should still exist, with a clear point from which to continue. The worker may be gone. The repository knowledge it built should not be.
Notes
- Engineering Reliable Coding Agents: Evaluating and Operating the System Around the Model
Supplied the long-horizon failure patterns, Coherence Collapse and Strained Coherence, and the case for execution-based verification between stages.
- DeltaBox: Scaling Stateful AI Agents with Millisecond-Level Sandbox Checkpoint/Rollback
Informed the design of checkpointing and rollback so an interrupted agent resumes from its last safe state outside the worker.
- AgentKernel: The Trust-Native Agentic Operating System
Provided the operating-system framing of a runtime layer that handles scheduling, memory management, and policy enforcement for agents.


