从生产盲区到自动合并 PR:基于运行时智能的 Agentic 性能持续优化 AI Engineer 2026-07-19

性能排查的“黑盒”痛点与研发团队的恶性循环

在软件工程团队中,性能优化(Performance Optimization)往往处于一种尴尬的境地。当产品经理发现某个页面响应过慢并提出优化建议时,工程团队的典型回复通常是:“我们需要深入排查代码才能知道原因。”由于排查过程是一个时间不可控的“黑盒”,这个问题便会被搁置。几周后,页面性能进一步恶化,排查优先级被迫提升。然而,当被问及需要消耗多少工时,工程师只能给出一个极为模糊的估算:“一小时到一周之间,取决于我们能发现什么。”

更糟糕的是,由于代码库历史悠久且人员流动,往往只有个别资深工程师(如演讲中提到的 Dave)熟悉这部分十年前编写的古老代码。这种对排查时间的极度不确定性,导致团队陷入了恶性循环:日常忽略性能债务 -> 性能降级触发业务危机 -> 开启“全员待命”(All hands-on-deck)的紧急修复模式 -> 危机解除后继续忽略性能,直到下一次恶化。团队之所以无法主动进行性能管理,根本原因在于定位问题的成本和收益(ROI)难以预测。

Original English Source

Hi everyone. I don't know if you're familiar with what I'm about to show. But remember when someone from the product is like saying that some page is too slow and maybe we can optimize it. And then someone from engineering would say, "Yeah, probably what we'd have to dig in to find out." So, we just kind of leave it as is. And then a few weeks later, Jenny would say, "No, no, no, but it's actually way too slow now. We have to prioritize it. How long is it going to take?" And we would say something like, "Well, somewhere between an hour and a week. We'd have to look at it to find out." And then when she asked who can even take it, the answer is only Dave. He's the only one who kind of knows that code and everyone else who wrote it left a decade ago. And amazingly, this still happens in teams all the time because we would know how much time it takes to do a specific optimization, but we never know how long it's going to take to investigate it and to find it. And miraculously, every time we look, we actually find things that can be done around performance and stability, but we never stop to proactively look for them because it doesn't make sense.

运行时智能与 AI Agent 带来的变革契机

根据 Google 发布的 2026年 DORA 度量指标(2026 DORA Metrics),AI 的引入显著提升了开发者的个人效能,让他们感觉开发速度空前加快。然而,软件交付的稳定性(Software Delivery Instability)却在下降,团队的整体吞吐量并未如预期般大幅增长。换言之,AI 让写代码变容易了,但软件也更容易崩溃了。为了打破这一僵局,我们需要将 AI 的能力从简单的代码生成,扩展到自动化的生产问题排查与修复。

Thundra 正在构建一个运行时智能层(Runtime Intelligence Layer),旨在为 AI 编码助手(Coding Agents)提供深度的函数级上下文和生产环境的取证信息。通过这种方式,AI 能够连续、主动地分析真实的生产环境上下文,自动识别高投资回报率(High ROI)的优化机会。这相当于将团队每隔几个月才进行一次的“性能冲刺”转变为全天候自动运行的常态化工作流。

Original English Source

So, hi. I'm Mike, co-founder and CTO at Thundra. We're building a runtime intelligence layer for coding agents that captures functional level context and deep forensic context on things that matter so that coding agents can help you fix what's going on with production. And as a part of that, we built an agentic workflow that helps with continuously optimizing performance of production applications. And I'm going to share a bit more about what we built, what were the challenges along the way, and hopefully you can take something out of it and apply it in your day-to-day. So, we're surrounded by a lot of agentic PRs that all look kind of good to us. And one agent wrote them and the other one says, "Yeah, I went over it and it looks fine." And we still feel that urge to verify before we just merge it to production. And then when it doesn't work, we end up asking ourselves, "How the hell did we get to this place?" And if you feel like that, I want you to know that you're not alone. So, Google just published their Dora metrics for 2026 and we can see that the biggest impact of AI adoption on engineering is individual effectiveness or that feeling of, "Oh my god, I'm so fast. I can do everything in the world." And for me personally, lack of sleep is another symptom of that. But the second one is software delivery instability. And the throughput is actually not impacted as much as we expected. So, we basically feel more effective, we're more effective individually, but as a team, our throughput is kind of the same and our software breaks more often, which is not exactly what we were hoping for with this AI revolution just yet. But maybe there's an agent for that and if we can build faster with AI and we can fix faster with AI, then we can get those gains that we were talking about. So, I'm going to start with why we even wanted to do this. Then we're going to go over the tech and the process, which I think is also really important. And then share some gotchas and takeaways along the way. So, that leaks kind of faster than we can bail. We have these issues that we ignore because they're not important enough then they degrade to the point where they are important enough and then we reach this crisis mode where we are all hands-on-deck. We fix it in emergency mode and then we go straight back to ignoring, which is a leaky bucket by definition. And that mostly happens because the research phase is a black box. It could take an hour or weeks and we have to pay that debt and to make sure that we spend time and engineering time on it in order to even know what can be done about it. And that's hard. It's legitimately hard to prioritize something where you're not sure exactly what you're going to get out of it. But what if we can automate that investigation? So, we can basically run on a weekly basis with real production context, analyze the sweet spot in the and flag the high ROI opportunities in a way that's scored. So, it runs automatically without us having to stop and do something about it. It has the production context in mind and it can give a high ROI scored performance opportunities of the things that are easy and impactful. Kind of like that performance sprint that you run every few months, just automate it.

