Repository navigation
docs(adr): trim PoC framing where it doesn't pull weight - #388
Merged
Merged
Conversation
Across the ADR set, PoC vs Production carve-outs accreted in three shapes: top-level diff-table sections, paired bold inline callouts, and one half-designed Production sketch. This pass walks each one and either keeps it (when the dual framing carries real explanatory weight), reframes it (when the structure is right but the labels overspecify), or drops it (when the PoC side is implementation-status disguised as design). Net: ~100 lines off across 11 files. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request refactors several Architecture Decision Records (ADRs) to remove explicit distinctions between Proof of Concept (PoC) and production implementations. It merges PoC-specific simplifications into unified protocol descriptions, updates sections on watchtower economics, reputation scoring, and account abstraction to reflect a more cohesive design, and moves certain production-only features to deferred or future work sections. I have no feedback to provide.
alpergundogdu
added a commit
that referenced
this pull request
May 5, 2026
The PoC/production split in §12 was decorative rather than load-bearing — this PR's selection module ships the full 4-tier tie-breaker that §12 listed as production-only, which is the cleanest evidence the framing isn't predicting what gets implemented. Following the trim pattern from PRs #388 and the architecture intro, drop the section so §9's tie-break spec stands as the single source of truth. What's wired vs. what's deferred remains visible in code and issue tracking. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
alpergundogdu
added a commit
that referenced
this pull request
May 5, 2026
The PoC/production split in §12 was decorative rather than load-bearing — this PR's selection module ships the full 4-tier tie-breaker that §12 listed as production-only, which is the cleanest evidence the framing isn't predicting what gets implemented. Following the trim pattern from PRs #388 and the architecture intro, drop the section so §9's tie-break spec stands as the single source of truth. What's wired vs. what's deferred remains visible in code and issue tracking. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
alpergundogdu
added a commit
that referenced
this pull request
May 11, 2026
* docs(plan): node selection algorithm (issue #322) Bite-sized TDD plan to implement ADR 001 §Node Selection Algorithm plus ADR 008 §9 four-tier tie-break (load → geo → stake → random), landing as a pure ranking module at crates/node/src/selection.rs. Stake stays Option<u64> until on-chain lookup is wired; reputation is taken as f32 per Candidate so ReputationEngine can ship later. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(selection): add Candidate / RankedCandidate types + module skeleton Skeleton for the node-selection algorithm specified in ADR 001 and ADR 008. Issue #322. * feat(selection): compute_score with reputation floor clamp Implements ADR 001's unified score formula. Reputation is clamped to a 0.1 floor so a node at 0.0 reputation scores identically to one at 0.1 (100x multiplier vs perfect reputation). Issue #322. * feat(selection): rank_candidates basic score-ascending sort No tie-breaking yet — that lands in tasks 4-7. Uses f64::total_cmp so the comparator is total even though score values are always finite. Issue #322. * feat(selection): tie-break tier 1 (lower load wins within 1% score) Adds tie-group detection on the 1% score-equivalence threshold from ADR 001 and orders tied candidates by LoadHint (bandwidth_utilization first, then active_streams). Tiers 2-4 follow. Issue #322. * feat(selection): tie-break tier 2 (geographic diversity) Refactors apply_tiebreaker into a stateful per-pick loop that prefers candidates in regions not yet emitted. Tier-1 load winners across multiple regions are now distributed before duplicates of the same region. Issue #322. * feat(selection): tie-break tier 3 (higher stake wins) Stake is Option<u64> because on-chain stake lookup is deferred (not in NodeAnnounce). When all pool candidates have stake = None the tier is a no-op and the next tier decides. Issue #322. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(selection): tie-break tier 4 (random) and complete ADR 008 §9 When all four tiers tie, picks uniformly at random from the remaining pool. The internal rank_candidates_with_rng entry point keeps tests deterministic via a seeded StdRng. Issue #322. * fix(selection): pin random seed in geo-diversity test geo_diversity_prefers_unseen_region was flaky: with three candidates fully tied by score and load, the tier-4 random tier could pick DE first, breaking the [US, DE, US] assertion ~1 in 3 runs. Switching to rank_candidates_with_rng with a fixed seed makes the path deterministic. Issue #322. * test(selection): make geo-diversity test invariant-based Replaces the seed-2 golden-output check with a loop over 32 seeds that asserts the actual invariant — WHEN the first pick is US, the second pick MUST be DE (the only unseen region). Robust to rand RNG changes and input ordering. Also adds a comment explaining why the random tier's pool.get(idx).copied().unwrap_or(0) is unreachable-None. Issue #322. * feat(selection): add top_n helper and MAX_PROVIDER_ATTEMPTS = 3 top_n(candidates, MAX_PROVIDER_ATTEMPTS) is the canonical entry point for the future cache-miss-pull caller — issue #322's 'max 3 provider attempts before returning error to caller' requirement. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(selection): scope geo tie-break tracker per tie group The emitted_regions HashSet was declared outside the outer while loop in apply_tiebreaker, so a region picked in one score tie group biased the geo tier of subsequent unrelated tie groups. ADR 008 §9 scopes tie-breaking to a single group; resetting the tracker per group fixes the leak and matches the function's doc comment. Adds a regression test using two distinct-score tie groups with overlapping regions. Issue #322. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(selection): drop intra-doc link to private rank_candidates_with_rng CI's rustdoc lint denies private_intra_doc_links: a public doc comment on rank_candidates can't link to the private rank_candidates_with_rng helper. Replace the [`...`] link with plain code formatting; the test module already uses the helper directly so no functional reference is lost. Issue #322. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(adr): drop ADR 008 §12 PoC Scope The PoC/production split in §12 was decorative rather than load-bearing — this PR's selection module ships the full 4-tier tie-breaker that §12 listed as production-only, which is the cleanest evidence the framing isn't predicting what gets implemented. Following the trim pattern from PRs #388 and the architecture intro, drop the section so §9's tie-break spec stands as the single source of truth. What's wired vs. what's deferred remains visible in code and issue tracking. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * perf(selection): use swap_remove for tie-group pick removal `pick_best_in_group` rescans the group from scratch on every iteration, so the order inside the Vec doesn't matter. swap_remove is O(1) where remove is O(K). Negligible at PoC scale but mechanical to fix. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * perf(selection): collapse pick_best_in_group to a single pool buffer Replace the load_tied / geo_pool / stake_pool intermediates with a single Vec<usize> filtered in place across the four tiers. Allocates one Vec per call regardless of group size, instead of three per call plus a clone in the geo-empty branch. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(selection): correctly group zero-score candidates in tie_group_end The previous denom <= 0.0 guard treated zero-score candidates as ungroupable: each became its own singleton tie group, so the load / geo / stake / random tiers were silently skipped between them. Replace with: a zero pivot ends the group only when the next score is strictly positive (zero is strictly better than any positive score), and zero scores tie with each other. Adds two regression tests: - zero_score_candidates_group_together_for_tie_break — two zero scores go through the load tier - zero_score_beats_positive_score — zero is not tied with positive Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(selection): apply review fixes — debug_asserts, non_exhaustive, ADR refs - Add `#[non_exhaustive]` to `Candidate` and `RankedCandidate` so future tie-break fields don't break downstream extractors. - Pair the unreachable safe fallbacks (slice bounds, pick_idx, empty group, random tier) with `debug_assert!` so invariant breaks surface in tests while release keeps the clippy-required indexing guard. - Fix Tier 3 comment: ADR 023 doesn't exist; stake-lookup wiring lives in ADR 001 §Node Registry / ADR 019. - Document why `compare_load` orders by `bandwidth_utilization` first (utilization is the primary saturation signal; `active_streams` is a coarser proxy). - Soften the ADR 008 §9 citation in `apply_tiebreaker` — §9 lists the four tiers but doesn't prescribe per-group scoping; that's this module's interpretation. - Add `some_zero_stake_beats_none_stake` test pinning the `Some(0)` vs `None` boundary (Some(0) wins because `max_stake = Some(0)` then retain drops `None` entries). Findings from /pr-review-toolkit:review-pr (5 specialist agents). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * chore(docs): remove node-selection implementation plan Plan completed; implementation lives in crates/node/src/selection.rs. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(selection): drop f32→f64 cast in compute_score, drain in apply_tiebreaker Addresses two open review threads on PR #380: - gemini: REPUTATION_FLOOR was f32 but compute_score works in f64; declaring the floor as f64 lets us promote-then-clamp in one expression and drop the intermediate `rep_clamped`. - Copilot: apply_tiebreaker cloned each tie group via `to_vec()`, copying every RankedCandidate (including its String region). Switching to `Vec::drain` moves elements out of `ranked` instead, eliminating K String clones per K-sized tie group. Also lets us drop the `start: usize` walk variable and the `.get(start..end)` ceremony required by clippy::indexing_slicing. Side effect of the f64 floor: `0.1f32` promotes to ~0.10000000149f64, slightly above the floor, so an exact-floor input no longer aliases the clamp output. The two clamp tests now compare two sub-floor inputs (0.0 and 0.01, or -0.5 and 0.01), which both clamp identically — preserves the original "clamping happens" semantic without depending on the f32→f64 promotion artifact. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(selection): add boundary + invariant tests, tighten doc-comments Round-2 review pass on PR #380 surfaced four polish items and four missing boundary tests. None block correctness; all are cheap quality wins. Doc nits: - tie_group_end: state the termination contract ("returns > start whenever start < ranked.len()") so the drain-the-front loop's progress invariant is local-to-read. - pick_best_in_group: state the order-independence INVARIANT that apply_tiebreaker's swap_remove relies on, and document the pool-index validity invariant (only shrinks via retain → every entry is a valid group index). - Tier 3 ADR ref: cite ADR 001's actual heading "Contract Interface: Node Registry" for greppability. New tests: - score_floor_value_is_zero_point_one — pins REPUTATION_FLOOR=0.1 by value (existing tests pin clamping behavior but not the floor value). - at_1_percent_boundary_counts_as_tied — covers the exact 1.0% boundary; tie_group_end uses `> TIE_THRESHOLD` so 1.0% is *inclusive*. Guards against a future change to `>=`. - three_way_zero_stake_falls_through_to_random_tier — two `Some(0)` plus one `None`; verifies tier 3 retains both `Some(0)` survivors and tier 4 picks fairly between them. Guards the `Some(0)` semantic from some_zero_stake_beats_none_stake against a one-winner short-circuit. - top_n_with_zero_returns_empty — locks the n=0 contract against a future truncate(n.max(1)). Drop #[non_exhaustive] from Candidate and RankedCandidate — the `node` crate doesn't expose a stable downstream API surface yet, and the markers were forward-looking insurance with no current consumer to protect. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(selection): clamp reputation in f32 before promoting to f64 Revert aaf9e42's REPUTATION_FLOOR f32→f64 change. The cleaner resolution to gemini's original concern is to inline the cast rather than change the constant's type: // before aaf9e42 (had intermediate var) let rep_clamped = reputation.max(REPUTATION_FLOOR); let rep = f64::from(rep_clamped); // aaf9e42 (f64 floor — promote then clamp) let rep = f64::from(reputation).max(REPUTATION_FLOOR); // now (f32 floor — clamp then promote, single line) let rep = f64::from(reputation.max(REPUTATION_FLOOR)); The aaf9e42 form had a subtle boundary surprise: f32(0.1) is not exactly representable in f32 (its true value is ~0.10000000149), and promotes to a value slightly above the f64 floor — so an exact-0.1 reputation input slipped past the clamp. That forced the two clamp-tests to compare two sub-floor inputs instead of the natural "clamped-zero == compute_score(_, _, 0.1)" assertion. Clamping in f32 (the input's domain) and promoting once at the end keeps the floor's type matching the input's, restores the natural test, and applies gemini's actual cleanup intent (one conversion, no intermediate variable). Rule of thumb: convert at the latest sensible point. Tests: - score_reputation_0_0_clamps_to_floor / score_negative_reputation_clamps_to_floor: reverted the sub-floor-vs-sub-floor workaround. - score_floor_value_is_zero_point_one: tolerance loosened from 1e-3 to 1e-2 to absorb the f32(0.1) → f64 promotion artifact (~3e-3 in score). Still catches a floor drift to 0.05 or 0.2. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]> Co-authored-by: Alper Gundogdu <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Across the ADR set, PoC vs Production carve-outs accreted in three shapes:
This pass walks each one and either keeps it (dual framing carries real explanatory weight), reframes it (structure is right but labels overspecify), or drops it (PoC side is implementation-status disguised as design). One commit, 11 files, ~100 LOC off.
Top-level scope sections
Inline
**PoC:** / **Production:**paired calloutsHalf-designed Production path
Other
Kept on purpose (dual framing earns its keep)
Test plan
Notes
🤖 Generated with Claude Code