Skip to content

feat(cli): add decdn node doctor diagnostic subcommand (#1598) - #1910

Merged
alpergundogdu merged 17 commits into
mainfrom
claude/blissful-shamir-e45b42
Sep 2, 2026
Merged

alpergundogdu merged 17 commits into
mainfrom
claude/blissful-shamir-e45b42

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Summary

Adds a read-only decdn node doctor subcommand that diagnoses node config, host state, and reachability on demand — the follow-up to #1899, which deliberately shipped no startup disk check and no disk-aware sizing, deferring diagnosis to this tool.

The motivating problem: cache LRU eviction fires at eviction_high_water_pct (90%) of cache.cache_size_mb — a config number, not real free disk — so a budget larger than the volume fills the disk and eviction never fires. doctor compares that config ceiling against actual statvfs free space at cache_dir and reports it clearly.

doctor is strictly additive to startup checks — it removes/weakens no boot-time validation — and runs both pre-boot and against a live daemon.

Checks (v1)

Grouped ✔ pass / ⚠ warn / ✖ fail checklist, each finding with a one-line remediation; --json for machines.

  • Config — runs the daemon resolver (resolve_config); surfaces every invariant it enforces.
  • Disk & cache budget — statvfs free space vs the eviction high-water target (the core check); cache_dir/data_dir writability; GC-disabled and max-blob-vs-free-disk warnings.
  • State (read-only, never generates/writes) — node.secret perms/size, keystore, the 6 redb stores (presence/perms/zero-length tripwire), receipt log.
  • Chain — dials rpc_url, checks chain_id match and contract code-presence at each configured address.
  • Origins — HTTP HEAD reachability, fs stat; S3 config-shape only (keeps the binary AWS-free, CLI binary-split regression: publisher links cache crate (iroh-blobs/AWS SDK) #578).
  • Ports — UDP/TCP bindability, daemon-aware AddrInUse handling.
  • Live enrichment (when a daemon is reachable) — admin health + a /metrics scrape of decdn_cache_bytes.

Exit 0 unless any Fail (or any Warn under --strict), via a DoctorFailed sentinel that prints the report without an Error: line. Flags: --json, --strict, --offline, --timeout-ms, --admin-url.

Notes

  • Only new normal dependency: nix (fs) for statvfs. No decdn-cache/AWS SDK enters the binary.
  • Security: the report prints without sanitize_err_chain, so chain transport errors are routed through it and HTTP-origin URLs are userinfo-redacted — no rpc_url/credential can reach printed output. S3 credentials are never read.
  • Deferred to a follow-up: an anvil-e2e happy-path integration test; a daemon-side admin_v1_doctor_live RPC for live S3 reachability and redb integrity under the daemon lock; a state.peers check.
  • Statvfs block counts use u64::from (u32→u64 widening on macOS; identity on Linux, where a scoped #[allow(clippy::useless_conversion)] covers it) — first Linux CI run confirms.

Testing

cargo nextest run -p decdn-cli — 475/475 pass (pure evaluate_* classifiers cover the disk boundaries, contract-code, binding, perms, and metric-parse branches; a hermetic CLI test drives node doctor --offline --json end to end). cargo fmt --check and cargo clippy -p decdn-cli --all-targets -- -D warnings clean.

🤖 Generated with Claude Code

alpergundogdu and others added 14 commits September 2, 2026 12:13
fsblkcnt_t is u32 on macOS (u64::from is a real widening) but u64 on
64-bit Linux glibc (identity conversion), so `u64::from(stat.blocks())`
trips clippy::useless_conversion on Linux CI while staying silent on
macOS. Add a narrowly-scoped allow with a one-line justification on
each conversion; keep u64::from over `as u64` per prior guidance.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
- Fix keystore finding to distinguish file vs non-file (Warn if exists but not regular file)
- Add receipt log check using decdn_common::config::RECEIPT_LOG_FILE constant
- Add tests for receipt log absent and present scenarios

Co-Authored-By: Claude Opus 4.8 <[email protected]>
RPC and get_code_at errors on the unreachable/DNS/TLS failure path embed
reqwest's Display, which includes the request URL (and any API key in its
path/query) verbatim. The doctor report is printed directly, not through
sanitize_err_chain, so route both error sites through it before building
the Finding detail.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Extract pure evaluate_redb/evaluate_receipts/evaluate_keystore helpers
out of check_state (mirroring evaluate_secret) and unit-test their
branches directly. Make probe_live push a Pass "live checks skipped"
Finding when admin_url resolution or client construction fails, matching
the existing client.health()-failure Pass path. Drop the unused _dir
param from the config.rs test helper. Note in report.rs that JSON `ok`
tracks Fail-count only, not --strict.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 2, 2026 14:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new doctor reporting has correctness/API issues (notably state-file metadata error handling and JSON ok semantics under --strict) that can mislead operators and machine consumers.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds a new read-only decdn node doctor diagnostic command to the CLI, intended to help operators validate node configuration and environment (disk/cache budget, on-disk state, reachability, and optional live-daemon enrichment) without weakening existing startup checks.

Changes:

  • Extend the shared CLI surface (decdn_common::cli) with a new node doctor subcommand + args (--json, --strict, --offline, --timeout-ms, --admin-url).
  • Implement decdn node doctor in crates/cli with grouped checks (config resolution, disk/budget, state, chain, origins, ports, and best-effort live enrichment) and human/JSON report rendering.
  • Add CLI-level integration coverage for node doctor --offline --json, and introduce nix (statvfs) to read real free disk.
File summaries
File Description
crates/common/src/cli/node.rs Adds NodeCommand::Doctor and defines DoctorArgs flags shared by CLI consumers.
crates/common/src/cli/mod.rs Re-exports DoctorArgs so the CLI crate can dispatch the new command.
crates/cli/tests/doctor_cli.rs Adds an end-to-end integration test for offline JSON report shape and exit semantics.
crates/cli/src/main.rs Special-cases DoctorFailed to exit nonzero without printing an Error: line.
crates/cli/src/commands/node.rs Dispatches node doctor and exposes resolve_admin_url for reuse by doctor live probing.
crates/cli/src/commands/mod.rs Registers the new doctor commands module.
crates/cli/src/commands/doctor/mod.rs Implements the orchestration, report model, and DoctorFailed sentinel for exit mapping.
crates/cli/src/commands/doctor/config.rs Adds the “Config” group that runs resolve_config and records its aggregated outcome.
crates/cli/src/commands/doctor/disk.rs Adds “Disk & cache” checks including statvfs-based free-space vs cache-budget evaluation and writability probes.
crates/cli/src/commands/doctor/state.rs Adds “State” checks for node.secret, keystore presence, redb store tripwires, and receipt log shape.
crates/cli/src/commands/doctor/chain.rs Adds “Chain” checks for RPC reachability, chain-id match, and code presence at configured contract addresses.
crates/cli/src/commands/doctor/origin.rs Adds “Origins” checks: HTTP HEAD probes, fs origin stat checks, and S3 shape-only validation.
crates/cli/src/commands/doctor/ports.rs Adds “Ports” checks for UDP/TCP bindability with daemon-aware AddrInUse handling.
crates/cli/src/commands/doctor/live.rs Adds “Live” enrichment: admin health probe and best-effort metrics scrape for decdn_cache_bytes.
crates/cli/src/commands/doctor/report.rs Adds human checklist + JSON rendering for the doctor report.
crates/cli/Cargo.toml Adds nix dependency (fs/statvfs) required for real disk free-space measurement.
Cargo.lock Locks the new nix dependency for the CLI crate.
Review details
  • Files reviewed: 16/17 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/cli/src/commands/doctor/state.rs Resolved
Comment thread crates/cli/src/commands/doctor/live.rs Resolved
Comment thread crates/cli/src/commands/doctor/state.rs Resolved
@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 82.70% (was 80.30%, ▲ +2.40%) — 74056/89548 lines

File Coverage Lines Δ
crates/cli/src/commands/doctor/chain.rs 29.37% 37/126 new
crates/cli/src/commands/doctor/config.rs 77.27% 34/44 new
crates/cli/src/commands/doctor/disk.rs 76.63% 141/184 new
crates/cli/src/commands/doctor/live.rs 32.58% 43/132 new
crates/cli/src/commands/doctor/mod.rs 87.80% 72/82 new
crates/cli/src/commands/doctor/origin.rs 22.09% 19/86 new
crates/cli/src/commands/doctor/ports.rs 62.79% 54/86 new
crates/cli/src/commands/doctor/report.rs 94.95% 94/99 new
crates/cli/src/commands/doctor/state.rs 95.43% 418/438 new
crates/cli/src/commands/node.rs 77.79% 1110/1427 ▲ +1.38%
crates/cli/src/main.rs 72.00% 36/50 ▲ +4.50%
crates/common/src/cli/mod.rs 100.00% 3/3 ● 0.00%
crates/common/src/cli/node.rs 100.00% 5/5 ● 0.00%
History
Commit Total Δ vs base
ea88009 82.67% ▼ 0.17%
919e551 (HEAD) 82.70% ▲ +2.40%

alpergundogdu and others added 3 commits September 2, 2026 15:41
Merge of main brought #1901's tightened lint posture (missing_docs,
unreachable_pub); the doctor submodules are private, so their items are
crate-internal, not public API.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu
alpergundogdu merged commit f9e4152 into main Sep 2, 2026
27 checks passed
@alpergundogdu
alpergundogdu deleted the claude/blissful-shamir-e45b42 branch September 2, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants