跳到主内容
@wquguru
精选80PostHog 博客(RSS)产品与增长

PostHog用自驱Agent与确定性检测器实现CI自动维护

Engineers are shipping faster, so we made our CI self-driving to keep up

原文
发到 X
推荐理由

给出了具体的CI自动化落地路径:数据入仓+MCP查询+确定性检测器,参数和工具链清晰,开发者可直接参考其架构思路优化自身研发效能。

PostHog ships code at a rapid pace, and that pace has only accelerated in recent months due to LLM adoption. We went from merging 1,354 PRs in October 2025 to more than 6,500 PRs in October 2026 so far (an increase of more than 380%).

PostHog 以极快的速度发布代码,而在最近几个月,随着大语言模型(LLM)的采用,这一节奏进一步加快。我们在 2025 年 10 月合并了 1,354 个 PR,而截至 2026 年 10 月已合并超过 6,500 个 PR(增长了 380% 以上)。

It's the job of the Developer Experience team to ensure engineers at PostHog are shipping as fast as possible while we work to balance code quality and CI stability. In fact, we have a goal of making 10,000 pull requests a month easy. That said, it's difficult to keep up with CI maintenance just by observing and reacting manually.

开发者体验团队(Developer Experience team)的职责是确保 PostHog 的工程师在平衡代码质量和 CI 稳定性的同时尽可能快地交付代码。事实上,我们的目标是让每月轻松完成 10,000 个拉取请求成为常态。话虽如此,仅靠手动观察和响应来跟上 CI 维护工作是很困难的。

So we took inspiration from how things are being shipped elsewhere at PostHog. This October, 11% of merged PRs were self-driving, meaning PostHog opened them on its own after a scout (a scheduled agent that explores your product data) found something worth acting on.

因此,我们借鉴了 PostHog 其他地方的交付方式。今年十月,11% 的已合并 PR 是“自动驾驶”的,这意味着 PostHog 在侦察兵(一个探索你产品数据的定时代理)发现值得采取行动的内容后,自行打开了这些 PR。

We saw this and decided to fight fire with fire. The same self-driving agents that are increasing our PR volume can help us keep up with CI maintenance. Here's how we set it all up:

我们看到这一点后决定以彼之道还施彼身。那些增加我们 PR 数量的自动驾驶代理也可以帮助我们跟上 CI 维护的步伐。以下是我们如何设置这一切的:

Step 1: Get CI/CD data out of GitHub

步骤 1:将 CI/CD 数据从 GitHub 中提取出来

We're proud to be open source and use GitHub to host our monorepo. This means most of our CI-related data lives on GitHub and is queryable from there. But querying this data frequently means we hit rate limits and, in any case, it would be really wasteful to constantly ask GitHub for mostly unchanging data (think last week's merged PRs and completed workflow runs). Above all, PostHog is a data company! So we decided to get CI/CD data into our own product and see what features and ideas we could unlock from there.

我们为开源感到自豪,并使用 GitHub 托管我们的单体仓库(monorepo)。这意味着我们的大多数与 CI 相关的数据都存储在 GitHub 上,并可以从那里进行查询。但频繁查询这些数据意味着我们会遇到速率限制,而且无论如何,不断向 GitHub 询问基本不变的数据(比如上周合并的 PR 和已完成的工作流运行)是非常浪费的。最重要的是,PostHog 是一家数据公司!因此,我们决定将 CI/CD 数据引入我们自己的产品中,看看能从中解锁哪些功能和想法。

To accomplish this, we rely on our GitHub warehouse source, which continuously syncs repository data. Specifically, we were interested in pull requests, workflow runs, and workflow jobs data.

为了实现这一目标,我们依赖于我们的 GitHub 仓库源,它持续同步仓库数据。具体来说,我们对拉取请求、工作流运行和工作流作业数据感兴趣。

Step 2: Add a queryable layer on the data (that agents can reach for)

步骤 2:在数据上添加一个可查询的层(供代理调用)

We originally considered existing services to analyze CI data and help the DevEx team better understand developer behavior and pain points, but we found that most of these services were built around measuring engineering team productivity. That's not really what we were interested in.

