OpenAI

Agent-driven development is advancing at a remarkable pace, and traditional approaches to performance engineering can no longer keep up. To keep pace, we built the performance factory: an autonomous system that draws on the capabilities of Codex and our models to find and fix performance regressions faster than ever before. The performance factory runs in the cloud, investigating and resolving performance problems automatically, and helps us keep up with the ambitious goals on our product roadmap.

[1]

In the performance factory, engineers define workflows for recurring work and write instructions for the Codex agents that carry them out. The performance regression workflow, for example, creates a task when a performance alert fires. An agent investigates the cause of the slowdown, records its findings in the task, and proposes a fix for engineers to review. Once the fix is deployed, another agent picks up the same task and checks whether performance has returned to baseline. From investigating the problem and writing the fix to verifying the mitigation, this first workflow in the performance factory automates the entire performance regression repair process. In just over three months, the performance regression workflow tracked more than 1,700 investigations and found root causes in more than 600 cases—the equivalent of 17 automated investigations every day.

[1]

In this post, we describe how we progressively deepened our use of Codex to build today’s performance factory, walk through the first workflow we put into production, and share early lessons from building and running agent workflows in production.

[1]

From manual investigation to automated workflows

[1]

As we used Codex for more performance work, we saw how our team’s way of working evolved. We hope other service teams adopting agent workflows in different domains can learn from our experience.

[1]
Software work evolved from manual operation to collaborating with machines, and then to an agent factory., OpenAI

1. Before Codex. Before using Codex, engineers had to manually review metrics and logs, compare traces, debug live machines, and read code to investigate the cause of a slowdown. This work was time-consuming, and it often required deep knowledge of the service to know where to start. Relevant clues were easy to miss. When we ran into the same kinds of problems repeatedly—for example, rising time to first token in ChatGPT—we built advanced tools such as CPU and memory allocation profilers to make investigation easier. Over time, we accumulated more than 30 performance tools.

[1]

2. Working alongside Codex. With Codex as a partner, engineers could ask, “Why is it slow here?” and investigate together with Codex, even in unfamiliar systems. Codex could search large codebases, find relevant metrics and traces, follow cross-service interactions, and run appropriate profiling to reconstruct what happened. But engineers still had to lead the process, knowing which performance tools to use and how to guide the investigation. More people could take on complex investigations, and the expertise and time required decreased.

[1]

3. Reusable skills. To automate further, we turned the performance team’s investigation process into a shared skill called perf-forensics. It tells Codex which tools are available, when to use them, and how to investigate a slowdown, letting Codex approach a problem from several angles:

[1]

Determine when the slowdown began; identify the affected requests; check whether a deployment or configuration change explains it.

[1]

We tested and improved the perf-forensics skill by evaluating it against past performance regressions. For the regression types we focus on—such as increased ChatGPT latency and reduced availability—we can now hand an alert to Codex and get a diagnosis in a single run, without step-by-step guidance.

[1]

4. Human relay. As we added and refined Codex skills for performance work such as perf-forensics, we began to feel like a relay between alerts and Codex. When an alert fired, engineers simply pasted it into Codex, invoked the right skill, and pasted the investigation results back into Slack.

[1]

5. Automated investigation. Next, we moved investigation to the cloud so alerts could start Codex sessions automatically. Codex investigated the slowdown and posted its findings to a Slack thread, but the automation stopped at that reply. Engineers still had to pick up the diagnosis, develop a fix, and check the results after deployment. As alerts piled up, even determining which regressions needed attention meant combing through Slack threads.

[1]

6. Running as a factory. We built the performance factory to run end-to-end, agent-driven performance engineering workflows. It tracks what each in-progress task needs next and assigns an agent when the next step is ready. Each task stores its state and findings, so work can pass between agents and engineers and continue after code review or deployment. For regressions, work starts with investigating an alert and ends with verifying recovery in production. We can turn common optimizations into workflows and run them regularly across services. When a workflow spots a potential optimization, it can create a task in another workflow to test and implement it.

