Repository navigation
Conversation
saveTeamReminder and setTeamReminderWebhook found the team's rule and created one when there was none, as two steps, so a double submit or two admins saving for the first time could create two rules. Both sent, and the page only edits the oldest. A unique index on the team would stop a team from ever having more rules, so each save now upserts a ReminderRuleLock for the team first, in the same transaction as the find and the create or update. Concurrent first saves conflict, and the retries, spaced by a short random wait, update the rule the winner created. The lock goes with the team. A team that doesn't exist is refused. Closes Team6083#147 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kennhung
reviewed
Nov 15, 2026
kennhung
left a comment
Member
There was a problem hiding this comment.
Looks good to me. The lock plus transaction matches the ClockInLock pattern, and the reasons for not using a unique index make sense. One nit inline. This does not clean up duplicate rules that already exist; that seems fine for this PR.
This PR, #151 and #152 all touch team-reminder-dto.ts and its test, so whichever merges later will need a conflict resolution. Suggested order: #150, #152, #151.
| }); | ||
|
|
||
| it("ends with one rule when another first save for the team wins, updating that rule", async () => { | ||
| db.rules = []; |
Member
There was a problem hiding this comment.
Nit: this db.rules = []; is redundant, the loop resets it on the next line.
This was referenced Nov 15, 2026
Open
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
saveTeamReminderandsetTeamReminderWebhookfound the team's rule and created one when there was none, as two steps. A double submit, or two admins saving for the first time, could create two rules for one team: both send, and the admin page only edits the oldest, so the second can't be changed or turned off (#147).(teamId, kind, channel)would also stop a team from ever having a second rule of the same kind, whichReminderRulewas designed to allow. So this takes the second option from the issue, the same pattern asClockInLock.ReminderRuleLockmodel, one row per team (teamIdunique,onDelete: Cascade), so deleting a team deletes it.Closes #147.
Evidence
Simultaneous first saves for a new team against a local MongoDB replica set: 4
saveTeamReminderand 2setTeamReminderWebhookat once, 3 runs.New tests: a first save that loses to another (P2034 and P2002) updates the winner's rule and leaves one, and a missing team is refused.
tsc --noEmitand ESLint on the changed files pass.Merge danger
Door: two-way. Two functions and one new collection.
Blast radius: saving a team's reminder settings or webhook.
npx prisma db pushwhen deploying so theReminderRuleLockcollection and its unique index exist.🤖 Generated with Claude Code