Ch.63: Coding Agent System Design: From Task to Tested Patch

Outline

Transcript

0:00 A coding agent takes a developer's task and uses a language model to choose steps such as reading files, editing code and running commands. We'll design the remote service behind that workflow, including how it returns a reviewable patch and tells you which checks actually ran on those files. Because a genuine green test result can accompany the wrong patch. The service may return files edited after that test finished. So trace that coding task through the complete architecture: accept it, queue it, provide an isolated workspace, then validate and return a fixed set of files.

0:34 The model chooses proposed steps inside that worker, but permission checks and the final completion decision belong to the service outside it. We'll return to this same map once we've followed a task through those boundaries. Start with what the developer is actually asking us to deliver. Before choosing components, our functional requirements are to accept an authenticated task, an allowed repository and a base revision, then expose status and cancellation. The agent can inspect that repository, edit permitted files and run permitted commands.

1:04 The response includes a patch, actual check results and unfinished work. Take an importer that drops the last CSV row when its input lacks a final newline. The developer wants that bug fixed and checked. Right, fix and check the importer, then stop. I'd keep merging and production access outside this service, even if the model writes a very persuasive completion message. Agreed. The developer gets something to review, not an unexpected release. That limit also gives us a tractable security boundary to design.

1:35 With that caller promise established, our non-functional requirements separate customers' workspaces and credentials, bound resource use, and preserve progress when a worker disappears. Completion may take minutes, so a quick acceptance response can't mean quick completion. We need fair admission and an honest queued state. A fictional workload makes the scale concrete: 50 jobs arriving per minute, each active for 6 minutes on average, means roughly 300 active jobs. At steady state, yes. But why not put the burst in a queue and add workers?

2:06 Are all those active jobs busy compiling? No. Our importer may spend most of its time waiting for a model response, then need CPU and memory to run its tests. Active jobs aren't all using the same resource. Ah, separate model-request limits from build slots. For example, if our importer never reaches a worker, adding build machines may not shorten its wait. Then what can our acceptance API promise while execution is still queued? Those constraints lead to admission and a durable job record containing the developer's identity, repository, base revision and allowed scope.

2:41 Task prose doesn't widen permissions. Suppose the developer's client times out while submitting. Does retrying create another agent fixing the same bug beside the first one? Use a caller-scoped request key so the retry returns the same job. Reusing that key with a different task or base is an error. Commit the accepted job and a pending queue message together. A dispatcher sends that message to the queue. If it crashes before delivery, the pending message is still recorded. And return the job identity, not a claim that execution started.

3:14 The caller can inspect that durable record even before a worker exists. Once queued, a worker creates a private workspace from the chosen base revision. That's an attempt, one worker's try at the job. The queue carries a job reference, not repository contents. The job record names which attempt is current, and that worker fetches only its granted repository access. I'm not sure persisting the request prevents two workers starting after a delivery retry. What keeps their edits from racing? Keep those workspaces separate.

3:45 An atomic update publishes only if that record still names this attempt as owner. An old worker's late result fails that check. Okay, the disposable workspace isn't our completion authority. We can abandon an old attempt without allowing its later files to overwrite the current result. Now use that private workspace for the model's decision loop. It sees the task and bounded repository context, then might propose reading the importer tests. The application receives that structured tool request, performs the allowed read and returns its actual result.

4:18 The model hasn't read a file merely by naming it. Yes, Anthropic's public tool-use docs separate the request from execution. We'll link them in the description. Our loop chooses its next step from the returned result. For our importer, it might look for a fixture without a trailing newline, read the parser, then propose an edit. Each step gets a real result back. And a missing file or failed command returns as a failure the next decision must address, rather than disappearing behind a confident summary.

4:49 That leaves job status grounded in the runner's result, not the model's summary of it. But reading files also exposes the model to unapproved instructions. Imagine a repository comment telling it to upload credentials to a debugging website. Even a helpful-looking instruction is still repository data. The service checks a proposed action against the caller, path, command and current job policy. So listing a tool for the model isn't the same as authorizing every invocation. I'd check the actual input when that invocation arrives.

5:21 Right, including paths after resolving them against the allowed filesystem root. Editing a test shouldn't grant permission to follow a link outside that root. Deny the action and return the denial as a tool result. Don't ask the same model to declare whether the hostile instruction is trustworthy. That policy boundary needs enforcement underneath commands too. Our locked-down execution environment separates a command from other jobs and restricts its access to the host and network. I'd avoid giving repository code production credentials at all.

