debugging-difficult-bugs
Skill này làm gì
Skill này hướng dẫn một phương pháp gỡ lỗi cẩn thận cho các lỗi mức trung bình hoặc khó. Nó yêu cầu agent tái hiện vấn đề thật và đọc nhật ký lúc chạy trước khi thử sửa.
Khi nào nên dùng
- ✓Khi một lỗi liên quan đến thời gian, trạng thái, luồng dữ liệu hoặc hành vi lúc chạy mà các bài kiểm thử có thể không bắt được.
- ✓Khi một bài kiểm thử đang thất bại nhưng có thể không mô phỏng đúng vấn đề thật.
- ✓Khi bạn đang muốn thử một bản sửa dựa trên phỏng đoán mà chưa có bằng chứng mới.
Liên kết skill
https://github.com/mastra-ai/mastra/blob/main/.claude/skills/debugging-difficult-bugs/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Lỗi này chỉ xảy ra khi hai yêu cầu đến cùng lúc. Hãy giúp tôi tìm nguyên nhân thật trước khi chúng ta đổi bất kỳ mã nào.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent nêu rõ những điều nó chưa chắc chắn, thêm nhật ký tạm thời vào đường chạy thật và tái hiện lỗi. Sau đó nó đọc nhật ký, hình thành kết luận rồi mới đề xuất bản sửa.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Nó có bỏ qua việc viết bài kiểm thử không?
Không. Nó nói rằng chỉ các bài kiểm thử có thể tạo cảm giác an toàn giả, nên bằng chứng lúc chạy đến trước, còn kiểm thử được thêm sau.
Khi nào có thể bỏ qua bước này?
Chỉ khi một stack trace hoặc một bài kiểm thử thất bại xác định đã chứng minh nguyên nhân.
Nhật ký có nên chứa dữ liệu riêng tư không?
Phương pháp khuyên chỉ ghi siêu dữ liệu, không ghi prompt hay nội dung.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 29k
- Vị trí xếp hạng
- #9360
- Giấy phép
- —
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
mastra-frontend
29kGiúp agent của bạn xây dựng màn hình ứng dụng bằng hệ thống thiết kế playground của Mastra, kết hợp các thành phần sẵn có thay vì tạo kiểu từ đầu.
pr-explainer
29kGiúp agent của bạn biến một pull request thành trang HTML độc lập, giải thích thay đổi cho người review một cách rõ ràng.
pr-splitter
29kGiúp agent của bạn chia một pull request lớn, lộn xộn thành nhiều pull request nhỏ dễ review, đồng thời giữ an toàn cho công việc gốc.
ralph-plan
29kGiúp agent của bạn lập kế hoạch một lệnh tác vụ có cấu trúc, rõ ràng qua một cuộc trao đổi ngắn, để công việc có các bước và kiểm tra rõ ràng.
Skill tương tự
test-driven-development
311kDạy agent của bạn viết kiểm thử thất bại trước, xem nó thất bại, rồi viết đoạn mã ngắn nhất để vượt qua trước khi làm bất kỳ tính năng hay bản sửa nào.
verification-before-completion
311kDạy agent của bạn chạy kiểm tra thực tế và đọc kết quả đầu ra trước khi khẳng định một việc, bản sửa hoặc bản build đã hoàn thành hay vượt qua.
migrate-to-shoehorn
310kThay các ép kiểu rủi ro trong tệp kiểm thử bằng thư viện shoehorn, để các bài kiểm thử dùng dữ liệu một phần vẫn qua được kiểm tra kiểu.