Skip to content
Back to course
Lesson 33 of 61 · Part 8

Design a Coding Agent (Claude Code / GitHub Copilot / Cursor)

Design a coding agent serving 1M concurrent sessions across autocomplete, chat, and autonomous loop modes with repo indexing, sandboxed tool use, and streaming diff application.

advanced18 min read4 diagramsUpdated 11 May 2026✓ Completed
On this page

TL;DR. A coding agent is three products sharing one backend: sub-200 ms autocomplete on a small model, conversational chat grounded in the repo, and an autonomous ReAct loop that edits files and runs shell commands for minutes per task. GitHub Copilot handles 400M+ completion requests per day at ~8,000 QPS peak1, Cursor crossed $2B ARR by early 20262, and agent benchmarks on real GitHub issues have climbed rapidly: Devin scored 13.86% on the original SWE-bench in March 20243, and Claude Opus 4.7 now leads SWE-bench Verified at 87.6% (April 2026)4. The pivotal trade-off is model tiering: a cheap small model for autocomplete, a frontier model for chat, and frontier-plus-tools for the autonomous loop, yielding roughly an order-of-magnitude cost reduction over a single-model deployment based on published model pricing differences5.

Learning Objectives

  • Design a three-mode coding agent (autocomplete, chat, autonomous loop) with distinct latency and cost budgets for each mode
  • Architect a hybrid repo-context retrieval layer combining embeddings, tree-sitter symbol graphs, and git-awareness
  • Justify per-session Firecracker microVM isolation for untrusted agent tool calls and size the warm pool
  • Estimate capacity for 1M concurrent sessions across three modes with different token economics
  • Stream generated diffs to the editor with atomic apply and one-key rollback
  • Build an eval harness on SWE-bench Verified that gates every model rollout before production

Intuition

A coding agent looks like autocomplete with extra steps. Type a few characters, get a suggestion. Easy at 10 users. At one million concurrent sessions it collapses, and the reason is that you are actually running three different products behind one interface.

Autocomplete must return ghost text before the developer types past it. That means sub-200 ms end-to-end, which means a small model, aggressive prompt caching, and HTTP/2 stream-reset for the 45-50% of requests the developer cancels by typing through1. Chat runs at conversational latency on a frontier model with retrieved repo context prepended. The autonomous loop is the hardest: a multi-step agent that reads files, edits them, runs shell commands, observes results, and iterates for minutes on a single prompt, all inside a sandbox that prevents it from destroying the host.

The naive approach (one frontier model for everything) fails on cost and latency simultaneously. A single GPT-4-class completion costs roughly 100x what a small-model autocomplete costs5. And the autonomous loop introduces a new failure mode: the agent can write code that exploits its own sandbox, install malicious packages, or enter an infinite retry loop burning tokens until someone notices.

The insight that unlocks the design: treat each mode as a separate product with its own model tier, latency SLO, and safety envelope, but share the repo-context retrieval index, the diff-application path, and the eval harness across all three.

Requirements

Clarifying Questions

  • Q: Which modes do we ship at launch? Assume: All three (autocomplete, chat, autonomous loop). Each has a separate latency budget.
  • Q: Cloud service or local-first CLI? Assume: Cloud SaaS (like Copilot/Cursor) with enterprise option for on-prem indexing (like Claude Code).
  • Q: Do we own the models or route to third-party providers? Assume: We operate inference for autocomplete (small tuned model) and route chat/autonomous to a frontier provider API.
  • Q: Can the agent run arbitrary shell commands? Assume: Yes, inside a per-session sandbox with network allowlist and resource ceilings.
  • Q: Do we index private repos server-side? Assume: Yes for SaaS; enterprise customers can opt for client-side-only indexing.
  • Q: Multi-tenant SaaS or single-tenant? Assume: Multi-tenant with strict isolation. Enterprise tier gets dedicated sandbox pools.

Functional Requirements

  • Inline autocomplete: ghost-text completion triggered by typing, dismissable with Escape
  • Chat: conversational panel grounded in the open file, selection, and repo index
  • Autonomous loop: multi-step agent that reads, edits, runs tests, and iterates until done
  • Diff review: every agent edit previewed as a diff the developer accepts or rejects per hunk
  • Repo indexing: background job keeps embedding + symbol index in sync with the current branch