5:53 A short-lived repository credential should have only the access needed for this job. For instance, our importer can run a download command through the command proxy. A separate documentation-fetching tool might call the web directly, outside that proxy. I'd initially put those requests behind the same proxy in the diagram. That would imply coverage we hadn't actually implemented. Exactly. Authorize that web tool and control its network path separately. Even an allowed package host can serve hostile content.

6:22 Isolation limits what code can reach; it doesn't make that code trustworthy. Those authority limits also leave the question of endless execution. At admission, attach disclosed limits on elapsed time, tool calls and execution resources. They're product-policy choices, not a universal number of useful agent steps. A repository search and a long integration build consume very different resources. Consider a loop that keeps changing its plan, running the same failed test and calling every attempt progress.

6:52 When should we stop it? The service can detect repeated tool inputs and unchanged results, then stop or request a narrower task. Don't keep spending solely because the model sounds optimistic. Yeah. I would return the partial patch and the unresolved check rather than let a progress indicator become more confident with age. So keep the execution record outside the workspace. Name each tool attempt, record when it starts, then save its real result and size-limited output. Capture the real command exit status.

7:23 A model saying the tests passed can't replace a runner reporting that the test process failed to start. What would the developer see while that importer test is still running? A running test command, not a completed check and not a model wait. They can inspect their own bounded logs, never another customer's output. Right. Redact secrets before storing or sending tool output back to the model, and authorize log access just as you authorize artifact access. That history explains completed steps, but it isn't a saved operating-system process.

7:56 A lost shell can't necessarily resume from the next line in a transcript. So restart from a known saved repository state, or report incomplete work. A transcript isn't a paused terminal waiting for us to press Play. Before declaring the importer fixed, run the relevant baseline checks where feasible. A test that already fails at the base changes what we can attribute to the patch. And add a case containing a final row without a newline. Ideally it demonstrates the bug before the fix and passes after it.

8:27 The agent might write both the patch and the regression test, though. Are we just letting it grade its own homework? It can. If the new assertion only checks that the importer returned something, it may never notice the missing row. The runner observes execution, not whether that assertion captures the request. Ah, so inspect what the test actually asserts, not just its exit code. Include changed tests and flag removed checks in the deliverable. But that baseline check leaves another trap: even a well-chosen test can describe the wrong files.

9:00 Walk me through how a genuine pass ends up beside the wrong importer patch. Take the newline fix as draft A. The runner tests A and records a pass. Then the agent tidies the parser, creating draft B. And the service packages B with the result from A. Oh, I see. Nothing fabricated the pass; we changed what it was attached to. The old result still describes A. It tells us nothing new about B, even if the edit looks harmless. My first thought was to ask the model for its final checks. But that leaves the same attachment mistake available.

9:34 What enforces the boundary? The service stops agent writes and captures a candidate, the source inputs for this validation run. Frozen means those files cannot change beneath the result. So tested means this check on this draft. But a draft includes more than the parser file. How do we name everything we're returning? With validation becoming a separate phase, first refuse new agent edits and capture the candidate's repository state, plus the base revision for computing its patch. A commit identifier can name the versioned tree, but the working directory may also contain an untracked helper file the importer now depends on.

10:10 Oh, that helper could make the test pass locally, then vanish from the download. How do we make its inclusion explicit? Explicitly inventory source inputs and changed files. Include allowed new source in the candidate, reject forbidden paths, and keep generated logs or secrets out of the deliverable. Okay. The candidate manifest describes the actual inputs we're prepared to return, rather than assuming every file near a Git checkout belongs in the patch. Once the candidate includes its required source inputs, validation gets its own execution copy.

10:42 The agent cannot keep editing that input while checks run. Suppose a dependency update changes how the importer opens files. The source hasn't changed, but its behavior might. I'd record the exact dependency versions. And the operating-system and tool bundle. Run the recorded command with its declared settings, keeping test logs and caches outside the candidate inputs. If a test must modify a source input, detect that change and invalidate the evidence for the original candidate. Don't pretend a source-mutating check left its inputs untouched.

11:15 That costs extra storage and setup, but I'd pay for an explicit tested state rather than save time by sharing a moving workspace. We can reuse verified dependency bytes. The old check result still belongs to its original candidate, not a similar-looking replacement. But a failed validation returns to the model as real feedback. It can propose another edit within the original scope and remaining policy limits. Any repair creates a new candidate identity. The previous checks stay attached to the previous candidate, including the ones that passed.

11:47 I'm thinking through the temptation to carry those passes forward. A small parser edit could affect several tests that look unrelated in the patch. Exactly. Our initial service reruns its required check set. Selective test reuse would need an explicit dependency and validity model, not the model's reassurance. And when the remaining limit can't cover another full validation, return incomplete validation. Don't lower the definition of tested to finish the job. Now the required check passes on draft B.

