Iโm not on the DEV team. I donโt have an admin panel, production database access, or internal Slack. Everything I know about how DEV works comes from reading the public forem/forem repository. ๐ต๏ธโโ๏ธ
Today, that was enough to diagnose why nobody on DEV was receiving multi-commit contributor badges, ship the service fix upstream, and get a "Thank you for this" and merge from @benhalpern Sir himself. ๐

The 4x DEV Contributor Club badge: "Awarded for 4+ merged commits to Forem โ Thank you so much for your contributions!"
It also taught me a humbling lesson about tests that pass for the wrong reason. ๐งช
1. The Itch: 4 Merged PRs, 1 Badge ๐ค
Over the past few days, I went on a contribution sprint in forem/forem and merged four pull requests:
- #24003 โ Docs: fix broken Kamal TOC anchor and index missing guides
-
#24056 โ A11y: remove duplicate
aria-describedbyattributes in admin forms -
#24094 โ A11y: remove dangling
aria-describedbyreferences in creator settings -
#24095 โ Views/Liquids: quote
srcand add missingaltinuser_subscriptiontag
My 1x (dev-contributor) badge showed up right away after PR #1. โ
When PR #4 merged, I knew from config/schedule.yml that BadgeAchievements::BadgeAwardWorker runs every hour at :20 past the hour (cron: "20 * * * *"). I checked GitHubโs Contributors API (/repos/forem/forem/contributors) and confirmed my account was sitting on page 2 with contributions: 4. Because Forem sets Octokit.auto_paginate = true, the worker was definitely reaching page 2.
One hourly cron passed. Then two. Then three. Still no 4x-commit-club badge. ๐

Me at :20 past the hour, every hour, refreshing my profile like it owes me money.
Instead of refreshing my profile for another 24 hours, I cracked open app/services/badges/award_contributor_from_github.rb. ๐
2. Reading the Code Like a Detective ๐ต๏ธโโ๏ธ
Here is how Badges::AwardContributorFromGithub looked on main:
BADGE_SLUGS = {
"dev-contributor": 1,
"4x-commit-club": 4,
"8x-commit-club": 8,
"16x-commit-club": 16,
"32x-commit-club": 32
}.freeze
When I compared award_single_commit_contributors (which awarded my 1x badge) against award_multi_commit_contributors (which handles 4x, 8x, 16x, and 32x), three bugs jumped right off the screen:
๐ Problem 1: Silent Slug Drops
Each key in BADGE_SLUGS is resolved via Badge.id_for_slug(slug). If a slug in the production badges table doesn't match the hardcoded constant, id_for_slug returns nil. The service called .compact on the resulting hash and moved on. No error. No log line. Just a badge tier that quietly vanishes into the void. ๐ป
Because Forem only exposes resources :badges, only: [:index] without public /badges/:slug show routes, you can't query individual badge slugs directly. However, inspecting the public dev.to/badges catalog gave me a massive clue:
Badge #423 on
/badges:
- Title:
4x DEV Contributor Club- Description:
4x-commit-club
Waitโwhy was 4x-commit-club sitting in the description field while the title was 4x DEV Contributor Club? Because Badge#generate_slug parameterizes the title when no explicit slug is set (4x-dev-contributor-club), the stored slug column in production didn't match the hardcoded "4x-commit-club" constant at all! ๐ก

