AI Engineer World's Fair 2024
Self-Evolving Code with AI: Enhancing Quality and Security in CI
Loading slides…
Read the talk
Self-Evolving Code with AI: Enhancing Quality and Security in CI
A CI-based assistant can clarify code, build a behavioral test baseline, and debate security fixes before handing a reasoned proposal to a human reviewer.
From a talk by Gunjan Patel
Before you start: Familiarity with pull requests, CI, and unit tests will help you follow the workflow; no prior experience building AI agents is required.
Keeping routine work out of the coding flow
How much of developing software is actually writing application code, and what happens to your concentration when the work shifts to tests, documentation, and deployment? Gunjan Patel explores that problem through an independent side project, not a Palo Alto Networks product. At the time of the talk, he was a director of engineering there and had spent the preceding year and a half to two years moving into generative AI. He dedicates the talk to his close friend Nikhil, who had been enthusiastic about the conference and died unexpectedly two weeks earlier.
Patel starts with the relationship between skill and challenge described in the book he calls The Flow. A green flow zone sits between anxiety and boredom. A developer begins with an idea and writes code; a difficult problem raises the challenge and can push the developer toward anxiety. Then unit tests and documentation arrive. In Patel’s framing, those tasks can pull the same developer toward boredom because the work no longer matches their skill level.
The surrounding work is substantial: Kubernetes manifests, Dockerfiles, deployment, and tests all compete with application development. A copilot helps overcome immediate technical hurdles, but the developer still has to steer each interaction. Patel’s proposed change is to move routine work into CI, where it can proceed without continuously interrupting the person writing the code.
A ChatGPT meme supplies the joke behind that ambition: people at both ends of the spectrum simply use ChatGPT, while the person in the middle—Patel includes himself—juggles tools to get the work done. Moving tasks offline is also an attempt to reduce that juggling.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
A ghostpilot has time to reconsider
Patel calls the offline assistant a ghostpilot. Sourcegraph Cody and GitHub Copilot illustrate the live alternative: they work beside a developer who expects a response in seconds. Code review has a different interaction pattern. A reviewer needs context, time to reflect, and opportunities to revise an answer.
| Dimension | Copilot | Ghostpilot |
|---|---|---|
| Interaction | Live assistance | Offline review |
| Immediate goal | Help with the next decision | Assess a change in context |
| Reasoning pattern | Quick response | Reflection and iteration |
Patel connects this distinction to Daniel Kahneman’s Thinking, Fast and Slow: the copilot fills the fast role, while the ghostpilot provides a slower, more deliberate process.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Establish intent and behavior before proposing fixes
The workflow begins with a developer writing code using an IDE assistant, then submitting it through the pull-request process. CI performs an ordered sequence:
- Clarify intent. Improve variable names and comments so subsequent model calls have a better account of what the code is supposed to do.
- Establish behavior. Generate and run unit tests in a loop, creating a baseline of expected outputs for given inputs.
- Identify security issues. Use environmental context to look for missing security practices and relevant vulnerabilities.
- Propose fixes and rerun tests. Prepare changes for human review, then check them against the earlier baseline.
The order matters: clearer intent informs the tests, and the tests provide a behavioral check on later changes. Patel explicitly corrects himself when describing the last stage: the system proposes fixes; a human reviews them.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Names and comments supply domain context
Why spend a CI stage on names and comments? Patel recalls a line from a conference session by Manuel: “LLMs are cultural technology.” The point is that a model’s knowledge extends beyond programming into domains such as finance, psychology, and art. Meaningful identifiers can connect the code to that broader knowledge.
In a finance application, rev may mean revenue to its author. Naming it annual_revenue makes both the domain and the time period explicit. Patel suggests that subsequent model calls—even calls to different providers—can then draw on financial knowledge and consider corner cases that an abbreviated name might not evoke. The name becomes context passed between stages.
Comments serve a related purpose, but they can become stale when someone changes code in a hurry. The useful information is the intended behavior, which may differ from what buggy code currently does. Improving comments should make that intention legible to the next model.
In Patel’s CI example, the assistant adds a high-level description of a code block’s expected flow. It also makes a server’s port identifier explicitly refer to a port number, distinguishing it from a port name. That small clarification becomes useful when the next stage decides which inputs and behaviors to test.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
List test cases before writing test code
The test stage builds coverage in layers: ordinary behavior first, corner cases second, and regression precautions drawn from historical bugs third. A project’s Jira history can reveal failures that deserve explicit coverage even when they are not obvious from the current code.
Patel reports that a single request to generate unit tests does a poor job in his workflow. CI offers room to separate the reasoning into multiple steps. People still care about CI completion time, but they are not waiting for each response in the same way they wait for an IDE suggestion.
The sequence is deliberately staged:
- Describe expected behavior. Have the model read the code, comments, README, and possibly a product requirements document, or PRD. It first states what the code should do. Requirements may describe overall intent without reaching function-level detail.
- Enumerate adversarial cases. Give the same model or another model an adversarial mindset. Ask for unusual characters, minimum and maximum values, and boundary conditions. List cases without writing tests yet.
- Personalize the list. Add cases based on team priorities in
context.yamland the project’s historical bugs. - Generate and run tests. Turn the assembled case list into test code, then iterate until the tests pass.
The intermediate case list makes the coverage decision explicit before the model commits to test implementation. Patel describes repeated model work as cheap or free labor, but supplies no cost measurements for this loop.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Combine declared context with inferred priorities
The context file describes the application’s operating environment: cloud provider, service, deployment location, whether the tool is internal or customer-facing, whether it handles personally identifiable information, and whether it is a frontend or backend application. Networking details, the PRD, and the Jira project connect that environment to requirements and bug history.
A Slack channel has a more ambitious proposed role: the assistant could ask a person for missing context. Patel explicitly says this interaction is not implemented. He compares the intended experience to Perplexity Pro asking a clarifying question when a request is unclear. Company security policies and InfoSec guidelines complete the declared context used for review.
A second portion of the context is inferred by AI. The model identifies the language and kind of code—such as infrastructure as code, backend code, or shell code—because each implies different review priorities. Historical bugs and escalations identify focus areas such as SQL injection, timeouts, and concurrent users. Patel also points to Quinn’s OpenCtx as a potential way to bring in additional context, rather than an integration already present in the project.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Debate which security findings warrant a fix
Security review uses that context to look for company security practices that are not being followed and for problems in logical flow. Patel distinguishes this goal from running static application security testing, or SAST. The task includes prioritizing findings, because asking a model to find problems tends to produce a list even when some issues are minor. A useful review must decide which ones warrant action.
To make that decision, Patel simulates three employees. For Python code, the roles receive different context:
| Role | Context supplied |
|---|---|
| Red-team engineer | Security policies and reviewed code |
| Python developer | Code author’s perspective and product requirements |
| Engineering manager | Business context, Zoom transcripts, Slack conversations, and PRD |
The developer represents the intent behind the implementation, while the manager brings in business constraints that a security-only reading could miss.
A prompt has the roles take turns debating each issue: what risk it creates, whether it needs fixing, and how much effort a fix requires. After the debate, a reflection step checks whether the answer still matches the original intent. That check can use a separate model. The output is therefore a considered priority decision, rather than merely the first reviewer’s list of concerns.
Patel then suggests an optional experiment he recalls from a podcast as an “Odyssey Journey”: imagine three possible future paths, then return to advise your past self. This is a proposed prompting exercise, not another established pipeline stage. He mentions research suggesting such approaches can outperform standard LLM use, but does not identify the study or give comparison conditions.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
A vulnerability in the placement of a condition
The concrete security example is a vulnerability in Kubernetes Go code that Patel describes as critical. He says he selected an issue from after GPT-3.5’s training cutoff. The relevant repair moves an if statement from one place in the control flow to another: the problem lies in when a condition is checked.
Patel reports that his workflow finds the issue and argues that SAST tools would miss it because it is a logical-flow problem. The talk does not identify the vulnerability, exact patch, model snapshot, or detection output, so this remains one reported example rather than a measured detection rate or a verified comparison with SAST.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Hand the reviewer a proposal, rationale, and test result
The final stage produces outcome-oriented suggestions, with the human reviewer deciding which fixes to accept. For each proposal, three bullet points summarize the simulated employees’ discussion and explain the priority. Security-policy citations give the reviewer a concrete basis for the recommendation. Before that handoff, CI reruns the unit tests established earlier to check the proposed change against the behavioral baseline.
Patel closes the technical demonstration with a deliberately simple example: a hard-coded API key. The review comment includes a risk score, an effort score, a recommendation, and a proposed code snippet. A Python recommendation for removing an embedded key can take this form:
python
import os
def load_api_key() -> str:
api_key = os.environ["SERVICE_API_KEY"]
if not api_key.strip():
raise ValueError("SERVICE_API_KEY must not be empty")
return api_key
This proposal moves the credential into runtime configuration and fails when it is missing or empty. The review still needs to explain the relevant policy, the risk being addressed, and the effort of supplying that configuration. The snippet is the proposed change; acceptance remains the human reviewer’s decision.
The closing slide points to Patel’s contact information and a GitHub repository. At the time of the recording, he says the code, GitLab CI files, and GitHub Actions files will be uploaded in the next few days. The implementation handoff is therefore a promised release, following a workflow whose final artifact is a tested, explained proposal for human review.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Resources
From the talk
Experimental standard and source code for bringing external developer-tool context into code views. The repository was archived in May 2026.
Daniel Kahneman's account of intuitive and deliberative thinking supplies Patel's copilot-versus-ghostpilot analogy.
Further reading
Research on improving reasoning and factual answers through repeated debate among language-model instances.
Full transcript
Loading transcript…