gstack-openclaw-investigate

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Systematic Debugging

系统化调试

Iron Law

铁则

NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST.
Fixing symptoms creates whack-a-mole debugging. Every fix that doesn't address root cause makes the next bug harder to find. Find the root cause, then fix it.

未先进行根本原因排查,绝不修复问题。
修复表面症状会导致“打地鼠式”调试。每一个未针对根本原因的修复都会让下一个bug更难定位。先找到根本原因,再进行修复。

Phase 1: Root Cause Investigation

第一阶段:根本原因排查

Gather context before forming any hypothesis.
  1. Collect symptoms: Read the error messages, stack traces, and reproduction steps. If the user hasn't provided enough context, ask ONE question at a time. Don't ask five questions at once.
  2. Read the code: Trace the code path from the symptom back to potential causes. Search for all references, read the logic around the failure point.
  3. Check recent changes:
    bash
    git log --oneline -20 -- <affected-files>
    Was this working before? What changed? A regression means the root cause is in the diff.
  4. Reproduce: Can you trigger the bug deterministically? If not, gather more evidence before proceeding.
  5. Check memory for prior debugging sessions on the same area. Recurring bugs in the same files are an architectural smell.
Output: "Root cause hypothesis: ..." ... a specific, testable claim about what is wrong and why.

在形成任何假设之前,先收集上下文信息。
  1. 收集症状: 阅读错误信息、堆栈跟踪和复现步骤。如果用户提供的上下文不足,一次只提一个问题,不要同时问五个问题。
  2. 阅读代码: 从症状出发,追溯代码路径,找到潜在原因。搜索所有相关引用,阅读故障点周围的逻辑。
  3. 检查近期变更:
    bash
    git log --oneline -20 -- <affected-files>
    之前是否正常工作?发生了什么变更?如果是回归问题,根本原因就在差异代码中。
  4. 复现问题: 你能否确定地触发这个bug?如果不能,先收集更多证据再继续。
  5. 检查历史记录: 查看同一区域之前的调试会话记录。同一文件反复出现bug是架构设计上的问题。
输出:“根本原因假设:……”……一个关于问题所在及原因的具体、可验证的结论。

Phase 2: Pattern Analysis

第二阶段:模式分析

Check if this bug matches a known pattern:
Race condition ... Intermittent, timing-dependent. Look at concurrent access to shared state.
Nil/null propagation ... NoMethodError, TypeError. Missing guards on optional values.
State corruption ... Inconsistent data, partial updates. Check transactions, callbacks, hooks.
Integration failure ... Timeout, unexpected response. External API calls, service boundaries.
Configuration drift ... Works locally, fails in staging/prod. Env vars, feature flags, DB state.
Stale cache ... Shows old data, fixes on cache clear. Redis, CDN, browser cache.
Also check:
  • Known issues in the project for related problems
  • Git log for prior fixes in the same area. Recurring bugs in the same files are an architectural smell, not a coincidence.
External search: If the bug doesn't match a known pattern, search for the error type online. Sanitize first: strip hostnames, IPs, file paths, SQL, customer data. Search the error category, not the raw message.

检查该bug是否符合已知模式:
竞态条件……间歇性、依赖时序问题。检查共享状态的并发访问情况。
空值传播……NoMethodError、TypeError。缺少对可选值的防护处理。
状态损坏……数据不一致、部分更新。检查事务、回调、钩子函数。
集成失败……超时、意外响应。外部API调用、服务边界问题。
配置漂移……本地运行正常, staging/prod环境失败。环境变量、功能开关、数据库状态问题。
缓存过期失效……显示旧数据,清除缓存后恢复正常。Redis、CDN、浏览器缓存问题。
同时检查:
  • 项目中已知的相关问题
  • 同一区域之前的修复记录。同一文件反复出现bug不是巧合,而是架构设计上的问题。
外部搜索: 如果该bug不符合已知模式,在线搜索错误类型。先脱敏处理: 移除主机名、IP、文件路径、SQL语句、客户数据。搜索错误类别,而非原始错误信息。

Phase 3: Hypothesis Testing

第三阶段:假设验证

Before writing ANY fix, verify your hypothesis.
  1. Confirm the hypothesis: Add a temporary log statement, assertion, or debug output at the suspected root cause. Run the reproduction. Does the evidence match?
  2. If the hypothesis is wrong: Search for the error (sanitize sensitive data first). Return to Phase 1. Gather more evidence. Do not guess.
  3. 3-strike rule: If 3 hypotheses fail, STOP. Tell the user:
    "3 hypotheses tested, none match. This may be an architectural issue rather than a simple bug."
    Options:
    • Continue investigating with a new hypothesis (describe it)
    • Escalate for human review (needs someone who knows the system)
    • Add logging and wait (instrument the area and catch it next time)
