fix(pat): clear expiry-alert metadata on PAT regeneration - #1724
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughSummary by CodeRabbit
WalkthroughMetadata 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. ChangesExported Metadata Keys and Regenerate Reset
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, 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
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 |
Coverage Report for CI Build 28506731718Coverage increased (+0.1%) to 43.922%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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
Regenerateclears theexpiry_reminder_sent_atandexpired_notice_sent_atmetadata keys in the sameUPDATE, so the new expiry cycle re-sends alerts.ExpiryReminderMetadataKey,ExpiredNoticeMetadataKey) and referenced by the repository queries.TestRegeneratecovering key clearing and reminder re-eligibility.Technical Details
Keys are removed via JSONB key subtraction (
metadata - 'key') in the existingRegenerateUPDATE, preserving all other metadata. The pending-alert queries keep a plainIS NULLgate.Test Plan
go test ./core/userpat/passes;TestRegenerate(postgres repo) added — runs under Docker via the dockertest suite.SQL Safety (if your PR touches
*_repository.goorgoqu.*)?placeholders,goqu.Ex{}, orgoqu.Record{}— neverfmt.Sprintfor+building a query that gets executed.ToSQL()callers capture and forward params (query, params, err := stmt.ToSQL(); db.…Context(ctx, …, query, params...)). Neverquery, _, err := ….?placeholders inside single-quoted SQL literals ingoqu.L(usemake_interval(hours => ?)-style functions instead).//nolint:forbidigoor// #nosec G20xannotation has a one-line justification on the same line that a reviewer can verify.🤖 Generated with Claude Code