Agentic Execution with Million-Token Contexts: From Writing Patches to Delivering Results

    This article examines why end-to-end completion rate, not first-patch speed, is the right metric for evaluating coding agents, and how million-token context windows and open-weight models change what agents can reliably do. It covers layered context supply, the types of dirty work worth delegating, a minimal verification loop with iteration limits and rollback safety, sandbox and cost boundaries, a three-stage rollout path, and the metrics that actually matter.

    1. The Problem Is Not Writing a Patch, It Is Finishing the Job

    Hand a coding tool a bug ticket and it will usually produce a plausible-looking change within seconds. The hard part comes afterward: do the tests pass, are edge cases covered, did the change introduce a regression, does it follow the conventions already in the repository, will it survive review on the first attempt? As the source material puts it, “one failed test” is the real issue — the deliverable is not a patch but a result that can be verified, merged, and rolled back.

    So the standard for judging whether a coding agent can “do the dirty work for you” should be end-to-end completion rate, not how fast it generates a first draft. End-to-end covers six stages: understanding the requirement, locating the code, proposing the change, running verification, fixing failures, and producing an explanation. Miss any one of them and a human engineer has to take over again, which cancels out the automation gains.

    2. What Long Context Actually Changes

    The point of a million-token context is not “stuff more in.” It is letting the agent see enough evidence in a single inference pass, reducing the information loss that comes from repeated retrieval.

    1. Cross-file reasoning: a defect often spans the interface layer, the business layer, and the data layer. Long context keeps the call chain, type definitions, and configuration in view at the same time.
    2. Convention awareness: directory layout, naming habits, and error-handling patterns are usually undocumented. Only by reading neighboring modules in full can imitation avoid drifting off form.
    3. Historical information: related commit messages, existing tests, and legacy comments are the key clues to “why was it written this way back then.”
    4. Less truncation error: chunked summarization drops details; long context significantly reduces the “summary distortion” variable.

    But long context is not free. Attention dilutes over extremely long inputs, irrelevant content interferes with judgment, and both cost and latency rise with length. The more robust engineering approach is layered supply: a stable layer for repository conventions and dependency lists, a task layer for the ticket and reproduction steps, an evidence layer for retrieved relevant snippets, and a constraint layer for output format. Sketch:

    1. [Stable layer] Directory conventions / build and test commands / code style points
    2. [Task layer] Ticket description / reproduction steps / expected behavior
    3. [Evidence layer] Call chain snippets / related tests / history of relevant changes
    4. [Constraint layer] Allowed scope of changes / checks that must pass / output format

    3. The Controllability Open Weights Bring

    The value of open-weight models is control: private deployment, pinned versions, fine-tuning, and auditability. For companies and teams, this means code never has to leave the internal network, behavior does not shift abruptly because an upstream version drifted, and the model can be tuned specifically to the repository’s coding style. It is worth stressing that open weights do not automatically guarantee quality — the surrounding engineering constraints are what produce stable output.

    4. Breaking Dirty Work into Acceptable Tasks

    What suits an agent is work with clear boundaries and machine-decidable outcomes:

    • Bulk refactors: interface renames, replacing deprecated usage, filling in logging and monitoring instrumentation.
    • Test backfill: adding cases for functions with insufficient branch coverage, constructing boundary and exception inputs.
    • First-pass bug fixes: failing cases with a clear reproduction path and assertions.
    • Dependency and configuration cleanup: version alignment, build script cleanup, environment variable consolidation.

    What should not be handed over directly is work with vague goals and subjective trade-offs, such as architecture decisions, cross-team interface negotiation, or trading performance against readability. For these, it is better to have the agent produce option comparisons and impact analysis, and let a human decide.

    5. The Verification Loop: Where Agents Differ from Ordinary Completion

    Without a closed loop, nothing is “done.” The minimum viable loop has five steps:

    1. Read task → generate change → run static checks and unit tests → collect failure logs → iterate on fixes → output change notes

    Key design points:

    1. The verdict must be machine-executable: translate “it’s fixed” into command exit codes and assertion pass rates.
    2. Failure information must be structured: return only the relevant errors and a minimal reproduction, so noise does not drown out the signal.
    3. Iteration must have a cap: set a maximum number of rounds and a timeout to prevent endless self-loops from burning resources.
    4. The change scope must be fenced in: only whitelisted paths may be touched; any violation aborts.
    5. Results must be rollback-able: isolate work in a separate branch or workspace so failure never affects the mainline.

    Illustrative pseudocode:

    1. for round in range(MAX_ROUNDS):
    2. patch = agent.propose(context)
    3. if not in_whitelist(patch.paths):
    4. return reject("Out-of-scope change")
    5. result = run_checks(patch) # static checks + unit tests
    6. if result.passed:
    7. return summarize(patch, result) # change notes + verification evidence
    8. context = append_failure(context, result.minimal_log)
    9. return escalate("Iteration limit exceeded, hand over to a human")

    6. Permission, Security, and Cost Boundaries

    Autonomous execution must be confined to a sandbox: mount credentials read-only outside the source tree, disable external network access, restrict system calls, and review artifacts. Least privilege is the baseline — an agent should not hold release, merge, or production access by default.

    On cost, separate “generation cost” from “verification cost.” Long context and multiple iterations amplify both, so do three things: retrieve evidence on demand instead of injecting everything; reuse shared dependency and build caches; and turn the stable layer into reusable templates so it is not fed in again every round.

    7. Rollout Path and Metrics

    A three-stage progression is advisable: start with read-only analysis (localization and impact assessment), then automated fixes inside an isolated environment (with the verification loop), and only then open up commits within a controlled scope. Measure not “how many lines were generated” but first-pass rate, average iterations per task, regression introduction rate, human takeover rate, and average time and cost per task.

    8. Conclusion

    Million-token context and open weights solve “seeing enough” and “staying in control.” What actually lets an agent finish the dirty work is machine-decidable acceptance criteria, strict permission and scope constraints, and a verification loop with an iteration cap. Make those three into infrastructure, and a coding agent moves from “can write a patch” to “can deliver a result.”