Repository navigation
fix(service-queue): the database queue main loop claims with one compare-and-set write - #38820
Conversation
…te over its candidate ids Claude-Session: https://claude.ai/code/session_01QSeKYnrQ7UMtHofKQVjcH2 Co-authored-by: Claude <noreply@anthropic.com>
…ine's predicate update Claude-Session: https://claude.ai/code/session_01QSeKYnrQ7UMtHofKQVjcH2 Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYnrQ7UMtHofKQVjcH2 Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 1 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 1 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 3 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 0d061c03f325a919358bc1f9f7aceea4a87d7278 && git checkout 0d061c03f325a919358bc1f9f7aceea4a87d7278
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 47bfc944a766e245e5684c8b9f2a1e2eecd31b34 e7992991b885692f51b63d0edd1a886f9a01b4b6 && git checkout -B drift-repro 47bfc944a766e245e5684c8b9f2a1e2eecd31b34 && git merge --no-ff e7992991b885692f51b63d0edd1a886f9a01b4b6
node scripts/docs-audit/affected-docs.mjs --json 47bfc944a766e245e5684c8b9f2a1e2eecd31b34
|
…e engine-double pinned ledger Claude-Session: https://claude.ai/code/session_01QSeKYnrQ7UMtHofKQVjcH2 Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack@os-justin · os-justin · session_01QSeKYnrQ7UMtHofKQVjcH2 L1 ACCEPT · PR #38820 (#38578) · head 席位核对
|
repo:objectstack@os-justin · os-justin · session_01QSeKYnrQ7UMtHofKQVjcH2
Fixes #38578
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
packages/services/service-queue/src/db-queue-adapter.ts: the main loop's claim (claimBatch) now takes a tick's candidate rows with ONE compare-and-set write over their id set, matched onstatus: 'pending'and due as well as id, then one read of the ids this worker holds when fewer rows matched. The write core is factored out of the batch path'sclaimSetinto one private helper,claimCandidates, which both call;claimSet's behaviour is unchanged. A sole writer's lease entries are recorded for won rows only (for every candidate only when the write throws, as before on the batch path).batchSize * 3, at mostbatchSizerows are claimed per tick, and each message goes to its handler alone.job-queue-retention.test.tsand threeplugin-emailsuites) implemented only the by-id update; they now openupdatewithassertEngineUpdateDispatchand answer the predicate (multi: true) write, and the threeplugin-emailmatchers answer$in, the shapedb-queue-idle-backoff.test.tsalready carries. Fixture-only: no assertion changed..changeset/38578-db-queue-main-loop-cas.md: patch for@objectstack/service-queue.Tests
db-queue-adapter.test.ts: PR perf(service-queue): claim and settle a database queue batch with set writes #38575's CONTROL case is flipped. Two adapters over one store that read the same 5 pending per-message rows now handle each message once (it pinned each handled twice), with one claim write per adapter tick. A new case pins pacing:batchSize: 2drains 5 messages as 2, 2, 1, 0 in claim order with 3 claim writes.Ablation: drop status pending from the claim match
On-disk edit removing
status: 'pending'from theclaimCandidateswhere, restored withgit checkout HEAD(porcelain clean after):Package runs at 4700c4a (code identical to b14de17)
Before the fixture fix the new claim turned 6 service-queue and 16 plugin-email tests red (the by-id-only doubles refused the predicate write).
Acceptance notes
email-plugin.queue-delivery.test.ts,email-plugin.outbox-sweep.test.ts), mail attachment reclaim (email-plugin.attachment-storage.test.ts) and API-flow subscriptions (packages/triggers/trigger-api/src/api-trigger.test.ts; its double is its own queue stand-in, not the database adapter, so it is unaffected and green).pnpm check:engine-double-contractexit 0,node scripts/check-tenant-audit-census.mjsexit 0, and its--self-testexit 0 (29 cases pass). The service-queue census now counts 12 write call sites (was 13: the two claim writes are now one), andscripts/engine-double-contract.pinned.jsonrecords the four doubles as pinned.scripts/engine-double-contract.seams.jsonis unchanged by--write(0 seams added or lost), so it is not in the diff.Verification
db-queue-adapter.tsclaimCandidates(the where clause is the fix), thenclaimBatch, then the flipped two-adapter case indb-queue-adapter.test.ts.pnpm --filter @objectstack/service-queue exec vitest run --maxWorkers=2 src/db-queue-adapter.test.ts-> all green; deletestatus: 'pending',from theclaimCandidateswhere and re-run -> the two two-adapter cases go red (10 vs 5, 40 vs 20).dispatch-gates --commandsderived 76 families;--ranreconciled 74 run, 2 NOT-MEASURED (check:dual-build-cjs-loadsexit 3 prerequisite,check:query-options-erasurerepo-wide eslint over the foreground budget), 0 unrun; both ledger gates green at e799299 after the regeneration commit.Generated by Claude Code