feat(backend): cleanup expired PlatformLinkTokens - #13022
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
WalkthroughThis PR adds a periodic cleanup job for expired ChangesPlatform Link Token Cleanup Job
Sequence Diagram(s)sequenceDiagram
participant Scheduler
participant AsyncRunner
participant DatabaseManager
participant PlatformLinkingDB
participant Database
Scheduler->>AsyncRunner: trigger cleanup_platform_link_tokens (interval)
AsyncRunner->>DatabaseManager: call cleanup_expired_platform_link_tokens()
DatabaseManager->>PlatformLinkingDB: invoke cleanup_expired_platform_link_tokens()
PlatformLinkingDB->>Database: delete expired rows older than cutoff
PlatformLinkingDB-->>DatabaseManager: return deleted_count
DatabaseManager-->>AsyncRunner: return result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## dev #13022 +/- ##
==========================================
- Coverage 70.59% 70.51% -0.09%
==========================================
Files 2193 2193
Lines 164774 164809 +35
Branches 16822 16823 +1
==========================================
- Hits 116325 116208 -117
- Misses 45093 45242 +149
- Partials 3356 3359 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Thanks for picking this up, it was on my TODO and you nailed it, I will approve 🙏 |
65e0ec0 to
864d473
Compare
|
Hi @Bentlybro / @ntindle , thanks for the approval! The PR is currently blocked by the Vercel check, which is failing with a I tried pushing an empty commit to retrigger the check, but it failed the same way on the new SHA, so it doesn’t seem fixable from my side. Could one of you please re-authorize / rerun the Vercel integration, or mark the check as non-blocking for this PR if this is a known issue? The branch is also currently showing as behind Thanks! |
|
You don't need vercel to pass for your PRs:) |
…atform-link-tokens
Got it, thanks! Branch is now up-to-date with |
c7210ba
Closes #12833. ## Why PR #12615 added `PlatformLinkToken` rows on every `/setup` and DM-link click but no cleanup job. The table grows unbounded; CodeRabbit + the autogpt-pr-reviewer bot flagged it as a should-fix follow-up. ## What - New `cleanup_expired_platform_link_tokens()` in `backend/platform_linking/db.py` — deletes rows where `expiresAt < now - 24h` (retention window keeps recently-expired rows for short-term debugging). - Exposed on `DatabaseManager` + `DatabaseManagerAsyncClient`. - Scheduler job `cleanup_platform_link_tokens` registered alongside `cleanup_oauth_tokens`, gated by a new `platform_link_token_cleanup_interval_hours` setting (default 6h, same as OAuth). ## How Mirrors the existing `cleanup_expired_oauth_tokens` pattern exactly — same delete shape, same scheduler hook, same config-driven cadence. Relies on the existing `@@index([expiresAt])` on the model. Adds two unit tests (cutoff position + zero-row case). Co-authored-by: devareddy05 <187963739+devareddy05@users.noreply.github.com>
Closes #12833.
Why
PR #12615 added
PlatformLinkTokenrows on every/setupand DM-link click but no cleanup job. The table grows unbounded; CodeRabbit + the autogpt-pr-reviewer bot flagged it as a should-fix follow-up.What
cleanup_expired_platform_link_tokens()inbackend/platform_linking/db.py— deletes rows whereexpiresAt < now - 24h(retention window keeps recently-expired rows for short-term debugging).DatabaseManager+DatabaseManagerAsyncClient.cleanup_platform_link_tokensregistered alongsidecleanup_oauth_tokens, gated by a newplatform_link_token_cleanup_interval_hourssetting (default 6h, same as OAuth).How
Mirrors the existing
cleanup_expired_oauth_tokenspattern exactly — same delete shape, same scheduler hook, same config-driven cadence. Relies on the existing@@index([expiresAt])on the model. Adds two unit tests (cutoff position + zero-row case).