12-04 更新 实时
首页/ 技术栈/ 正文

OpenAI 性能工厂如何让 ChatGPT 保持高速

技术栈 来源:OpenAI Blog 2026-11-19 16:00 2 阅读 机器翻译
OpenAI 性能工厂如何让 ChatGPT 保持高速

在这里,我们将分享我们对 Codex 的使用如何演变为如今的 Performance Factory,介绍我们第一个投入运行的 workflow,并分享在生产环境中构建和运行智能体工作流的早期经验。

随着我们把 Codex 用于越来越多的性能工作,我们注意到团队的工作方式也在逐步演进。我们希望其他服务团队在将智能体式工作流引入其他领域时,能从我们的过程中有所借鉴。

1. 前 Codex 时代。在使用 Codex 之前,工程师需要手动检查指标和日志、对比追踪数据、调试线上机器,并阅读代码来排查性能下降问题。这项工作十分耗时,而且往往需要对该服务有深入了解,才知道该从哪里入手。相关信号很容易被遗漏。当我们反复遇到同类问题——比如 ChatGPT 首 Token 延迟的回退——我们便构建了 CPU 与内存分配分析器等高级工具,让这些排查工作更容易进行。随着时间推移,我们积累了 30 多个性能工具。

2. 作为伙伴的 Codex。一旦有了 Codex 作为伙伴,工程师就可以问“这里为什么变慢了?”,并与 Codex 一起排查,即使面对的是一个不熟悉的系统。Codex 能够搜索庞大的代码库、找到相关的指标和追踪数据、跟踪服务之间的交互,并进行恰当的 profiling,从而拼凑出事情的经过。但工程师仍然需要主导整个过程,需要知道该使用哪些性能工具、如何引导排查方向。困难的排查工作对更多人来说变得更可调试,所需的专业知识和时间也更少。

3. 可复用的技能。为了进一步自动化,我们把性能团队的排查流程固化在一个名为 perf-forensics 的共享技能中。它会告诉 Codex 有哪些工具可用、何时使用这些工具,以及如何逐步排查性能下降,从而让 Codex 尝试从几个角度解决问题:

找出性能下降始于何时

识别受影响的请求

排查是否由部署或配置变更导致

我们基于过往回归案例的评估(evals)测试并打磨了 perf-forensics 技能。对于我们关注的回归类型(例如 ChatGPT 延迟和可用性下降),我们现在只需把告警交给 Codex,就能在一次运行中得到诊断结果,而无需一步步引导它。

4. 人类代理层。随着我们不断添加和完善 perf-forensics 这类与性能相关的 Codex 技能,我们开始感觉自己成了告警与 Codex 之间的代理。告警一触发,工程师就把它复制粘贴到 Codex 中并配上相应的技能,然后再把排查结果粘贴回 Slack。

5. 自动化排查。接下来,我们把排查迁移到云端,让告警能够自动启动一个 Codex 会话。Codex 会排查性能下降并在 Slack 线程中发布排查结果,但自动化到此为止。工程师仍然需要接手诊断结果、制定修复方案,并在部署后确认修复是否奏效。随着告警不断累积,即便只是判断哪些回归需要处理,也得在 Slack 线程里逐一翻找。

6. 工厂。我们构建了 Performance Factory,用于运行端到端的智能体式性能工程工作流。它会跟踪每个活跃任务下一步需要什么,并在该步骤就绪时分配智能体。每个任务都会保留自身状态和发现,因此工作可以在智能体与工程师之间传递,并在代码审查或部署之后继续推进。对于性能回退,工作从调查一个告警开始,到验证生产环境的恢复结束。我们可以把常见的优化转化为工作流,定期在我们的各项服务上运行。一个发现潜在优化点的工作流,可以在另一个工作流中开启任务,对其进行测试并落地实现。

Performance Factory 由四个组件构成:一个带可配置工作流的任务跟踪器;一个把就绪工作分配给智能体的派发循环;一个在云端运行 Codex 的 API;以及订阅机制,在发生变更时(例如 GitHub 上发布审查评论或部署完成)唤醒智能体。

任务服务是工程师定义工作流的地方,他们通过添加配置文件和用 Markdown 编写的、供智能体遵循的提示词来完成。配置列出了任务可以经历的状态、允许的状态转换,以及哪些步骤需要工程师参与。另有独立的提示词告诉智能体在每个步骤该做什么。