Connecting Badge#generate_slug to DOM element IDs on /badges at 9 AM with zero database access.
๐ Problem 2: Missing Context Messages
Single-commit badges were awarded with:
BadgeAchievement
.where(user_id: i.user_id, badge_id: dev_contributor_badge_id)
.first_or_create(rewarding_context_message_markdown: msg)
Multi-commit badges, however, were awarded with a bare .create:
BadgeAchievement.create(user_id: user_id, badge_id: slug_id)
Even when a multi-commit badge was created, it omitted rewarding_context_message_markdown: msg ("Thank you so much for your contributions!"). Four times the commits, zero times the thank-you note. ๐ญ
๐ Problem 3: Missing Idempotency Guard
create_badges_for_user called BadgeAchievement.create(...) on every hourly run instead of .where(...).first_or_create(...). Every hour, it re-attempted already-earned badges for every contributor on the list, relying on ActiveRecord's uniqueness validation to fail silently. Worse, if a badge ever had allow_multiple_awards: true, bare .create would insert a duplicate achievement every hourโfiring after_create_commit :notify_recipient and send_email_notification (flooding your inbox from yo@dev.to) each time. ๐ฌ๐ฅ
3. Filing the Issue & Shipping PR #24113 ๐ ๏ธ
I opened Issue #24114 laying out the slug mismatch on badge IDs 423โ426, and paired it with PR #24113 to fix the service itself:
- โ
Attached
rewarding_context_message_markdown: msgto multi-commit badge awards. - ๐ Replaced bare
BadgeAchievement.createwith.where(...).first_or_create(...). - ๐ Deferred slug lookup behind the GitHub auth provider check and added logging whenever configured slugs are missing from the database.
4. The Plot Twist in Code Review ๐ฌ
The initial deep-dive review on @benhalpern Sirโs account was posted by Forem's automated review agent (OpenHands), and it did something awesomeโit ran a read-only lookup against the badges table and confirmed my exact diagnosis from Issue #24114:
"I ran a read-only lookup on the
badgestable for the fiveBADGE_SLUGSkeys. Only one of the five slugs resolves. The fourNx-commit-clubslugs have no matching row, socreate_badges_for_userskips them and nobody can earn them today. The issue reporter's guess is correct."
Bingo. ๐ฏ
Even better, the review caught two subtle flaws in my PR that taught me more than the bug itself:
๐ข Lesson A: My Rails.logger.warn Was Log Spam
I originally logged a Rails.logger.warn inside the loop for each missing slug. Why was that bad?
- Until the production slugs were aligned, DEV would log 4
warnlines every hour. - Forem powers many independent communities. Most self-hosted Forems enable GitHub auth without seeding DEV-specific contributor badges. Five
warnlines an hour for expected configuration turnswarninto permanent background noise.
The Fix (5e36999): Collect all missing slugs and emit a single Rails.logger.info line per run. ๐งน
๐คก Lesson B: My Regression Test Passed on main (For the Wrong Reason!)
To test idempotency, I wrote a spec that ran described_class.call twice and asserted that the user still had only 1 badge achievement for 4x-commit-club.
It passed! Green dots everywhere. ๐ข
Except the review pointed out something brutal: that test also passed on origin/main without my fix.

When your shiny new regression test passes on main without your bugfix.
Why? The badge factory defaults to allow_multiple_awards: false. On main, the second BadgeAchievement.create hit validates :badge_id, uniqueness: { scope: :user_id, if: :single_award_badge? }, failed validation silently, and left the count at 1. My test wasn't testing first_or_create at allโit was testing ActiveRecord's uniqueness validator! ๐คฆโโ๏ธ
The Fix (5e36999): I updated the spec to create the badge with allow_multiple_awards: true (where bare .create genuinely inserts duplicates on main) and asserted expect { described_class.call }.not_to change(BadgeAchievement, :count) on the second run.
After I pushed 5e36999 and all 34 checks went green, @benhalpern Sir stepped in personally, dropped a comment:
That "Thank you for this" from @benhalpern Sir genuinely made my entire day! ๐ And right after that, he merged #24113 into forem:main as d1b962e (my 5th merged PR!). ๐
Shortly after, the badge email from yo@dev.to hit my inbox and the 4x DEV Contributor Club badge landed on my profileโcomplete with the "Thank you so much for your contributions!" context message my PR wired up. The code is cleaner, the PR is merged, and the green 4x circuit board is finally home. ๐
๐ก 3 Takeaways Iโd Tell Past Me
- ๐ด A regression test isn't real until you watch it fail on
main. Before you celebrate a green spec,git stashyour change and run the spec againstmain. If it still passes, you haven't written a regression testโyou've written a test that agrees with you. - ๐ชต Log levels are an operator contract.
warnmeans someone should act. If a platform supports optional data seeds, missing optional rows areinfo, notwarn. - ๐ You don't need production access to debug production. You just need the public source code, a falsifiable hypothesis, and the curiosity to follow the trail.
Your turn: Whatโs the sneakiest time one of your tests passed for the completely wrong reason? Drop it in the comments ๐



Top comments (65)
Thank you for this!
This bug has been around so long it had completely faded from everyone's consciounseness.
Thank you so much, Sir! That really means a lot. It was such an awesome rabbit hole to trace from the outside.
Also, your reply really made my day!
Always happy to support the DEV Community!
Have A Great Day!
What type of PR is this? (check all applicable)
Description
Extends the existing
ProfilePinmodel (previouslyUser-only) to also supportOrganizationas aprofile_type, reusing the polymorphic pin/unpin pattern already used on individual user profiles.ProfilePinnow validatesOrganizationas a validprofile_typeand checks that a pinned article belongs to the organization (viaorganization_id) when the profile is an Organization.OrganizationProfilePinsController(slug-scoped, reusesOrganizationAdminScopedfor authorization) handles create/destroy of organization pins. Only org admins (or site admins) can pin/unpin.stories_controller#handle_organization_indexnow loads the organization's pinned articles separately from the regular chronological feed and excludes them from it, mirroringassign_user_storiesfor users.organizations/_main_feedrenders a dedicated "Pinned" section above the regular feed when pinned posts exist, reusing the same badge/styling as the user profile pinned section.published_at.Related Tickets & Documents
QA Instructions, Screenshots, Recordings
/dashboard, open "Manage" on a post that belongs to your organization./<org-slug>) โ the post now appears in a "Pinned" card above the regular feed, and does not also appear in the regular feed below.POST /:slug/profile_pins(raisesPundit::NotAuthorizedError).UI accessibility checklist
_main_feed/single_storymarkup and existing pin badge markup)<button type="submit">form controls)CriticalandSeriousissues?Added/updated tests?
spec/models/profile_pin_spec.rb: organization pin validity, ownership check, 5-pin cap.spec/requests/organization_profile_pins_spec.rb: create/destroy as org admin, five-pin cap, rejecting pins for articles outside the org, authorization failures for member/outsider/signed-out user.spec/requests/stories_index_spec.rb: organization page renders the pinned section and does not duplicate the pinned post in the regular feed.[optional] Are there any post deployment tasks we need to perform?
None.
Ok thanks
๐ Plot twist: the bug wasn't the only thing I had to debug. My own test was wrong, too.
This started with four merged PRs and a missing badge. It turned into a dive through Forem's public code, a fix that got merged, and a code review that taught me why a passing test isn't always proof that your fix works.
Huge thanks to everyone who reviewed the PR and helped me catch what I'd missed!
Your turn: Have you ever had a test pass green while completely missing the bug it was supposed to catch? I'd love to hear that story. ๐
And Sir @francistrdev, I'd love a comment in here because I know you've contributed to forem before and skilled in ruby on rails.
Don't want to bother you, only when you're free!๐
I was wondering about this issue for a while. Thanks for fixing it!
@ben I know a lot of my PR's have been merged onto Forem and not received a badge for it, is it possible to fix that?
@dj29 Got it fixed lol
Turns out there is a use case where if you change your primary email, Forem will not detect your commits. I made it where it counts your merged prs instead of your commits. Makes it much simpler and handles that unique case.
I have another open PR to refine it, since initially I thought it didn't work. Since it works, as of today, not sure if that will be closed or merge. We will see haha
That's great Sir @francistrdev, I actually saw your issue and PR both.๐
I'm kind of taking OSS contributions on forem way too seriously!๐
1 thing though, when you commit your changes to branch, the code rabbit and open hands review triggers by itself. I maybe wrong but I didn't have to call it by asking for full review.
Again really great!
Have A Great Day!
I think the Open Hand review @ben would have to do it manually (triggering the flow to do so). Code Rabbit is given for every PR regardless lol.
You can do commands for Code Rabbit, which is nice. I notice everytime I fix a bug or a suggestion, they keep on recommending it.
Just to confirm: Code Rabbit is tied to the repo and triggers automatically based on actions.
Open Hands is more of an experimental sidecar which I trigger and have some other algorithmic triggers, but isn't bound to repo i/o as nicely as Code Rabbit, so it's kind of random at this point how it dips in and out, but I'm refining it.
Ultimately myself or Mikey or sometimes another person in the company needs to stop by for a proper final review before anything gets merged.
(Btw Francis I got your email and considering the options, really appreciate your interest in helping more)
(Oops I posted this from my testing account ๐)
โ๏ธ I concur
@ben Sir, can someone please solve this issue?

