Debug systematically with root cause analysis before fixes. Use for bugs, test failures, unexpected behavior, performance issues, call stack tracing, multi-layer validation, log analysis, CI/CD failures, database diagnostics, system investigation.
Frontend/Problem-solving: Chrome browser or hi-chrome-devtools for visual verification; hi-problem-solving when stuck
../
wiki/en/hi-debug-skill.md
Wiki guide
Hi Debug Skill: Complete Guide
hi-debug is a skill for investigating bugs, test failures, unexpected behavior, performance issues, call stacks, logs, CI/CD, databases, and system incidents using evidence and root-cause analysis. It is not a shortcut for fixing code right away.
1. What problems does Hi Debug solve?
A symptom can appear in a completely different place from its root cause:
UI error -> API response -> service state -> database data -> migration/config
If you only fix the symptom location, the error can:
come back through another call path;
be masked by a fallback or suppression;
only disappear locally but still occur in production;
make tests pass while the contract is still wrong;
create regressions when data/state changes.
hi-debug organizes an investigation into verifiable activities:
observe and capture the state before any fix;
build a specific hypothesis;
test each hypothesis with a small experiment;
trace backward to the root cause;
design the fix and defense-in-depth;
run fresh verification before making any claim.
2. Two layers of debugging
The skill has two main workflows:
2.1 Code-level debugging
Used for bugs, tests, type/lint checks, call stacks, or behavior in code. It consists of four phases:
Root Cause Investigation -> Pattern Analysis -> Hypothesis and Testing -> Implementation
2.2 System-level investigation
Used for incidents, server 500s, CI/CD, databases, deployments, multi-component failures, or behavior changes with no clear cause. It consists of five steps:
Initial Assessment -> Data Collection -> Analysis -> Root Cause Identification -> Solution Development
Loading diagram…
3. The supreme principle: Iron Law
NO COMPLETION CLAIMS WITHOUT FRESH VERIFICATION EVIDENCE
You must not claim "fixed", "passed", or "completed" without running a fresh verification command and reading its output/exit code.
Before any completion claim:
Identify: which command proves the claim?
Run: run that command in full.
Read: read the output and exit code, count the failures.
Verify: does the output actually confirm the claim?
Report: if it does not, report the actual status honestly.
3.1 Not enough to claim
Claim
Required evidence
Not sufficient
Tests pass
Fresh test command, 0 failures
Old test or "should pass"
Lint clean
Lint output, 0 errors
Part of the file or typecheck
Build succeeds
Build exit 0
Lint pass
Bug fixed
Original symptom reproduced and passing
Code changed
Regression test works
Red-green cycle if needed
Test passed once
Agent completed
VCS diff + independent verification
Agent says success
Requirements met
Checklist of each requirement
Tests pass but a requirement is missed
3.2 Red flags
Stop and verify when you see these statements or thoughts:
"should work";
"probably fixed";
"looks correct";
"I'm pretty sure";
"linter passes so the build should pass";
"the agent said it's done";
"just this once";
"a partial check is enough".
Loading diagram…
4. When to use which technique?
Technique
Use when
Reference
Systematic Debugging
Any bug/code issue that needs investigation and fix
systematic-debugging.md
Root Cause Tracing
Deep error in the call stack, unclear origin of invalid data
root-cause-tracing.md
Defense-in-Depth
Root cause found, need to prevent recurrence at every layer
defense-in-depth.md
Verification
About to claim fixed/passing/completed
verification.md
Investigation Methodology
Server incident, multi-component failure
investigation-methodology.md
Log & CI/CD Analysis
Pipeline, deployment, server logs
log-and-ci-analysis.md
Performance Diagnostics
Latency, slow query, CPU/memory/disk
performance-diagnostics.md
Reporting Standards
Writing diagnostic/incident/performance reports
reporting-standards.md
Task Management
Investigation with 3+ steps or multiple agents
task-management-debugging.md
Frontend Verification
UI, layout, responsive, visual regression
frontend-verification.md
Main tool integrations:
psql for PostgreSQL;
gh for GitHub Actions logs/pipeline;
hi-docs-seeker for package docs;
hi-repository-search and hi-codebase-research-explorer for code/docs context;
Chrome MCP or hi-chrome-devtools for frontend;
hi-problem-solving when stuck.
5. Code-level workflow: four phases
5.1 Overview
Loading diagram…
Each phase must be completed before the next one. Do not use the Implementation phase to replace diagnosis.
5.2 Phase 1: Root Cause Investigation
Before any fix:
read the error carefully, never skip the stack trace;
reproduce consistently if possible;
check recent changes:
git diff;
recent commits;
dependency changes;
config/environment;
capture data in/out at each component boundary;
trace the data flow backward through the call stack to its source.
Key questions:
where does the error occur?
where does the first abnormal value appear?
which boundary fails to validate?
when did the new behavior start?
is the error deterministic or intermittent?
5.3 Phase 2: Pattern Analysis
Don't just look for the failing code; look for code that works correctly in the same codebase:
a working example of the same pattern;
a complete reference implementation;
every difference between the working and failing paths;
component, config, and environment dependencies;
test setup and fixtures.
Never dismiss a difference with "that probably isn't relevant". Every difference is a candidate hypothesis until it is refuted.
5.4 Phase 3: Hypothesis and Testing
A hypothesis must be specific:
X is the root cause because of Y; if true, experiment Z should observe W.
Example:
The projection missing userId is the root cause because the mapper receives an object without the required field;
running the test with a projection variant will reproduce undefined before token creation.
Rules:
one specific hypothesis at a time;
the smallest experiment with high discriminative power;
change one variable;
verify results before moving on;
if it fails, go back with a new hypothesis;
say "I don't understand X" when you don't understand it, don't pretend to be certain.
5.5 Phase 4: Implementation
Only start when the root cause has been confirmed:
create a failing test case before fixing;
implement a single fix aimed at the root cause;
run tests and verification;
check for regressions;
add prevention/defense-in-depth.
If the fix does not work:
fewer than 3 attempts: go back to Phase 1 with new evidence;
3 attempts or more: stop and question the architecture with a human partner.
6. Root-cause tracing
6.1 Trace skeleton
1. Observe: Error: <symptom> at <location>
2. Immediate cause: <code line that directly fails>
3. Call chain: callee <- caller <- ... <- entry point
4. Bad value: <param> = <unexpected value>
5. Original trigger: <test/setup that introduced the bad value>
6.2 Trace backward
Loading diagram…
Do not fix at the error location if the bad data is created by the caller or setup. Fix the source that creates the wrong invariant, then validate at the layers the data passes through.
6.3 Instrumentation when manual tracing is hard
In tests, you can add console.error() so the logger is not hidden:
Instrumentation is an investigation tool, not the final fix. Once you have the evidence, decide deliberately whether to keep or remove the instrumentation.
6.4 Find the test causing pollution
When tests fail due to shared state or pollution, use the script scripts/find-polluter.sh:
Immediate mitigation must not be mistaken for a permanent fix.
8. Log and CI/CD analysis
8.1 GitHub Actions
gh run list --limit 10
gh run list --workflow=ci.yml --limit 5
gh run view <run-id>
gh run view <run-id> --log-failed
gh run view <run-id> --log > /tmp/ci-full.txt
gh run rerun <run-id> --failed
When reading a failed pipeline:
identify the failed step;
get focused logs;
look for Error:, FAIL, exit code, stack trace;
check annotations:
gh api repos/{owner}/{repo}/check-runs/{id}/annotations
8.2 Common patterns
Pattern
Likely cause
Investigation
Local pass, CI fail
Environment difference
Node/Python/OS/env/secret
Intermittent
Race/flaky/shared state
Run 3 times, check timing
Timeout
Resource limit/infinite loop
CPU/memory/loop/timeout
Permission error
Token/secret config
Secret names, token scope
Install fail
Registry/lockfile/version
Lockfile and registry
Build pass, test fail
Test setup/DB/fixture
Test config and fixture
8.3 Server/application logs
Collection strategy:
identify log locations;
filter by incident timeframe;
correlate request IDs across services;
find repeated errors and rate changes;
preserve original lines.
Priority fields:
timestamp;
level;
message;
stack trace;
request ID;
user ID if not sensitive;
endpoint;
response code;
duration.
8.4 Error pattern recognition
Pattern
Suggestion
Sudden spike
Deploy, config, external dependency
Gradual increase
Resource leak or data growth
Cyclical
Cron/scheduled job
Single endpoint
Code or data specific to that endpoint
All endpoints
Infra, DB, or network
9. Performance diagnostics
9.1 Measure before optimizing
You must have baseline and current metrics:
expected response time;
actual response time;
percentiles if available;
when the degradation started;
which endpoints are affected;
consistent or intermittent;
traffic/load at that time.
Do not optimize based on the feeling that "the app is slow".
9.2 Locate bottleneck layer
Request -> Network -> Web Server -> Application -> Database -> Filesystem
| |
+-> External APIs/Services
Layer
Check
Tool
Network
Latency, DNS, TLS
curl -w, network logs
Web server
Queue, connections
Server metrics/access logs
Application
CPU, memory
Profiler, APM, process.memoryUsage()
Database
Query, connections
EXPLAIN ANALYZE, pg_stat_statements
Filesystem
I/O, disk
iostat, df -h
External API
Duration, timeout
Request logs with duration
9.3 PostgreSQL diagnostics
Slow queries:
SELECT query, calls, mean_exec_time, total_exec_time
FROM pg_stat_statements
ORDER BY mean_exec_time DESC
LIMIT 20;
Active queries:
SELECT pid,
now() - pg_stat_activity.query_start AS duration,
query,
state
FROM pg_stat_activity
WHERE state != 'idle'
ORDER BY duration DESC;
Table sizes:
SELECT relname,
pg_size_pretty(pg_total_relation_size(relid))
FROM pg_catalog.pg_statio_user_tables
ORDER BY pg_total_relation_size(relid) DESC
LIMIT 20;
Missing-index signal:
SELECT relname, seq_scan, seq_tup_read, idx_scan
FROM pg_stat_user_tables
WHERE seq_scan > 100
AND seq_tup_read > 10000
ORDER BY seq_tup_read DESC;
Connection pool:
SELECT count(*), state
FROM pg_stat_activity
GROUP BY state;
Specific query:
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) <your-query>;
Look for:
sequential scan on large tables;
nested loop with high row counts;
sort without an index;
excessive buffer hits;
N+1 queries;
connection exhaustion;
bloat.
9.4 Application performance patterns
Issue
Symptom
Investigation/fix direction
N+1 queries
Many small DB calls per request
Eager load or batch
Memory leak
Memory grows over time
Heap profile, listeners
Blocking I/O
High latency, low CPU
Async, pool
CPU-bound
CPU high with load
Algorithm, cache
Connection exhaustion
Intermittent timeouts
Pool size, reuse
Large payload
High transfer/memory
Pagination, compression, streaming
9.5 Optimization priority
One change at a time, re-measure after each change:
A performance report must include baseline, bottleneck evidence, root cause, expected impact, and a verification plan.
10. Frontend verification
Only use this workflow when the issue involves the frontend: tsx, jsx, Vue, Svelte, HTML, CSS, SCSS, components, layout, DOM, responsive, animation, UI, or UX.
10.1 Detect browser capability
Prefer Chrome MCP. If unavailable, use hi-chrome-devtools. If both are unavailable, explicitly record that visual verification was skipped.
10.2 Chrome verification flow
Loading diagram…
Steps:
chrome__navigate to the local URL;
chrome__screenshot;
read the screenshot;
evaluate console errors;
click/type to test interactions;
get content to verify the DOM/text;
check responsiveness if the issue involves the viewport.
Limit to 3 cycles, then question the architecture.
Tasks are session-scoped. The diagnostic report is a persistent artifact and must be written after the investigation. If TaskCreate fails, continue with sequential debugging and record a warning; tasks increase visibility but are not core functionality.
13. Reporting standards
13.1 Principles
concise: facts and evidence, no long stories;
honest: distinguish likely cause from confirmed cause;
state unknowns;
report impact and status;
separate immediate mitigation from the permanent fix.
15. Code-level example: undefined data in the call stack
Issue:
A test fails at token creation with `userId is undefined`.
15.1 Observe
Capture:
exact stack trace;
test name;
input fixture;
command;
recent diff;
value at the token service boundary.
15.2 Pattern analysis
Find a working test that creates tokens successfully. Compare:
repository query projection;
mapper;
fixture fields;
async setup;
transaction state.
15.3 Hypothesis
Hypothesis: the new projection drops `userId`, so the mapper receives an object missing the field.
Experiment: run the mapper with the old/new projection and log the input boundary.
If the projection variant reproduces the error and the old projection passes, the hypothesis is confirmed.
15.4 Root-cause trace
Token error
-> token service reads undefined userId
-> mapper output misses required field
-> repository projection excludes userId
-> test setup introduced new projection
15.5 Implementation and verification
write a regression test for the new projection;
enforce the required field at the repository/domain boundary;
fix the projection or contract;
run old tests + new tests;
run typecheck/lint/build as scoped;
claim only after fresh output confirms it.
16. System-level example: CI passes locally but fails in the pipeline
Issue:
Local tests pass, GitHub Actions fails the integration test with a database timeout.
16.1 Initial assessment
workflow/run ID;
failing job/step;
which commit/deploy started it;
all jobs or only integration;
data/user impact if CI is blocking the release.
16.2 Data collection
gh run list --workflow=ci.yml --limit 5
gh run view <run-id> --log-failed
git log --oneline -20
git diff HEAD~5 -- '.github/**' '*.yml' '*.yaml' '*.json'
Also check:
DB service startup log;
Node/Python version;
env vars/secret names;
migration status;
connection pool;
test parallelism.
16.3 Hypotheses
Hypothesis
Experiment
CI DB not ready
Check service health and startup timing
Connection pool too small
Compare config and active connections
Migration not run
Inspect migration logs/schema
Test pollution
Run tests one-by-one, find the polluter
CI version differs from local
Compare runtime/lockfile
16.4 Solution development
immediate: add a readiness check if the service is not ready;
root cause: fix the lifecycle/config/migration contract;
prevention: health check, explicit timeout, CI log fields;
verify: rerun the failed job and local reproduction.
Do not claim "CI fixed" just because a rerun passed once if you do not understand the intermittent cause.
17. Performance example: increased API latency
Issue:
P95 of `/orders` increased from 300ms to 2s after adding a filter.
17.1 Quantify
baseline/current p50/p95/p99;
traffic and payload size;
start time;
endpoint/tenant affected;
query count/request.
17.2 Eliminate layers
Measure duration at the network, web server, application, DB, and external API. If app time is high, profile; if DB time is high, run EXPLAIN ANALYZE.
17.3 Hypothesis
The filter creates an N+1 query because each order loads its customer again.
Experiment:
count queries per request;
compare the endpoint before/after the filter;
inspect the query plan;
change one variable, measure again.
17.4 Report
The report must include baseline/current numbers, bottleneck evidence, expected impact, and the command/metric that proves the optimization.
18. Frontend example: visual regression
Issue:
The mobile layout overflows after changing the data table.
Workflow:
detect frontend scope;
start dev server;
screenshot desktop/mobile;
inspect overflow/overlap;
check console errors;
click/scroll/filter interaction;
read the DOM/rendered text;
fix the correct component/style owner;
take a new screenshot and record the path;
run tests if any.
Visual pass can only be claimed when the fresh screenshot, console output, and matching interaction evidence have all been read.
hi-debug can end at a diagnosis report if the user only needs to understand the incident or has not authorized a fix. Fixing is a later step and requires appropriate scope/approval.
20.2 The root cause may be architecture
If three fix attempts do not resolve it, the problem may be shared state, coupling, or contract architecture. Continuing to patch increases risk; ask a human partner.
20.3 Mitigation is not a permanent fix
A rollback or config change can restore the service but does not address the cause. The report must separate the status of the immediate mitigation from the permanent root-cause fix.
20.4 Partial evidence is not enough for broad claims
One passing unit test does not prove integration; one passing screenshot does not prove the backend; one passing CI rerun does not prove the flaky cause is gone.
20.5 Session tasks and persistent reports
Debug tasks can be session-scoped. The investigation report must be a persistent artifact so others can review the timeline, evidence, decisions, and unresolved risks.
21. Relationship with other skills
Loading diagram…
Skill
Relationship
hi-codebase-research-explorer
Locate files, call paths, and external context
hi-fix
Use the diagnosis to fix the root cause
hi-craft
Call hi-fix after multiple test failures or for implementation orchestration
hi-plan
Record architectural changes or follow-up plans
hi-docs-seeker
Read package/framework/API docs
hi-chrome-devtools
Browser screenshot, console, and interaction
hi-problem-solving
Reframe when the hypothesis loop is stuck
hi-log
Write the investigation/finalization log
22. Quick summary
Loading diagram…
The shortest sentence to remember:
hi-debug does not start with "which line should I fix?", but with "what evidence tells us what happened, where the root cause lies, and which command proves the conclusion?".