我们最初考虑使用现有服务来分析 CI 数据,帮助 DevEx 团队更好地了解开发人员的行为和痛点,但我们发现大多数这些服务都是围绕衡量工程团队生产力而构建的。这并不是我们真正感兴趣的。

Instead, we built our own internal product called Engineering Analytics. Its core vision is:

相反,我们构建了自己的内部产品,称为 Engineering Analytics。其核心愿景是:

It's product analytics, but the "users" are pull requests and the "events" are what happens to them on the way to production.

它是产品分析,但“用户”是拉取请求,“事件”是它们在通往生产过程中的发生情况。

In building this, we benefited from the many data analysis, logic, and display primitives that other PostHog products had already built. We leaned on their best practices and just added CI/CD data and our own product needs.

在构建过程中,我们受益于 PostHog 其他产品已经建立的大量数据分析、逻辑和展示原语。我们借鉴了它们的最佳实践,并仅添加了 CI/CD 数据以及我们自身的产品需求。

Under the hood, Engineering Analytics is basically a curated view into the surfaces the DevEx team cares about: our CI system, the merge queue, and tests.

在底层,Engineering Analytics 本质上是对 DevEx 团队关注的界面的一种精选视图:我们的 CI 系统、合并队列和测试。

Besides being a useful place for engineers to quickly get a general sense for CI health, we included MCP support from the start so our agents could query for specific data when investigating CI troubles or looking for optimization opportunities. This way, agents don't need to rely on the GitHub API, and we can better control the data and agentic flows here. It also lets us build and use specific skills like investigating-ci-failures that help agents find the commit that broke a particular CI job, and then check whether a later commit fixed it.

除了为工程师提供一个快速了解 CI 健康状况的有用场所外,我们从一开始就包含了 MCP 支持,以便我们的代理在调查 CI 问题或寻找优化机会时能够查询特定数据。这样,代理就不需要依赖 GitHub API,我们可以更好地控制这里的数据和代理流程。它还让我们能够构建和使用特定的技能,例如 investigating-ci-failures(调查 CI 失败),帮助代理找到导致特定 CI 作业失败的提交,然后检查后续提交是否修复了它。

Step 3: Make it self-driving

步骤 3:使其具备自动驾驶能力

Engineering Analytics plugs into PostHog's self-driving capabilities and generates its own "signals" (findings along with their evidence), which agents then investigate autonomously and potentially attempt to remediate by opening pull requests.

Engineering Analytics 接入 PostHog 的自动驾驶功能,并生成自己的“信号”(发现及其证据),代理随后自主调查这些信号,并可能通过打开拉取请求来尝试修复。

These signals are generated from three deterministic detectors that run over the ingested GitHub data (each one is a pre-baked query):

这些信号由三个确定性检测器生成,它们对摄入的 GitHub 数据运行(每个检测器都是一个预置查询):

  • Flaky check: a job that fails and then passes on a rerun of the same commit.
  • Broken default branch: a workflow that keeps failing on our main branch.
  • Duration regression: a workflow that got slower than it was in a previous window.
  • 不稳定检查:一个在重新运行同一提交时失败后又通过的作业。
  • 主分支损坏:在我们的主分支上持续失败的流程。
  • 持续时间回归:比之前窗口中更慢的流程。

These detectors led to real fixes, like:

这些检测器带来了实际的修复,例如:

  • Fixing a failing CI job: a WebKit Storybook shard was failing on every push to our default branch.
  • Deflaking a Rust test job: the job flaked twice in one week (two tests were racing over shared tracing state).
  • Speeding up a check on every pull request: a workflow job installed the whole workspace before a dry run that didn't really need any dependencies. After the fix, the whole job takes 33 seconds (down from 51 seconds).
  • 修复失败的 CI 作业:WebKit Storybook 分片在我们每次推送到默认分支时都会失败。
  • 消除 Rust 测试作业的不稳定性:该作业在一周内出现了两次不稳定(两个测试竞争共享的跟踪状态)。
  • 加速每次拉取请求上的检查:一个流程作业在实际上不需要任何依赖项的试运行之前安装了整个工作区。修复后,整个作业耗时缩短至 33 秒(从 51 秒减少)。

