debugging-difficult-bugs
できること
このスキルは、中程度から難しいバグのための慎重なデバッグ手法を導きます。タイミング、状態、ストリーミングなど実行時の動作にまつわるバグについて、修正の前に実際の問題を再現し、実行時のログを読むよう求めます。
使う場面
- ✓バグがタイミング、状態、ストリーミングなど実行時の動作に関わり、テストではそれを捉えられないとき。
- ✓テストが失敗していても、それが実際の問題を表していないかもしれないとき。
- ✓新しい証拠がないまま、推測による修正をまたしたくなったとき。
スキルのリンク
https://github.com/mastra-ai/mastra/blob/main/.claude/skills/debugging-difficult-bugs/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“このバグは、2つのリクエストが同時に来たときにだけ起きます。コードを変える前に、本当の原因を見つける手伝いをしてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、自分が確信していない点を述べ、実際のコードパスに一時的なログを追加して問題を再現します。その後、ログを読み、修正を提案する前に結論を立てます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Debugging Difficult Bugs
Use this skill early for medium or hard bugs where normal TDD may give false confidence because the test does not fully capture the real bug.
Core idea: instrument the actual runtime path, reproduce the real issue, then inspect append-only JSONL logs before deciding on a fix.
When to Use
Use this workflow near the start of debugging when any of these are true:
- The bug is medium or hard complexity, especially if it spans multiple functions, packages, processes, or UI/runtime boundaries.
- A test is red, but the failing test might be an incomplete model of the real bug.
- You are tempted to make a second speculative fix without new runtime evidence.
- The bug depends on runtime ordering, state, caching, streaming, concurrency, persistence, UI interaction, or external services.
- The user says they can reproduce the issue manually.
- The test passes after a change, but you are not confident it proves the actual reported bug is fixed.
Do not keep iterating only on tests if you do not understand the runtime behavior.
Skip this workflow only when the root cause is already directly proven by a stack trace or by a deterministic failing test that exercises the real runtime path. If you are tempted to make a second speculative fix, use this workflow.
Required Approach
State the uncertainty
- Acknowledge that the current test may not capture the actual bug.
- Identify the real code path that must be observed.
Add temporary unconditional instrumentation
- Add minimal but sufficient logs through the suspected code flow.
- Log boundaries, meaningful branch decisions, state transitions, async ordering points, return values, and caught errors; do not log every line.
- Logs must be unconditional: do not gate them behind an env var, debug flag, or log level.
- Each log point must append one JSON object per line to a
.jsonlfile in the current working directory. - Include enough context to reconstruct the path: event name, timestamp, relevant ids, input shape, state transitions, branch decisions, return values, and caught errors.
Reproduce the real issue
- Prefer to run the reproduction yourself if possible.
- If the issue requires the user's environment or manual interaction, ask the user to reproduce it after instrumentation is added.
- Tell the user exactly which
.jsonlfile to send or ask them to tell you when reproduction is complete so you can inspect it.
Analyze the log before fixing
- Read the JSONL log chronologically.
- Compare expected flow vs actual flow.
- Identify the first point where state or behavior diverges.
- Only then implement the fix.
Clean up instrumentation
- Remove all temporary unconditional logs after root cause is understood and the fix is verified.
- Remove debug imports, helper functions, generated
.jsonlfiles, and any other temporary artifacts. - Check the final diff for instrumentation remnants.
- Do not leave debug files, log helpers, or noisy runtime logging in the final diff unless the user explicitly asks.
Keep or improve tests
- Add or adjust a focused regression test once the real bug is understood.
- Make the test assert the actual broken behavior discovered from logs, not the earlier incorrect assumption.
JSONL Logging Pattern
Use append-only JSONL in cwd so it works across CLIs, dev servers, tests, and manual reproduction.
Node / TypeScript
import { appendFileSync } from 'node:fs';
import { join } from 'node:path';
function debugBug(event: string, data: Record<string, unknown> = {}) {
appendFileSync(
join(process.cwd(), 'debug-difficult-bug.jsonl'),
`${JSON.stringify({
ts: new Date().toISOString(),
event,
...data,
})}\n`,
);
}
Call it at every meaningful branch or state transition:
debugBug('workflow.start', { runId, stepId, inputKeys: Object.keys(input ?? {}) });
debugBug('workflow.beforeStep', {
runId,
stepId,
status: step.status,
hasResumeData: Boolean(resumeData),
});
try {
const result = await executeStep();
debugBug('workflow.afterStep', { runId, stepId, resultShape: Object.keys(result ?? {}) });
return result;
} catch (error) {
debugBug('workflow.stepError', {
runId,
stepId,
errorName: error instanceof Error ? error.name : typeof error,
errorMessage: error instanceof Error ? error.message : String(error),
});
throw err
よくある質問
テストを書くのを省略しますか?
いいえ。テストだけでは誤った安心を生むことがあるため、まず実行時の証拠を集め、その後でテストを追加すると説明されています。
いつ省略できますか?
スタックトレースや、決定的に失敗するテストがすでに原因を証明している場合に限ります。
ログに機微なデータを含めるべきですか?
この方法では、プロンプトや内容ではなく、メタデータのみをログに残すことが推奨されています。
詳細
作者による元の説明
Use early when debugging a medium or hard bug, especially when tests alone may not reveal the real runtime failure. Trigger this before extended TDD iteration when a bug involves runtime state, ordering, persistence, streaming, concurrency, UI/manual reproduction, external services, or when a red or newly passing test may not model the real issue. Skip only when the root cause is already directly proven by a stack trace or deterministic test that exercises the real runtime path.
repo: mastra-ai/mastra
人気
- GitHubのスター
- 29k
- ランキング
- #9360
- ライセンス
- —
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
mastra-frontend
29kエージェントが、スタイルを一から書くのではなく、既製のコンポーネントを組み合わせて、Mastraのプレイグラウンドのデザインシステムで画面を作れるよう支援します。
pr-explainer
29kエージェントが、プルリクエストを、レビューアー向けに変更内容を説明する、単独で読める分かりやすいHTMLページに変換できるよう支援します。
pr-splitter
29kエージェントが、大きく入り組んだプルリクエストを、元の作業を安全に保ちながら、レビューしやすい小さなプルリクエストに分けられるよう支援します。
ralph-plan
29kエージェントが、短いやり取りを通じて、作業に明確な段階と確認項目がある、構造化されたタスクのコマンドを計画できるよう支援します。
似ているスキル
test-driven-development
311k機能や修正を作る前に、まず失敗するテストを書き、それが失敗するのを確認してから、合格させる最小のコードを書くようエージェントに教えます。
verification-before-completion
311kタスク、修正、ビルドが完了した、または合格したと主張する前に、実際のチェックを実行し、その出力を読むようエージェントに教えます。
migrate-to-shoehorn
310kテストファイル内の危険な型キャストを、shoehornライブラリに置き換え、テストが部分的なデータを使いつつ型チェックを通るようにします。