feat(pam): automatic wallet-based tags with high_risk resweep and race-safe assignment#20
Open
marek-chmielowski-blurify wants to merge 1 commit into
Open
feat(pam): automatic wallet-based tags with high_risk resweep and race-safe assignment#20marek-chmielowski-blurify wants to merge 1 commit into
marek-chmielowski-blurify wants to merge 1 commit into
Conversation
…e-safe assignment Adds withdrawal_review (assigned on wallet.withdrawal.requested) and dormant_high_roller (daily co-occurrence sweep) tags, plus a daily high_risk resweep that removes the tag once withdrawal frequency drops below threshold. Gates all tag routes behind adminGuard, closes the concurrent-assignment race with a partial unique index, and maps domain errors to proper HTTP statuses instead of a raw 500. Fixes AppError's callers to match its actual (message, code) constructor signature.
marek-chmielowski-blurify
requested review from
agniev-a-hub,
klaudia-blazyczek-blurify and
zaxovaiko
as code owners
July 17, 2026 13:04
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
Adds two automatic wallet-based player tags (
withdrawal_review,dormant_high_roller) and a dailyhigh_riskresweep, and closes gaps found while building them: tag routes were unguarded, concurrent tag assignment could race, andAppError's callers didn't match its constructor signature.Changes
pam/tag:withdrawal_reviewtag assigned onwallet.withdrawal.requested(the attempt, before funds move);dormant_high_rollerassigned by a new daily co-occurrence sweep (inactive + holdshigh_roller); dailyhigh_riskresweep removes the tag once withdrawal frequency drops below threshold (frequency dimension only, amount dimension is never resweepable - see AGENTS.md for the AML rationale).pam/tag: all tag routes (createTag/deleteTag/listPlayerTags/listAssignableTags/assignPlayerTag/removePlayerTag) now gated byadminGuardon a newtagpermission resource (view/create/delete); domain errors mapped viamapErrorsinstead of leaking as raw 500s.pam/tagschema: partial unique index (player_tag_active_keyon(tagId, playerId) WHERE removedAt IS NULL) backing anonConflictDoNothinginsert - closes the concurrent-assignment / at-least-once-redelivery race that the app-level pre-check alone couldn't.wallet:WalletReader.getWithdrawalCountsInWindow- batched per-user withdrawal counts for thehigh_riskresweep (one query for all holders, not N).audit: subscribes to newtag.created/tag.deletedevents so tag catalog admin actions are audited.common/errors: fixedConflictError/NotFoundError/ValidationError/mapDbErrorto callAppErrorwith the correct(message, code)argument order (was(code, message), silently swapped).0002-0004for thepam/tagmodule (new tag keys, partial unique index).Acceptance criteria
withdrawal_reviewtag assigned on withdrawal request when amount crosses the configured threshold, sticky, never auto-removeddormant_high_rollertag assigned/removed by the daily sweep based on inactivity +high_rollerco-occurrencehigh_risktag auto-removed once withdrawal frequency drops back under thresholdChecklist
pnpm verifyis green (typecheck + lint + boundaries + module-shape + tests)pnpm verify:driftis green (catalog / OpenAPI not stale)/schemasubpath (no direct module imports)tenantIdand are RLS-covered - N/A, no new tables (index-only migration)