一个代码变更任务包含一个配置文件,以及用于实现和审查的 Markdown 提示词。

每一项工作都会成为某个工作流中的一个任务,所有工作流都在一个 UI 中可见。工程师可以看到哪些任务是开放的、跟踪进展,并把任务分享给可能掌握更多背景、或能帮忙推进下一步的同事。

调度循环会定期检查哪些任务已准备好进入下一步。它为每个任务分配一个智能体:按照任务当前状态对应的指令启动一个 Codex 轮次。智能体在任务上记录自己的进展,如果完成了该步骤,就把任务推进到下一个状态。

任务一旦被分配,智能体就需要一个执行工作的环境,并能访问工程师会使用的同样工具。我们构建了一个内部 API,以编程方式在云端调用 Codex 轮次。该 Codex 轮次运行在我们网络内部的环境中,可访问我们的代码仓库,以及工程师使用的可观测性工具,例如指标、日志、链路追踪、CPU 性能剖析和内存快照。

智能体以服务身份运行,因此我们可以限定其权限范围,并看清哪些操作来自我们的性能智能体。把智能体式工作迁到云端,让我们可以并行运行工作,而无需依赖工程师的笔记本电脑保持开机,也不必手动管理各个云端开发机。

有些工作必须等待某个人或某次部署;在此期间,智能体不应该一直运行。当任务需要等待时,它可以订阅事件,例如 GitHub pull request 上的评审评论或失败的 CI 检查,以便在需要重新接手工作时收到通知。当传入事件与订阅匹配时,任务会再次变为就绪,调度循环随后便可分配一个智能体继续这项工作。

发现、定位根因并解决性能回退,是我们在 Performance Factory 中构建的第一个工作流。我们称之为 Regression Workflow。性能回退会经历几个阶段:待调查(needs investigation)、已定位根因(root caused)、已提出修复方案(fix proposed)和已解决(resolved),因此我们构建了这个自动化工作流,以反映这些阶段并让任务依次流转。

当其配置的某项性能告警触发时,Regression Workflow 会创建一个任务,由智能体领取并推动其在这些阶段之间流转。任务会把自己的状态和关键发现记录在任何单个智能体的上下文之外,以便其他智能体或工程师接手这项工作。工程师可以在 Slack 或 Regression Workflow UI 中跟进这项工作、补充上下文,并审阅提议的变更。修复部署之后,智能体会在解决该任务之前,检查性能是否已恢复到原始状态。

找到根本原因(可能不止一个)是工作流中的第一个重要步骤。智能体首先弄清楚哪些指标变差了、它们从何时开始变化,以及哪些服务请求受到了影响。perf-forensics 技能让 Codex 能够使用我们性能工程师所用的工具,并提供了一套用于厘清这些问题的操作手册。

指标越过阈值时告警便会触发,但性能回归可能早在数小时之前就已开始。智能体回溯数据,找出该指标最初开始恶化的时间点。随后它会对比各组请求:是相似的请求确实变慢了,还是我们服务的更多请求原本就很慢?这些发现指向不同的原因。

一旦知道该在何时、何处查看,智能体就会检查部署和功能开关变更,然后阅读相关代码。它会确认某项变更实际是在何时影响到受影响的请求,并利用日志或链路追踪来验证代码是否能解释所发生的情况。

早期,智能体有时会在找到第一个看似合理的解释后就停下,而其中一些诊断后来被证明是错的。为了捕捉这类错误,我们加入了一道对抗性审查:由一个独立的 Codex 会话尝试推翻所提出的诊断。审查者会重新核查各项假设,并检验反事实。如果某次上线导致了性能放缓,那些未受影响的类似请求是否仍然保持正常?如果被怀疑的变更被回滚,受影响的指标是否恢复了?

在一次调查中,一个智能体将失败的 ChatGPT 对话追溯到图像下载错误,并标记为已找到原因。Codex 审查者注意到,负责定位文件的内部服务已经恢复,而图像请求仍在失败。该诊断无法解释持续存在的故障,于是这位 AI 审查者重新开启了调查,并记录下仍需确认的内容。

原文较长,译文为节选;译文由英文原文机器翻译,术语按行业惯例统一,可在文末展开原文核对。

查看英文原文(How OpenAI’s Performance Factory keeps ChatGPT fast)

Here, we’ll share how our use of Codex evolved into what’s now the Performance Factory, walk through our first running workflow, and share early lessons from building and running agent workflows in production.

