Skip to content

fix(user_status): make setUserStatus() idempotent for concurrent duplicate requests#59913

Open
miaulalala wants to merge 1 commit intomasterfrom
fix/noid/user-status-phase2b-idempotent-set-status
Open

fix(user_status): make setUserStatus() idempotent for concurrent duplicate requests#59913
miaulalala wants to merge 1 commit intomasterfrom
fix/noid/user-status-phase2b-idempotent-set-status

Conversation

@miaulalala
Copy link
Copy Markdown
Contributor

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

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@miaulalala miaulalala added this to the Nextcloud 34 milestone Apr 25, 2026
@miaulalala miaulalala self-assigned this Apr 25, 2026
@miaulalala miaulalala added the bug label Apr 25, 2026
@miaulalala miaulalala requested a review from a team as a code owner April 25, 2026 15:44
@miaulalala miaulalala requested review from ArtificialOwl, artonge, come-nc and provokateurin and removed request for a team April 25, 2026 15:44
…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>
@miaulalala miaulalala force-pushed the fix/noid/user-status-phase2b-idempotent-set-status branch from 6597362 to b3313cd Compare April 25, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant