Skip to content

Make revoke_seat idempotent to prevent duplicate seat-revoked webhooks#13237

Open
pieterbeulque with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-revoke-seat-duplicate-webhooks
Open

Make revoke_seat idempotent to prevent duplicate seat-revoked webhooks#13237
pieterbeulque with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-revoke-seat-duplicate-webhooks

Conversation

Copilot AI commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

SeatService.revoke_seat was not idempotent: re-revoking an already revoked seat emitted duplicate customer_seat_revoked webhooks and overwrote revoked_at. This change makes repeated revocation calls a no-op for already revoked seats and adds regression coverage for that contract.

What

  • Service behavior
    • Added an early return in revoke_seat when seat.is_revoked() is true.
  • Regression test
    • Added a focused service test that calls revoke_seat twice on the same seat and asserts:
      • webhook is sent only once
      • revoked_at remains the original value

Why

Single-seat revoke can be called repeatedly (including via endpoint retries), so revocation must be idempotent. Without this guard, downstream webhook consumers receive duplicate events and seat audit timing becomes incorrect.

How

Use a guard before any side effects in revoke_seat:

async def revoke_seat(self, session: AsyncSession, seat: CustomerSeat) -> CustomerSeat:
    if seat.is_revoked():
        return seat
    ...

This prevents duplicate webhook emission and preserves the original revocation timestamp on subsequent calls.

Checklist

  • This PR addresses a single concern (one bug fix, one feature, one refactor)
  • The diff is reasonably sized and easy to review
  • New functionality is covered by tests
  • Linting and type checking pass (uv run task lint && uv run task lint_types)
  • No unrelated changes or drive-by fixes are included

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
orbit Ready Ready Preview, Comment Jul 17, 2026 7:48am
polar Ready Ready Preview, Comment Jul 17, 2026 7:48am
polar-sandbox Ready Ready Preview, Comment Jul 17, 2026 7:48am
polar-test Ready Ready Preview, Comment Jul 17, 2026 7:48am

Request Review

Co-authored-by: pieterbeulque <144075+pieterbeulque@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix duplicate webhooks and timestamp overwrite in revoke_seat Make revoke_seat idempotent to prevent duplicate seat-revoked webhooks Jul 17, 2026
Copilot AI requested a review from pieterbeulque July 17, 2026 07:45
@pieterbeulque
pieterbeulque marked this pull request as ready for review July 17, 2026 08:02
@github-actions

Copy link
Copy Markdown
Contributor

OpenAPI Changes

No changes detected in the OpenAPI schema.

@pieterbeulque
pieterbeulque enabled auto-merge July 17, 2026 08:22
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.

2 participants