fix(user_status): make setUserStatus() idempotent for concurrent duplicate requests#59913
Open
miaulalala wants to merge 1 commit intomasterfrom
Open
fix(user_status): make setUserStatus() idempotent for concurrent duplicate requests#59913miaulalala wants to merge 1 commit intomasterfrom
miaulalala wants to merge 1 commit intomasterfrom
Conversation
…icate requests When two automated events of the same type fire simultaneously (e.g. a calendar webhook is delivered twice, or two Talk clients both trigger a call status at the same time), both requests race through setUserStatus(). The first request succeeds: it creates a backup of the user's previous status and sets the new automated status. The second request finds the backup slot already occupied (unique constraint on user_id), so backupCurrentStatus() returns false. Previously this caused setUserStatus() to return null, which the caller interpreted as a failure even though the desired status was already correctly set by the first request. Fix: after backupCurrentStatus() returns false, re-read the current active status row. If it already carries the same messageId that we were trying to set, the operation is effectively complete — return the existing status instead of null. If it carries a different messageId (a higher-priority automated status is active), we still return null to abort as before. This also covers the meeting-with-call scenario: if a calendar BUSY status is active and a Talk call starts, the call correctly overrides it via the priority shortcut path. If the calendar fires a duplicate webhook while the call is already active, the re-read finds MESSAGE_CALL ≠ MESSAGE_CALENDAR_BUSY and correctly aborts rather than overriding the ongoing call. AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Anna Larch <anna@nextcloud.com>
6597362 to
b3313cd
Compare
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
When two automated events of the same type fire simultaneously (e.g. a calendar webhook is delivered twice, or two Talk clients both trigger a call status at the same time), both requests race through setUserStatus().
The first request succeeds: it creates a backup of the user's previous status and sets the new automated status. The second request finds the backup slot already occupied (unique constraint on user_id), so backupCurrentStatus() returns false. Previously this caused setUserStatus() to return null, which the caller interpreted as a failure even though the desired status was already correctly set by the first request.
Fix: after backupCurrentStatus() returns false, re-read the current active status row. If it already carries the same messageId that we were trying to set, the operation is effectively complete — return the existing status instead of null. If it carries a different messageId (a higher-priority automated status is active), we still return null to abort as before.
This also covers the meeting-with-call scenario: if a calendar BUSY status is active and a Talk call starts, the call correctly overrides it via the priority shortcut path. If the calendar fires a duplicate webhook while the call is already active, the re-read finds MESSAGE_CALL ≠ MESSAGE_CALENDAR_BUSY and correctly aborts rather than overriding the ongoing call.
AI-Assisted-By: Claude Sonnet 4.6 noreply@anthropic.com
Checklist
3. to review, feature component)stable32)AI (if applicable)