[1]

The four components of the performance factory

[1]

The performance factory has four components: a task tracker that supports configurable workflows, a scheduling loop that assigns ready work to agents, an API that runs Codex in the cloud, and a subscription mechanism that wakes agents when something changes—for example, when a review comment is posted on GitHub or a deployment completes.

[1]
The performance factory consists of a task service, a scheduling loop, cloud execution, and a subscription mechanism., OpenAI

A task service that supports configurable workflows

[1]

Engineers define workflows in the task service by adding a configuration file and prompts written in Markdown for agents to follow. The configuration lists the states a task can pass through, the allowed state transitions, and the steps that require engineer involvement. The prompts for each step tell the agent what to do.

[1]
code-change/
├── config.toml
└── work/
    ├── implementing.md
    └── reviewing.md
A code-change task contains a configuration file and Markdown prompts for implementation and review.

Every piece of work becomes a task in a workflow, and all workflows are visible in the interface. Engineers can see outstanding tasks, track progress, and share tasks with colleagues who know more context or can help move the next step forward.

[1]

A scheduling loop that assigns work

[1]

The scheduling loop periodically checks which tasks are ready for their next step. It starts a Codex run using the instructions for the task’s current state, assigning an agent to each task. The agent records progress in the task and, once it completes the current step, moves the task to its next state.

[1]

Codex in the cloud

[1]

Once a task is assigned, the agent needs a working environment and access to the same tools engineers use. We built an internal API that can programmatically invoke a Codex run in the cloud. The run executes in an environment on our internal network with access to the code repository and the observability tools engineers use, including metrics, logs, traces, CPU profiling, and memory snapshots.

[1]

Agents run as service identities, so we can scope their permissions and identify which actions come from performance agents. Moving agent work to the cloud let us execute work in parallel without keeping engineers’ laptops open or manually managing cloud development machines.

[1]

A subscription mechanism that wakes agents when something changes

[1]

Some work must wait for a human or for a deployment, and agents shouldn’t keep running in the meantime. When a task needs to wait, it can subscribe to events such as review comments on a GitHub pull request (PR) or a failing CI check, and be notified when it can continue. When an incoming event matches the subscription, the task becomes ready again, and the scheduling loop can assign an agent to continue the work.

[1]

The first workflow: from alert to recovery

[1]

The first workflow we built in the performance factory finds regressions, identifies root causes, and resolves them. We call it the performance regression workflow. Regression work passes through several stages: awaiting investigation, root cause identified, fix proposed, and resolved. So we built the automated workflow around these stages and move tasks through them in order.

[1]

When one of the configured performance alerts fires, the regression workflow creates a task, and an agent picks it up and moves it through these stages. A task’s state and key findings are stored outside any single agent’s context, so another agent or an engineer can take over. Engineers can follow progress in Slack or in the regression workflow interface, add context, and review proposed changes. After the fix is deployed, the agent first checks whether performance has returned to its previous level, then marks the task resolved.

[1]

The performance regression workflow’s steps are: identify the root cause, propose a fix, review and deploy, and verify recovery.

[1]

Agents identify the root cause

[1]

Finding one or more root causes is the first major step in the workflow. The agent first determines which metrics degraded, when they began to change, and which service requests were affected. The perf-forensics skill gives Codex access to performance engineers’ tools and a playbook for investigating these questions.

[1]

Alerts fire when a metric crosses a threshold, but a regression may have started hours earlier. The agent looks back through the data to find when the metric first began to degrade. It then compares groups of requests: did the same kind of request actually get slower, or are we handling a larger share of requests that were already slow? These findings point to different causes.

[1]

Once it has established the time window and scope to focus on, the agent reviews deployment and feature-flag changes, then reads the relevant code. It verifies when a change actually took effect for the affected requests and uses logs or traces to confirm whether the code explains what happened.

[1]

Improving diagnostic reliability with adversarial review

[1]

Early on, agents sometimes stopped at the first plausible explanation, and some of those diagnoses later turned out to be wrong. To catch these errors, we added adversarial review: we start a separate Codex session that tries to disprove the proposed diagnosis. The reviewer re-examines the hypothesis and tests counterfactuals. If a release caused the slowdown, are similar requests that weren’t affected by that release still normal? If the suspect change were rolled back, would the affected metrics recover?

[1]

In one investigation, an agent traced failed ChatGPT conversations to an image download error and marked the cause as found. The Codex reviewer noticed that the internal service responsible for locating files had recovered, yet image requests were still failing. That diagnosis couldn’t explain the continued failures, so the reviewer reopened the investigation and recorded what still needed to be determined.

[1]

Splitting larger jobs into multiple focused Codex runs has worked well. In a manual review of 100 root cause determinations, we rated 70% as accurate; the other 30% needed further refinement or didn’t establish causality well enough. In the regression workflow, separate runs investigate the regression, challenge the diagnosis, and propose a fix, and this mutual checking and balancing improves accuracy.

[1]

Fixing regressions is the hard part

[1]

Once a diagnosis passes adversarial review, the workflow asks Codex to implement the fix and open a pull request. Engineers review the PR and decide whether to merge. We invested heavily in making this handoff as easy as possible. Every task has a report with an automatically generated summary covering the regression, its impact, the root cause, and the proposed fix. We tuned these summaries for quick skimming and added metric time series, CPU flame graphs, and traces to help engineers quickly understand the findings and check the evidence. Engineers can edit the PR directly or write their own fix based on the diagnosis. If an engineer leaves a comment on the PR, the workflow wakes an agent to address it.

[1]
An example regression task report showing key details, the root cause, and a proposed fix., OpenAI

After an engineer deploys the fix, the workflow wakes an agent to check whether performance has recovered to its previous baseline. If it has, the agent marks the task resolved. If performance has recovered only partially, the agent marks the original regression resolved and creates a new task for the remaining slowdown, which may have a different cause. If there is no improvement, the agent records the situation and sends the regression back to investigation.

[1]

In practice, fixing correctly is harder than finding the cause. For example, we’ve seen agents propose changes that were too complex or introduced new problems. As with root cause analysis, we added adversarial review to every proposed fix to check whether it addresses the root cause and to help surface defects or unintended consequences. Some fixes also require higher-level architectural decisions. For example, adding caching may improve performance but can introduce staleness. Changes like these need guidance from engineers who know the service and can weigh the tradeoffs.

[1]

We’re using these cases to build an evaluation and improvement loop. By comparing the fixes agents propose with the changes engineers ultimately merge, we can better understand where proposals fall short, build evaluations, and improve the workflow. We’re also experimenting with synthetic performance tests so agents can measure and adjust a proposed fix before asking an engineer to review it. In addition, we’re exploring how agents can use other agent review tools to identify low-risk changes and eventually deploy those fixes without human involvement.

[1]

What we learned

[1]

Building and running the performance factory has taught us a lot about developing and operating agent workflows in production. These lessons may help teams building their own agent workflows.

[1]

Protect engineers’ attention

[1]

Codex’s raw investigation output can be a long wall of text that’s hard to sort through. Engineers spend effort working out what the agent actually concluded and then finding the charts to confirm whether the data supports it. We want engineers to spend their attention on decisions, not on re-tracing work the agent has already done.

[1]

The number of regressions agents can investigate can exceed what a team has time to read. Our first version gave engineers a full screen of investigation findings, but someone still had to judge which information mattered. The same regression can also appear as multiple incidents across different alerts, monitors, and channels. Now the workflow links related incidents, groups them by the metrics a team cares about, and orders them by estimated impact. Engineers can focus on adding context, weighing tradeoffs, and deciding which changes to ship.

[1]

Evaluate changes to agents

[1]