This is there since nearly 2 months and I've done countless mails and no action has been taken.
Also, somehow the MLH account now points to @star_dev

And I can't remove it! I lost 2 virtual stickers on hacktoberfest cause the DEV profile is wrongfully pointing to secondary mail.
Thanks Ben and Ben Variant :)
@ben @heyitsjem Can you resolve the issue? Still an issue to this day.
Thats so awesome! Good job!
Thanks! Have A Great Day!
Great work! Nice contribution ๐
Thanks!๐
Have A Great Day!
The most valuable lesson here is that green tests donโt always mean correct code! ๐ Testing against the original code before celebrating a fix is such a simple but powerful habit. Loved how you turned a missing badge into a real open-source contribution! ๐
Really enjoyed your perspective! It's great connecting with people who care about writing reliable code. Hope we can keep in touch and share ideas along the way!
Absolutely! Passing tests doesn't always guarantee correct code. Great insight! ๐ I'd love to stay connected, exchange ideas, and keep in touch as friends!
Congrats!!
Thanks Sir!
Have A Great Day! and sorry for late comment!๐
thank you and good day!
Same class, from the other side. I published a fix for a 422 "Invalid authenticity token" on a scripted comment POST, then tested it by posting a comment. Green. Posted a second one to be sure. Green.
Then I ran the same recipe cold, fresh cookie jar, and it 422'd. The token I'd been grabbing off the article page belonged to a different form. It only ever worked because of state left over in a warm session.
The test wasn't wrong about the fix. It was wrong about the world. Same shape as your factory default: the thing that made it green was a default I didn't know I'd chosen.
Borrowed from your takeaway: for anything auth-shaped, "it passed" usually means "it passed with the session I happened to be holding." The regression run has to start from nobody. That's the
git stashstep, just for cookies.(Token-side writeup, if the details are useful: dev.to/kaj_ilands/your-scripted-po...)
The allow_multiple_awards: true detail is what makes the regression test meaningful. It removes the uniqueness validation as a safety net, so the test can actually expose duplicate creation on a second run. Good example of testing the failure mode, not just the expected outcome
Problem 1 is the one that sticks with me: a hardcoded constant quietly depending on a slug the database generated from a title. A cheap guard for DEV's own setup would be a spec or health check asserting that every key in BADGE_SLUGS resolves through Badge.id_for_slug. Then a renamed badge title fails CI loudly instead of switching off a whole badge tier for who knows how long. Debugging production from the public repo alone, with no DB access, is a seriously good skill to show off.
Thanks!
Have A Great Day! and sorry for late comment!๐
that moment when you realize the test passes because it hits a fixture instead of the pagination edge case is a classic. green CI gives you so much false confidence until the cron actually runs against the real list and quietly drops the tail.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.