npx skills add ...
npx skills add mastra-ai/mastra --skill debugging-difficult-bugs
npx skills add mastra-ai/mastra --skill debugging-difficult-bugs
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.
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.
Use this workflow near the start of debugging when any of these are true:
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.
State the uncertainty
Add temporary unconditional instrumentation
.jsonl file in the current working directory.Reproduce the real issue
.jsonl file to send or ask them to tell you when reproduction is complete so you can inspect it.Analyze the log before fixing
Clean up instrumentation
.jsonl files, and any other temporary artifacts.Keep or improve tests
Use append-only JSONL in cwd so it works across CLIs, dev servers, tests, and manual reproduction.
Call it at every meaningful branch or state transition:
Prefer compact, structured data over huge dumps.
Log:
Avoid logging:
Treat debug logs as potentially sensitive. Do not ask the user to paste them into public issues, PRs, or shared channels unless they have reviewed/redacted them first.
If sensitive data might appear, log redacted summaries:
When the user needs to reproduce manually, say exactly this shape:
If multiple processes have different working directories, either:
process.cwd(), process role, and pid at startup, ordebug-server-flow.jsonl, debug-worker-flow.jsonl, and debug-client-flow.jsonl.Before writing the fix, answer:
A difficult bug is not done until:
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 error;
}debugBug('request.received', {
hasAuthHeader: Boolean(headers.authorization),
bodyKeys: Object.keys(body ?? {}),
messageCount: body?.messages?.length,
});I added temporary unconditional JSONL instrumentation. Please reproduce the issue once, then send me or point me at:
<cwd>/debug-difficult-bug.jsonl
After I inspect that log, I’ll remove the instrumentation and make the actual fix.