🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

fix(pat): clear expiry-alert metadata on PAT regeneration - #1724

Merged
AmanGIT07 merged 1 commit into
mainfrom
fix/pat-regenerate-expiry-reminder
Jul 1, 2026
Merged

fix(pat): clear expiry-alert metadata on PAT regeneration#1724
AmanGIT07 merged 1 commit into
mainfrom
fix/pat-regenerate-expiry-reminder

Conversation

@AmanGIT07

@AmanGIT07 AmanGIT07 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Regenerating a PAT did not reset its expiry-alert state, so a regenerated token received no reminder for its new expiry when one had already been sent for the previous cycle.

Changes

  • Regenerate clears the expiry_reminder_sent_at and expired_notice_sent_at metadata keys in the same UPDATE, so the new expiry cycle re-sends alerts.
  • Alert-sent metadata keys are exported from the alert service (ExpiryReminderMetadataKey, ExpiredNoticeMetadataKey) and referenced by the repository queries.
  • Added TestRegenerate covering key clearing and reminder re-eligibility.

Technical Details

Keys are removed via JSONB key subtraction (metadata - 'key') in the existing Regenerate UPDATE, preserving all other metadata. The pending-alert queries keep a plain IS NULL gate.

Test Plan

  • Manual testing completed
  • Build and type checking passes
  • go test ./core/userpat/ passes; TestRegenerate (postgres repo) added — runs under Docker via the dockertest suite.

SQL Safety (if your PR touches *_repository.go or goqu.*)

  • Values flow through ? placeholders, goqu.Ex{}, or goqu.Record{} — never fmt.Sprintf or + building a query that gets executed.
  • ToSQL() callers capture and forward params (query, params, err := stmt.ToSQL(); db.…Context(ctx, …, query, params...)). Never query, _, err := ….
  • No ? placeholders inside single-quoted SQL literals in goqu.L (use make_interval(hours => ?)-style functions instead).
  • Any //nolint:forbidigo or // #nosec G20x annotation has a one-line justification on the same line that a reviewer can verify.

🤖 Generated with Claude Code

Regenerate now removes the expiry_reminder_sent_at and expired_notice_sent_at metadata keys so the new expiry cycle re-sends alerts. Previously the stale keys carried over and the cron's IS NULL gate skipped the regenerated PAT.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview, Comment Jul 1, 2026 9:13am

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 25f3814a-32c3-4583-99f8-caf6980fcde6

📥 Commits

Reviewing files that changed from the base of the PR and between 1e95e03 and 386fe63.

📒 Files selected for processing (3)
  • core/userpat/alert_service.go
  • internal/store/postgres/userpat_repository.go
  • internal/store/postgres/userpat_repository_test.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved PAT regeneration so alert history is cleared correctly and regenerated tokens become eligible for reminder processing again.
    • Fixed alert tracking to keep unrelated metadata intact while resetting only the relevant sent-status markers.
    • Updated alert handling to use consistent metadata keys, reducing the chance of missed or duplicated expiry notifications.

Walkthrough

Metadata key constants for alert-sent timestamps in the userpat alert service are renamed from unexported to exported identifiers. The postgres repository is updated to reference these exported constants, resetting alert-sent metadata during token regeneration and using parameterized keys in pending-alert queries. Tests cover the new regenerate behavior.

Changes

Exported Metadata Keys and Regenerate Reset

Layer / File(s) Summary
Export alert metadata key constants
core/userpat/alert_service.go
expiryReminderMetadataKey and expiredNoticeMetadataKey are renamed to exported ExpiryReminderMetadataKey and ExpiredNoticeMetadataKey, with import ordering adjusted and sendAlert calls updated to use the new names.
Reset alert metadata on regenerate and filter pending alerts
internal/store/postgres/userpat_repository.go
Imports core/userpat and uses its exported constants: Regenerate now removes both alert-sent metadata keys from JSONB (coalescing NULL to {}), and ListExpiryReminderPending/ListExpiredNoticePending use parameterized JSON key checks instead of hardcoded field names.
Regenerate behavior tests
internal/store/postgres/userpat_repository_test.go
Adds TestRegenerate validating that regeneration clears alert-sent metadata while preserving unrelated metadata, and that a previously alert-sent PAT becomes eligible again for expiry reminder listing after regeneration.

Estimated code review effort: 2 (Simple) | ~12 minutes

Related PRs: None identified from the provided information.

Suggested labels: postgres, userpat, bug

Suggested reviewers: None identified from the provided information.

🐰 A key once hidden, now shines out bright,
Regenerate wipes the alert's old plight,
Metadata cleared, reminders reset anew,
Tests confirm the pending queue is true.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
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.

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.

@AmanGIT07 AmanGIT07 changed the title fix(userpat): clear expiry-alert metadata on PAT regeneration fix(pat): clear expiry-alert metadata on PAT regeneration Jul 1, 2026
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 28506731718

Coverage increased (+0.1%) to 43.922%

Details

  • Coverage increased (+0.1%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (5 of 6 lines covered, 83.33%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
internal/store/postgres/userpat_repository.go 4 3 75.0%
Total (2 files) 6 5 83.33%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 37098
Covered Lines: 16294
Line Coverage: 43.92%
Coverage Strength: 12.41 hits per line

💛 - Coveralls

@AmanGIT07
AmanGIT07 enabled auto-merge (squash) July 1, 2026 09:20
@AmanGIT07
AmanGIT07 merged commit 655d4df into main Jul 1, 2026
8 checks passed
@AmanGIT07
AmanGIT07 deleted the fix/pat-regenerate-expiry-reminder branch July 1, 2026 09:31
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.

3 participants