Loading...
Loading...
Compare original and translation side by side
┌─────────────────────────────────────────────────────────────────┐
│ HARD-GATE: NEVER GUESS. NEVER SHOTGUN DEBUG. │
│ NEVER CHANGE CODE WITHOUT UNDERSTANDING WHY IT IS BROKEN. │
│ │
│ You are a detective gathering evidence, not a gambler trying │
│ random fixes. If you are changing code without understanding │
│ the root cause, STOP immediately. │
└─────────────────────────────────────────────────────────────────┘┌─────────────────────────────────────────────────────────────────┐
│ 硬门槛:绝不猜测。绝不进行散弹式调试。 │
│ 在未理解代码损坏原因前,绝不修改代码。 │
│ │
│ 你是收集证据的侦探,不是尝试随机修复的赌徒。如果你在不了解根本 │
│ 原因的情况下修改代码,请立即停止。 │
└─────────────────────────────────────────────────────────────────┘git loggit diffgit loggit diffgit log --oneline -20git log --oneline -20| Factor | Working Case | Broken Case | Different? |
|---|---|---|---|
| Input data | |||
| Environment | |||
| Configuration | |||
| Dependencies | |||
| Timing/order | |||
| User/permissions | |||
| State/context |
| 因素 | 正常场景 | 故障场景 | 是否存在差异? |
|---|---|---|---|
| 输入数据 | |||
| 环境 | |||
| 配置 | |||
| 依赖 | |||
| 时序/执行顺序 | |||
| 用户/权限 | |||
| 状态/上下文 |
Hypothesis #1: [description]
Test: [what you did]
Result: CONFIRMED / DENIED
Learning: [what this taught you]
Hypothesis #2: ...假设 #1: [描述]
测试动作: [你执行的操作]
结果: 验证通过 / 推翻
收获: [本次测试的结论]
假设 #2: ...| Hypothesis Type | Testing Method | Example |
|---|---|---|
| Recent code change caused it | | "The bug was introduced in commit abc123" |
| Data shape mismatch | Add logging/assertion | "The API returns null instead of array" |
| Race condition | Add timing logs or serialize | "Request B completes before request A" |
| Configuration error | Compare configs across environments | "Production uses different DB host" |
| Dependency version issue | Lock to known-good version | "Library 2.0 changed the API surface" |
| 假设类型 | 测试方法 | 示例 |
|---|---|---|
| 近期代码变更导致 | | "Bug是在abc123提交中引入的" |
| 数据结构不匹配 | 添加日志/断言 | "API返回null而非数组" |
| 竞态条件 | 添加时序日志或序列化执行 | "请求B比请求A先完成" |
| 配置错误 | 跨环境对比配置 | "生产环境使用了不同的数据库主机" |
| 依赖版本问题 | 锁定到已知正常的版本 | "2.0版本的库修改了API接口" |
Error encountered
|
v
Can you reproduce it?
|
+-- NO --> Gather more information (logs, user reports, monitoring)
| Try different inputs, environments, timing
| Do NOT proceed until reproducible
|
+-- YES -> Read the FULL error message and stack trace
|
v
Is the cause obvious from the error?
|
+-- YES -> Form hypothesis, test it (Phase 3)
| Still write a regression test
|
+-- NO --> Complete Phase 1 evidence gathering
|
v
Find working case for comparison (Phase 2)
|
v
Identify differences
|
v
Form and test hypotheses (Phase 3)
|
+-- Fixed --> Write regression test, verify
|
+-- 3+ failed hypotheses --> Phase 4遇到错误
|
v
你能复现它吗?
|
+-- 否 --> 收集更多信息(日志、用户反馈、监控)
| 尝试不同的输入、环境、时序
| 可复现前禁止继续推进
|
+-- 是 --> 阅读完整错误信息和堆栈跟踪
|
v
从错误中能明显看出原因吗?
|
+-- 是 --> 形成假设,测试(第三阶段)
| 仍需编写回归测试用例
|
+-- 否 --> 完成第一阶段的证据收集
|
v
找到用于对比的正常案例(第二阶段)
|
v
识别差异
|
v
形成并测试假设(第三阶段)
|
+-- 已修复 --> 编写回归测试,验证
|
+-- 3个及以上假设失败 --> 进入第四阶段| Red Flag | What It Means | Action |
|---|---|---|
| Changing code without understanding the bug | Shotgun debugging | Go back to Phase 1 |
| Fix works but you do not know why | Accidental fix, likely to regress | Investigate until you understand |
| Same bug keeps coming back | Root cause not addressed | Go to Phase 4, question design |
| Fix causes new bugs elsewhere | Unexpected coupling | Map dependencies before proceeding |
| "It works on my machine" | Environment difference | Go to Phase 2, comparison matrix |
| Fix requires more than 20 lines | Might be a design issue | Go to Phase 4 |
| Debugging for 30+ minutes | Tunnel vision | Take a break, re-read evidence from Phase 1 |
| Reading the same code repeatedly | Missing something fundamental | Get a fresh perspective, explain aloud |
| Multiple causes seem equally likely | Insufficient investigation | Go back to Phase 1, gather more evidence |
| 危险信号 | 含义 | 应对动作 |
|---|---|---|
| 不理解Bug就修改代码 | 散弹式调试 | 返回第一阶段 |
| 修复生效但你不知道原因 | 意外修复,很可能回退 | 继续调查直到完全理解 |
| 相同Bug反复出现 | 根本原因未解决 | 进入第四阶段,质疑设计 |
| 修复导致其他地方出现新Bug | 非预期的耦合 | 继续前先梳理依赖关系 |
| "我本地运行正常" | 环境差异 | 进入第二阶段,填写对比矩阵 |
| 修复需要超过20行代码 | 可能存在设计问题 | 进入第四阶段 |
| 调试超过30分钟 | 管状视野(思维受限) | 休息一下,重读第一阶段的证据 |
| 反复阅读同一段代码 | 遗漏了一些根本性的内容 | 换个视角,大声解释问题 |
| 多个原因看起来可能性相同 | 调查不充分 | 返回第一阶段,收集更多证据 |
| Anti-Pattern | Why It Is Wrong | Correct Approach |
|---|---|---|
| Changing random things to see if bug goes away | Wastes time, introduces new bugs | Form a hypothesis first |
| Adding try/catch to suppress the error | Hides the real problem | Fix the root cause |
| Rewriting the feature from scratch | Nuclear option is rarely needed | Isolate and fix the specific issue |
| Blaming the framework/library without evidence | Usually your code is wrong | Prove the framework bug with minimal repro |
| Skipping the regression test after fixing | Bug will return | Write the test, always |
| Fixing symptoms instead of root causes | Patches accumulate, system degrades | Trace to the actual cause |
| Debugging for 45+ minutes without stepping back | Tunnel vision reduces effectiveness | Take a break, re-read Phase 1 evidence |
| Ignoring error messages or stack traces | The answer is often in the error | Read every line of the error |
| 反模式 | 错误原因 | 正确做法 |
|---|---|---|
| 随机修改代码看Bug是否消失 | 浪费时间,引入新Bug | 先形成假设 |
| 添加try/catch抑制错误 | 掩盖真正的问题 | 修复根本原因 |
| 从头重写整个功能 | 很少需要用到这种极端方案 | 隔离并修复具体问题 |
| 无证据指责框架/库有问题 | 通常是你的代码写错了 | 用最小复现示例证明框架存在Bug |
| 修复后跳过回归测试 | Bug会再次出现 | 始终编写测试用例 |
| 修复症状而非根本原因 | 补丁越积越多,系统逐渐腐化 | 追踪到真正的原因 |
| 调试45分钟以上都没有退一步梳理 | 管状视野会降低效率 | 休息一下,重读第一阶段的证据 |
| 忽略错误信息或堆栈跟踪 | 答案通常就在错误信息里 | 阅读错误的每一行内容 |
| Skill | Relationship |
|---|---|
| Every bug fix MUST include a regression test (RED-GREEN cycle) |
| After fixing a bug, verify with fresh evidence |
| When debugging during task execution, pause task, complete debugging, resume |
| Review the fix for completeness and side effects |
| Record new debugging patterns in learned-patterns.md |
| Verify fix does not break acceptance criteria |
| 技能 | 关联关系 |
|---|---|
| 每个Bug修复都必须包含回归测试用例(RED-GREEN周期) |
| 修复Bug后,用新的证据验证 |
| 任务执行过程中需要调试时,暂停任务,完成调试后再恢复 |
| 评审修复的完整性和副作用 |
| 在learned-patterns.md中记录新的调试模式 |
| 验证修复不会破坏验收标准 |