As we used Codex for more of our performance work, we noticed a progression in how our team worked. We hope other service teams can learn from our process as they adopt agentic workflows in other domains.

1. Pre-Codex.Before Codex, engineers manually examined metrics and logs, compared traces, debugged live machines, and read code to investigate a slowdown. This work was time consuming, and knowing where to look often required deep knowledge of the service. Relevant signals were easy to miss. When we encountered the same kinds of problems repeatedly—like regressions in ChatGPT’s first token latency—we built advanced tools, like CPU and allocation profilers, to make those investigations easier. Over time, we accumulated more than 30 performance tools.

2. Codex as a partner. Once we hadCodex as a partner, engineers could ask, “Why did this get slower?” and work with Codex to investigate, even in an unfamiliar system. Codex could search large codebases, find relevant metrics and traces, follow interactions across services, and do appropriate profiling to piece together what had happened. But engineers still had to steer the process, knowing which performance tools to use and how to guide the investigation. Difficult investigations were more debuggable for more people, with less expertise and time required.

3. Reusable skills. To automate further, we captured our performance team’s investigation process in a shared skill called perf-forensics. It tells Codex which tools are available, when to use them, and how to work through a slowdown so Codex can try to resolve the problem from a few angles:

Find when the slowdown began

Identify the affected requests

Investigate whether deployments or configuration changes could explain it

We tested and refined the perf-forensics skill using evals based on past regressions. For the types of regressions we focused on (for example, ChatGPT latency and availability drops), we could now give Codex an alert and get back a diagnosis in a single run, without guiding it through each step.

4. The human proxy. As we added and refined perf-related Codex skills like perf-forensics, we started to feel like a proxy between our alerts and Codex. An alert would fire, and an engineer would simply copy and paste it into Codex with the right skill, then paste the findings back into Slack.

5. Automated investigations. Next, we moved investigations to the cloud so an alert could start a Codex session automatically. Codex investigated the slowdown and posted its findings in the Slack thread, but the automation ended with that reply. An engineer still had to pick up the diagnosis, develop a fix, and check whether it worked after deployment. As alerts accumulated, even figuring out which regressions needed attention meant sifting through Slack threads.

6. The factory. We built the Performance Factory to run end-to-end agentic performance engineering workflows. It tracks what each active task needs next and assigns an agent when that step is ready. Each task keeps its state and findings, so work can pass between agents and engineers and resume after a code review or deployment. For a regression, the work starts with investigating an alert and ends with verifying recovery in production. We can turn common optimizations into workflows that run regularly across our services. A workflow that spots a potential optimization can open a task in another workflow to test and implement it.

The Performance Factory is made up of four components: a task tracker with configurable workflows, a dispatch loop that assigns ready work to agents, an API that runs Codex in the cloud, and subscriptions that wake agents when something changes (such as a GitHub review comment posting or a deployment completing).

The task service is where engineers define workflows by adding configuration files and prompts for the agents to follow, written in Markdown. The configuration lists the states a task can move through, the allowed transitions, and which steps need an engineer. Separate prompts tell agents what to do at each step.

A code change task contains a configuration file, along with Markdown prompts for implementing and reviewing.

Each piece of work becomes a task in a workflow, and all workflows are visible in a UI. Engineers can see what’s open, follow progress, and share a task with a teammate who might have more context or be able to help with the next step.

A dispatch loop periodically checks which tasks are ready for the next step. It assigns an agent to each task by starting a Codex turn with the instructions for the task’s current state. The agent records its progress on the task and moves it to the next state if it completes the step.

Once a task is assigned, the agent needs a place to do the work, with access to the same tools an engineer would use. We built an internal API to programmatically invoke a Codex turn in the cloud. The Codex turn runs on an environment inside our network, with access to our code repositories and the observability tools our engineers use, such as metrics, logs, traces, CPU profiles, and memory snapshots.

The agent runs under a service identity, so we can scope its permissions and see which actions came from our performance agents. Moving agentic work to the cloud lets us run work in parallel without relying on engineers’ laptops being open or manually managing individual cloud development boxes.

Some work has to wait for a person or a deployment; an agent shouldn’t have to keep running in the meantime. When a task needs to wait, it can subscribe to events like review comments or failed CI checks on a GitHub pull request to get notified when it’s time to pick the work back up. When an incoming event matches the subscription, the task becomes ready again and the dispatch loop can then assign an agent to continue the work.

