Skip to content

fix(server): lock operator generation state transitions - #5650

Merged
thedotmack merged 4 commits into
thedotmack:mainfrom
Afloat16:afloat/20261110-server-operator-transition-locks
Nov 9, 2026
Merged

thedotmack merged 4 commits into
thedotmack:mainfrom
Afloat16:afloat/20261110-server-operator-transition-locks

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Problem

Operator retry/cancel read state without a lock and then UPDATE unconditionally. A delayed retry can reset another request's processing/completed generation, clear its lock and republish it. Cancellation can overwrite a completion that committed between check and write. Concurrent duplicate actions also duplicate queue publication/removal and lifecycle events.

Change

After existing scope authorization, reload the generation job FOR UPDATE and keep the status check plus UPDATE in one transaction. Return existing no-op/conflict outcomes from that fresh row. Publish queue and audit work after commit. Preserve the existing explicit operator retry attempt policy.

Validation

  • Regression tests fail against the unchanged upstream implementation and pass with this correction.
  • The focused native Bun test selection, root and viewer TypeScript checks, and the complete production build pass.
  • Database integration tests run against PostgreSQL 16.
  • Runtime artifacts are generated and compared against a baseline built with the same dependencies; only artifacts changed by this correction are included.
  • Native verification; final branch head: 0cc8fdf924f5589c13ea6313eb6dc8a560206fd3.

@thedotmack
thedotmack merged commit e7978b0 into thedotmack:main Nov 9, 2026
9 checks passed
@thedotmack

Copy link
Copy Markdown
Owner

Merged, thank you @Afloat16! Operator retry and cancel now check and change a generation job under a row lock in one transaction, so a late retry can't reset a job that already moved on, and a cancel can't overwrite a completion that just committed. Waiting on real lock state in the tests instead of sleeps is excellent. I merged main and dropped the generated bundles.

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