Non-Functional Requirements

  • Sessions: 1M concurrent across all modes
  • Autocomplete latency: p99 < 200 ms from keystroke to ghost text1
  • Chat latency: first-token < 1 s; streaming at 40+ tokens/sec
  • Autonomous task duration: up to 5 minutes; continuous progress visible
  • Sandbox isolation: agent shell commands cannot escape to host, hit arbitrary internet, or exceed CPU/memory/time budgets
  • Cost per autocomplete: < $0.0002 (supports ~$20/month subscription at 100K completions/month)

Capacity Estimation

MetricValueDerivation
Active sessions (peak)300K1M concurrent, ~70% idle
Autocomplete QPS600K300K active x 2 req/s
Chat QPS30K300K x 0.1 req/s
Concurrent autonomous tasks10K~3% of active sessions
Autocomplete tokens/req7050 input + 20 output (small model)
Chat tokens/req4,4004K input + 400 output (frontier)
Autonomous tokens/task58K50K input + 8K output over full run
Daily cost (unoptimized)~$700Kautocomplete $260K + chat $310K + autonomous $130K
Repo index storage50 TB1M repos x 50 MB avg index
Sandbox fleet10K VMs10K concurrent tasks x 2 GB RAM x 1 vCPU

Key ratios: autocomplete dominates request count but is cheapest per request. Chat dominates daily cost. Prompt caching (90% savings on repeated prefixes6) is the single biggest cost lever for chat and autonomous modes.

API and Data Model

API Design

POST /v1/complete
  Body: { "file": "src/main.ts", "cursor": 142, "prefix": "...", "suffix": "...", "lang": "typescript" }
  Returns: 200 { "suggestion": "...", "tokens": 20, "model": "small-v3" }
  Target: p99 200 ms

POST /v1/chat (SSE)
  Body: { "session_id": "uuid", "messages": [...], "context_refs": ["file://src/auth.ts"] }
  Returns: SSE stream of token deltas + tool_call events

POST /v1/task (SSE)
  Body: { "prompt": "Fix the failing test in auth.ts", "repo": "repo-id", "permissions": ["read", "edit", "run_tests"] }
  Returns: SSE stream of thought, tool_call, tool_result, diff, done events

POST /v1/diff/apply
  Body: { "hunks": [...], "workspace_id": "uuid" }
  Returns: 200 { "rollback_token": "uuid" }

POST /v1/diff/rollback
  Body: { "rollback_token": "uuid" }
  Returns: 204

Rate limiting enforces per-tenant token budgets in Redis. A runaway autonomous task hits a spend ceiling and pauses for human approval.

Data Model

-- Sessions (Redis hot + PostgreSQL cold)
CREATE TABLE sessions (
  session_id    UUID PRIMARY KEY,
  user_id       UUID NOT NULL,
  repo_id       UUID,
  mode          TEXT NOT NULL,  -- autocomplete | chat | autonomous
  model         TEXT NOT NULL,
  token_spend   BIGINT DEFAULT 0,
  created_at    TIMESTAMPTZ DEFAULT now()
);

-- Task state (PostgreSQL + object storage for large payloads)
CREATE TABLE task_state (
  task_id       UUID PRIMARY KEY,
  session_id    UUID NOT NULL,
  status        TEXT NOT NULL,  -- running | waiting_approval | succeeded | failed
  scratchpad    TEXT,           -- agent chain-of-thought (summarized)
  sandbox_id    TEXT,
  created_at    TIMESTAMPTZ DEFAULT now()
);

-- Repo index chunks (vector DB + PostgreSQL metadata)
CREATE TABLE repo_chunks (
  chunk_id      UUID PRIMARY KEY,
  repo_id       UUID NOT NULL,
  commit_sha    TEXT NOT NULL,
  file_path     TEXT NOT NULL,
  symbol_name   TEXT,
  embedding     vector(1536),
  last_indexed  TIMESTAMPTZ
);

-- Diff log (training signal)
CREATE TABLE diff_log (
  diff_id       UUID PRIMARY KEY,
  task_id       UUID,
  hunks         JSONB,
  accepted      BOOLEAN,
  created_at    TIMESTAMPTZ DEFAULT now()
);

