Skip to content

Fix community XP ranking and sync consistency#920

Merged
JoaquinBN merged 3 commits into
devfrom
JoaquinBN/discord-xp-rank-missing
Jul 11, 2026
Merged

Fix community XP ranking and sync consistency#920
JoaquinBN merged 3 commits into
devfrom
JoaquinBN/discord-xp-rank-missing

Conversation

@JoaquinBN

@JoaquinBN JoaquinBN commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Include pending social-task awards in effective community totals, rankings, participant metrics, dashboard deltas, monthly leaderboards, and earned-role eligibility.
  • Roll distributed task points into MEE6 baselines without double counting.
  • Prevent XP distribution from racing MEE6 fetch and application by sharing the sync lock and using fetch start as the snapshot boundary.

Summary by CodeRabbit

  • New Features
    • Monthly leaderboards now include social-task points alongside contribution points (with separate totals).
    • Community rankings, profiles, participant growth, and earned roles now include eligible community social-task points via updated “effective” scoring.
  • Bug Fixes
    • Strengthened XP synchronization safeguards to prevent conflicting updates, reject stale/concurrent runs, and avoid double counting when applying distributions.
    • Discord XP mutation endpoints now fail fast during active sync (409) to keep state consistent.
  • Documentation
    • Updated leaderboard/community attribution documentation to reflect the new breakdown and pending attribution mechanics.
  • Tests
    • Expanded leaderboard, participant growth, and sync/role assignment test coverage for social tasks and locking behavior.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d5c8d1aa-2071-4056-a341-7377e1981005

📥 Commits

Reviewing files that changed from the base of the PR and between ed224fc and 77d0f1b.

📒 Files selected for processing (1)
  • backend/leaderboard/tests/test_stats.py

📝 Walkthrough

Walkthrough

Community social-task completions now contribute to effective community scores, leaderboard and dashboard totals, participant growth metrics, and earned-role qualification. MEE6 synchronization validates social-task distributions and shares lock ownership across fetch, apply, and Discord XP mutations.

Changes

Social-task scoring and synchronization

Layer / File(s) Summary
Effective community scoring and role inputs
backend/community_xp/utils.py, backend/leaderboard/views.py, backend/social_connections/tests/*, backend/CLAUDE.md
Effective community totals, member selection, serialized breakdowns, and earned-role qualification now include community social-task points without double counting.
Leaderboard and dashboard aggregation
backend/leaderboard/views.py, backend/leaderboard/tests/*, backend/social_tasks/tests/*, backend/CLAUDE.md
Monthly, category, global, profile, and community leaderboard responses aggregate social-task points and expose separate contribution and social-task totals.
Community participant metrics
backend/api/metrics_views.py, backend/api/tests.py
Visible users with community social-task completions are included in participant growth from their earliest completion date.
XP synchronization locking and baseline application
backend/community_xp/services.py, backend/community_xp/views.py, backend/community_xp/tests/*, backend/contributions/views.py, backend/contributions/tests/*, backend/CLAUDE.md
MEE6 apply validates contribution and social-task distribution timestamps, propagates lock ownership, and returns conflicts for concurrent Discord XP mutations.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant SocialTaskCompletion
  participant EffectiveCommunityScores
  participant LeaderboardViewSet
  User->>SocialTaskCompletion: complete community task
  SocialTaskCompletion->>EffectiveCommunityScores: contribute awarded points
  EffectiveCommunityScores->>LeaderboardViewSet: provide effective totals
  LeaderboardViewSet->>User: return leaderboard and profile totals
Loading
sequenceDiagram
  participant SyncRequest
  participant SyncLock
  participant Mee6Sync
  participant DiscordXPState
  SyncRequest->>SyncLock: acquire owner token
  SyncRequest->>Mee6Sync: fetch and apply snapshot
  Mee6Sync->>SyncLock: refresh and validate ownership
  DiscordXPState->>SyncLock: request mutation lock
  SyncLock-->>DiscordXPState: return conflict during sync
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes to community XP ranking and synchronization consistency.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch JoaquinBN/discord-xp-rank-missing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/contributions/views.py (1)

1866-1919: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

record_copy holds the MEE6 sync lock during an uncapped Discord request.
refresh_connection_username() makes synchronous Discord calls without an explicit timeout, so a slow or hung response can keep the global lock occupied until the stale-lock window (default 3600s) and block other syncs. Since this path only updates last_copied_at/last_copied_by, scope the lock to the actual XP mutation or add a bounded timeout around the Discord refresh.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/contributions/views.py` around lines 1866 - 1919, Update record_copy
so the global lock acquired by _acquire_xp_mutation_lock is not held while
_refresh_discord_connection performs synchronous Discord requests. Move lock
acquisition to immediately before the last_copied_at/last_copied_by mutation, or
enforce a bounded timeout for the refresh, while preserving the existing atomic
update and release behavior.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@backend/contributions/views.py`:
- Around line 1866-1919: Update record_copy so the global lock acquired by
_acquire_xp_mutation_lock is not held while _refresh_discord_connection performs
synchronous Discord requests. Move lock acquisition to immediately before the
last_copied_at/last_copied_by mutation, or enforce a bounded timeout for the
refresh, while preserving the existing atomic update and release behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 60df5f3c-6f70-4903-99c3-de0ebea9d447

📥 Commits

Reviewing files that changed from the base of the PR and between fa36ffe and ed224fc.

📒 Files selected for processing (13)
  • backend/CLAUDE.md
  • backend/api/metrics_views.py
  • backend/api/tests.py
  • backend/community_xp/services.py
  • backend/community_xp/tests/test_mee6_sync.py
  • backend/community_xp/utils.py
  • backend/community_xp/views.py
  • backend/contributions/tests/test_discord_xp.py
  • backend/contributions/views.py
  • backend/leaderboard/tests/test_stats.py
  • backend/leaderboard/views.py
  • backend/social_connections/tests/test_earned_roles.py
  • backend/social_tasks/tests/test_leaderboard_integration.py

@JoaquinBN JoaquinBN merged commit dac26cb into dev Jul 11, 2026
3 checks passed
@JoaquinBN JoaquinBN deleted the JoaquinBN/discord-xp-rank-missing branch July 11, 2026 16:43
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.

1 participant