Finding, root causing, and solving regressions is the first workflow we built inside the Performance Factory. We call it the Regression Workflow. A performance regression moves through several stages: needs investigation, root caused, fix proposed, and resolved, so we built the automated workflow to reflect and move a task through those same stages.

When one of its configured performance alerts fires, the Regression Workflow opens a task that agents pick up and move across these stages. The task records its status and key findings outside of any one agent’s context so that other agents or engineers can pick up the work. Engineers can follow the work in Slack or the Regression Workflow UI, add context, and review proposed changes. After a fix is deployed, an agent checks whether the performance has recovered to its original state before resolving the task.

Finding the root cause (or causes) is the first major step in the workflow. The agent starts by figuring out which metrics got worse, when they started to change, and which service requests were affected. The perf-forensics skill gives Codex access to the tools our performance engineers use and a playbook for working through those questions.

An alert fires when a metric crosses a threshold, but the regression may have started hours earlier. The agent looks back through the data to find when the metric first got worse. It then compares groups of requests: did similar requests actually get slower, or were we serving more requests that were already slow? Those findings point to different causes.

Once it knows when and where to look, the agent examines deployments and feature flag changes, then reads the relevant code. It checks when a change actually reached the affected requests and uses logs or traces to test whether the code could explain what happened.

Early on, agents sometimes stopped at the first plausible explanation they found, and some of those diagnoses turned out to be wrong. To catch these mistakes, we added an adversarial review: a separate Codex session that tries to disprove the proposed diagnosis. The reviewer rechecks the assumptions and tests counterfactuals. If a rollout caused the slowdown, did similar requests that weren’t exposed stay healthy? If the suspected change was rolled back, did the affected metric recover?

In one investigation, an agent traced failing ChatGPT conversations to errors in image downloads and marked the cause as found. The Codex reviewer noticed that the internal service responsible for locating files had already recovered while image requests were still failing. The diagnosis did not explain the continuing failures, so the AI reviewer reopened the investigation and recorded what still needed to be established.

We’ve had success breaking larger jobs into focused Codex turns. In a manual review of 100 root cause suggestions, we graded 70% as accurate, with 30% needing further refinement or not fully establishing causality. In the Regression Workflow, different turns investigate regressions, challenge diagnoses, and propose fixes to increase accuracy numbers through checks and balances.

Once the diagnosis passes adversarial review, the workflow asks Codex to implement a fix and open a pull request. An engineer reviews the PR and decides whether to merge it. We’ve put a significant amount of work into making this handoff as easy as possible. Each task has a report with an automatically generated summary of the regression, its impact, the root cause, and the proposed fix. We’ve tuned these summaries to be easy to scan, including metrics time series, CPU flame graphs, and traces to help engineers quickly understand the findings and inspect the evidence. Engineers can edit the PR directly or use the diagnosis to write their own fix. If they leave comments on the PR, the workflow wakes an agent to address them.

After an engineer deploys the fix, the workflow wakes an agent to check whether performance has returned to its earlier baseline. If it has, the agent marks the task as resolved. If performance has only partially recovered, the agent resolves the original regression and opens a new task for the remaining slowdown, which may have a different cause. If there’s no improvement, the agent records what happened and sends the regression back for investigation.

Getting fixes right has been harder than finding the cause. For example, we’ve seen cases where the agent-proposed changes are more complicated than necessary or introduce new issues. Similar to the root cause step, we added an adversarial review of each proposed fix to check whether they address the root cause and help catch bugs or unintended consequences. Some fixes also require higher level architectural decisions. For example, adding a cache might improve performance but introduce stale data. Changes like these benefit from guidance from an engineer who knows the service and can weigh the tradeoffs.

We’re building an evaluation and improvement loop using these cases. By comparing the fixes agents propose with the changes engineers ultimately merge, we can better understand where proposals fall short, build evals, and improve the workflow. We’re also working on using synthetic performance tests so agents can measure proposed fixes and revise them before asking an engineer for review. We’re also exploring how agents could use our other agentic review tools to identify low-risk changes and eventually ship those fixes without a human in the loop.

Building and running the Performance Factory has taught us a lot about developing and operating agent workflows in production. Here are some lessons for teams building their own agentic workflows.

The raw output from a Codex investigation can be a wall of text that’s hard to parse. It takes effort to figure out what the agent is claiming and track down the graphs to see whether the data backs it up. We want engineers to spend their attention on decisions rather than reconstructing the agent’s work.

Agents can investigate more regressions than a team has time to read about. Our first version gave engineers a UI full of findings, but someone still had to decide which information mattered. One regression can also appear as several incidents across alerts, monitors, and channels. The workflow now links related incidents, groups them by the metrics teams care about, and ranks their estimated impact. Engineers can focus on adding context, weighing tradeoffs, and deciding what to ship.

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

For investigations, we backtest against past production incidents. We turn those incidents into a suite of test cases we can rerun when we change the skill. A Codex agent attempts to investigate and resolve the incident, and we compare the agent’s behavior to the actual past resolution data. Each case starts with a fresh Codex investigator and the original signal, stripped of details that might give away the answer.

Historical tests need care. Metrics and traces expire, while evidence collected after recovery can give away the cause. A test is only useful if we understand what evidence the investigator could see. The agent can inspect code and query production telemetry within set limits. It cannot use saved memories (notes from earlier investigations), read the incident writeup, or see results from previous runs. We also inspect its transcript afterward for information that might have spoiled the test.

We score when the problem began, how large it was, and which requests were affected. We also evaluate how the agent uses evidence to rank possible causes and explain what remains uncertain. An agent can get the timing right and still blame the wrong deployment, so we score those separately.

We evaluate task summaries using snapshots of saved tasks. These make particularly good backtests because summarization does not 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 kept, and whether the proposed next step is supported by the evidence.

Lastly, our agents need monitoring just as much as the services they investigate. A broken profiler or a missing permission can keep an agent from verifying what caused a slowdown. Those failures can be hard to spot in the final report, so we run an agent every day to look through messages and logs from recent runs for tool failures and access errors.

We use the Performance Factory to self-repair and fix the problems this check uncovers. When the same tool error blocks several investigations, the agent creates a task to fix it. If the cause is clear, an agent proposes a fix, and an engineer reviews the change and decides whether to merge it. After merging changes like this, we also use evals to check whether agents can get past the step that previously blocked them.

The Regression Workflow is just one instance of the agent factory pattern that moves tasks through explicit states. Agents advance the task when more work is ready; separate reviewers challenge the conclusions; engineers step in when the next decision requires judgment. Other workflows can reuse the same machinery with different states, instructions, and events.

Currently, our Regression Workflow starts when an alert fires. However, we’re working on more proactive ways for the Performance Factory to find slowdowns and optimizations even when no alert fires. We want agents to use the large amount of fine-grained performance data we already collect to spot regressions our alerts miss or discover optimizations. By comparing different kinds of data (batches of CPU and memory profiles, heap dumps, and request traces across releases), an agent might notice a small increase in CPU for a given request. It can then open a task in the Regression Workflow to trace the increase to its cause, implement a fix, and open a PR for an engineer to review.

In cases where we already know what to look for, we’re working to encode known signals into more Performance Factory workflows. Our service rightsizing skill, for example, helps agents spot autoscaling settings that keep more replicas running than a service needs. When we learn to recognize a pattern like that, we want to build and regularly run a workflow for it across all our services, constantly optimizing in a rapidly changing environment. With the Performance Factory, what an engineer learns from one slowdown can shape how we investigate and fix the next one, even months later in a different service.

Next time you’re using ChatGPT and notice a slowdown, there’s a good chance the Performance Factory is already figuring out why. Today, the bottleneck may be waiting for an engineer to review and merge the fix. We’re already exploring whether agents can do this themselves. As product development keeps accelerating with Codex, performance systems need to become increasingly autonomous and self-improving to keep up. Codex already helps us build ChatGPT faster. Now it’s helping us keep ChatGPT fast.

Special thanks to the team that built the Performance Factory, as well as our post contributors Brendan Gregg, Pieter Hooimeijer, Nick Cooper, and Louis Brandy.

Inside the Codex sandbox — art card

Inside the Codex sandbox

EngineeringNov 18, 2026

Rapidly scaling online storage to serve over 1 billion ChatGPT users (Part II)

EngineeringOct 23, 2026

原文为英文,正文由自动抓取并保留原文。

本文由采集器自动同步

原文发布于 OpenAI Blog(How OpenAI’s Performance Factory keeps ChatGPT fast),标题、摘要与正文由机器翻译,术语按行业惯例统一,未经人工逐句校订。

阅读原文 ↗