High-Level Architecture

Diagram
Three mode-specific services share a common retrieval index and sandbox fleet, with the API gateway routing by mode and enforcing per-tenant budgets.
flowchart LR
    IDE[Editor Client<br/>VS Code / CLI] --> GW[API Gateway<br/>auth, rate limit, route]
    GW --> AC[Autocomplete Service<br/>small model, warm GPU pool]
    GW --> Chat[Chat Service<br/>frontier model + retrieval]
    GW --> Orch[Agent Orchestrator<br/>ReAct loop]
    Chat --> Ret[Repo-Context Retrieval<br/>embeddings + symbols + git]
    Orch --> Ret
    Orch --> SCP[Sandbox Control Plane]
    SCP --> Pool[Warm MicroVM Pool<br/>Firecracker]
    Pool --> VM[Per-session VM<br/>RO repo, tmpfs, allowlist]
    AC --> IDE
    Chat --> IDE
    Orch --> IDE
    Orch --> Diff[Diff Applicator<br/>atomic apply + rollback]

Autocomplete path: The IDE debounces keystrokes, sends prefix + suffix to the gateway, which forwards to a warm small-model GPU pool. The model returns ghost text within 200 ms. HTTP/2 stream-reset handles cancellation without tearing down the TCP connection1.

Chat path: The gateway loads conversation history, queries the retrieval service for relevant repo chunks, prepends them to the prompt, and streams tokens from a frontier model over SSE.

Autonomous path: The orchestrator runs a ReAct loop7: reason (LLM generates a tool call), act (execute in sandbox), observe (capture stdout/exit code), repeat. Each iteration updates the scratchpad. A risk gate requires human approval for destructive actions.

Diagram
Autocomplete completes within a 200 ms budget; HTTP/2 stream-reset handles the 45-50% of requests cancelled by type-through without tearing down the connection.
sequenceDiagram
    participant IDE
    participant Proxy as Edge Proxy (HTTP/2)
    participant Model as Small Model Pool
    IDE->>Proxy: POST /v1/complete (prefix, suffix, lang)
    Note over IDE,Proxy: debounce + 50 ms network
    Proxy->>Model: forward on persistent HTTP/2 stream
    Note over Proxy,Model: 80-120 ms inference
    Model-->>Proxy: ghost text tokens
    Proxy-->>IDE: stream suggestion
    Note over IDE: 45-50% cancelled by type-through
    IDE->>Proxy: RST_STREAM (cancel)
    Proxy->>Model: propagate cancellation

Deep Dives

Repo-context retrieval architecture

The retrieval layer is the product differentiator. Embeddings alone miss structural questions like “where is authenticate called?” A hybrid retriever combines three signals.

Signal 1: Semantic embeddings. Code is chunked at roughly function-level granularity and embedded. On each commit, only changed files are re-embedded. The vector DB serves approximate nearest-neighbor queries against the developer’s current query or cursor context.

Signal 2: Tree-sitter symbol graph. Aider parses every source file with tree-sitter to extract definition and reference tags, builds a directed multigraph where each file is a node and each referencer-to-definer edge carries a weight, then runs PageRank with personalization biased toward files in the active chat8. Identifiers mentioned by the user get a 10x multiplier; identifiers in chat-active files get 50x9. The top-ranked symbols render into a token-budgeted tree (default 1,024 tokens)8.

Signal 3: Git awareness. Recently changed files and files in the current PR get a score boost. This mirrors what human developers reach for: the code they are already thinking about.

Diagram
The hybrid retriever merges semantic, structural, and recency signals into a single ranked context block that fits within the model’s token budget.
flowchart LR
    subgraph Indexer
      Commit[Git commit hook] --> Diff[Changed files]
      Diff --> Chunk[Chunker]
      Chunk --> Embed[Embedding model]
      Chunk --> TS[tree-sitter tags]
      Embed --> Vec[(Vector DB)]
      TS --> Sym[(Symbol graph)]
    end
    subgraph Query Path
      Q[Agent query + open file] --> R[Retriever]
      R -->|ANN search| Vec
      R -->|graph walk + PageRank| Sym
      R -->|blame + PR files| Git[(Git metadata)]
      Vec --> Rank[Reranker + token budget]
      Sym --> Rank
      Git --> Rank
      Rank --> Ctx[Context block]
    end
    Ctx --> LLM[LLM prompt]

