بنقرة واحدة
debug-protocol
Protocol D — systematic debugging methodology (RIDHV). Evidence-based, one change at a time.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Protocol D — systematic debugging methodology (RIDHV). Evidence-based, one change at a time.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Parse and execute a TDDAB plan via CVM planexecutor. Autonomous block-by-block execution with RED/GREEN/VERIFY/COMMIT phases. Supports resume after interruption.
TDDAB plan format and rules — test-first, atomic blocks, RED/GREEN/VERIFY, bottom-up decomposition.
Decompose the task instruction into an exhaustive list of atomic, independently-testable requirements BEFORE planning. Surfaces buried/secondary clauses that all-or-nothing graders punish.
Review plan for TDDAB/Step conformity. Checks methodology compliance, dependency ordering, and validates with CVM parsePlan.
Validate a TDDAB plan file using CVM parsePlan. Shows block count, IDs, validation errors.
Step plan format for removal, migration, and cleanup work (non-TDD). Uses actions tag instead of red.
| name | debug-protocol |
| description | Protocol D — systematic debugging methodology (RIDHV). Evidence-based, one change at a time. |
Systematic debugging methodology for AI agents. Apply this mindset whenever you encounter errors, failures, or unexpected behavior.
Debugging is NOT "trying things until it works". Debugging IS systematic investigation.
You are a detective, not a trial-and-error generator.
| WRONG Debugging | CORRECT Debugging |
|---|---|
| "Let me try changing this" | "The error says X, therefore the cause is Y" |
| Modify and see what happens | Understand first, then modify |
| Change 5 things at once | One change, one verification |
| Skim the error message | Read the ENTIRE error |
| Assume where the problem is | Find EXACTLY where it fails |
| Hope it works | Know WHY it will work |
Never write code before understanding the problem.
If you cannot explain in words what causes the error, you are not ready to fix it.
Question: "What does the error say EXACTLY?"
The error contains the answer. Always. The problem is we don't read it.
Rules:
Output Required:
**ERROR TYPE**: [exception/error type]
**MESSAGE**: "[exact error text]"
**LOCATION**: [file:line if available]
Anti-patterns:
Question: "Where PRECISELY does it fail?"
It's not enough to know "something is wrong". You must find the exact point.
Rules:
Techniques:
Output Required:
**FAILURE POINT**: [file:line where error appears]
**ORIGIN**: [file:line where problem originates, if different]
**CONTEXT**: [2-3 relevant lines of code]
Anti-patterns:
Question: "What does the documentation say for this case?"
Before inventing solutions, check if the answer already exists.
Rules:
When to Apply:
When to Skip:
Output Required:
**DOCS**: [reference link or "N/A - business logic error"]
**KNOWN PATTERN**: [yes/no, description if yes]
Question: "What is my hypothesis about the cause? WHY?"
This is the critical moment. BEFORE touching any code:
Rules:
Output Required:
**HYPOTHESIS**: [what I think causes the error]
**REASONING**: [chain of logic - how I arrived at this conclusion]
**PREDICTION**: [what I expect to happen after the fix]
Anti-patterns:
Question: "ONE change. Did it work? Was the prediction correct?"
STRICT Rules:
The Cycle:
Change → Test → Result
↓
Matches prediction?
↓ ↓
YES NO
↓ ↓
DONE Return to READ
(new cycle with new info)
Output Required:
**CHANGE**: [single change made]
**RESULT**: [actual outcome]
**PREDICTION MATCH**: [yes/no]
**CONCLUSION**: [what we learned]
Anti-patterns:
RIDHV tells you HOW to debug. These rules tell you what to NEVER do while debugging. They are born from real failures and corrected through painful experience.
The project already has structured logging (Serilog, log4j, winston, NLog, Python logging, etc.). Logs go to files, not console. Use this infrastructure before anything else.
The Hierarchy (follow in order):
Level 1: FIND the project's log files
→ Search config: appsettings.json, application.yml, .env, logging config
→ Common locations: ./logs/, /var/log/[app]/, ~/logs/
→ READ existing logs — the answer may already be there
Level 2: RAISE the log level in CONFIG (not in code)
→ .NET: appsettings.json → "MinimumLevel": "Debug" or "Trace"
→ Java: application.yml → logging.level.root: DEBUG
→ Node: LOG_LEVEL=debug or config file
→ Python: logging.basicConfig(level=logging.DEBUG)
→ This reveals what the code ALREADY logs at lower levels
Level 3: ADD trace logging in code at critical points
→ Use the project's logger (ILogger, @Slf4j, winston, etc.)
→ Log: input parameters, intermediate state, raw responses, output
→ Mark temporary: // TRACE-DEBUG or # TRACE-DEBUG
Level 4: LAST RESORT — raw file trace
→ Only when the logging framework itself doesn't work
(plugin DLLs, bootstrap before DI, static initializers)
→ File.AppendAllText / fs.appendFileSync to a temp log
→ This is the exception, not the rule
NEVER: Console.WriteLine / console.log / System.out.println / print()
as FIRST approach. Console output interferes with STDIO transports,
gets lost in containerized environments, and is not searchable.
After debugging: remove all temporary trace logging (Level 3-4), restore log level to original (Level 2).
Why: Without version verification, you can build new code but test old code. You think you fixed the bug, but the old binary is still running.
Protocol:
Anti-pattern: Build, deploy, test, celebrate — but the old process was still running.
Every step depends on the previous one. Skipping any step means testing old code.
Build (from correct source directory)
→ Deploy (copy artifacts to correct location)
→ Start (from correct working directory)
→ Verify startup (check process, port, logs)
→ Verify version (confirm correct code is running)
→ NOW test
Rules:
Why: sleep(2000) / Task.Delay(200) / setTimeout(200) is a probabilistic hack. It masks the real problem and fails unpredictably under load.
Use deterministic mechanisms instead:
The only acceptable delay: explicit rate limiting or backoff with a clear reason documented in a comment.
Why: Repeating a failing operation expecting a different result wastes time and tokens.
Protocol:
Anti-pattern: API call fails → retry → fails → retry → fails → give up. Instead: API call fails → read error → "401 Unauthorized" → token expired → refresh token → retry → succeeds.
Why: "I started the server" is not the same as "the server is ready to accept requests". The process may have crashed, thrown an exception during startup, or still be loading.
Protocol:
Anti-pattern: Start server in background, immediately send test requests, get connection refused, blame the code.
Why: Bugs hide in untested branches. The happy path works, but the error path, the edge case, the fallback — those are where bugs live.
Rules:
if branch needs at least one test that exercises each sideAnti-pattern: A function has 3 paths (success, not-found, error). Only the success path is tested. The not-found path has a bug that stays hidden for months.
Why: When a bug is NOT in your code but in a dependency, library, or external service, document it with evidence. Don't hide it, don't work around it silently.
Protocol:
Anti-pattern: Spend hours debugging, discover it's a library bug, fix it with a hack, tell nobody. Next developer spends the same hours.
You MUST be able to answer these questions:
If you cannot answer all four → you are NOT ready to write code.
After 3 cycles on the same error without progress:
The error is not an obstacle. It's free information. A clear error is worth gold. A vague error requires more investigation. Never be frustrated by errors - be grateful for the information.
If the code produces X instead of Y, there's a reason. The computer executes exactly what you tell it. If the result is wrong, the instructions are wrong. Never blame the framework/language/computer - find what YOU got wrong.
If you can't reproduce the error reliably, you can't verify the fix. Before fixing: make sure you can make it fail on command. A fix you can't verify is not a fix - it's a hope.
The correct fix is almost always simpler than you think. If your solution requires 50 lines, you probably don't understand the problem. Complexity in the fix often indicates confusion about the cause.
Why one change at a time?
When applying Protocol D, structure your response like this:
## DEBUG: [brief problem description]
### READ
**Error**: [type]
**Message**: "[exact text]"
**Location**: [file:line]
### ISOLATE
**Failure point**: [where it appears]
**Origin**: [where it originates]
**Context**: [relevant code]
### DOCS
[reference or "N/A - business logic"]
### HYPOTHESIZE
**Hypothesis**: [cause]
**Reasoning**: [why]
**Prediction**: [expected outcome after fix]
### VERIFY
**Change**: [what you'll change]
[after making change]
**Result**: [outcome]
**Match**: [prediction correct? + explanation]
This mindset applies ALWAYS during debugging, regardless of:
The methodology scales:
| Anti-Pattern | Why It's Wrong | Correct Approach |
|---|---|---|
| "Let's try X" | No reasoning, no learning | "Hypothesis: X because Y" |
| Change multiple things | Can't isolate cause | One change per cycle |
| Skim error message | Miss critical info | Read complete error, quote exactly |
| Assume location | Waste time in wrong place | Isolate precisely first |
| Skip to code | Fix wrong thing | Complete RIDH before V |
| Ignore failed attempts | Repeat mistakes | Log what didn't work |
| "It works now" (no understanding) | Will break again | Understand WHY it works |
console.log as first approach | Gets lost, interferes with transports | Use project's file logging first |
sleep(2000) for sync | Probabilistic, fails under load | Use deterministic readiness probes |
| Retry failing operation blindly | Wastes time, same result | Read error, fix cause, then retry |
| Skip build/deploy steps | May test stale artifacts | Complete Build→Deploy→Verify chain |
| Test without version check | May be testing old code | Verify version before testing |
| Start server, immediately test | Server may not be ready | Verify readiness first |
| Only test the happy path | Bugs hide in untested branches | Test every code path |
| Silent workaround for upstream bug | Next developer hits same issue | Document with evidence |
READ → ISOLATE → DOCS → HYPOTHESIZE → VERIFY
↑ ↓
└──────── if wrong ────────────┘
METHODOLOGY (RIDHV):
No guessing. No assumptions. No multiple changes.
No code before understanding.
DISCIPLINE:
Logs first (file logs, not console). Version verified.
Build chain complete. No sleep-as-sync. No blind retry.
Every path tested. Upstream documented.
Systematic. Evidence-based. One step at a time.