Skip to content

fix: tolerate concurrent queue creation - #221

Open
obckelbley wants to merge 1 commit into
sidequestjs:masterfrom
obckelbley:codex/handle-concurrent-queue-creation
Open

obckelbley wants to merge 1 commit into
sidequestjs:masterfrom
obckelbley:codex/handle-concurrent-queue-creation

Conversation

@obckelbley

Copy link
Copy Markdown
Contributor

Summary

  • recover when another engine creates a queue between the initial lookup and insert
  • reuse the existing force-update reconciliation path after the race
  • preserve the original insertion error when no queue exists
  • add a deterministic concurrent-start regression test

Why

grantQueueConfig() currently performs getQueue() followed by createNewQueue(). Two replicas starting against a new queue can both observe that it is absent, then race on the unique queue name. One succeeds and the other fails startup with a duplicate-key error even though the desired queue now exists.

After a failed insert, this change re-reads the queue. If it now exists, the operation has reached its intended postcondition and returns (or reconciles) that row. If it does not exist, the original error is rethrown. Keeping the recovery in grantQueueConfig makes it backend-neutral rather than matching database-specific duplicate error shapes.

Validation

  • corepack yarn vitest run packages/engine/src/queue/grant-queue-config.test.ts
  • corepack yarn workspace @sidequest/engine build
  • corepack yarn lint
  • corepack yarn format:check

This branch has not been deployed

No deployments
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