在复杂执行链路中逆向追踪错误根因,定位异常数据或错误触发点。
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "root-cause-tracing" 技能: 1. 下载 https://raw.githubusercontent.com/microsoft/FluidFramework/main/.agency/plugins/nori/skills/root-cause-tracing/SKILL.md 2. 保存为 ~/.claude/skills/root-cause-tracing/SKILL.md 3. 装好后重载技能,告诉我可以用了
请帮我做根因追踪:某个接口最终返回了错误的用户状态。请从报错点开始,沿调用链向前追踪,标出每一层输入输出、关键状态变化,并指出最可能的源头问题;如果信息不足,请建议应添加哪些日志或断点。
一份按调用链逆向展开的排查结果,包含可疑环节、证据和建议补充的观测点。
我发现下游报表中的订单金额异常,请帮我从异常结果倒推到数据写入源头,分析可能在哪个处理步骤引入了错误值,并给出验证每个假设的方法。
一份数据流逆向分析,说明错误值可能出现的位置、原因及验证步骤。
程序在深层函数调用中崩溃,但表面报错信息不明显。请帮我基于调用栈逐层回溯,找出最早出现异常状态的位置,并提出最小化复现和修复建议。
一份根因定位报告,包含最早异常点、复现思路与修复建议。
Bugs often manifest deep in the call stack (git init in wrong directory, file created in wrong location, database opened with wrong path). Your instinct is to fix where the error appears, but that's treating a symptom.
Core principle: Trace backward through the call chain until you find the original trigger, then fix at the source.
digraph when_to_use {
"Bug appears deep in stack?" [shape=diamond];
"Can trace backwards?" [shape=diamond];
"Fix at symptom point" [shape=box];
"Trace to original trigger" [shape=box];
"Bug appears deep in stack?" -> "Can trace backwards?" [label="yes"];
"Can trace backwards?" -> "Trace to original trigger" [label="yes"];
"Can trace backwards?" -> "Fix at symptom point" [label="no - dead end"];
}
Use when:
Error: git init failed in /Users/jesse/project/packages/core
What code directly causes this?
await execFileAsync('git', ['init'], { cwd: projectDir });
WorktreeManager.createSessionWorktree(projectDir, sessionId)
→ called by Session.initializeWorkspace()
→ called by Session.create()
→ called by test at Project.create()
What value was passed?
projectDir = '' (empty string!)cwd resolves to process.cwd()Where did empty string come from?
const context = setupCoreTest(); // Returns { tempDir: '' }
Project.create('name', context.tempDir); // Accessed before beforeEach!
When you can't trace manually, add instrumentation:
// Before the problematic operation
async function gitInit(directory: string) {
const stack = new Error().stack;
console.error('DEBUG git init:', {
directory,
cwd: process.cwd(),
nodeEnv: process.env.NODE_ENV,
stack,
});
await execFileAsync('git', ['init'], { cwd: directory });
}
Critical: Use console.error() in tests (not logger - may not show)
Run and capture:
npm test 2>&1 | grep 'DEBUG git init'
Analyze stack traces:
If something appears during tests but you don't know which test:
Use the bisection script: @find-polluter.sh
./find-polluter.sh '.git' 'src/**/*.test.ts'
Runs tests one-by-one, stops at first polluter. See script for usage.
Symptom: .git created in packages/core/ (source code)
Trace chain:
git init runs in process.cwd() ← empty cwd parametercontext.tempDir before beforeEach{ tempDir: '' } initiallyRoot cause: Top-level variable initialization accessing empty value
Fix: Made tempDir a getter that throws if accessed before beforeEach
Also added validation at multiple layers:
digraph principle {
"Found immediate cause" [shape=ellipse];
"Can trace one level up?" [shape=diamond];
"Trace backwards" [shape=box];
"Is this the source?" [shape=diamond];
"Fix at source" [shape=box];
…
帮助你严谨评估代码评审意见,澄清疑点后再决定是否采纳与实现
帮助你定位常见故障、兼容性问题并诊断状态机异常