Updating an investigation skill or upgrading a model can make an agent diagnose some cases better and others worse, so we need to test the impact before updating. We test two things separately: 1) how well the agent investigates; and 2) how useful its summaries are to engineers.

[1]

Evaluating investigation capability

[1]

For investigation capability, we backtest against past production incidents. We turn those incidents into a set of test cases we can rerun after changing a skill. A Codex agent attempts to investigate and resolve the incident, and we compare its behavior with the data from how the incident was actually resolved. Each case starts with a fresh Codex investigation agent and the original signals, with details that could reveal the answer removed.

[1]

Testing with historical cases requires care. Metrics and traces expire, and evidence collected after recovery can reveal the cause. Testing is only meaningful once you know which evidence the investigation agent can see. The agent can read code within set limits and query production telemetry. It cannot use saved memory (notes from earlier investigations), read incident reports, or view results from previous runs. We also review its interaction logs afterward for information that could undermine the test’s validity.

[1]

We score the agent’s judgments about when the problem began, its severity, and which requests were affected. We also evaluate how it ranks likely causes based on evidence and how it explains what remains uncertain. An agent may get the timing right but blame the wrong deployment, so we score these separately.

[1]

Evaluating the agent’s handoff to engineers

[1]

We evaluate task summaries using snapshots of saved tasks. These snapshots are especially good for backtesting because generating a summary doesn’t depend on external metrics or traces that expire. A separate grader checks: whether an engineer unfamiliar with the system can understand what happened and why it matters; whether useful charts were preserved; and whether the proposed next steps are supported by evidence.

[1]

Let recurring failures drive self-repair

[1]

Finally, agents need monitoring just like the services they investigate. A broken profiler or missing permission can prevent an agent from verifying the cause of a slowdown. These failures can be hard to spot in the final report, so we run an agent every day to check the messages and logs from recent runs for tool failures and access errors.

[1]

We use the performance factory to fix what this check finds. When the same tool error blocks several investigations, an agent creates a task to fix it. If the cause is clear, the agent proposes a fix, and an engineer reviews the change and decides whether to merge. After such a change merges, we also check through evaluation whether the agent can get past the steps that were previously blocked.

[1]

Next: expanding use, monitoring proactively

[1]

The agent factory pattern moves tasks forward through explicit states, and the regression workflow is just one instance of it. Agents advance tasks when the next step is ready; an independent reviewer challenges conclusions; and engineers step in when the next decision requires expert judgment. Other workflows can reuse the same machinery, with different states, instructions, and events.

[1]

Expanding from a single workflow to multiple workflows. The performance factory can coordinate agents across workflows, letting an agent in one workflow create tasks for another.

[1]

Today, the regression workflow starts when an alert fires. But we’re exploring more proactive approaches so the performance factory can find slowdowns and optimization opportunities even without an alert. We want agents to use the large amount of fine-grained performance data we already collect to find regressions that alerts miss or to spot optimization opportunities. By comparing different kinds of data—for example, batch CPU and memory profiles, heap dumps, and request traces across releases—an agent might notice that CPU usage for a class of requests rose slightly. It could then create a task in the regression workflow to trace the cause, implement a fix, and open a PR for engineers to review.

[1]

Where we already know what to look for, we’re encoding known signals into more performance factory workflows. For example, our service resource fit skill helps agents find autoscaling settings that keep more replicas running than a service actually needs. As we learn to recognize these patterns, we want to build workflows for them and run them regularly across all services, continuously optimizing in a fast-changing environment. With the performance factory, what engineers learn from one slowdown can guide the investigation and fix of the next, even if that happens months later and in a different service.

[1]

The next time you notice ChatGPT responding more slowly, the performance factory is probably already investigating why. Today, the bottleneck may be waiting for an engineer to review and merge the fix. We’re already exploring whether agents can do that work themselves. As Codex continues to accelerate product development, performance systems also need to become more autonomous and self-improving to keep up. Codex is already helping us develop ChatGPT faster. Now it’s also helping ChatGPT stay fast.

[1]