Contents
What to cover
Sketch your own design first. A complete answer has these parts; the notes say what each should settle.
- Requirementsrepo sizes and languages; test coverage; allowed actions (network, package installs); autonomy level; cost per issue budget; security of secrets
- Estimates
- API
- Data model
- Architectureingestion of issue + repo context (search tools, code index, file reading); planning; edit tools with constrained interfaces; sandbox per task (container, no secrets, egress limits); test execution and verification loop; context management/compaction; PR creation with summary; human review; trajectory logging; offline benchmark of real past issues with hidden tests; cost/turn budgets
- Deep divesthe agent “fixes” a test by deleting it — prevent it.; How do you measure success beyond tests passing?; What stops prompt injection from issue text?
- Trade-offsretrieval/indexing vs agentic search; single agent vs sub-agents; run full test suite vs targeted tests; autonomy vs review burden
- Evaluationstrong sandbox and permission story; verification-driven loop; evaluation on held-out real issues with repeated trials; guardrails against reward hacking
Reference design
One way to answer it, part by part. Open a part once you have your own version of it.
Requirements
Functional: triggered by a label or command on a GitHub issue; works on a sandboxed checkout at a pinned commit; reproduces, edits, runs tests; opens a draft pull request with a summary and test evidence; iterates on review comments.
Assumptions to confirm
- Repo sizes and languages: 10k–5M lines; Python, TypeScript, Go and Java first; monorepos included.
- Test coverage: ranges from strong to none. Without tests the agent must write a reproduction test first, and the PR must say verification is weak.
- Allowed actions: read and write inside the sandbox; run builds and tests; package installs only through an allow-listed mirror; no other network egress; no pushes except to
agent/*branches; never merges. - Autonomy level: draft PRs for human review only; humans decide merge.
- Cost per issue budget: ≤ $5 of model spend and ≤ 30 minutes wall clock by default, configurable per repo; the agent stops and reports when the budget is spent.
- Security of secrets: no production or CI secrets in the sandbox; the GitHub credential lives in a separate PR service; issue text and repo content are untrusted input.
- Success: PRs merged with little rework, not just green tests.
Estimates
- Volume: assume 2,000 tasks/day across customers, peaking at ~300/hour on weekday afternoons.
- Turns and tokens: ~40 agent steps per task; context grows to ~30k tokens on average per step → 40 × 30k = 1.2M input tokens per task. With ~80% prefix-cache hits (cached at ~10% price) and an assumed $3/M input, $15/M output: uncached 0.24M × $3 = $0.72, cached 0.96M × $0.30 = $0.29, output 40 × 500 = 20k × $15 = $0.30 → ~$1.30 per task, $2.6k/day.
- Sandboxes: average 20 minutes each, 4 vCPU / 8 GB RAM. Peak 300 tasks/h × 1/3 h ≈ 100 concurrent sandboxes ≈ 400 vCPU; daily 2,000 × 20 min ≈ 670 sandbox-hours.
- Start-up time: cloning a large repo and installing dependencies can take minutes; prebuilt images per repo and dependency hash, refreshed nightly, cut start-up to ~20–30 s.
- Test time: often dominates wall clock. Targeted tests per iteration (seconds), full suite once before the PR (minutes); suites over ~15 minutes are delegated to the customer’s CI.
- Trajectory storage: ~40 steps × ~20 KB of truncated observations ≈ 1 MB per task → 2 GB/day.
API
POST /v1/tasks {repo, issue_url | issue_text, base_ref, budget: {usd: 5, minutes: 30},
autonomy: "draft_pr", test_command?, setup_command?}
→ {task_id}
GET /v1/tasks/{id} → {status, plan, steps[], cost_usd, tests: {before, after}, pr_url}
POST /v1/tasks/{id}/messages {text} (follow-up from a reviewer)
POST /v1/tasks/{id}/cancel
GitHub App webhooks: issues.labeled, issue_comment ("/agent fix"), pull_request_review
Tools available to the model inside the harness (narrow, typed, logged):
search(pattern, path_glob?) ripgrep over the checkout
semantic_search(query) optional code index
read_file(path, start_line?, end_line?)
list_dir(path)
edit(path, old_text, new_text) exact-match replace; fails if not unique
create_file(path, content)
run(command, timeout_s) inside the sandbox only
run_tests(selector?) wraps the repo's test command, parses results
git_diff()
finish(summary, risk_notes)Data model
- Task: id, repo, issue reference and snapshot, base commit, budget, autonomy, status, cost, wall time, outcome.
- Trajectory step: task_id, index, model and prompt version, action (tool + arguments), observation (truncated, with a pointer to the full blob), tokens, latency.
- Sandbox: image digest, resource limits, egress policy, lifetime, teardown confirmation.
- Patch: diff, files touched, tests added/modified/deleted, test results before and after, verifier findings.
- PullRequest: url, branch, review comments, iterations, merged?, merged with edits?, reverted within 30 days?
- RepoProfile: languages, setup and test commands, prebuilt image, typical test durations, policy overrides.
- EvalInstance: repo snapshot, issue text, hidden tests (from the real fix), gold patch, date (for contamination control).
Postgres for tasks and PR outcomes, object storage for trajectories and blobs, a queue for task dispatch.
Architecture
Flow · 4 stepsHow a GitHub issue becomes a draft pull request
- Intake The issue arrives by label or command; the task is queued and budgeted.
- Execute The agent reproduces, edits and runs targeted tests inside the sandbox, logging each step.
- Verify and PR The verifier checks test integrity and the diff; the PR service opens a draft PR with evidence.
- Review loop Human review comments re-enter the loop as new iterations.
Data
| Step | Title | What happens |
|---|---|---|
| 1 | Intake | The issue arrives by label or command; the task is queued and budgeted. |
| 2 | Execute | The agent reproduces, edits and runs targeted tests inside the sandbox, logging each step. |
| 3 | Verify and PR | The verifier checks test integrity and the diff; the PR service opens a draft PR with evidence. |
| 4 | Review loop | Human review comments re-enter the loop as new iterations. |
Source: This page's text
| Box | Group | Detail |
|---|---|---|
| GitHub issue | Input | label or /agent fix |
| Task service | Input | POST /v1/tasks |
| Orchestrator | Orchestration | budget manager |
| Agent loop | Execution | LLM + narrow typed tools |
| Trajectory store | Execution | truncated observations |
| Verifier | Execution | test-integrity checks |
| PR service | Review | draft PR + evidence |
| Human review | Review | comments re-enter loop |
Source: This page's text
GitHub App ─► Task service ─► queue ─► Orchestrator (budget manager: $, steps, minutes)
─► Sandbox per task: microVM (Firecracker) or gVisor container,
repo at base commit, prebuilt dependency image, no secrets,
egress denied except package mirror, CPU/RAM/disk limits
─► Agent loop: LLM ⇄ narrow typed tools (search, read, exact-match edit, run)
plan (written down, revised as evidence arrives)
─► reproduce (failing test) ─► edit ─► targeted tests
─► lint/typecheck ─► full suite ─► self-review of the diff
Context manager: file views by line range, old observations
summarised, compaction near the context limit
─► Verifier: test-integrity rules, diff size, secret scan,
sensitive paths (CI config, auth, dependencies) flagged
─► PR service (holds the GitHub credential): push agent/* branch,
open draft PR with summary, test evidence, risk notes, cost
─► Human review ─► comments re-enter the loop as new iterations
Trajectory store ─► analytics, offline eval, future training dataDeep dives
The agent “fixes” a test by deleting it. Make it impossible to pass that way: the verifier diffs test files and blocks PRs that delete, skip or weaken existing tests (removed assertions, broadened expected values, xfail, @skip) unless the issue explicitly asks for it, in which case the PR is labelled for reviewer attention. Run the base commit’s original tests against the patched code as well as the new ones. An LLM reviewer checks whether the patch addresses the issue or games the checks. Offline, hidden tests from the real fix catch reward hacking the agent cannot see.
Success beyond tests passing. Merge rate, merged without human edits, review rounds, time to merge, revert or follow-up-fix rate within 30 days, reviewer ratings, and cost per merged PR. A PR that passes tests but is closed counts as failure.
Stopping prompt injection from issue text. Treat issue text, comments and repository files as data. Containment does the real work: the sandbox has no secrets and no egress, so there is nothing to steal and nowhere to send it; the GitHub credential sits in a separate service that can only push agent branches and open drafts. The verifier flags diffs touching CI workflows, dependency manifests, auth code or adding network calls. Issues from outside the organisation need a maintainer’s approval before the agent runs.
Trade-offs
- Retrieval/indexing vs agentic search: an embedding index finds conceptually related code fast but goes stale per commit and must be rebuilt per branch; ripgrep plus file reading is always fresh and precise. Default to agentic search, add an index for very large monorepos.
- Single agent vs sub-agents: one agent keeps reasoning coherent; sub-agents with isolated contexts parallelise exploration (e.g. “find all callers”) and return summaries, costing more tokens and coordination. Use them for exploration only, keep edits in one agent.
- Full suite vs targeted tests: targeted tests keep iterations fast; run the full suite (or the customer’s CI) once before opening the PR so regressions surface before review.
- Autonomy vs review burden: more autonomy (auto-merge for trivial dependency bumps) saves time but raises the blast radius; low-quality PRs waste reviewer time and erode trust, so precision matters more than volume — abstaining with a written diagnosis is a valid outcome.
Evaluation
- Strong sandbox and permission story: microVM isolation, no secrets, egress allow-list, separate PR credential; penetration tests and injection red-team cases run in CI.
- Verification-driven loop: reproduce first, then fix; record tests before and after in every PR.
- Held-out real issues with repeated trials: build an eval from real past issues and their merged fixes, with the fix’s tests hidden; prefer issues newer than the model’s training cut-off to limit contamination; run each instance 5 times and report mean pass@1 and pass^k, cost and wall time per solved issue, plus results by repo and language.
- Guardrails against reward hacking: count test deletions, skips and weakened assertions in eval trajectories; any increase blocks a release.
- Online: merge rate, merged-without-edits rate, revert rate, reviewer satisfaction, cost per merged PR, budget-exhaustion rate; trajectory sampling reviewed weekly to find new failure modes and turn them into eval cases.
What a strong design shows
- Builds the security story on containment (no secrets, no egress, separate PR credential), not on prompt instructions.
- Puts verification at the centre: reproduce, fix, targeted tests, full suite, self-review.
- Defends explicitly against reward hacking with test-integrity checks and hidden tests.
- Evaluates on held-out real issues with repeated trials, contamination control and cost per solved issue.
- Defines success as merged, unreverted PRs with little rework, not green tests.