一盏灯
首页文章视频生词本复习
首页文章视频生词本我的

Pair Debugging with an AI Assistant

和 AI 助手结对排错的一段对话

科技互联网情景对话初级约 3 分钟场景 · ai pair programming# AI 与自动化# 效率与方法

读完你能和同事用英语一起排一个查不出原因的错:先让 AI 助手解释而不是直接改、一开始就把版本和堆栈喂足、用一条日志验证它的猜测、把含糊报错变成清晰问题,再从它给的几个方案里自己挑一个。文中还有一条能直接搬进团队的规矩:提 PR 时必须用自己的话把修复讲清楚。

当前浏览器暂不支持语音朗读

Scene: A checkout page is throwing an error and nobody knows why. Nadia and Tom sit together on a call, with an AI coding assistant open in the editor. Neither of them is the expert here. The point of this session is not to look smart; it is to narrow the problem down step by step, and to say out loud what each of them is thinking.

场景:结账页面在报错,谁也说不清为什么。Nadia 和 Tom 开着会一起看,编辑器里开着一个 AI 编程助手。两个人都不是这块的专家。这次结对的意义不在于显得聪明,而在于一步一步把问题范围缩小,并且把各自心里在想什么说出口。

Tom: Okay, the error says "undefined is not a function" on line 40. Should we just ask the assistant to fix it? Nadia: Let's not. If we ask it to fix the file, we get a change we do not understand, and neither of us can defend it later. Let's ask it to explain line 40 first, and we keep the decision. Ten minutes of reading now saves an afternoon next week.

Tom:好,报错说第 40 行『undefined is not a function』。我们直接让助手修掉行不行? Nadia:先别。如果我们让它改文件,拿到的就是一个我们看不懂的改动,回头谁也说不清为什么这么改。先让它解释第 40 行,决定权留在我们手里。现在多读十分钟,下周能省一个下午。

Tom: Fair. I will paste the stack trace and the file, and ask what could make that value undefined. Nadia: Give it the version of the library too. Last week it guessed an old API and we lost an hour to that. It has no way of knowing what we actually run unless we tell it. The more context we hand it up front, the fewer wrong turns we take later.

Tom:有道理。我把堆栈信息和那个文件一起贴过去,问问什么情况会让那个值变成 undefined。 Nadia:把库的版本号也一并给它。上周它猜了个老 API,我们为此白搭进去一小时。我们不说,它根本无从知道我们跑的到底是什么。我们一开始给的上下文越多,后面走的弯路就越少。

Tom: It says the cart object may be empty on the first render, so the method does not exist yet. That matches what we see. Nadia: It matches, but it is still a guess. Let's check it before we trust it. Add a log above line 40 and reload the page. If the cart is empty there, we have our answer.

Tom:它说 cart 对象在首次渲染时可能是空的,所以那个方法还不存在。这和我们看到的现象对得上。 Nadia:对得上,但这仍然只是一个猜测。信它之前先验证一下。在第 40 行上面加一条日志,然后刷新页面。如果那时 cart 是空的,答案就有了。

Tom: Confirmed. The cart is empty on the first render. Nadia: Good. Now we know the real question: why does the page render before the cart loads? That is a different bug from the one we started with. Let's ask the assistant for two or three ways to handle it, and then we pick one ourselves.

Tom:确认了,首次渲染时 cart 是空的。 Nadia:很好。现在我们知道真正的问题是什么了:页面为什么会在 cart 加载完成之前就渲染?这和我们一开始查的那个 bug 已经不是同一个了。让助手给两三种处理方案,然后我们自己来挑。

Tom: It gave three options. The first one adds a loading state, the second one moves the fetch, the third one just adds a null check. Nadia: The null check would hide the problem, not fix it. I would go with the loading state. Do you want to write it, or should we walk through it together?

Tom:它给了三个方案。第一个加一个加载态,第二个把请求挪个位置,第三个就是加一个空值判断。 Nadia:空值判断是把问题盖住,不是修好它。我倾向于加载态。你想自己写,还是我们一起走一遍?

Tom: I will write it, and I will ask the assistant for a test too. Nadia: Good idea. One rule when we open the pull request: we explain the fix in our own words, not the assistant's. If we cannot explain it, we are not ready to ship it. The reviewers are trusting us, not the tool.

Tom:我来写,顺便让助手也补个测试。 Nadia:好主意。等我们提 PR 的时候有一条规矩:用我们自己的话解释这个修复,而不是助手的话。如果我们讲不清楚,就说明还不该合。评审的人信的是我们,不是工具。

Look at how they talked. They never let the assistant own the decision. They asked it to explain before asking it to fix, they gave it context up front, they checked its guess with a log, and they turned a vague error into a clear question. Working with an AI assistant is a conversation with three voices, and the two human ones still have to agree on what is true.

看看他们是怎么对话的。他们始终没让助手替他们做决定。他们先让它解释、再谈让它改,一开始就把上下文喂足,用一条日志验证了它的猜测,并把一个含糊的报错变成了一个清晰的问题。和 AI 助手一起工作,是一场有三个声音的对话,而其中两个人类的声音,依然必须就『什么是事实』达成一致。