Skip to content

feat(reputation): local EWMA scoring (ADR 008 §3, §14a) (#321) - #468

Merged
thiras merged 1 commit into
mainfrom
feat/321-reputation-local-ewma
May 8, 2026
Merged

thiras merged 1 commit into
mainfrom
feat/321-reputation-local-ewma

Conversation

@thiras

@thiras thiras commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements PoC-scope local reputation scoring in crates/reputation/, which was a stub. Closes #321.

  • LocalReputation — per-peer EWMA store keyed by iroh::PublicKey, Arc-shareable, RwLock-protected
  • Outcome::{Unreachable, Corruption, Delivered{bytes, elapsed}} — sum type forecloses nonsensical signal combinations at the type level
  • LocalReputationConfig — ADR §3 defaults validated at construction (LocalReputation::new -> Result<Self, ConfigError>); rejects NaN/inf, out-of-[0,1], weights not summing to 1.0, and expected_bps == 0 so a single bad config can't NaN-poison every future score
  • #[non_exhaustive] on Outcome and LocalReputationConfig for forward-compat with Implement network reputation gossip aggregation (ReputationReport) #326 / paid delivery

Spec mapping (ADR 008)

Spec Implementation
§3 EWMA local_score = ewma(prev, sample, α=0.1) LocalReputation::fold
§3 interaction = 0.4·speed + 0.4·correctness + 0.2·reachability LocalReputation::interaction_score
§3 speed_score = min(1, actual_bps / expected_bps) (default 10 MiB/s) speed_score free fn
§8 ±0.05 per-report clamp max_delta_per_update field — wired but defaults to 1.0 (no-op) per §14a
§14a PoC scope: in-memory, no gossip, no clamping This crate
§14a.3 no persistence Honored — supersedes the issue body's data_dir line

Out of scope (deferred)

Test plan

  • cargo nextest run -p decdn-reputation — 17/17 pass
  • cargo nextest run --workspace — 509/509 pass, no regressions
  • cargo clippy --workspace --all-targets -- -D warnings — clean (anti-panic compliant: PoisonError::into_inner for lock recovery, clamp for f64 bounds, zero-elapsed guard in speed_score)
  • cargo fmt --all -- --check — clean
  • Concurrency: concurrent_record_and_score_does_not_lose_updates — 8 threads × 1000 ops, snapshot consistency + score-in-range
  • Config validation: invalid_config_rejected — NaN α, zero expected_bps, weight-sum mismatch, out-of-range initial_score
  • ADR canonical-defaults pin: default_config_matches_adr_008_section_3
  • Free-function coverage: speed_score_function_is_correct

Notes for reviewers

🤖 Generated with Claude Code

Implements per-peer EWMA reputation scoring in the previously-stub
`decdn-reputation` crate. Scope is ADR 008 §14a (PoC):

- `LocalReputation` store keyed by `iroh::PublicKey`, RwLock-shared
- `Outcome::{Unreachable, Corruption, Delivered{bytes, elapsed}}` enum
  forecloses nonsensical states (e.g. unreachable-but-delivered)
- `LocalReputationConfig` with ADR §3 defaults (α=0.1, initial=0.5,
  weights 40/40/20) validated at `LocalReputation::new`; rejects
  non-finite values, weights not summing to 1.0, zero `expected_bps`
- §8 per-report ±0.05 clamp wired but defaults to no-op (1.0) per
  §14a's "no clamping" PoC scope; production opts in via config
- 17 unit tests including default-config pinning, zero-elapsed safety,
  multi-thread concurrency, and config-validation rejects

In-memory only — persistence is intentionally not implemented per ADR
008 §14a.3, superseding the `data_dir` line in the issue body. Network
gossip aggregation deferred to #326; outcome producer wiring waits on
#317 (paid delivery handler); selection consumer waits on #380.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 7, 2026 19:17

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

Implements ADR 008 PoC-scope local reputation scoring in decdn-reputation by replacing the prior stub/gossip-oriented surface with an in-memory per-peer EWMA model keyed by iroh::PublicKey. This provides the leaf-level API that future node-side outcome producers and selection consumers can integrate without bringing in persistence or gossip aggregation yet.

Changes:

  • Added LocalReputation in-memory store with per-peer EWMA folding and thread-safe access (RwLock<HashMap<...>>).
  • Introduced Outcome (typed delivery outcome signals) and LocalReputationConfig with construction-time validation via LocalReputation::new.
  • Updated the crate root to expose the new local-scoring API and clarify PoC scope in docs.

Reviewed changes

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

File Description
crates/reputation/src/local.rs Adds the full local EWMA reputation model (config, outcome type, scoring, validation) plus comprehensive unit tests.
crates/reputation/src/lib.rs Updates crate-level docs to reflect PoC scope and re-exports the new local reputation API.

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

@codecov

codecov Bot commented May 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.71910% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/reputation/src/local.rs 99.71% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@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 local reputation scoring system for deCDN nodes according to ADR 008, using an in-memory EWMA model to evaluate peer performance based on reachability, correctness, and delivery speed. The implementation provides thread-safe score management and extensive unit tests. Feedback identifies a potential memory exhaustion issue due to the unbounded growth of the peer score map and recommends implementing an eviction strategy for inactive peers.

Comment thread crates/reputation/src/local.rs Resolved
@alpergundogdu

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

@thiras
thiras merged commit 165a1d9 into main May 8, 2026
15 checks passed
@thiras
thiras deleted the feat/321-reputation-local-ewma branch May 8, 2026 13:09
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.

Implement local reputation scoring (EWMA from delivery outcomes)

3 participants