Skip to content

fix(badge): do not award a tiered badge below the tier already held - #1632

Open
rstrzelecki-inne-projekty wants to merge 1 commit into
apache:mainfrom
rstrzelecki-inne-projekty:fix/tiered-badge-no-downgrade
Open

rstrzelecki-inne-projekty wants to merge 1 commit into
apache:mainfrom
rstrzelecki-inne-projekty:fix/tiered-badge-no-downgrade

Conversation

@rstrzelecki-inne-projekty

Copy link
Copy Markdown

Problem

ReachAnswerAcceptedAmount awards every badge whose amount threshold the user has passed. For single award badges that form a ladder (each one marks a level reached), that produces two odd results:

  1. A user who already holds a higher badge of the ladder is awarded a lower one. This happens whenever an administrator grants the higher badge by hand: the moment that user's first answer is accepted, they receive the lowest badge of the ladder, congratulations dialog and all. It reads as a demotion.
  2. Crossing several thresholds at once (a batch of acceptances, an import) grants the whole ladder in one go instead of the level actually reached.

We hit the first one on a community where the ladder is a set of ranks: an account holding the rank for 80 accepted answers was awarded the rank for 1 as soon as an answer of theirs was accepted.

Change

For the single award badges behind this handler, only the highest tier reached is awarded, and only when that tier is above the one the user already holds. Multi award badges — the ones every post can earn on its own, such as the answer vote badges — keep the previous behaviour, so nothing changes for the default nice_answer / good_answer / great_answer set.

The tier picking and the "tier already held" lookup are separate helpers, so they can be tested without a database.

Tests

internal/repo/badge/badge_event_rule_test.go covers picking the highest tier reached, ignoring a tier below the one already held, not awarding the top tier twice, and the split between single and multi award badges. go test ./internal/... passes.

ReachAnswerAcceptedAmount awards every badge whose threshold the user has
passed. For single award badges that form a ladder this reads as a demotion: a
user who was granted the top badge by an administrator receives the lowest one
the moment their first answer is accepted, congratulations dialog included.
Crossing several thresholds at once grants the whole ladder in one go as well.

Single award badges behind this handler now yield only the highest tier reached,
and only when that tier is above the one the user already holds. Multi award
badges, which every post can earn on its own, are untouched.

Unit tests cover picking the tier, the tier already held, and the split between
single and multi award badges.
rstrzelecki-inne-projekty pushed a commit to rstrzelecki-inne-projekty/answer that referenced this pull request Sep 22, 2026
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

2 participants