Sourcegraph Cody uses the same pattern: code search, symbol intelligence, and embeddings layered in a hybrid retriever that can pull context from repositories the developer does not have open10. The key trade-off is index freshness: a rebase invalidates thousands of chunks. Mitigation: prioritize reindex of files the developer has open, invalidate lazily by commit SHA, and expose index lag to the UI8.

Tool-use sandbox isolation

Every agent-initiated shell command runs inside a per-session Firecracker microVM. Firecracker is a Rust VMM built on KVM with thread-specific seccomp filters and a jailer process that applies cgroup/namespace isolation then drops privileges11. AWS Lambda and Fargate run on it. Practical boot latency is ~125-150 ms12, making a warm pool viable.

Sandbox anatomy:

  • Read-only mount of the repo snapshot at task start
  • tmpfs scratch for agent writes (destroyed on finish)
  • Network allowlist: package registries + model API only
  • cgroup-enforced CPU (1 vCPU), memory (2 GB), and wall-clock (60 s per command) ceilings
  • Destroy-on-finish: no persistent state survives between tasks
Diagram
Each autonomous task gets a dedicated microVM with hardware-enforced isolation; destroy-on-finish limits persistence of any compromise.
flowchart LR
    Orch[Agent Orchestrator] -->|tool_call| CP[Sandbox Control Plane]
    CP --> Pool[Warm VM Pool<br/>pre-booted Firecracker]
    Pool -->|assign| VM[Per-session MicroVM]
    subgraph VM[MicroVM Internals]
      RO[Read-only repo mount]
      TMP[tmpfs scratch]
      CG[cgroup limits<br/>1 vCPU, 2 GB, 60s]
      SEC[seccomp + jailer]
    end
    VM -->|stdout, exit code| Orch
    VM -->|egress| FW{Allowlist firewall}
    FW -->|registries, model API| Net[Internet]
    FW -->|all else| Drop[Block + alert]
    VM -.->|task done| Destroy[Destroy VM]

Why not containers? A container escape requires only a kernel CVE, not a hypervisor escape. Container-based sandboxes for AI agents remain vulnerable to kernel exploits, as multiple security researchers have documented12. MicroVM-per-session gives hardware-enforced isolation where a kernel escape costs an attacker a fresh hypervisor CVE rather than a container breakout.

Cognition’s Devin runs each task in a cloud sandbox with browser, editor, and shell3. Cursor adapted its Background Agents VM scheduler to run “hundreds of thousands of concurrent sandboxed coding environments” during Composer RL training13.

Streaming diff application

The model streams edits; the client renders them inline as hunks the developer accepts or rejects. The critical insight from Cursor: full-file rewrite outperforms unified diffs for files under 400 lines because models see more full-file code than diffs in pretraining and struggle to count line numbers14.

Cursor’s fast-apply model: As described in their May 2024 blog post, a specialized 70B model (fine-tuned from Llama 3) rewrites the full file at ~1,000 tokens/sec (3,500 char/s) using speculative edits, a deterministic-draft variant of speculative decoding tuned for code14. This yields a ~13x speedup over vanilla Llama-3-70b inference and a ~9x speedup over Cursor’s previous GPT-4 speculative edits deployment.

Aider’s search/replace format: Aider interprets unified diffs as search/replace operations: the - and space lines form the search text, the + and space lines form the replacement15. Cursor adopted a variant of this format with redundant + and - markers that make the parser resilient to minor model failures14. Both formats avoid line-number hallucinations because the model specifies what to find and what to replace, not where.

Apply semantics: Each apply is atomic. The client accumulates hunks, the developer approves per-hunk or batch, and the filesystem transaction either succeeds completely or rolls back. A rollback token enables single-keystroke undo.

For files over 400 lines, Cursor is training long-context variants to reach 2,500 lines14. The trade-off: full-file rewrite costs more output tokens but eliminates positional errors that cause silent corruption.

