From freenet-freenet-agent-skills
Guides systematic debugging of non-trivial bugs, test failures, and unexpected behavior using hypothesis formation, parallel subagent investigation, and a scope ladder for reproducible reproduction.
How this skill is triggered — by the user, by Claude, or both
Slash command
/freenet-freenet-agent-skills:systematic-debuggingThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Invoke this methodology automatically when:
Invoke this methodology automatically when:
Always prefer the smallest, most reproducible scope that demonstrates the bug. Work up the ladder only when the smaller scope can't reproduce or doesn't apply:
| Priority | Scope | When to Use | Command |
|---|---|---|---|
| 1 | Unit test | Logic errors, algorithm bugs, single-function issues | cargo test -p freenet -- specific_test |
| 2 | Mocked unit test | Transport/ring logic needing isolation | Unit test with MockNetworkBridge / MockRing |
| 3 | Simulation test | Multi-node behavior, state machines, race conditions | cargo test -p freenet --test simulation_integration -- --test-threads=1 |
| 4 | SimNetwork + FaultConfig | Fault tolerance, message loss, network partitions | SimNetwork with configured fault injection |
| 5 | fdev single-process | Quick multi-peer CI validation | cargo run -p fdev -- test --seed 42 single-process |
| 6 | freenet-test-network | 20+ peer large-scale behavior | Docker-based freenet-test-network |
| 7 | Real network | Issues that only manifest with real UDP/NAT/latency | Manual multi-peer test across machines |
Why this order matters:
If you're working on a GitHub issue, check if it's already assigned before starting. If someone else is assigned, stop and inform the user — don't duplicate effort. If unassigned, assign it to yourself so others know it's being worked on:
gh issue view <ISSUE> --repo freenet/<REPO> # Check assignees
gh issue edit <ISSUE> --repo freenet/<REPO> --add-assignee @me
SimNetwork with FaultConfigSimulation-first approach for distributed bugs:
# Run simulation tests deterministically
cargo test -p freenet --features simulation_tests --test sim_network -- --test-threads=1
# With logging to observe event sequences
RUST_LOG=info cargo test -p freenet --features simulation_tests --test sim_network -- --nocapture --test-threads=1
# Reproduce with a specific seed
cargo run -p fdev -- test --seed 0xDEADBEEF single-process
When a bug comes from production observations (user reports, telemetry, monitoring), the goal is to translate the network observation into a local reproduction as fast as possible. Live-network debugging has the slowest feedback loop — adding telemetry, redeploying, waiting — so minimize time spent there.
The workflow:
| Network Observation | Simulation Translation |
|---|---|
| "GET times out at hop 3" | #[freenet_test] with 4+ nodes, specific node_locations matching topology |
| "Peer X never responds" | Node configured to drop/delay messages via FaultConfig |
| "73% timeout rate" | FaultConfig { message_loss_rate: 0.7, .. } or unresponsive target node |
| "Works for PUT but not GET" | Test both operations — likely incomplete wiring in dispatch path |
| "Rapid connect/disconnect cycles" | Simulation with transport-level fault injection |
| "Messages dropped after acknowledgement" | FaultConfig with selective message loss after initial handshake |
#[freenet_test] or SimNetwork + FaultConfig. Use a deterministic seed.If a telemetry-monitor skill is available (project-local, not part of this plugin), use it to query the centralized OpenTelemetry collector for constraining the problem. But treat telemetry as input to simulation design, not as the primary debugging tool.
Resist the temptation to keep adding telemetry to find the root cause. Once you know what fails (operation type, peer pattern, timing), stop analyzing network data and reproduce locally. The simulation feedback loop is orders of magnitude faster.
Before touching any code, explicitly list potential causes:
Hypotheses:
1. [Most likely] The X component isn't handling Y case
2. [Possible] Race condition between A and B
3. [Less likely] Configuration mismatch in Z
Rank by likelihood based on evidence. Avoid anchoring on the first idea.
Freenet-specific hypothesis patterns:
std::time::Instant::now() instead of TimeSource, or rand::random() instead of GlobalRngJoinHandle stored and polled? what happens if the task exits?), broadcast sent to zero targets with no warning, channel overflow silently dropping messages. Look for: tokio::spawn without .await/.abort(), let _ = sender.send(), missing logging on empty target sets_ => Irrelevant catch-alls, and missing match arms are commonSee Module-Specific Debugging Guide for detailed bug patterns, data collection strategies, and test approaches per module.
For each hypothesis:
Freenet-specific data gathering:
| What You Need | How to Get It | Access |
|---|---|---|
| Event sequences | RUST_LOG=info + --nocapture on simulation tests | Everyone |
| Network message patterns | sim.get_network_stats() in simulation tests | Everyone |
| Convergence behavior | sim.await_convergence(timeout, poll, min_contracts) | Everyone |
| Virtual time state | sim.virtual_time().now_nanos() | Everyone |
| Git history of affected code | git log --oneline -20 -- path/to/file.rs | Everyone |
| Fault injection results | SimNetwork + FaultConfig, then inspect stats | Everyone |
| Gateway logs | Access to running gateway node | Limited — not all contributors |
| Aggregate telemetry | telemetry-monitor skill (if available) or production dashboards | Limited — core team only |
| Real network packet captures | Physical access to test machines | Limited — specific environments |
Note on telemetry: If a telemetry-monitor skill is available in the project, use it to query network telemetry for constraining the problem (see Phase 1b). But remember: telemetry constrains, simulation reproduces. Don't spend cycles iterating on telemetry queries when you have enough information to write a simulation test.
Asserting on freenet-core logs from E2E tests: use structured fields,
not wire-level markers. Modern freenet-core (0.2.6x and later) emits
tracing output as structured fields — phase="update_complete",
phase="relay_started", op="GET", tx="01KK70…". Legacy
wire-level grep markers (UPDATE_PROPAGATION, OP_FORWARDED, etc.)
that older tests and tutorials reference have been removed. An E2E test
that greps for them will pass forever — the line will never appear, so
the negative assertion is vacuously true, and the test gives a false
green.
When writing or fixing an E2E log assertion against a freenet node:
RUST_LOG you'll use in CI and
read what's actually emitted around the event you care about. Don't
copy a grep pattern from an old test.phase="<value>" is the most
stable; transaction IDs (tx=) are good for following a single
op across nodes.When a test fails because of a conclusively-traced upstream bug
(e.g. a freenet-core relay timeout that has an open issue and a
recognizable signature in the logs), quarantine the path, do not
remove the test. Detect the exact upstream signature, emit a Playwright
test.skip() (or equivalent) with the issue link, and let the assertion
that would have caught the upstream bug stay in place. Genuine app-side
regressions (contract errors, deserialization, panics, wrong state
contents) still fail the gate. Removing the test, or weakening the
assertion to make it always pass, loses the regression coverage you'd
otherwise get for free the day upstream is fixed.
For module-specific data gathering techniques, see Module-Specific Debugging Guide — it covers observation APIs, #[freenet_test] event capture, RUST_LOG targets, and fault injection per module.
Parallel investigation with subagents:
Use general-purpose agents with codebase-investigator instructions for independent, readonly investigations. Spawn multiple in parallel, each with a specific focus.
Spawn investigators in parallel using Task tool (subagent_type="general-purpose"):
1. "You are a codebase-investigator. [Include agents/codebase-investigator.md instructions]
Search for similar error handling patterns in the codebase related to [bug description]"
2. "You are a codebase-investigator. [Include agents/codebase-investigator.md instructions]
Check git history for recent changes to [affected module/files]"
3. "You are a codebase-investigator. [Include agents/codebase-investigator.md instructions]
Read and analyze [test file] and related fixtures for [component]"
Guidelines:
cargo test -p freenetTimeSource and GlobalRng (not std::time / rand directly)Always ask: "Why didn't CI catch this?"
Freenet has multiple test layers:
| Layer | Scope | What It Catches |
|---|---|---|
| Unit tests (~1000) | Individual functions | Logic errors, algorithm bugs |
| Integration tests (~80) | Component interactions | Interface mismatches, data flow bugs |
| Simulation tests | Multi-node deterministic | State machine bugs, race conditions, protocol errors |
fdev single-process | Quick multi-peer | Basic distributed behavior |
freenet-test-network | 20+ peers in Docker | Scale-dependent bugs, realistic network behavior |
| Real network tests | Physical machines | NAT traversal, real latency, UDP behavior |
If a bug reached production or manual testing, there's a gap. Investigate:
Which test layer should have caught this?
#[freenet_test]Why didn't the existing tests catch it?
TimeSource/GlobalRngDocument the gap — Include in the issue/PR:
codebase-investigator agents to read A, B, C concurrently, synthesize findingsstd::time::Instant::now() or rand::random() in core logicTimeSource trait and GlobalRng so simulation tests remain reproducibleRUST_LOG that any contributor can runnpx claudepluginhub freenet/freenet-agent-skillsSystematic debugging methodology for finding and fixing bugs through root cause analysis. Covers reproduce-investigate-hypothesize-fix-prevent workflow, evidence-based diagnosis, and bug category strategies.
Enforces systematic root cause analysis for bugs, test failures, and unexpected behavior. Requires proof of root cause before any fix.
Disciplined methodology to isolate bugs through hypothesis-driven testing. Form hypotheses, test them with minimal changes, narrow scope systematically. Use when bugs are unclear or reproduce intermittently.