Skip to content

refactor(config): dedup unit-interval validators and complete must_use sweep#4939

Merged
bug-ops merged 1 commit into
mainfrom
refactor/config-de-helpers-must-use
Jun 6, 2026
Merged

refactor(config): dedup unit-interval validators and complete must_use sweep#4939
bug-ops merged 1 commit into
mainfrom
refactor/config-de-helpers-must-use

Conversation

@bug-ops

@bug-ops bug-ops commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

Code-quality cleanup in zeph-config, continuing the DRY/must_use sweep from #4928/#4930/#4934. Two related P3 refactors:

#4935 — dedup unit-interval serde validators

Replaced 9 copy-pasted private deserializers with two shared generic helpers in the new crates/zeph-config/src/de_helpers.rs:

  • de_unit_open — half-open interval (0.0, 1.0]
  • de_unit_closed — closed interval [0.0, 1.0]

Both are generic over f32/f64 through a crate-private UnitFloat trait, so the same two functions serve every caller via #[serde(deserialize_with = "crate::de_helpers::...")].

Converted callers:

  • (0.0, 1.0]: embedding_guard.threshold, causal_ipi.threshold, shadow_memory.drift_threshold, the three classifier thresholds, decay_lambda, link_weight_decay_lambda
  • [0.0, 1.0]: similarity_threshold (×6 across graph.rs/hebbian.rs), admission threshold, fast_path_margin

Range and finiteness semantics are unchanged. The only behavioral delta is the error text: the inline field-name prefix (e.g. embedding_guard.threshold must be in ...) is dropped in favor of a generic message, because the toml parser already pins the offending field and value via its parse span. Validators with non-unit ranges ([0.5, 1.0], [0.0, 10.0]) or distinct multi-bound messages (importance_weight) are intentionally left untouched.

#4936 — complete the #[must_use] sweep

Added #[must_use = "validation result must be checked"] to the remaining 7 validate(&self) -> Result<(), String> methods (GatewayConfig, TrajectorySentinelConfig, UtilityScoringConfig, LearningConfig, FidelityConfig, PlanCacheConfig, ExperimentConfig). PR #4934 already annotated the other 2; this covers the rest so a validation error can never be silently discarded.

Notes

  • No public API change. de_helpers items are pub(crate); UnitFloat is crate-private.
  • Verified no workspace caller discards any of the now-must_use validate() results.

Verification

  • cargo +nightly fmt --check -p zeph-config
  • cargo clippy -p zeph-config --all-targets --all-features -- -D warnings
  • cargo nextest run -p zeph-config --all-features — 525 passed (+4 new de_helpers tests)
  • RUSTFLAGS="-D warnings" cargo check --workspace --all-targets --features desktop,ide,server,chat,pdf,scheduler --locked — clean (confirms no unused_must_use regression)
  • RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --all-features -p zeph-config + cargo test --doc -p zeph-config — clean

Closes #4935
Closes #4936

…e sweep

Replace 9 copy-pasted unit-interval serde deserializers with two shared
generic helpers in de_helpers.rs: de_unit_open for the half-open (0.0, 1.0]
interval and de_unit_closed for the closed [0.0, 1.0] interval, each generic
over f32/f64 via a crate-private UnitFloat trait. Callers reference them via
deserialize_with. Range and finiteness semantics are unchanged; the offending
field stays pinpointed by the TOML parse span.

Add #[must_use = "validation result must be checked"] to the remaining 7
validate(&self) -> Result<(), String> methods (GatewayConfig,
TrajectorySentinelConfig, UtilityScoringConfig, LearningConfig, FidelityConfig,
PlanCacheConfig, ExperimentConfig) so callers cannot silently discard the
validation error.

Closes #4935
Closes #4936
@github-actions github-actions Bot added documentation Improvements or additions to documentation rust Rust code changes refactor Code refactoring without functional changes size/L Large PR (201-500 lines) labels Jun 6, 2026
@bug-ops
bug-ops enabled auto-merge (squash) June 6, 2026 16:13
@bug-ops
bug-ops merged commit 5686e69 into main Jun 6, 2026
32 checks passed
@bug-ops
bug-ops deleted the refactor/config-de-helpers-must-use branch June 6, 2026 16:19
bug-ops added a commit that referenced this pull request Jun 7, 2026
…rkspace (#4974)

Extends the #[must_use] sweep from PR #4939 to cover all remaining
public validate-style functions that return non-() values. Annotated
15 functions across 9 crates:

- zeph-config: VigilConfig::validate, Config::validate, two entry.rs validate()
- zeph-skills: SkillRegistry::scan_loaded (body() skipped — Result already #[must_use])
- zeph-orchestration: DependencyGraph::validate, validate_verify_config
- zeph-experiments: EvalCase::validate
- zeph-common: MemoryConfig::validate
- zeph-core: QualityConfig::validate
- zeph-mcp: validate_command, validate_env
- zeph-plugins: validate_url_scheme_ephemeral
- zeph-tools: validate_sandbox_denied_domains, validate_domain_patterns

Closes #4943, #4961, #4963
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation refactor Code refactoring without functional changes rust Rust code changes size/L Large PR (201-500 lines)

Projects

None yet

1 participant