Real-World Example

GitHub Copilot: 1.3M paid subscribers and 400M+ completions per day.

Copilot reached 1.3 million paid subscribers by Q1 2024 with 30% quarter-over-quarter growth, and more than 50,000 organizations had adopted it at the time of the Accenture study1617. The service handles 400M+ completion requests daily, peaking at ~8,000 QPS during the overlap of European afternoon and US morning1.

The architecture centers on a global authenticating proxy written in Go. The IDE exchanges an OAuth credential for a signed 10-30 minute code-completion token. The proxy validates the signature locally, swaps in the real Azure API key, and forwards over a long-lived HTTP/2 connection. octoDNS does weighted geographic routing to the nearest healthy proxy region1.

HTTP/2 is load-bearing. Stream-reset cancels a single request without tearing down the TCP connection. This matters because 45-50% of completion requests are cancelled by type-through before a response arrives1. Cloud-provider ALBs that downgrade to HTTP/1 on the backend would have made this impossible, so the team uses GitHub’s internal HAProxy-based GLB1.

The team explicitly rejected a PoP model: since every completion requires model inference, edge proxies back to centralized models create traffic tromboning with no caching benefit1. When a model upgrade emitted a bad EOF token, the team added negative token affinity at the proxy rather than waiting weeks for a client rollout1.

An Accenture enterprise study of Copilot found that developers accepted around 30% of suggestions, committed code from 90% of those accepted suggestions, and retained 88% of Copilot-generated characters; teams saw an 8.69% increase in pull requests and a 15% increase in merge rate17. Separate GitHub lab studies have measured task-completion speedups of up to 55%17.

Trade-offs

ApproachProsConsWhen to use
Client-only retrieval (index on laptop)Code never leaves device; zero privacy surfaceCold start slow; cross-repo impossibleSecurity-sensitive enterprise, offline-first18
Server-side retrieval (cloud index)Cross-repo queries; fast cold start; shared team cacheMust store code at rest; compliance surfaceSaaS at scale (Copilot, Cursor)10
Single frontier model for all modesSimplest routing; consistent qualityAutocomplete too slow and expensiveDemos and early-stage products19
Tiered models by modeOrder-of-magnitude cost reduction; meets 200 ms budgetMultiple models to eval and roll outProduction above ~10K DAU15
MicroVM-per-session (Firecracker)Hardware isolation; destroy-on-finishWarm pool cost; ~125 ms bootMulti-tenant untrusted execution1112
Shared-host sandbox (chroot + seccomp)Lower latency; lower costOne kernel CVE from escapeSingle-tenant or internal tools12
Human-in-the-loop on every diffZero silent bad editsSlower; requires attentionAutonomous on production branches19
Auto-apply with rollbackFast; feels magicalBad edit lands unnoticedAutocomplete and experimental branches14

The meta-decision: model tiering. Without it, autocomplete at frontier-model prices costs ~$0.01 per request, making a $20/month subscription unprofitable at 100K completions/month. With tiering, autocomplete costs ~$0.00005 per request, and the subscription works.

Scaling and Failure Modes

At 10x (6M autocomplete QPS): The warm GPU pool saturates. Mitigation: scale on queue depth (not CPU), request coalescing for identical prefixes within 20 ms, and aggressive prompt-prefix caching.

At 100x (60M QPS): The retrieval index becomes the bottleneck. Mitigation: shard the vector DB by repo, replicate hot repos, and move to a CDN-first pattern where the most common completions are cached at the edge.

At 1000x: The architecture shifts to federated regional inference fleets with a global control plane for routing and billing only.

Failure: Runaway autonomous loop. The agent retries a failing test forever, burning tokens. Detection: per-task step/token/wall-clock ceilings plus duplicate-tool-call detection. Recovery: circuit-breaker halts the task and notifies the developer19. Anthropic’s April 2026 post-mortem documents exactly this pattern: Claude Code “would continue executing, but increasingly without memory” during a broken-cache bug20.

Failure: Prompt-caching regression. A cache optimization silently corrupts agent memory; quality degrades for days. Anthropic’s clear_thinking bug (March 26 to April 10, 2026) cleared thinking on every turn instead of once, making the agent “seem forgetful and repetitive”20. Detection: per-request diagnostics exposing cache-hit vs fresh; eval suites on every system-prompt change.

Failure: Sandbox escape. Agent installs a malicious package that exploits a kernel CVE. Mitigation: Firecracker hypervisor isolation (not just containers), network allowlist, package-hash verification, destroy-on-finish1112.

Common Pitfalls

Follow-up Questions

1. How do you keep the repo index consistent during an in-progress rebase?

Invalidate chunks lazily by commit SHA. Prioritize reindex of files the developer has open. Expose index lag to the UI so the developer knows when context may be stale. Rate-limit reindex jobs per repo to avoid thrashing.

2. A customer reports the agent leaked content from their private repo into another session. Walk through the investigation.

Check sandbox isolation (was the VM shared?). Audit the retrieval index for cross-tenant contamination. Verify that embedding shards are keyed by (tenant_id, repo_id). Check prompt-cache key isolation. The fix: strict tenant-scoped cache keys and per-tenant vector DB partitions.

3. How do you A/B test a new autocomplete model when accept-rate takes hours to stabilize?

Use a larger sample size (10% canary minimum). Measure both immediate accept-rate and 24-hour retention of accepted suggestions (did the developer revert?). Gate on both metrics. Copilot’s 45-50% cancellation rate means you need to exclude cancelled requests from the denominator1.

4. A single autonomous task enters an infinite loop. How does the orchestrator detect and break it?

Hard ceiling on steps (50), tokens (200K), and wall-clock (10 minutes). Duplicate-tool-call detection on the action log (same tool + same args 3x in a row triggers halt). Per-tenant budget circuit breaker. Anthropic recommends “stopping conditions to maintain control” as a first-class agent design principle19.

5. How would you redesign for a regulated customer who cannot send code to a cloud?

Client-side retrieval index (Claude Code CLI pattern)18. On-prem small model for autocomplete. Frontier model calls route through a customer-controlled proxy with DLP scanning. Sandbox runs on customer infrastructure. The trade-off: no cross-repo search, slower cold start, customer bears GPU cost.

6. A new model claims 20% better SWE-bench Verified. What checks before 100% rollout?

Run internal regression set (not just SWE-bench). Replay the diff_log: does the new model produce diffs that match historical accepts? 1% canary measuring accept-rate and task-success-rate. Check for mode-specific regressions (a model tuned for autonomous may regress autocomplete)20. Soak for 48 hours minimum.

Exercise

Exercise 1: Sandbox fleet sizing

Your coding agent has 10,000 concurrent autonomous tasks. Each task holds a Firecracker microVM for an average of 3 minutes. Your warm pool boots VMs in 125 ms. Tasks arrive at a Poisson rate. How large should the warm pool be to ensure 99% of tasks get a VM within 500 ms?

Hint

Calculate the arrival rate (tasks/sec) and the service time. Use Little’s Law to find steady-state occupancy. The warm pool must absorb burst arrivals beyond steady state at the 99th percentile.

Solution
  1. Steady-state VMs in use: 10,000 (given as concurrent)
  2. Arrival rate: 10,000 / 180s = ~56 tasks/sec
  3. Boot time: 125 ms. To serve within 500 ms, a cold-start task has 375 ms of queue budget.
  4. Burst buffer: At Poisson arrivals, the 99th percentile burst over 1 second is ~56 + 3*sqrt(56) = ~78 arrivals. The warm pool needs ~22 extra pre-booted VMs beyond steady state.
  5. Total warm pool: 10,000 active + ~50 warm spares (accounting for return lag and boot pipeline).

Trade-off accepted: over-provisioning 50 idle VMs costs ~100 GB RAM but ensures 99% of tasks start within 500 ms. Under-provisioning forces cold boots that add 125 ms and risk SLO breach during bursts.

Key Takeaways

  • Three modes, three systems. Autocomplete, chat, and autonomous loop share infrastructure but have fundamentally different latency budgets, model tiers, and safety envelopes.
  • Retrieval quality is the product. Embeddings alone miss structural queries; pair them with a tree-sitter symbol graph and git-recency signal810.
  • Sandbox isolation is non-negotiable. Any agent running shell commands on untrusted input needs per-session microVM isolation with network allowlist and destroy-on-finish1112.
  • The diff is the interface. Full-file rewrite at 1,000 tokens/sec beats unified diffs because models cannot count line numbers14.
  • Evals gate the rollout. SWE-bench Verified, diff-log replay, and online canary metrics catch regressions that user-facing signals reveal only days later2320.

Further Reading

Flashcards

What are the three modes of a coding agent and their latency budgets?

Autocomplete (p99 < 200 ms), chat (first-token < 1 s), and autonomous loop (minutes per task). Each uses a different model tier: small/cheap, frontier, and frontier-plus-tools respectively.

Why does GitHub Copilot use HTTP/2 end-to-end for autocomplete?

HTTP/2 stream-reset cancels a single request without tearing down the TCP connection. This is critical because 45-50% of completion requests are cancelled by type-through before a response arrives1.

What three signals does a hybrid repo-context retriever combine?

(1) Semantic embeddings over code chunks, (2) a tree-sitter symbol graph with PageRank scoring, and (3) git awareness (recently changed files, current PR files). The reranker merges all three into a token-budgeted context block810.

Why use Firecracker microVMs instead of Docker containers for agent sandboxing?

Containers share the host kernel; a single kernel CVE enables multi-tenant escape. Firecracker provides hardware-enforced isolation via KVM where escape requires a hypervisor CVE, a much higher bar1112.

Why does Cursor's fast-apply model rewrite the full file instead of generating a unified diff?

Models see more full-file code than diffs in pretraining and struggle to count line numbers. Full-file rewrite eliminates positional errors. The fast-apply model runs at ~1,000 tokens/sec via speculative edits, yielding 9-13x speedup14.

What is the cost reduction from model tiering in a coding agent?

Roughly 10x overall. A small tuned model for autocomplete costs ~$0.00005 per request vs ~$0.005 for a frontier model. Tiering lets a $20/month subscription support 100K completions/month profitably5.

How does prompt caching reduce cost for coding agents?

Cached reads cost 10% of normal input price, yielding up to 90% cost reduction and 85% latency reduction for long prompts6. The repo context prefix is identical across turns, so you pay full price once and a fraction thereafter.

What caused Anthropic's April 2026 Claude Code quality regression?

Three compounding bugs: (1) reasoning-effort default lowered, (2) a cache optimization cleared thinking on every turn instead of once, making the agent “forgetful and repetitive,” and (3) a system-prompt line capping output length. The cache bug bypassed all automated tests because it only triggered on stale sessions20.

What is SWE-bench Verified and what is the current state of the art?

A 500-instance human-validated subset of SWE-bench that asks agents to resolve real GitHub issues. Scores have climbed rapidly: Devin scored 13.86% on the original SWE-bench in March 20243, and Claude Opus 4.7 now leads SWE-bench Verified at 87.6% (April 2026)4.

How do you detect and break a runaway autonomous agent loop?

Hard ceilings on steps (50), tokens (200K), and wall-clock (10 min). Duplicate-tool-call detection (same tool + args 3x triggers halt). Per-tenant budget circuit breaker. Anthropic recommends stopping conditions as a first-class design principle19.

References

