Skip to content

fix(database): serialize incident creation per server#155

Merged
passcod merged 1 commit into
mainfrom
pr/incident-open-serialize
May 20, 2026
Merged

fix(database): serialize incident creation per server#155
passcod merged 1 commit into
mainfrom
pr/incident-open-serialize

Conversation

@passcod
Copy link
Copy Markdown
Member

@passcod passcod commented May 20, 2026

Summary

  • Two concurrent event pushes against different issues on the same server could each insert a fresh incident row, leaving two open incidents for one server. The per-issue `FOR UPDATE` on the issue row doesn't help — the two events lock different issue rows, so they don't conflict at the issue level, but they then race on the find-or-create in `find_or_open_incident`.
  • Take a `SELECT ... FOR UPDATE` on the root server's row at the top of `find_or_open_incident` so the find-or-create pair serializes per-server.
  • Promote the existing `incidents_open_by_server` partial index on `(server_id) WHERE closed_at IS NULL` to UNIQUE. Belt-and-braces backstop at the DB layer: even if the lock is ever bypassed, the second concurrent insert fails outright.

🤖 Generated with Claude Code

Two concurrent event pushes against different issues on the same server
could each insert a fresh incident row, leaving two open incidents for
one server. The per-issue FOR UPDATE on the issue row doesn't help —
the two events lock different issue rows.

Take a FOR UPDATE lock on the root server's row at the top of
find_or_open_incident so the find-or-create pair serializes per-server.
Belt-and-braces backstop at the DB layer: promote the existing partial
index on incidents (server_id) WHERE closed_at IS NULL to UNIQUE.
@passcod passcod added this pull request to the merge queue May 20, 2026
Merged via the queue into main with commit 96c9c89 May 20, 2026
3 checks passed
@passcod passcod deleted the pr/incident-open-serialize branch May 20, 2026 19:46
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.

1 participant