Coding with Agents: The Verify-First Harness
Nearly half of agent-authored fix PRs get rejected—so put rules, tests, and human gates inside the harness before you add another tool.
Watch
Also on our YouTube channel.
Executive Summary
Nearly half of agent-authored fix PRs get rejected in public datasets—so put rules, tests, and human gates inside the harness before you add another tool.
At a Glance
Who this is for: Engineers and tech leads shipping code with agentic IDEs (Cursor, Claude Code, custom SDK harnesses)—not researchers comparing foundation models.
Anthropic’s production agent loop is deceptively simple: gather context → take action → verify work → repeat [1]. Most “coding with agents” tutorials stop after tool access. Production fails when verify is a post-demo checklist—lint runs only in CI, human review happens after merge, and no one can replay which policy_version authorized a bash call.
The cost of that gap shows up in the open. In the AIDev dataset, 46.41% of fix PRs from Copilot, Devin, Cursor, and Claude were rejected—wasted review, CI, and validation cycles on patches that never merge [11]. Instruction files alone do not fix it: across 15,549 agentic PRs, merge rate rose ≥20% in some projects and fell in roughly as many others after instructions were added [12]. Verify has to be executable and in-loop, not a markdown hope.
This playbook shows how to embed verify inside the harness before autonomy expands. It complements The production loop agents and ML share (cross-stack operating model) and The MCP Tax (integration debt)—it does not re-teach FinOps charts or ML drift plots.
Figure 1: Gather → act → verify → repeat for coding harnesses
Same loop as production ML—different surface area. Every cycle should emit `workflow_id` and `policy_version` for audit replay.
Why “More Tools” Is Not a Strategy
A twelve-person platform team wired six MCP servers in one sprint: CRM, docs, ticketing, SQL, GitHub, and a custom deploy hook. Demos shipped in days. Within eight weeks, integration hours exceeded inference spend—and on-call could not name an owner per server.
The pattern is familiar from API gateway sprawl: surface area grows O(n²) in cross-tool failures [2]. Agentic IDEs make onboarding frictionless; they do not make governance automatic.
Figure 2: More servers, more cross-tool incident surface
Budget integration tax before adding the seventh connector—especially for write tools.
Operator rule: Add a tool only when (a) revenue or risk reduction exceeds modeled integration hours over twelve months, (b) an existing server cannot expose a narrower schema, and (c) security can enforce allowlists and human gates on write paths.
Gather Like an Operator
Context is a finite production asset, not an infinite scratchpad [3]. Coding agents that stuff entire repos, email threads, and tangential docs into every turn pay in latency, cost, and hallucination rate.
Gather tactic: Agentic search (files, ripgrep, bash) · Coding harness implication: Prefer before semantic search—transparent, auditable paths
Gather tactic: Subagents · Coding harness implication: Parallel tasks return excerpts, not full windows
Gather tactic: Compaction · Coding harness implication: Summarize long sessions before context overflow
Gather tactic: Context budget · Coding harness implication: Cap retrieved tokens per turn; version corpora
Maps to context engineering for operators: relevance beats fill.
Composite vignette: A fintech platform team let an agent refactor a payments module with full-repo context on every turn. Latency doubled; the model cited a deprecated API from a sibling service folder that should never have been in scope. After imposing a 32K-token gather cap and path allowlists, human correction rate on generated patches fell from 38% to 11% in two sprints—without changing the base model. Illustrative composite.
Subagents help when tasks parallelize (security scan + unit test synthesis), but each subagent should return structured excerpts with source paths—not raw window dumps that pollute the parent session.
Act with Boundaries
“Take action” in coding harnesses means tools, bash, MCP, and generated patches—not chat completions alone [1].
policy_version = "harness-2026-06-11"
workflow_id = "refactor-auth-module"
ALLOW: read_file, search_repo, run_tests (read-only)
GATE: write_file, apply_patch, deploy_stub → human_gate if path matches /prod/
LOG: every tool call → workflow_id, policy_version, decision_outcomeFail closed: If validate_pre blocks a write, escalate to human—do not retry with a “more creative” prompt. Reference implementation: langgraph_production_loop_reference.py (validate_pre → act_tools → validate_post).
Figure 3: LangGraph-style harness—gates before and after tool execution
Checkpoint state (e.g. PostgresSaver) makes replay possible; MemorySaver is for demos only [8].
Verify Before You Ship
Anthropic’s verify hierarchy for coding agents [1]:
Rank: 1 · Method: Rules — lint, schema, policy checks · When to use: Default; fast; explain which rule failed
Rank: 2 · Method: Visual feedback — screenshot diff, render tests · When to use: UI, email, PDF outputs
Rank: 3 · Method: LLM-as-judge · When to use: Last resort; expensive and fragile
Verify is not “run CI later.” Pre-commit hooks, type-checkers, and contract tests belong in the agent loop—the harness should not mark a task complete until rules pass [6]. LLM judges belong only where rules cannot encode the criterion and incident lift justifies cost [7].
High-risk segments (payments, auth, PII) get human_gate before merge—same pattern as regulated blueprints in regulated-agentic-router.
Agent-generated tests are not ground truth
Self-generated unit suites (the Reflexion pattern) help when the compiler and AST filter bad tests—but they can also pass incorrect code or fail correct code [13]. Prefer project-owned tests and linters as the primary gate; treat agent-authored tests as candidates until a human or CI corpus accepts them.
Passing tests also is not the same as policy compliance. Agents will hardcode credentials or introduce injection paths that still “go green” unless policy checks sit in validate_pre / validate_post [14].
Long unstructured repeat loops hit a reliability cliff: high per-step success compounds into low end-to-end success across many steps [14]. Cap iterations, checkpoint state, and escalate to a human when the same failure repeats.
What “done” means for a coding task
An agent should not mark a task complete when:
Tests fail or were never run
Linter/type-check errors remain
The diff touches paths outside the stated
workflow_idscopepolicy_versiondoes not match the deployed rules bundleEnd-to-end smoke (dev server + one user-path check) was skipped for UI or API work [15]
Treat “I believe this is correct” as not verified. Ground truth comes from executable checks and environment state—not model self-report alone [5]. Anthropic’s long-running harness work names the same failure mode for short IDE loops: agents declare victory after local edits without proving the feature works as a user would [15].
When LLM-as-judge is allowed
Use a judge only when:
A written rule cannot encode the acceptance criterion (e.g. tone in user-facing copy where schema checks pass but brand voice fails).
Offline eval shows judge decisions correlate with human review above your segment gate.
Cost and latency are budgeted per
workflow_id—judges are not free verifiers.
Otherwise, invest in narrower rules: JSON schema for outputs, snapshot tests for APIs, screenshot diff for UI agents.
A Minimal Harness Checklist
Install this before expanding tool access:
Name the workflow — stable
workflow_idon every session; no anonymous agent runs in shared repos.Version the policy — prompt + tool allowlist + rules bundle under one
policy_version; rollback is one revert. Instruction files are inputs to that version—not a substitute for executable gates [12].Gather on a budget — cap retrieval; log corpus version for RAG-assisted coding.
Gate writes —
validate_prebefore patch application; path-based rules for prod directories.Verify in-loop — project tests and linters (hooks) before the agent declares success; end-to-end smoke when the surface is user-facing [15].
One feature, clean state — work a single scoped item; leave the tree green and documented (micro-commit + progress note) so the next session does not inherit half-done work [15].
Log for replay — Decision Ledger fields on every transition; 30-day incident review [10].
30 / 60 / 90 cadence:
Window: Days 1–30 · Action: Inventory agent workflows; tag read vs write tools; baseline human correction rate and agent-PR merge/reject rate
Window: Days 31–60 · Action: Ship
validate_pre/validate_poston top three workflows; freeze new MCP serversWindow: Days 61–90 · Action: Promote autonomy one tier only where rollback was exercised in drill
Learn Next
Practice these patterns on the Agentic AI in Production learn path—especially the red-teaming lab (app_building_and_coding routing) for API-level boundaries after agent-assisted changes.
Key Takeaways
Verify-first beats tool-first: rules and tests inside the loop, not only in CI after merge.
Rejection tax is real — roughly half of agent fix PRs in AIDev never merge; instructions alone are not a gate [11][12].
Integration tax compounds faster than token cost when MCP sprawl goes unpriced.
Context budget and compaction are gather-phase production requirements, not optimizations.
policy_version + workflow_id on every action enable audit replay and one-step rollback.
Cross-link the shared production loop article when you move from harness to platform FinOps.
References
Anthropic. (2025). Building agents with the Claude Agent SDK. https://www.anthropic.com/engineering/building-agents-with-the-claude-agent-sdk
Anthropic. (2024). Building effective agents. https://www.anthropic.com/research/building-effective-agents
National Institute of Standards and Technology. (2023). Artificial Intelligence Risk Management Framework (AI RMF 1.0). https://www.nist.gov/itl/ai-risk-management-framework
Board of Governors of the Federal Reserve System. (2011). SR 11-7: Guidance on Model Risk Management. https://www.federalreserve.gov/supervisionreg/srletters/sr1107.htm
Board of Governors of the Federal Reserve System. (2011). SR 11-7 — conceptual soundness and ongoing monitoring. https://www.federalreserve.gov/supervisionreg/srletters/sr1107.htm
National Institute of Standards and Technology. (2023). AI RMF Measure / Manage functions. https://www.nist.gov/itl/ai-risk-management-framework
Anthropic. (2024). Building effective agents — evaluate tool use with executable checks. https://www.anthropic.com/research/building-effective-agents
LangChain. (2025). LangGraph persistence. https://langchain-ai.github.io/langgraph/concepts/persistence/
Google NotebookLM. Multi-Agent Frameworks: CrewAI, LangGraph, and AutoGen Orchestration (research notebook). https://notebooklm.google.com/notebook/697e2eb8-6723-4cf0-8e58-bc67ad2deff6
The AI Operator. The production loop agents and ML share — Decision Ledger pattern. https://www.theaioperator.net/articles/operator-production-loop-agents-ml
arXiv:2606.13468. (2026). Understanding the Rejection of Fixes Generated by Agentic Pull Requests — Insights from the AIDev Dataset. https://arxiv.org/abs/2606.13468
arXiv:2606.13449. (2026). Toward Instructions-as-Code: Understanding the Impact of Instruction Files on Agentic Pull Requests. https://arxiv.org/abs/2606.13449
Shinn, N., et al. (2023). Reflexion: Language Agents with Verbal Reinforcement Learning. https://arxiv.org/abs/2303.11366
NotebookLM synthesis — Multi-Agent Frameworks notebook (CrewAI / LangGraph / AutoGen / Claude Code comparison; agent reliability cliff; policy vs efficacy). See [9].
Anthropic. (2025). Effective harnesses for long-running agents. https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents
Learn Next
Editorial transparency. Essays at The AI Operator may use AI-assisted research, drafting, and editing tools under staff editorial review. Facts, figures, and recommendations are checked before publication; we correct the record when evidence changes. Questions: hello@theaioperator.net.
Published on [Substack](https://theaioperator.net/p/coding-with-agents-verify-first).





