0028. BullMQ job ids and analysis persistence
Source:
docs/decisions/0028-bullmq-job-ids-and-analysis-persistence.md. Generated at build time; edit the source file.
Date: 2026-11-21 Status: Accepted
Context
Section titled “Context”Task 12 adds the import-account and analyse-game queues. Importing must be idempotent, an analysis must be retryable without duplicate rows, and a game must never be enqueued before its row is committed.
Decision
Section titled “Decision”- Analyse jobs use the deterministic job id
analyse-<gameId>, so duplicate enqueues are no-ops. The plannedanalyse:<gameId>is not possible: BullMQ rejects custom ids that contain “:” (unless they have exactly three parts). handleImportAccountupserts each game withanalysisStatus: "pending"and callsenqueueAnalyseonly after that write has committed, and only for newly inserted rows. Games whose account username matches neither player are skipped and counted.handleAnalyseGamesetsanalysingon every attempt, replaces the game’smovesand marks itdone(protocol, both accuracies) in one transaction, and on any error stores afailedstatus with the message (at most 2000 characters) and rethrows so BullMQ retries. Unsupported variants and games under 2 plies becomeskippedwithout calling the engine.- Queue defaults: 3 attempts, exponential backoff starting at 5000 ms. Workers share one ioredis connection created with
maxRetriesPerRequest: null. msgpackr-extract(an optional native accelerator pulled in by BullMQ) is set tofalseinallowBuilds, so the frozen install passes.
Alternatives considered
Section titled “Alternatives considered”Encoding the job id with another separator and parsing it back (not needed, the payload carries the id); enqueueing inside the DB transaction (a worker could pick the job up before commit).
Consequences
Section titled “Consequences”A game inserted but not enqueued (crash between the two steps) stays pending until the reconciler of Task 12b re-enqueues it. Finished jobs keep their id until removed; since ADR 0029, enqueueAnalyse removes a retained completed or failed job before re-adding, so re-analysis is not swallowed.