Red flags ... if you see any of these, slow down:
  • "Quick fix for now" ... there is no "for now." Fix it right or escalate.
  • Proposing a fix before tracing data flow ... you're guessing.
  • Each fix reveals a new problem elsewhere ... wrong layer, not wrong code.

在编写任何修复代码之前,先验证你的假设。
  1. 确认假设: 在疑似根本原因处添加临时日志语句、断言或调试输出。运行复现步骤。证据是否与假设匹配?
  2. 如果假设错误: 搜索错误信息(先脱敏敏感数据)。回到第一阶段,收集更多证据。不要猜测。
  3. 三次失败规则: 如果3次假设都不成立,停止操作。告知用户:
    “已测试3个假设,均不匹配。这可能是架构问题而非简单bug。”
    可选方案:
    • 提出新假设并继续排查(描述新假设)
    • 升级请求人工审核(需要熟悉系统的人员处理)
    • 添加日志并等待(对该区域进行监控,下次出现时捕获)
危险信号……如果遇到以下情况,请放慢节奏:
  • “先临时修复一下”……没有“临时”一说。要么正确修复,要么升级处理。
  • 未追踪数据流就提出修复方案……你在猜测。
  • 每次修复都会在其他地方引发新问题……修复层级错误,而非代码本身错误。

Phase 4: Implementation

第四阶段:修复实现

Once root cause is confirmed:
  1. Fix the root cause, not the symptom. The smallest change that eliminates the actual problem.
  2. Minimal diff: Fewest files touched, fewest lines changed. Resist the urge to refactor adjacent code.
  3. Write a regression test that:
    • Fails without the fix (proves the test is meaningful)
    • Passes with the fix (proves the fix works)
  4. Run the full test suite. No regressions allowed.
  5. If the fix touches >5 files: Flag the blast radius to the user before proceeding. That's large for a bug fix.

一旦确认根本原因:
  1. 修复根本原因,而非表面症状。 用最小的改动消除实际问题。
  2. 最小化差异: 最少的文件改动,最少的代码行数变更。克制重构相邻代码的冲动。
  3. 编写回归测试:
    • 无修复时测试失败(证明测试有意义)
    • 有修复时测试通过(证明修复有效)
  4. 运行完整测试套件。 不允许出现回归问题。
  5. 如果修复涉及超过5个文件: 在继续之前向用户标记影响范围。这对于bug修复来说范围过大。

Phase 5: Verification & Report

第五阶段:验证与报告

Fresh verification: Reproduce the original bug scenario and confirm it's fixed. This is not optional.
Run the test suite.
Output a structured debug report:
DEBUG REPORT
  • Symptom: what the user observed
  • Root cause: what was actually wrong
  • Fix: what was changed, with file references
  • Evidence: test output, reproduction showing fix works
  • Regression test: location of the new test
  • Related: prior bugs in same area, architectural notes
  • Status: DONE | DONE_WITH_CONCERNS | BLOCKED
Save the report to
memory/
with today's date so future sessions can reference it.

重新验证: 复现原始bug场景,确认问题已修复。这一步必不可少。
运行测试套件。
输出结构化调试报告:
调试报告
  • 症状: 用户观察到的现象
  • 根本原因: 实际存在的问题
  • 修复方案: 修改内容及文件引用
  • 证据: 测试输出、证明修复有效的复现结果
  • 回归测试: 新测试的位置
  • 相关信息: 同一区域的过往bug、架构说明
  • 状态: 已完成 | 完成但存疑 | 受阻
将报告保存至
memory/
目录,命名包含当日日期,以便后续会话参考。

Important Rules

重要规则

  • 3+ failed fix attempts: STOP and question the architecture. Wrong architecture, not failed hypothesis.
  • Never apply a fix you cannot verify. If you can't reproduce and confirm, don't ship it.
  • Never say "this should fix it." Verify and prove it. Run the tests.
  • If fix touches >5 files: Flag to user before proceeding.
  • Completion status:
    • DONE ... root cause found, fix applied, regression test written, all tests pass
    • DONE_WITH_CONCERNS ... fixed but cannot fully verify (e.g., intermittent bug, requires staging)
    • BLOCKED ... root cause unclear after investigation, escalated
  • 3次及以上修复尝试失败:停止操作并质疑架构设计。 是架构问题,而非假设错误。
  • 绝不应用无法验证的修复。 如果无法复现并确认修复效果,不要发布。
  • 绝不说“这个应该能修复问题”。 要验证并证明。运行测试。
  • 如果修复涉及超过5个文件: 在继续之前向用户标记。
  • 完成状态:
    • 已完成……找到根本原因,完成修复,编写回归测试,所有测试通过
    • 完成但存疑……已修复但无法完全验证(如间歇性bug,需要staging环境验证)
    • 受阻……排查后仍不清楚根本原因,已升级处理