12:15 What has to exist before the status API can announce success? The fixed artifact and its evidence must already be stored and verified. Only then can the authorized attempt conditionally mark the job complete. Without that ordering, a worker can die leaving the developer a success message and no patch to download. Put the parcel on the shelf before sending the tracking number. Yes. The record names the starting revision and candidate B, including its file inventory. Each check entry names its command, environment and actual outcome.

12:48 And the authorized download keeps serving B, not a later worker's draft. Right. A late worker fails the ownership check, so its files never replace the delivered patch. With the result ready to return, why explicitly list a check that wasn't run? Because the developer might read that green result as broader coverage. An integration check missing its dependency stays explicitly not run, beside the pass. The absence belongs in the result, not in the developer's imagination. A check required by job policy can't be replaced by a green command the agent picked.

13:22 Neither proves every CSV edge case was covered or the task understood. Right. Code review still examines the changed code and assertions. This evidence describes the exact returned state; it doesn't replace judgment about that state. Which is a useful starting point. We can inspect the patch instead of first reconstructing whether the completion message came before or after its last edit. But cancellation can race with artifact publication. Record the request, stop admitting new tool work, revoke job authority and terminate the execution environment where possible.

13:55 If a command already started, cancellation doesn't erase its earlier effects. How should the response separate a stop request from an observed shutdown? Report that cancellation was requested, then separately report what stopped and any uncertain outcome. Never repeat an uncertain external action to obtain a cleaner-looking result. Our no-production-access requirement helps limit those effects, but an allowed network action can still matter. A sandbox isn't a time machine. Right. Keep partial artifacts labeled partial, and use one conditional final-state transition so a canceled job can't later become an apparently successful delivery.

14:31 The same publication order guides crash recovery. If a worker dies before publishing, restart from an explicit checkpoint rather than its vanished process memory. If the artifact and evidence were already stored, recovery can verify them and finish the still-pending conditional publication instead of rerunning the successful test. Picture this: the record says a command started, but contains no final result. How much work can recovery safely claim in that case? Then it doesn't say the command passed.

15:00 Repeating a file search may be safe; repeating an upload could duplicate an effect we haven't verified. If we can't check, report uncertainty. Okay. Reuse verified completed artifacts, but don't confuse a durable start event with evidence of a completed command. With recovery covered for a single job, now consider our importer competing with another customer's batch. How do we keep that customer from taking every execution slot? Enforce per-customer concurrency limits and account for queue age. Our importer shouldn't stay behind fresh batches just because the other customer keeps submitting.

15:34 Then our job reaches a long model wait. Would you keep its workspace warm while it isn't running commands? Release it when its idle limit expires, after saving our importer's repository state. That saves resources now, but our job pays setup time again when the model responds. Right. The model response can arrive while no build slot is free. Restoring our importer still needs admission, not just a saved directory. That workspace eviction creates a reason to cache dependencies. For example, rebuild our importer using a verified immutable bundle within its access boundary, not another customer's edited checkout.

16:08 Otherwise their source changes, logs or credentials can turn up in our job. Reusing dependency bytes and reusing a live workbench are very different decisions. And identify that bundle by the inputs that built it, including dependency versions and the runtime platform. The same package name doesn't establish the same environment. I'd measure setup time first, because otherwise, we could complicate the cache while most of the delay is still waiting for the model. So if that importer fix is slow, how would we decide whether a cache would help?

16:40 Follow its job trace. Separate queue wait and repository setup from model waiting, commands, validation and publication. A slow model response isn't slow dependency installation. Ah, now the measurement changes the decision. Queue age and execution counts point toward admission or capacity. Repeated tool denials point toward permissions or task scope. Track stale-candidate rejections too: investigate our freeze boundary, not just model quality. Tie costs to the job, but redact secrets. The operator needs phase timings, not a copy of private source.

17:10 Finally, return to the original architecture with our importer fix: the API records a scoped job, the queue admits an attempt, and private storage holds evolving edits. The model proposes actions, but an external policy authorizes execution and the runner records outcomes. Neither repository instructions nor completion prose can promote itself into a permission grant. When editing stops, the candidate crosses into validation as a fixed input. The stored artifact and check evidence keep that same identity through conditional publication.

17:40 So a later parser tidy-up can't inherit the old green result. It becomes new work needing new evidence, or it isn't the patch we return. And passing checks still don't prove the chosen fix matches what the developer needed. Our contract makes the reviewable result explicit about its files and its limits. That's the coding service we set out to build: a task becomes an inspectable patch, with no mystery about what was tested. Thanks for listening to Learning Podcasts.