Footnotes

  1. ZenML LLMOps Database, “Github: Building a Low-Latency Global Code Completion Service,” summarising InfoQ presentation by the copilot-proxy team. https://www.zenml.io/llmops-database/building-a-low-latency-global-code-completion-service ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10 ↩11 ↩12 ↩13 ↩14

  2. Sacra, “Cursor revenue” (Feb 2026 update: $2B ARR, up from $1B in Nov 2025 and $500M in June 2025). https://www.sacra.com/c/cursor ↩

  3. Cognition Labs, “Introducing Devin, the first AI software engineer” (13.86% SWE-bench). https://www.cognition-labs.com/introducing-devin ↩ ↩2 ↩3

  4. Anthropic, “Raising the bar on SWE-bench Verified with Claude 3.5 Sonnet.” https://www.anthropic.com/research/swe-bench-sonnet ↩ ↩2

  5. Systemprompt, “Reduce Claude Code Costs 60% With These Four Habits” (model tiering economics). https://systemprompt.io/guides/claude-code-cost-optimisation ↩ ↩2 ↩3 ↩4 ↩5

  6. Anthropic, “Prompt caching with Claude” (up to 90% cost reduction, 85% latency reduction). https://www.anthropic.com/news/prompt-caching ↩ ↩2

  7. Yao et al., “ReAct: Synergizing Reasoning and Acting in Language Models,” arXiv:2210.03629, ICLR 2023. https://arxiv.org/abs/2210.03629 ↩

  8. Aider, “Building a better repository map with tree sitter.” https://aider.chat/2023/10/22/repomap.html ↩ ↩2 ↩3 ↩4 ↩5 ↩6

  9. Aider-AI/aider, aider/repomap.py on GitHub (PageRank and tree-sitter implementation). https://github.com/Aider-AI/aider/blob/main/aider/repomap.py ↩

  10. Sourcegraph, “Lessons from building AI coding assistants: Context retrieval and evaluation.” https://sourcegraph.com/blog/lessons-from-building-ai-coding-assistants-context-retrieval-and-evaluation ↩ ↩2 ↩3 ↩4

  11. firecracker-microvm/firecracker on GitHub (KVM-based microVMs, seccomp, jailer). https://github.com/firecracker-microvm/firecracker ↩ ↩2 ↩3 ↩4 ↩5

  12. Viet Anh, “A Practical Guide to Running AI-Generated Code Safely,” Feb 2026; Tian Pan, “Agent Sandboxing and Secure Code Execution,” Mar 2026. https://www.vietanh.dev/blog/2026-02-02-agent-sandboxes ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7

  13. Cursor Team, “Composer: Building a fast frontier model with RL,” Oct 2025. https://cursor.com/blog/composer ↩ ↩2

  14. Aman Sanger (Cursor), “Editing Files at 1000 Tokens per Second” (fast-apply, speculative edits). https://cursor.com/blog/instant-apply ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7

  15. Aider, “Unified diffs make GPT-4 Turbo 3X less lazy.” https://aider.chat/docs/unified-diffs.html ↩

  16. CIO Dive, “GitHub Copilot drives revenue growth amid subscriber base expansion” (1.3M paid subscribers, 30% QoQ growth). https://www.ciodive.com/news/github-copilot-subscriber-count-revenue-growth/706201/ ↩

  17. GitHub Blog, “Research: quantifying GitHub Copilot’s impact in the enterprise with Accenture” (55.8% faster). https://github.blog/news-insights/research/research-quantifying-github-copilots-impact-in-the-enterprise-with-accenture/ ↩ ↩2 ↩3

  18. Anthropic, Claude Code documentation - memory and persistence. https://docs.claude.com/en/docs/claude-code/memory ↩ ↩2

  19. Erik Schluntz and Barry Zhang (Anthropic), “Building Effective Agents,” Dec 2024. https://www.anthropic.com/engineering/building-effective-agents ↩ ↩2 ↩3 ↩4 ↩5

  20. Anthropic Engineering, “An update on recent Claude Code quality reports” (Apr 23, 2026 post-mortem). https://www.anthropic.com/engineering/april-23-postmortem ↩ ↩2 ↩3 ↩4 ↩5 ↩6

  21. OWASP, “LLM Prompt Injection Prevention Cheat Sheet.” https://cheatsheetseries.owasp.org/cheatsheets/LLM_Prompt_Injection_Prevention_Cheat_Sheet.html ↩

  22. “Hacking the AI Hackers via Prompt Injection,” arXiv:2508.21669. https://arxiv.org/html/2508.21669v1 ↩

  23. OpenAI, “Why SWE-bench Verified no longer measures frontier coding capabilities” (SOTA 74.9% to 80.9% in 6 months). https://openai.com/index/why-we-no-longer-evaluate-swe-bench-verified/ ↩

Finished reading?

Mark it complete to track your progress through the course. Progress is saved in this browser.

This lesson is adapted from “Design a Coding Agent (Claude Code / GitHub Copilot / Cursor)” in The Engineering Handbook by Handbook Academy and contributors, used under CC BY-SA 4.0. Changes: restyled and reorganized for this site. View original source.