Thanks to Engineering Analytics combined with self-driving, we've shipped more than a dozen related improvements since.

得益于 Engineering Analytics 与自动驾驶功能的结合,此后我们已经发布了十多项相关的改进。

What we learned from building all this out

我们在构建这一切中学到的经验

Finding the right signal-to-noise ratio requires some experimentation and a bit of prompt massaging. For us, having deterministic detectors has helped keep the signal-powered agents grounded in data we know we care about and expect to be continuously triaged.

找到合适的信噪比需要一些实验和提示词的微调。对我们来说,拥有确定性检测器有助于让基于信号的代理扎根于我们知道其重要性且期望被持续分类处理的数据中。

Besides the utility of the MCP-first approach, Engineering Analytics's UI has gained traction inside the DevEx team, primarily as a "one-stop shop" where we can get a useful, at-a-glance look across our ownership surfaces. Because of this, we are working on optimizing product performance by moving from ad-hoc queries into pre-computed tables and otherwise optimizing our queries whenever possible. As an added bonus from both UI and MCP sharing the query layer, optimizations here also benefit the performance of agents reaching for these tools.

除了 MCP-first 方法的实用性之外,Engineering Analytics 的 UI 在 DevEx 团队内部也获得了关注,主要作为一个“一站式商店”,让我们能够一目了然地查看我们负责的所有领域。因此,我们正在通过将临时查询迁移到预计算表以及在可能的情况下优化查询来优化产品性能。由于 UI 和 MCP 共享查询层带来的额外好处,这里的优化也能提升代理调用这些工具的性能。

Finally, once we had GitHub and related CI data ingested, the team came up with other ways to build useful features around the data. As an example, we recently shipped a "CI Explorer" feature that graphs out our CI workflows. It's a lot more intuitive (not to mention faster) than clicking around the static GitHub UI.

最后,一旦我们完成了 GitHub 及相关 CI 数据的摄入,团队想出了围绕数据构建其他有用功能的方法。例如,我们最近推出了一项“CI Explorer”功能,用于图形化展示我们的 CI 工作流。这比在静态 GitHub UI 中点击操作要直观得多(更不用说更快了)。

How you can set up a self-improving CI yourself

如何自行设置一个自我改进的 CI

We're continuing to shape Engineering Analytics as an internal beta product, but you can build something similar today by combining warehouse sources with our MCP and scouts. To do this:

我们仍在将 Engineering Analytics 塑造为一款内部测试产品,但你今天可以通过结合仓库源与我们的 MCP 和 scouts 来构建类似的东西。要做到这一点:

  • Get your CI data into the warehouse. Link the GitHub source and sync the pull request, workflow run, and workflow job tables. Add webhooks to keep runs and jobs up to date in real time.
  • Let your agent query it. Connect your agent(s) to the PostHog MCP and try asking it something specific, like which CI workflow got slower this week.
  • Make it self-driving. Set up self-driving and connect the GitHub app so agents can open pull requests on your behalf. Then, try writing a scout that watches your newly synced tables. Consider something like our deterministic detectors as a starting point, but there are more ideas for custom scouts in the docs.
  • 将你的 CI 数据导入仓库。链接 GitHub 源并同步拉取请求、工作流运行和工作流任务表。添加 webhook 以保持运行和任务实时更新。
  • 让你的代理查询它。将你的代理连接到 PostHog MCP,并尝试让它回答一些具体问题,比如本周哪个 CI 工作流变慢了。
  • 使其实现自动驾驶。设置自动驾驶并连接 GitHub 应用,以便代理可以代表你打开拉取请求。然后,尝试编写一个 scout 来监控你新同步的表。可以考虑使用我们的确定性检测器作为起点,但文档中还有更多关于自定义 scout 的想法。

Your CI/CD platform is already collecting all this data. You might as well put it to work for you!

你的 CI/CD 平台已经在收集所有这些数据。不妨让它为你所用!

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件