fix(compliance): review follow-ups to #270 — re-pin the admission floor, stop a NaN crash - #273
Merged
Merged
Conversation
…onship This PR's own test_admission.py change replaced an equality assertion on DEFAULT_MIN_QUOTE_24H_VOLUME vs ScreenPolicy().min_median_daily_volume with a `<` relationship check. That relationship guard is correct and stays, but it was also the suite's only test pinning the admission floor's VALUE -- and nothing replaced that. Verified: dropping min_median_daily_volume from 1,000,000 to 200,000 (a 5x cut to the real criterion that decides which assets a money-moving tool may buy) left the whole suite green, 2741 passed / 1 skipped, `<` assertion included. Add an absolute pin alongside the `<` assertion so both are guarded: the relationship (discovery must never be stricter than the gate) and the criterion itself. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…iant, fix the incident-cluster record, and make discovery's dataclasses genuinely frozen Four independent fixes from an adversarial review of #270: - discover_candidates parsed quote_24h_volume inside a try/except but compared it outside: Decimal("NaN")/"nan"/float("nan")/"sNaN" all parse cleanly and then crash the whole sweep on `<` with decimal.InvalidOperation. Decimal("Infinity") also parses cleanly, compares fine, and would silently become a candidate. Both are now caught and counted unreadable_volume, same bucket as a value that failed to parse outright -- a NaN/Infinity venue row is exactly as uninformative as one that failed to parse. - render_discover_report derives survivor_count by subtraction (venue_product_count - excluded.total) but nothing asserted the invariant that subtraction relies on, and DiscoverReport is a public frozen dataclass constructable directly with inconsistent fields -- confirmed one such report renders "10 venue products -> -89 candidates". Added a test pinning len(candidates) + excluded.total == len(products) over a mixed product list, and clamped the subtraction so it can never go negative. - The DiscoveryPolicy comment and the regression test both misnamed the 2026-08-15 incident cluster as (ATOM, BCH, CRV, ALGO)/"all but AAVE". Measured against the venue: the cluster is ATOM, AAVE, BCH, CRV; ALGO was a separate, lower outlier at 437,712 (430,520 an hour later) -- the lowest of the five. The regression test pinned only the cluster's top value (852,133), which a future floor of 500,000 would still pass while silently re-hiding ALGO. Now pinned to ALGO's 437,712, the actual constraint; verified 500,000 fails this corrected test and would not have failed the old one. - DiscoveryResult and DiscoverReport were @DataClass(frozen=True) but held list[Candidate]: mutable in place, and unhashable regardless of the decorator. Both candidates fields are now tuple[Candidate, ...], with callers and tests updated accordingly. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Follow-ups from the independent adversarial review of #270. That PR was merged before these landed, so they come as a separate change against current
main.1. HIGH — the admission floor lost its only value pin
#270 changed the floor assertion from
DEFAULT_MIN_QUOTE_24H_VOLUME == ScreenPolicy().min_median_daily_volumeto<. The relationship guard is right and stays. But it was also the only test pinning the admission floor's value, and nothing replaced it.Verified on
mainbefore this change: editingScreenPolicy.min_median_daily_volumefrom1000000to200000— a 5× loosening of the criterion deciding which assets a money-moving tool may buy — passed all 2756 tests.This adds
test_the_admission_liquidity_floor_is_pinned_to_its_actual_valuealongside the<test. The two are not redundant: one guards the relationship (discovery must never be stricter than the gate), the other guards the criterion itself.Mutation proof on this branch:
2. MEDIUM —
NaNvolume crashedassets discoveroutrightThe parse was inside a
try, the comparison was not.Decimal("NaN")parses fine, then<raisesdecimal.InvalidOperationand takes the whole command down. Separately"Infinity"parsed and silently became a candidate.Both are now counted as
unreadable_volume, with the reasoning commented. Verified end to end:3. MEDIUM — the survivor-count identity was load-bearing but unguarded
render_discover_reportderivessurvivor_count = venue_product_count - excluded.total. Nothing asserted the underlying invariant, and an inconsistentDiscoverReportrendered nonsense (10 venue products -> -89 candidates). Adds a test pinninglen(candidates) + excluded.total == len(products), and makes the subtraction defensive.4. LOW/MEDIUM — the incident record was wrong, and the regression test pinned the wrong end
The comments described the 852,133–979,000 cluster as including ALGO. Measured against the live venue, the cluster is ATOM, AAVE, BCH, CRV; ALGO was a separate low outlier at 437,712.
Worse, the regression test pinned only
852133— the top. A future floor of 500,000 would have passed it while silently re-hiding ALGO. Re-pinned to ALGO's437712, which is what actually constrains the floor. Verified: a floor of 500,000 fails the corrected test and would not have failed the old one.5. LOW —
frozen=Truewas cosmeticDiscoveryResultandDiscoverReportwerefrozen=Truebut held a mutablelist[Candidate]— appendable and unhashable. Nowtuple[Candidate, ...].Gates
🤖 Generated with Claude Code