structured-debugging
它能做什么
这项技能是一种不靠猜测、解决疑难缺陷的方法。适合遇到意外行为、时好时坏的测试或简单修复没有解决的问题的开发者和智能体。
适用场景
- ✓当一个缺陷很难解决,第一次修复尝试没有奏效的时候。
- ✓当某个测试时好时坏,或者行为看起来不可能发生的时候。
- ✓当你想在拿到证据之前,就把问题归咎于外部系统的时候。
技能链接
https://github.com/QwenLM/qwen-code/blob/main/.qwen/skills/structured-debugging/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“这个缺陷只是偶尔出现,我的快速修复没有用。请帮我一步一步地调试它。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会先写下一个具体的假设,然后添加有针对性的日志或检查,运行它们,并利用结果缩小原因的范围。对于更难的缺陷,它会跨会话保留笔记,并且只在原因得到确认后才进行修复。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Structured Debugging
When debugging hard issues, the natural instinct is to form a theory and immediately apply a fix. This fails more often than it works. The fix addresses the wrong cause, adds complexity, creates false confidence, and obscures the real issue. Worse, after several failed attempts you lose track of what's been tried and start guessing randomly.
This methodology replaces guessing with a disciplined cycle that converges on the root cause. Each iteration narrows the search space. It's slower per attempt but dramatically faster overall because you stop wasting runs on wrong theories.
The Cycle
1. Hypothesize
Before touching code, write down what you think is happening and why. Be specific about the expected state at each step in the execution path.
Bad: "Something is wrong with the wait loop." Good: "The leader hangs because
hasActiveTeammates() returns true after all agents have reported completed,
likely because terminal status isn't being set on the agent object after the
backend process exits."
For bugs you expect to take more than one round, create a side note file for the investigation in whichever location the project uses for such notes.
Write your hypothesis there. This file persists across conversation turns and even across sessions — it's your investigation journal.
2. Design Instrumentation
Add targeted debug logs or assertions at the exact decision points that would confirm or reject your hypothesis. Think about what data you need to see.
Don't scatter console.log everywhere. Identify the 2-3 places where your
hypothesis makes a testable prediction, and instrument those.
Prefer logging values (return codes, payload contents, stream types, message bodies, env state) over presence checks ("was this function called?", "was this branch taken?"). Code-path traces tell you what ran; data traces tell you what it ran on. Most non-trivial bugs are correct code processing wrong data.
Ask yourself: "If my hypothesis is correct, what will I see at point X? If it's wrong, what will I see instead?"
3. Verify Data Collection
Before running, confirm that your instrumentation output will actually be captured and accessible.
Common traps:
- stderr discarded by
2>/dev/nullin the test command - Process killed before flush (logs lost)
- Logging to a file in a directory that doesn't exist
- Output piped through something that truncates it
- Looking at log files from a previous run, not the current one
A test run that produces no data is wasted.
4. Run and Observe
Execute the test. Read the actual output — every line of it. Don't assume what it says.
When the data contradicts your hypothesis, believe the data. Don't rationalize it away. The whole point of this step is to let reality override your theory.
5. Document Findings
Update the side note with:
- What the data showed (quote specific log lines)
- What was confirmed vs. disproved
- Updated hypothesis for the next iteration
This is critical for not losing context across attempts. Hard bugs typically take 3-5 rounds. Without notes, you'll forget what you ruled out and waste runs re-checking things.
6. Iterate
Update the hypothesis based on the new evidence. Go back to step 2. Each round should narrow the search space.
If you're not making progress after 3 rounds, step back and question your assumptions. The bug might be in a layer you haven't considered.
Failure Modes to Avoid
These are the specific traps this methodology is designed to prevent. When you notice yourself drifting toward any of them, stop and return to the cycle.
Jumping to fixes without evidence
The most common failure. You have a plausible theory, so you "fix" it and run again. If the theory was wrong, you've added complexity, wasted a test run, and possibly introduced a new bug. The side note should always show "hypothesis verified by [specific data]" before any fix is applied.
Blaming external systems
"The model is hallucinating." "The API is flaky." "The library has a bug." These conclusions feel satisfying because they put the problem outside your control. They're also usually wrong.
Before blaming an external system, inspect what it actually received. A model that appears to hallucinate may be responding rationally to stale data you didn't know was there. An API that appears flaky may be receiving malformed requests. Look at the inputs, not just the outputs.
Inspecting code paths but not data
You
常见问题
为什么不直接马上试一个修复?
靠猜测往往修复了错误的原因,还会增加复杂性,因此这种方法要求先提出可以检验的假设。
它会保留笔记吗?
会的,对于更难的缺陷,它会保存一份跨会话持续存在的调查日志。
它只适用于一种编程语言吗?
不是,它是一种在复杂系统中追踪问题的通用方法。
详情
作者的原始描述
Hypothesis-driven debugging methodology for hard bugs. Use this skill whenever you're investigating non-trivial bugs, unexpected behavior, flaky tests, or tracing issues through complex systems. Activate proactively when debugging requires more than a quick glance — especially when the first attempt at a fix didn't work, when behavior seems "impossible", or when you're tempted to blame an external system (model, API, library) without evidence.
repo: QwenLM/qwen-code
热度
- GitHub 星标
- 29k
- 排名
- #9770
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …