skills/investigate-root-cause/SKILL.md
--- name: investigate-root-cause description: Systematic debugging with root cause investigation. Four phases: investigate, analyze, hypothesize, implement. Iron Law: no fixes without root cause. Use when asked to "debug this", "fix this bug", "why is this broken", "investigate this error", or "root cause analysis". description_zh: 系统性根因调试:investigate → analyze → hypothesize → implement。铁律:无根因不修复。适用于报错、异常行为、故障排查。 tags: [workflow, optimization] version: 1.0.0 license: MIT recommended_scope: both
npx skillsauth add nesnilnehc/ai-cortex skills/investigate-root-causeInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
通过系统性根因调查与假设验证,在未确认根因前不实施修复,避免症状修补导致的连锁问题。适用于报错、异常行为或「之前能跑、现在坏了」的故障排查。
首要目标:在确认根因后实施最小修复,并附回归测试与验证证据。
成功标准(必须满足所有要求):
验收测试:回归测试在无修复时失败、有修复时通过;原始问题场景已复现并验证修复。
本技能负责:
本技能不负责:
automate-repair)review-diff、review-code)转交点:根因确认并修复后,若需迭代运行测试并修复,移交 automate-repair。若三次假设失败,输出 BLOCKED 状态并建议人工介入。
NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST.
修补症状会形成打地鼠式调试。每次非根因修复都会增加后续排查难度。先确认根因,再修复。
在形成假设前收集上下文。
git log --oneline -20 -- <affected-files>。之前能跑吗?改了什么?回归意味着根因在 diff 中。输出:"Root cause hypothesis: ..." — 可验证的、具体的断言:哪里错了、为什么。
检查是否匹配已知模式:
| 模式 | 特征 | 关注点 | |------|------|--------| | 竞态条件 | 间歇性、依赖时序 | 并发访问共享状态 | | nil/null 传播 | NoMethodError、TypeError | 可选值缺少守卫 | | 状态损坏 | 数据不一致、部分更新 | 事务、回调、钩子 | | 集成失败 | 超时、意外响应 | 外部 API、服务边界 | | 配置漂移 | 本地能跑、staging/prod 失败 | 环境变量、特性开关、DB 状态 | | 陈旧缓存 | 显示旧数据、清缓存后恢复 | Redis、CDN、浏览器缓存 |
同时检查:TODOS.md 中相关已知问题;git log 同区域历史修复 — 同一文件反复出 bug 多为架构问题。
外部模式搜索:若不匹配上述模式,WebSearch "{framework} {generic error type}" — 先脱敏:去掉主机名、IP、路径、SQL、客户数据。仅搜索错误类别。WebSearch 不可用时跳过。
在编写任何修复前,验证假设。
3 次假设验证均未匹配。可能是架构问题而非简单 bug。
A) 继续调查 — 我有新假设:[描述]
B) 升级人工审查 — 需熟悉系统的人
C) 增加日志等待 — 在相关区域加日志,下次发生时捕获
红旗:提出「先临时修一下」、在未追溯数据流前提议修复、每次修复都暴露出新问题 — 放慢节奏,考虑是否在错误层级。
根因确认后:
新鲜验证:复现原始 bug 场景,确认已修复。不可省略。
输出结构化 Debug Report:
DEBUG REPORT
════════════════════════════════════════
Symptom: [用户观察到的现象]
Root cause: [实际根因]
Fix: [变更内容,含 file:line]
Evidence: [测试输出、复现结果]
Regression test: [新测试的 file:line]
Related: [TODOS 项、同区域历史 bug、架构备注]
Status: DONE | DONE_WITH_CONCERNS | BLOCKED
════════════════════════════════════════
不要做这些(其他技能可以处理它们):
automate-repairreview-diff、review-code回归测试在无修复时失败、有修复时通过?
症状:NoMethodError: undefined method 'x' for nil。
Phase 1:追溯调用链,发现某处返回 nil 未守卫。
Phase 2:匹配 nil 传播模式。
Phase 3:在疑似处加断言,复现后确认。
Phase 4:加 nil 检查;编写测试覆盖该路径。
Phase 5:原始场景验证;输出 Report。
Phase 3:三次假设均被验证否决。输出 BLOCKED,建议人工审查或增加日志等待下次捕获。
本技能产出 Debug Report:
| 元素 | 格式 | 必填字段 | 路径模式 | | :--- | :--- | :--- | :--- | | 报告主体 | Markdown 或聊天结构化输出 | 章节:症状(可复现步骤)/ 假设链 / 证据 / 根因 / 修复建议 / 预防措施 | 默认聊天输出;如需落盘则 docs/calibration/debug-<slug>.md | | 假设链 | 表格 | hypothesis / supporting_evidence / refuting_evidence / verdict(accepted/rejected/inconclusive) | 「假设链」节 | | 修复建议 | 列表项 | fix_kind(patch / config_change / rollback / handoff)/ target_files / risk / verification_step | 「修复建议」节 |
development
Generate an LLM agent test suite (golden cases, mock-LLM unit tests, evaluator harness) from an agent implementation and its agent-test contract. Use when an agent has no tests, or a contract exists but the test code is missing.
development
After code changes, auto-detect the project's build system and local deployment method for a given directory, then build the project and restart its locally-deployed environment (Docker Compose / systemd / process manager). Never assumes — asks only when detection is ambiguous. Caches detected commands per project in .cortex/redeploy-local.yaml; re-invocations on the same project skip re-scanning until signal files change, the cache expires (30 days), or the skill version bumps.
tools
Publish a NATS message conforming to a cross-team contract, using NATS MCP tools. Authors the contract on first use if missing. Reads project-level cache (.cortex/nats.yaml) to avoid re-prompting basics across sessions.
tools
Drain pending NATS messages from a producer contract via NATS MCP tools (default batch / drain-style). Applies Tolerant Reader semantics and per-message ack/nak/term, returning aggregated stats. Reads project-level cache (.cortex/nats.yaml) to avoid re-prompting.