闭环优化:从生产追踪到自动化测试验证

将性能排查自动化的核心在于设计一套厂商中立、安全且易于维护的 Agentic 工作流。Thundra 基于 GitHub Actions 搭建了每周定时运行的任务,配合 Cloud Code 并通过 Model Context Protocol(MCP: 开放式模型上下文协议)接入生产环境的运行时智能。该流程不仅仅是静态分析代码,而是深度分析生产环境的 Trace(调用链)、查询开销和 Latency(延迟)。

为了确保生成的修复方案行之有效,工作流实现了一个闭环的验证机制:

  1. 自动识别:根据 P99 延迟阈值或 SLO 违规指标,自动捕捉生产中的异常请求。
  2. 根因分析:AI Agent 结合运行时上下文定位到函数级别的性能瓶颈。
  3. 代码修复与本地验证:Agent 修改代码后,自动在测试沙盒中重新运行单元与集成测试,并模拟生产流量以度量优化前后的性能差异。
  4. 人类审查网关:只有在测试通过且性能提升得到实测数据验证后,优化方案才会提交给人类工程师进行审查,从而保证人类只需作为最后的审查网关,而不需要承担排查的重担。
Original English Source

Now, let's talk about how we can actually do it cuz the dream is very nice, but the devil's in the details. So, first of all, we wanted an infrastructure for the agentic workflows that would be vendor neutral in terms of compute and where it runs, in terms of the harness and in also in terms of the model. Things are changing all the time. We wouldn't want to constrain ourselves to a specific vendor, specific model or anything like that. And especially like with hot, we want our customers to be able to use whatever agents they wish. We also wanted it to be secure in terms of the tool calls, permissions, and authentication. We want some trigger system, whether those are scheduled runs like the weekly run or a set of webhooks. For example, if we see some SLO breach, we would want to investigate it. And we really wanted it to be easy to maintain and update over time. I think one of the biggest learnings we've had with agentic workflows is that even if they work out of the box or we get to a point where we're happy about them. In time, we evolve and our expectations go up. So, just being able to maintain and update those logics and build that feedback loop was very important for us so that it's reliable and the people actually trust the outcome. Specifically, we chose to work with GitHub agent workflows for that and we can choose whatever agent we want to work with and build the workflows on top of that, but there are many other great tools that could be used for that. So, this is basically how it looks like. You can see that there's a description of the job and the goal and the analysis and then we basically go over the GitHub repository and generate that weekly deep insight report analyzing production data and finding those low-hanging high-ROI opportunities. So, for this specific setup, GitHub actions runs weekly and it uses Cloud Code, that was our specific choice, and then captures the runtime intelligence overhead via MCP so that we can basically look at the different endpoints, connect to the function level of overhead is there, and send a report to Slack. Of course, that could have been Teams or an email or anything like that. It could have been Cursor or Copilot. It's just the setup that we started with to make sure that we have something that runs without us in the loop and sends that report to somewhere we actually live in, which is Slack. So, we want to take the production context, the traces, the queries, the latencies, and analyze them with the agent, score and flag which opportunities matter because if you can optimize something, but it runs every 3 weeks or you can like reduce 20 milliseconds, then it doesn't matter. And then the most important part here is the evidence. So, the agent actually fixes it reruns the tests and sees the impact that it had on that specific flow that was optimized. So that the human gets something after we already detected it. We understood the root cause. We understood why it matters to the business and we verified that the fix actually impacted that time. And then a human reviews that. And the loop is actually closed. So it's not hey, I have this idea of something that you can do. It's here's something that works. And we believe would make an impact on these specific business flows in production that are running 7,000 times a week. And then the human gets in the loop as a review gate.

攻克 Agentic 落地三大绊柱:看似合理但未验证的修复、复杂查询与偷懒式代码

在实践过程中,团队遇到了三大主要挑战:

  1. 看似合理但未经验证的修复(Plausible Unverified):Agent 给出的修改方案看起来完全合乎逻辑,甚至符合最佳实践,但在真实的生产流量下却没有产生任何优化效果,甚至可能由于忽略了冷启动等边界条件而失效。为此,必须建立 Prod-to-Code(生产到代码的映射机制),将高层次的微服务、接口监控指标转化为 Agent 能够直接阅读的函数和文件级上下文,让 Agent 紧贴真实运行时表现进行推理。
  2. 复杂数据库查询(Complex Queries):团队在底层使用了列式数据库 ClickHouse。ClickHouse 具有极佳的分析性能,但其语法和优化逻辑与传统的行式 SQL(如 PostgreSQL)有很大差异。Agent 很容易套用错误的 SQL 优化经验,这要求我们必须为 Agent 装备针对特定数据库的专项优化“技能”(Skills)。
  3. 偷懒式修复(Lazy Fix):这是 AI 最常见的偷懒行为。比如当系统抛出超时或连接异常时,Agent 的本能反应是加一个 try-catch 块把异常捕获吞掉,或者简单粗暴地增加超时时间。这虽然能消除报错,但并未解决根本的系统延迟问题。团队必须通过工作流中的 Guardrails 限制此类敷衍性修改,强制 Agent 追溯数据流和调用链以解决根本性能问题。
Original English Source

And of course it didn't work out of the box if you were wondering. So the first hurdle we had along the way is what we call the plausible unverified. So the agent would suggest a fix. It sounds right. It would look fairly real and then after we verified it it it just didn't work. And it's it's right that the agent suggested something that could theoretically cause that flow down. But what we wanted is to ground it on what's actually happening in production. Second part was complex queries. We specifically use ClickHouse. It's just an amazing columnar database but it's also slightly different than the classic SQL patterns. Now I'll talk about that in a bit. And the third one is the lazy fix. I'm sure you guys also experienced that when something throws an exception and then the agent says, "Well, maybe we can just catch that exception and then everything will be fine." But what we really want is to understand why that exception was even thrown in the first place or why are the results lagging. So those were things that we found that methodology could be very, very impactful with. It's not just the understanding of the data and how to connect it. It's also being quite thorough on what we want to do in that process and sort of building the playbook of how a senior engineer would do that. And of course, we need the context to be right. So, the problem with context there are also There are only two problems with context. You either have too much of it or you have too little of it. And what we found around runtime context, especially from production, is that more often than not, you actually have these two problems together because on one hand, you have a lot of low signal data that is hard for the agent to reason over. And on the other, you might not have all the logs and traces and metrics that you need in order to investigate that issue, which would still leave some room for assumptions and theories of that are not necessarily what our users are experiencing in production. And also, when we talk about metrics like service level, CPU and memory, or endpoints in the P90s, they are not connected to the function level. So, our coding agents reason over code and they look at these metrics and there are some relations between them, but they don't exactly speak the same language. So, when we ask questions about taking time and what can I do about it, we're often finding that there are some gaps there and again, accuracy could drop from that. So, what we did is what we call prod-to-code, which is to be able to explain what's going on in production in the same level that agents reason over because the agent's context lies on a function and file level, not on an service and endpoint level. So, basically, our context is running on a function level, and it is also connected to the endpoint or event consumer or cron job that ended up starting this task. So, you can ask a question like, "Hey, this endpoint that sometimes takes 7 seconds, where is the time spent, and what can be done about it?" Whether that's a function or an outbound call to a database, an LLM, or another microservice. And with that, you basically have the complete function level context for every single function, sort of like this service map, but on a function level of the different invocations, where they come from, how often they run, and the difference the context only when it's needed, only when we see requests that are taking longer than the P99 or some threshold that we can define. Then, we will capture those forensic evidence so that we can say, "Hey, here is an example of a request that took longer. Let's find out why." And we also have the ability to see that on top of the code, which is the HUD, the heads-up display, but but I guess it's kind of a way to explain how that data set is actually structured in a way that is much more comprehensive for a coding engineer to read and over. And then, we talked about the complex queries and what to do with them. So, the basic layer gave us the HUD query language, which are basically ClickHouse queries over that structure of functions and endpoints and forensics.

从“PR 轰炸”到人性化报告:人机协同的灰度设计

当工作流调试完成后,AI Agent 很快就表现出了极高的生产力,但也暴露出另一个现实问题:PR 暴雨。AI 可以轻易地针对每一个潜在优化点自动开启几十甚至上百个 Pull Requests。然而,作为需要负责系统稳定性的人类工程师,根本没有精力去逐一审查这海量的碎片化 PR,这反而成为了开发者的心智负担。

为了解决人机协同中的摩擦力,团队采取了两项关键改进:

  1. 专项技能开发与精准自动化:利用 HUD 查询语言,为 Agent 注入针对特定性能反模式(Performance Anti-patterns)的主动识别技能。例如主动搜寻代码中的人工作战延迟(如不合时宜的 sleep 和超长的 timeout)、数据库N+1查询、缺失的索引、以及可以异步化的串行操作。此外,Agent 还能自动检测出过去 60 天内从未运行过的“死代码”(Dead Code)并将其静默清理。
  2. 人性化的“说服型”报告而非直接提 PR:与其用上百个 PR 轰炸开发者,系统选择每周在 Slack 中推送一份提炼过的卡片式报告。报告用极其精炼的中文解释核心痛点,比如:“此接口通常只需 200 毫秒,但在偶发情况下需要 45 秒。根源在于该接口直接执行了 distinct 查询,绕过了 MongoDB 的查询索引。”报告中附带详细的性能对比数据和修复思路,工程师可以选择一键自动生成 PR,或者自行处理。这种“小步快跑”的灰度策略,帮助团队逐步建立起对 AI 优化方案的信任与日常习惯。
Original English Source

On top of that, we also added a set of skills. We found that sometimes just querying the data is enough, but being able to get to the right query and to ask it again and again really created a lot of variance in our eval, and the skills actually help work with that data so that agents can use it. So for example, if we're talking about a 500, an HTTP 500, we would want to understand where that error came from. If we're talking about a memory spike, we want to understand what was running on those specific pods at that specific time where memory was higher and compare it to a baseline so that we see the diff. And all of these things were extremely helpful to be able to be a bit more methodological around how that works and to create more consistent results. And on top of that, there are a set of automations. So if we have the data, the query language, a set of skills, we can build automations on top of them like auto fixing issues as they arise or detecting dead code that isn't even running for the last 60 days and eliminating it or this automated performance improve- improvements automation that are we are talking about right now. So for performance, one example of that is to be looking for artificial delays like timeouts and sleeps and plus one queries, missing indexes, sequential assings and so on so forth. These are specific things that are much easier to find when you actually look for them. And in a code base that's 20 years old and has hundreds of contributors, it makes sense that you'll find quite a lot of those. And removing them is fairly easy and impactful. And then when you're asking something like, "Why are my endpoints taking long?" you can actually find the specific reasons and not just guess a bunch of static code analysis which could get you some result. I'm not saying it's never going to work. But, when you're talking about an automation, we have to think about how to build something that is robust enough for us to trust over time. And then we said, "Okay, now that our evas are looking good, we run weekly, we find real slow endpoints from production that are invoked. We score them, we test them, we verify them. Maybe we can just open pull requests and everyone will fix everything and the world will be amazing." Well, that's not exactly how that worked because people are still people and no one wants to wake up for, you know, a rain of 80 pull requests, as small as small as they can be. That's just not how people operate. And no one has time for that. We're too busy building other things and it's fine. So, what we actually do is we use that priority to make sure that we only flag the ones that matter and we actually started with one at a time to create that appetite and that habit. So, we look at whether this is a hot path in terms of how often it runs and how critical is it for the business. The business impact as in, you know, if this is something that has to do with payments or sign-up flows, obviously, we're more sensitive to that. Kind of like asking ourselves, would we be able to convince the product manager to prioritize it? And we also looked at the risk. If it's a risky change that requires a migration or anything like that, then obviously, it would require more time from the human that's reviewing it. And in that case, we're not necessarily looking for the highest impact ones, but for the highest ROI ones. And because we automate the investigation, we can look at the impact and the risk together and only surface and and require attention on the ones that we believe are the right ones that are worth the engineering time. So, instead of opening ADPRs, we built this human-friendly report that basically tries to convince you that it's worth your while. Something like, "Hey, this endpoint, it's usually taking around 200 ms, but every once in a in a while it takes like 45 seconds, and it happens because you're using distinct and not the search index of Mongo." And there's a very short explanation of what's happening and what's the fix. And then you can either create a ticket and fix it on your own, and create a PR, or just look at it. And we found that building these small gists that are humanly readable and it's easy to understand what's the thing, made a huge, huge difference. Because we're still living in this hybrid world where humans are in the loop, and we want to respect our place in people's lives and to make sure that we flag things that really matter, and that we have some confirmation, not only that the fix is good, but also that this issue is worth fixing. And then, when you look at that endpoint and you deploy that change, and all of a sudden it's flat again, it is pretty satisfying. And then next time you'll get that report, maybe you'll have a look, and it will be easier to convince you.

