debugging-difficult-bugs
Ce qu’il fait
Cette skill guide une méthode de débogage rigoureuse pour les bugs de difficulté moyenne ou élevée. Elle demande à l'agent de reproduire le vrai problème et de lire les journaux d'exécution avant de tenter une correction.
Quand l’utiliser
- ✓Quand un bug concerne le timing, l'état, le streaming ou un autre comportement à l'exécution que les tests ne capturent pas forcément.
- ✓Quand un test échoue sans forcément modéliser le vrai problème.
- ✓Quand vous êtes tenté de faire une nouvelle correction au hasard sans nouvelle preuve.
Lien du skill
https://github.com/mastra-ai/mastra/blob/main/.claude/skills/debugging-difficult-bugs/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Ce bug n'apparaît que lorsque deux requêtes arrivent en même temps. Aide-moi à trouver la vraie cause avant de modifier le moindre code.”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
L'agent indique ce dont il n'est pas sûr, ajoute une journalisation temporaire sur le chemin d'exécution réel et reproduit le problème. Il lit ensuite les journaux et tire une conclusion avant de proposer une correction.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis 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
Questions fréquentes
Passe-t-il l'écriture de tests ?
Non. Il indique que les tests seuls peuvent donner une fausse assurance, donc les preuves d'exécution passent en premier, et les tests sont ajoutés ensuite.
Quand peut-on s'en passer ?
Seulement lorsqu'une trace d'erreur ou un test déterministe en échec prouve déjà la cause.
Les journaux doivent-ils contenir des données privées ?
La méthode recommande de journaliser uniquement les métadonnées, pas les prompts ni le contenu.
Détails
Description originale de l’auteur
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
Popularité
- Étoiles GitHub
- 29k
- Position au classement
- #9360
- Licence
- —
- Mis à jour
- 02/11/2026
Commentaires
- …
Autres skills de ce dépôt
mastra-frontend
29kAide votre agent à construire les écrans d'une application avec le système de design du playground Mastra, en combinant ses composants prêts à l'emploi.
pr-explainer
29kAide votre agent à transformer une pull request en page HTML claire et autonome, qui explique la modification aux relecteurs.
pr-splitter
29kAide votre agent à découper une grande pull request confuse en plusieurs pull requests plus petites et relisibles, tout en protégeant le travail d'origine.
ralph-plan
29kAide votre agent à planifier une tâche structurée et ciblée, grâce à un court échange, afin que le travail ait des étapes claires et des contrôles.
Skills similaires
test-driven-development
311kApprend à votre agent à écrire d'abord un test qui échoue, à le voir échouer, puis à écrire le code minimal qui le fait réussir, avant de construire toute fonctionnalité ou correction.
verification-before-completion
311kApprend à votre agent à lancer de véritables contrôles et à lire leurs résultats avant d'affirmer qu'une tâche, une correction ou une compilation est terminée ou réussie.
migrate-to-shoehorn
310kRemplace les conversions de type risquées dans vos fichiers de test par la bibliothèque shoehorn, afin que les tests utilisent des données partielles et passent les contrôles de types.