Repository navigation
feat(cli): add decdn node doctor diagnostic subcommand (#1598) - #1910
Conversation
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…-water) Co-Authored-By: Claude Opus 4.8 <[email protected]>
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]>
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]>
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]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
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]>
There was a problem hiding this comment.
🟡 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 newnode doctorsubcommand + args (--json,--strict,--offline,--timeout-ms,--admin-url). - Implement
decdn node doctorincrates/cliwith 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 introducenix(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.
Coverage reportTotal: 82.70% (was 80.30%, ▲ +2.40%) — 74056/89548 lines
History
|
…ric parse, json ok Co-Authored-By: Claude Opus 4.8 <[email protected]>
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]>
Summary
Adds a read-only
decdn node doctorsubcommand 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%) ofcache.cache_size_mb— a config number, not real free disk — so a budget larger than the volume fills the disk and eviction never fires.doctorcompares that config ceiling against actualstatvfsfree space atcache_dirand reports it clearly.doctoris 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 / ✖ failchecklist, each finding with a one-line remediation;--jsonfor machines.resolve_config); surfaces every invariant it enforces.statvfsfree space vs the eviction high-water target (the core check);cache_dir/data_dirwritability; GC-disabled and max-blob-vs-free-disk warnings.node.secretperms/size, keystore, the 6 redb stores (presence/perms/zero-length tripwire), receipt log.rpc_url, checkschain_idmatch and contract code-presence at each configured address.AddrInUsehandling.health+ a/metricsscrape ofdecdn_cache_bytes.Exit
0unless anyFail(or anyWarnunder--strict), via aDoctorFailedsentinel that prints the report without anError:line. Flags:--json,--strict,--offline,--timeout-ms,--admin-url.Notes
nix(fs) forstatvfs. Nodecdn-cache/AWS SDK enters the binary.sanitize_err_chain, so chain transport errors are routed through it and HTTP-origin URLs are userinfo-redacted — norpc_url/credential can reach printed output. S3 credentials are never read.anvil-e2ehappy-path integration test; a daemon-sideadmin_v1_doctor_liveRPC for live S3 reachability and redb integrity under the daemon lock; astate.peerscheck.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 (pureevaluate_*classifiers cover the disk boundaries, contract-code, binding, perms, and metric-parse branches; a hermetic CLI test drivesnode doctor --offline --jsonend to end).cargo fmt --checkandcargo clippy -p decdn-cli --all-targets -- -D warningsclean.🤖 Generated with Claude Code