构建生产级自动化 Agent 的四大核心启示

迈向生产级 Agentic 自动化的道路上,有四个核心结论值得每一位软件架构师借鉴:

  • 确立可靠的度量指标与评分护栏(Scoring & Guardrails):虽然 AI 排查和修复代码的边际成本极低,但这绝非免费。每一次修改都占用审查工时并隐含上线风险。必须在工作流中建立严格的过滤机制,只有影响核心业务链路(如支付、注册等高频热路径)、技术风险低且实测性能提升明显的高 ROI 方案,才值得递交人类审查。
  • 开发全新维度的研发活动:过去,没有哪个研发团队能奢侈到每周指派资深工程师主动去梳理生产环境的微小性能瓶颈。AI Agent 的意义不仅在于“把旧的开发工作做快”,更在于“开拓了过去由于人力局限而根本无法开展的新工作”。
  • 上下文大于巧妙的设计(Context over Cleverness):在 Agentic 系统设计中,为 AI 提供精准、不多不少的运行时上下文(如函数级 Trace 与对应代码的映射关系),其效果远比设计复杂的长链推理算法更实用。
  • 跨越 80-90% 的信任鸿沟:在 IDE(如 Cursor)中使用 AI 是一种人机紧密协同的交互,AI 即使犯错也会被人类当场修正,80% 的置信度已足够惊艳。但当运行一个无人值守的自动化 Agent 时,系统必须跨越 90% 以上的信任红线,这需要我们在自动化流程中内置极其完备的单元测试、防偷懒检查和指标比对闭环。
Original English Source

So, four things that I learned that could be relevant for you. One is we need to define what matters, and the scoring and the guardrails are what makes this reliable. We can automate a bunch of things, and it becomes easier to just create some slop, but when we start with what are the things that are worth it, even though it's much cheaper to fix these things than it was a few years ago, it's still not free and therefore we need to understand that it's worth the impact the human reviewer and the risk that it entails if it does. Second part is that a lot of what we're talking about today is accelerating developers and what they do and I think what's interesting about this experience is that we automated something that it's not just doing it faster. We're automating a phase that just did not happen in the day-to-day lives of engineers. No one actually stopped every week and had a look on whether there are low-hanging fruits that could be relevant. But now we can use the agents to not only do the things that we're doing faster, but also to help us surface opportunities that we would probably never do without them. This is It sounds simple, but it's hard to actually apply it in the day-to-day, but context over cleverness works almost every time. If they have the right context, if they have the right skills, if they know exactly what these agents get much much more useful and every time a new model comes out, things get better and yet I do believe that at least for most of the cases, the models are good enough already to be able to to automate that. But it is up to us to help steer and guide to the right directions to make sure that we get the results that we want. They're not necessarily the the absolute right thing because it doesn't necessarily exist and you know, when we know our domain and our business, we understand which issues matter more. What's worth fixing, what latencies actually impact our customers' experience in the most significant way. And that helps us make sure that we focus on the right things. And in that aspect, agentic engineering is not like coding with an agent. If something works 80% of the time and you're using it with your cursor in your IDE, that's fine because you're there, you're in context, and you can help fix and steer. If we're talking about an automation that runs autonomously, we have to have a very high confidence that we're doing the right thing and that it's not going to just stray off and hand us a bunch of things that we would either waste time on reviewing or just not be able to trust over time. And I think like the hardest part of this automation was to get to a point where we feel confident enough that the issue is worth fixing and that the fix is verified in runtime so that it is handed to a person when we have a fairly good confidence that it actually works. And yet, they still review it, but we know it's worth their time. And getting to that agentic engineering automation level requires crossing towards the 80-90% trust, and it's something that is dramatically different than using an agent directly as an engineer. So, I hope that was helpful. And if there are any questions or anything like that, I'm available and always love to geek out on the AI and the LDC, and uh looking forward to hear about cool automations that you build on your own. Thank you.

📌 文中提及的人物和组织

公司/组织: Thundra, GitHub

产品/模型: Cloud Code, ClickHouse, MongoDB

关键字: agentic-workflow performance-optimization runtime-intelligence production-debugging