Skip to content

feat(config): aggregate all resolution problems into one error (#222) - #606

Merged
alpergundogdu merged 4 commits into
mainfrom
feat/222-aggregated-config-validation
May 20, 2026
Merged

alpergundogdu merged 4 commits into
mainfrom
feat/222-aggregated-config-validation

Conversation

@yigitdot

@yigitdot yigitdot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #222. resolve_config used to fail fast on the first problem, forcing an operator with N config mistakes through N edit/run cycles. It now threads a ConfigErrorBag through every section so a single pass reports every problem as one actionable bulleted list.

configuration has 6 problem(s):
  - identity.region: identity.region must be 2 ASCII letters (ISO 3166-1 alpha-2), got "USA"
  - blockchain.rpc_url: missing required option: --rpc-url (or blockchain.rpc_url in config file)
  - blockchain.eth_keystore: invalid eth_keystore: cannot access /tmp/keystore.json: ...
  - blockchain.payment_channel_address: invalid payment_channel_address: value "0xNOTACHECKSUM"; expected an EIP-55 checksummed ... address
  - cache.max_blob_size_mb: cache.max_blob_size_mb (500) must be strictly less than cache.cache_size_mb (100); ...
  - payment.rate_per_mb: payment.rate_per_mb must be > 0 (used in the node selection score, ADR 001); got 0

Design

  • crates/common/src/config/errors.rs (new) — ConfigErrorBag: check (static-message ensure! replacement), check_with (lazy || format!(...) for dynamic messages, restoring ensure!'s allocate-on-failure behaviour), try_with (replaces ? / .context()), has_field (cascade-suppression guards; exact-string match, not prefix), into_result (one bulleted anyhow::Error, with continuation lines of multi-line messages indented under their bullet), plus the one_section shim helper. IDENTITY_REGION / IDENTITY_DATA_DIR pub(crate) const labels make the only two cascade-guarded field strings refactor-safe (a rename can't silently disable suppression).
  • crates/common/src/config/mod.rs — every fallible section gains a *_into(&mut bag) worker; resolve_config runs all 8 sections + both cross-section checks against one shared bag, then bag.into_result()?. Public resolve_payment / resolve_observability / resolve_security (and parse_pinned_hashes) keep their anyhow::Result signatures — runtime::reload calls them — via thin one_section shims; the test-only private shims (resolve_blockchain, resolve_cache, resolve_gossip, resolve_identity, validate_port_layout, ensure_region_when_publishing_global) are gated #[cfg(test)].
  • Cascade-suppression guards — required-but-invalid fields get placeholders so later independent checks still run, with explicit suppression for: rpc_url URL-parse + scheme (skipped when missing), slash_judge zero-address (skipped on parse failure), region ↔ subscribe_global (skipped when region present-but-invalid via has_field(IDENTITY_REGION)), defaulted keystore existence (skipped on placeholder data_dir — an explicitly-set keystore path is always checked). Placeholders never escape resolve_config: bag.into_result()? short-circuits before the materialized ResolvedConfig is returned.
  • load_file_config stays fail-fast — file-not-found / TOML-parse / env-var-expansion errors cannot be accumulated against a FileConfig that never parsed; integration test asserts they are not wrapped in the aggregate header.
  • Port-collision labels are per-pair distinct (network.bind_port vs observability.metrics_port, etc.) so an operator who set all three equal sees three distinguishable bullets, not two collisions under one key.
  • Single-line resolver messages are preserved verbatim under a dotted field label, so the existing substring-based test suite is unchanged.

Review feedback addressed

  • Copilot Add devcontainer for secure Claude Code sessions #1 — lazy message build: added check_with; the 12 dynamic-message call sites format only on failure.
  • Copilot docs: Generalize architecture to content-agnostic CDN, refocus slashing on bad edges #2 — multi-line bullets: into_result indents continuation lines (with a unit test).
  • Copilot docs: convert ASCII art schemas to Mermaid diagrams #3 — allowlist labels: gossip.allowlist[<idx>] via .enumerate(), matching the cache.origins[<idx>] pattern.
  • pr-test-analyzer gaps: added intra-section accumulation tests (cache origins + gossip allowlist), cascade-guard tests (missing rpc_url emits no parse cascade; malformed slash_judge emits no zero-address cascade), a combined cross+intra exact-count test, and a config validate fail-fast boundary assertion. Strengthened the check_records_only_on_false_and_returns_cond unit test to assert exact count + absence of the unwanted message.
  • type-design-analyzer Add devcontainer for secure Claude Code sessions #1 / silent-failure Finding 3: IDENTITY_REGION / IDENTITY_DATA_DIR consts at both push and has_field sites.
  • code-reviewer suggestion 1: per-pair distinct labels in validate_port_layout_into.
  • comment-analyzer: rewrote migration-narrative phrasings to present-tense; updated the resolve_gossip doc to the drop-and-record-by-index behaviour; tightened the keystore-guard comment.
  • Self-audit cleanup: removed #222 references from production code/comments (they belong in this PR description, not the merged source); dropped the #[cfg(test)]-only is_empty method (no production consumer; into_result().is_ok() encodes the same predicate); simplified the one_section doc to name runtime::reload as the navigation target without enumerating specific shim functions.

Test plan

  • cargo nextest run -p decdn-common -p decdn-cli -p decdn-node — all green (1 skipped: bundle_create::determinism_…, a pre-existing macOS case-insensitive-FS issue confirmed identical on clean main, unrelated).
  • cargo clippy --workspace --all-targets, cargo fmt --check, cargo doc -D warnings, cargo deny — clean (verified via pre-commit hooks on every push).
  • Manual: a broken TOML with 6 simultaneous errors through decdn config validate emits all 6 at once, exit 1, with the region→subscribe_global cascade suppressed and gossip.allowlist[0] / gossip.allowlist[1] as distinct indexed bullets.

Commits

  • ea53bc3 — feat: ConfigErrorBag + *_into workers + one_section shims
  • 21c1b68 — refactor: lazy check_with, multi-line indentation, indexed allowlist labels
  • 3507615 — test: close review gaps, IDENTITY_* label consts, comment accuracy
  • 776ff73 — refactor: drop #222/migration-narrative cruft, drop unused is_empty, per-pair port-collision labels, strengthen weakened test

🤖 Generated with Claude Code

resolve_config used to fail fast on the first problem, forcing an
operator with N config mistakes through N edit/run cycles. It now
threads a ConfigErrorBag through every section so a single pass
reports every problem as a bulleted list.

- New config::errors module: ConfigErrorBag (check/try_with/
  has_field/into_result) plus one_section shim helper.
- Each fallible section gains a *_into(&mut bag) worker; the public
  resolve_payment/resolve_observability/resolve_security keep their
  anyhow::Result signatures (runtime::reload depends on them) via
  thin one_section shims, as do the test-only private shims.
- Required-but-invalid fields get placeholders so later independent
  checks still run; cascade-prone dependents are guarded (rpc_url
  scheme, slash_judge zero-addr, region/subscribe_global,
  keystore-on-placeholder-data_dir).
- load_file_config stays fail-fast (cannot validate a FileConfig
  that never parsed).
- Original message text is preserved verbatim under a dotted field
  label, so the existing substring-based test suite is unchanged.
- Adds multi-error coverage: a resolve_config unit test and a
  config validate integration test.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@yigitdot
yigitdot requested a review from Copilot May 19, 2026 15:48
@github-actions

github-actions Bot commented May 19, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 89.90% (was 89.66%, ▲ +0.24%) — 16587/18450 lines

File Coverage Lines Δ
crates/common/src/config/errors.rs 97.28% 143/147 new
crates/common/src/config/mod.rs 96.36% 4233/4393 ▲ +0.17%
History
Commit Total Δ vs base
ea53bc3 89.83% ▲ +0.16%
21c1b68 89.81% ▲ +0.13%
3507615 89.85% ▲ +0.19%
776ff73 (HEAD) 89.90% ▲ +0.24%

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a structured error accumulation mechanism for configuration validation to address issue #222. By implementing a ConfigErrorBag utility, the system now collects and reports all validation errors across various configuration sections—such as identity, blockchain, and cache—in a single pass, rather than failing on the first error encountered. The resolve_config function and its sub-resolvers have been refactored to support this aggregated reporting, and new tests ensure that multiple errors are correctly identified and reported without misleading cascades. I have no feedback to provide.

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.

Pull request overview

This PR improves operator UX during configuration resolution by accumulating all validation/resolution problems into a single aggregated error (instead of failing fast on the first issue), addressing #222.

Changes:

  • Introduces ConfigErrorBag to collect validation errors and emit one combined “configuration has N problem(s)” error.
  • Refactors config resolution to thread a shared error bag through section resolvers (*_into) and cross-section validations.
  • Adds unit/integration tests to ensure multiple independent errors are reported in one run.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
crates/common/src/config/mod.rs Refactors resolution flow to accumulate errors across sections and adds a unit test for multi-error aggregation.
crates/common/src/config/errors.rs Adds the new ConfigErrorBag + helpers (check, try_with, into_result, one_section) and unit tests.
crates/cli/tests/config_validate.rs Adds an integration test asserting config validate emits multiple problems at once.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +54 to +55
if !cond {
self.push(field, message);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 21c1b68: added a lazy check_with(field, cond, || format!(...)) and converted the 12 dynamic-message call sites to it, so formatting/allocation happens only on failure (matching the original anyhow::ensure! behaviour). Static-message sites keep check.

Comment on lines +99 to +109
let n = self.problems.len();
let bullets = self
.problems
.iter()
.map(|p| format!(" - {}: {}", p.field, p.message))
.collect::<Vec<_>>()
.join("\n");
Err(anyhow::anyhow!(
"configuration has {n} problem(s):\n{bullets}"
))
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 21c1b68: into_result now indents continuation lines (replace('\n', "\n ")) so a multi-line message stays under its bullet. Added a unit test covering it.

Comment thread crates/common/src/config/mod.rs Outdated
.transpose()?
.map(|v| {
v.iter()
.filter_map(|s| bag.try_with("gossip.allowlist", parse_node_id_hex(s)))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 21c1b68: allowlist entries are now recorded under gossip.allowlist[<idx>] (via .enumerate()), matching the cache.origins[<idx>] pattern. Verified manually — two bad entries now report as distinct gossip.allowlist[0] / gossip.allowlist[1] bullets.

- ConfigErrorBag: add lazy `check_with` (closure-built message) so the
  12 dynamic-message call sites format only on failure, restoring the
  `anyhow::ensure!` semantics this PR replaced; static-message sites
  keep `check`.
- into_result: indent continuation lines of multi-line messages so a
  wrapped message still reads as one bullet.
- resolve_gossip_into: index allowlist error labels
  (`gossip.allowlist[idx]`) for actionable, per-entry reporting,
  matching the existing `cache.origins[idx]` pattern.
- Adds errors.rs unit tests for check_with laziness and multi-line
  bullet indentation.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@yigitdot

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request implements a structured configuration validation error accumulator, ConfigErrorBag, to address issue #222. Instead of failing fast on the first configuration error, the system now collects all validation issues across different sections (identity, blockchain, cache, payment, etc.) and reports them collectively. The changes include refactoring existing resolver functions into *_into variants that accept the error bag, adding logic to suppress misleading cascade errors, and introducing comprehensive unit and integration tests to verify the aggregated error reporting. I have no feedback to provide as there were no review comments.

)

Addresses the multi-agent review of PR #606. No production control-flow
change (label constants are value-identical strings).

Tests (pr-test-analyzer Gaps A/B/C):
- resolve_cache_origins_accumulates_every_bad_entry: two malformed
  origins (idx 0, 2) both reported by index, valid idx 1 absent.
- Strengthened resolve_gossip allowlist test → accumulates every
  invalid entry by index (was the stale pre-#222 fail-fast premise).
- resolve_config_missing_rpc_url_emits_no_parse_cascade: missing
  rpc_url is the sole problem, no "is not a valid URL" cascade.
- resolve_config_malformed_slash_judge_emits_no_zero_address_cascade.
- resolve_config_aggregates_cross_and_intra_section_problems: exact
  4-count across cross + intra-section with region cascade suppressed.
- config_validate: lock the fail-fast boundary (file-load errors must
  not be wrapped in the aggregate header).

Hardening (type-design-analyzer #1 + silent-failure-hunter Finding 3):
- IDENTITY_REGION / IDENTITY_DATA_DIR consts used at both the
  producing and has_field guard sites so a rename can't silently
  disable cascade suppression.

Comments (comment-analyzer): qualified the "verbatim" claims (multi-line
messages get indented continuations), corrected the resolve_gossip doc
to the drop-and-record-by-index behaviour, and tightened the keystore
guard comment to state the defaulted-keystore skip is deliberate.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@yigitdot
yigitdot requested a review from alpergundogdu May 19, 2026 21:55
#606)

Self-audit cleanup of comment cruft and a weakly-tested invariant
introduced earlier in this PR. No production behaviour change.

errors.rs:
- Drop migration-narrative phrasings ("used to fail fast", "matches
  what ? produced before", "all current ones") and #222 issue
  references — replace with present-tense behaviour descriptions.
- Tighten one_section doc: drop the per-function enumeration that
  would rot, name runtime::reload as the navigation target.
- Remove the #[cfg(test)]-only is_empty method (no production
  consumer; into_result().is_ok() encodes the same predicate, and
  has_field covers the targeted mid-flight peek).
- Strengthen check_records_only_on_false_and_returns_cond: assert
  exact "1 problem(s):" count and the absence of the true-branch
  message, so a regression that pushed regardless of cond fails.

mod.rs:
- Drop #222 references from resolve_config and test docs.
- Per-pair distinct labels in validate_port_layout_into
  ("network.bind_port vs observability.metrics_port", etc.) so an
  operator who set all three equal sees three distinguishable
  bullets instead of two collisions under one key.
- Expand the data_dir / placeholder / has_field rationale comments
  to spell out why the placeholder never escapes resolve_config.

config_validate.rs:
- Drop the "(issue #222 boundary)" phrasing; describe the
  fail-fast/aggregate split present-tense.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@alpergundogdu
alpergundogdu merged commit a274e6d into main May 20, 2026
12 checks passed
@alpergundogdu
alpergundogdu deleted the feat/222-aggregated-config-validation branch May 20, 2026 08:45
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.

Add structured config validation pass after resolution that emits all errors at once

3 participants