fix(aml): distinguish Scorechain provider failure from real high-risk hit#4207
Merged
Conversation
… hit Screening failures (provider 5xx, timeout, quota, misconfiguration) were reduced to the same boolean as a real high-risk hit and surfaced as AmlError.SCORECHAIN_HIGH_RISK, so compliance saw Scorechain hits for transactions that were never screened (no screening row, no PDF). Replace the boolean channel with a ScorechainOutcome enum (Pass/HighRisk/Unavailable) and add AmlError.SCORECHAIN_UNAVAILABLE. Both outcomes stay fail-closed (CRUCIAL -> PENDING / generic ManualCheck, no tipping-off), but the internal classification is now distinct. Closes #4205
…ilure paths A missing risk threshold makes isHighRisk throw only after the screening row and the compliance PDF have been persisted, so the blanket claim that neither exists was wrong for that path. Also drop a tautological assertion from both preparation specs.
… spec A soft wrap right after the slash rendered as "provider/ infrastructure".
Collaborator
Author
|
Took 3 review passes (conformance / logic / adversarial, each finding independently verified against the code) to reach zero findings. Pass 1 surfaced two real defects, both fixed in
Pass 2 found a markdown soft wrap that rendered as "provider/ infrastructure" (fixed in Verified locally on the final commit: |
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.
Closes #4205
Problem
screenScorechain()collapsed two very different outcomes into the sameboolean true:Both surfaced as
AmlError.SCORECHAIN_HIGH_RISK. Compliance therefore saw a "Scorechain hit" for transactions that were never screened at all — noscorechain_screeningrow, no compliance PDF. Observed in prod: a buy-crypto stuck onPending/ManualCheck/ commentScorechainHighRiskafter aScorechain POST /scoringAnalysis failed: status code 500; the manual re-trigger later returnedNoCoverage, i.e. no hit.Change
The screening gate no longer speaks in booleans. New enum
ScorechainOutcome(Pass/HighRisk/Unavailable) replaces thescorechainHighRiskboolean end to end (preparation service → entity →AmlHelperService), which also resolves the "magic boolean" anti-pattern from CONTRIBUTING.md.AmlError/ commentScorechainHighRisk(unchanged)PENDINGScorechainUnavailable(new)PENDINGPASS, never settles.catchpath can no longer emitSCORECHAIN_HIGH_RISK— structurally, not by convention.amlReasonstays the genericMANUAL_CHECKfor both, so the customer-facing story is unchanged (no tipping-off).ScorechainOutcomeError), so a future outcome cannot be forgotten.SCORECHAIN_UNAVAILABLEis added to neitherDelayResultErrornor the manual-pass white/blacklist — exactly likeSCORECHAIN_HIGH_RISKtoday. No cross-repo sync ofManualPassWhitelistErrorsis required.commentis a free-text field.Out of scope, as per the issue: fail-open behaviour, customer-facing copy, and the re-trigger endpoint (
POST /buyCrypto/:id/scorechain) are untouched.Tests
Both AML paths (buy-crypto and buy-fiat) are covered at all three layers:
Unavailable, explicitly notHighRisk;isHighRiskthrowing on a misconfigured risk threshold →Unavailable; real high-risk screen →HighRisk(+ compliance PDF on a fresh screen); disabled / no API key / unsupported chain →Pass.AmlHelperService:Unavailable→ commentScorechainUnavailable,PENDING/ManualCheck;HighRisk→ScorechainHighRiskas before.PASS, and now flipsPASS→PENDINGonUnavailableas well.Docs
docs/specs/scorechain-integration.mdupdated: the fail-closed decision now states that a provider failure classifies asScorechainUnavailable, and that a compliance PDF is only guaranteed for a successful fresh screen.