Skip to content

Fix Slack profile synchronization for HCA users - #1520

Merged
skyfallwastaken merged 1 commit into
mainfrom
fix/hca-slack-profile-sync
Aug 4, 2026
Merged

Fix Slack profile synchronization for HCA users#1520
skyfallwastaken merged 1 commit into
mainfrom
fix/hca-slack-profile-sync

Conversation

@skyfallwastaken

@skyfallwastaken skyfallwastaken commented Aug 4, 2026

Copy link
Copy Markdown
Member

Summary of the problem

Users authenticated through HCA can provide a Slack ID, but Hackatime did not adopt that ID or immediately synchronize the user's Slack profile. The existing nightly sync also processed only 100 users inline, so profile updates could remain stale for days and one failure could interfere with the sweep.

Describe your changes

  • Adopt HCA's Slack ID when the Hackatime user does not already have a Slack link and the ID is not claimed by another account
  • Enqueue an independent SlackProfileSyncJob after HCA authentication for linked users
  • Fetch Slack profile data with the shared workspace token when configured, persist username/avatar/sync time only on success, and retry Slack 429 responses with backoff honouring Retry-After
  • Convert the nightly job into a reconciliation sweep that enqueues all stale or never-synchronized linked users rather than synchronously limiting work to 100 users

Screenshots / Media

N/A

Copilot AI review requested due to automatic review settings August 4, 2026 18:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@greptile-apps

greptile-apps Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR links eligible HCA users to their Slack identities and moves profile synchronization into independent GoodJob tasks.

  • Adds per-user Slack profile synchronization with shared-token support and rate-limit backoff.
  • Enqueues profile synchronization after HCA authentication.
  • Reworks the nightly updater into a stale-user reconciliation sweep without the previous 100-user limit.
  • Adds model and job coverage for linking, token selection, API responses, retries, and reconciliation fan-out.

Confidence Score: 5/5

The PR appears safe to merge, with the changed authentication and background synchronization paths covered by focused tests.

The HCA linking logic preserves existing links and uniqueness constraints, while Slack failures avoid corrupting stored profile data and stale users remain eligible for subsequent reconciliation.

Important Files Changed

Filename Overview
app/jobs/slack_profile_sync_job.rb Introduces isolated per-user synchronization, concurrency controls, rate-limit retries, and error reporting.
app/jobs/slack_username_update_job.rb Replaces the inline 100-user update with batched fan-out for every stale linked user.
app/models/concerns/oauth_authentication.rb Safely adopts unclaimed HCA Slack IDs for existing users and schedules immediate synchronization.
app/models/concerns/slack_integration.rb Selects the shared workspace token when configured and only applies successful Slack API responses.
test/jobs/slack_profile_sync_job_test.rb Covers successful synchronization, rate limiting, API errors, and unlinked users.
test/jobs/slack_username_update_job_test.rb Covers stale-user selection and reconciliation beyond the former 100-user limit.
test/models/user_test.rb Covers HCA linking safety and shared-token preference.

Sequence Diagram

sequenceDiagram
  participant HCA as HCA Authentication
  participant User as User
  participant Sync as SlackProfileSyncJob
  participant Slack as Slack API
  participant Sweep as SlackUsernameUpdateJob

  HCA->>User: Authenticate and adopt unclaimed Slack ID
  HCA->>Sync: Enqueue linked user
  Sweep->>User: Find stale or never-synchronized users
  Sweep->>Sync: Enqueue one job per user
  Sync->>Slack: users.info with shared or personal token
  alt Successful response
    Slack-->>Sync: Profile data
    Sync->>User: Persist username, avatar, and sync time
  else HTTP 429
    Slack-->>Sync: Retry-After
    Sync->>Sync: Re-enqueue with backoff
  else Other failure
    Sync->>Sync: Report error without changing profile
  end
Loading

Reviews (1): Last reviewed commit: "Fix Slack profile synchronization for HC..." | Re-trigger Greptile

@skyfallwastaken
skyfallwastaken merged commit 9cb3121 into main Aug 4, 2026
20 checks passed
@skyfallwastaken
skyfallwastaken deleted the fix/hca-slack-profile-sync branch August 4, 2026 18:32
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