InsertChatTask and EnqueueCallTask both allocate the synthetic chat issue_number as COALESCE(MAX(issue_number) ...) + 1 in a single statement. Under READ COMMITTED the second concurrent statement computes MAX from the snapshot taken before it blocked on the CTE's SELECT ... FOR UPDATE, so both pick the same number and the second INSERT fails with SQLSTATE 23505 on tasks_org_identity_owner_repo_number_key.
Measured (independent verification of archie-core-32ae, a fresh probe against pgstore with a throwaway postgres:18): 2 goroutines on one caller, 4/20 rounds failed; two callers in one repo, 1/20 failed. Reachable from a supported configuration, not only from calls: workflow.call is explicitly allowed in parallel branches (parallelSafe), and any two chat or binding dispatches can land together. Pre-existing: the allocator is unchanged by the workflow.call key work and is shared by InsertChatTask (queries/tasks.sql) and EnqueueCallTask (queries/call_tasks.sql). The FOR UPDATE does not close it because the snapshot is fixed at statement start.
Smallest producer-side fix: allocate the number from a sequence seeded past max(issue_number) per repo (a migration plus the two queries) instead of reading MAX in the insert. A retry-on-23505 loop would paper over it at the consumer. Done when two concurrent chat enqueues in one repo both commit, and an idempotency test covers it.
Close reason
Verified: fixed in code or doc/file no longer exists (see burndown 2026-10-13)
Imported from beads archie-core-mo0x · GitHub #1563 · type bug · priority P2 · created 2026-10-08 · closed 2026-10-12
InsertChatTask and EnqueueCallTask both allocate the synthetic chat issue_number as COALESCE(MAX(issue_number) ...) + 1 in a single statement. Under READ COMMITTED the second concurrent statement computes MAX from the snapshot taken before it blocked on the CTE's SELECT ... FOR UPDATE, so both pick the same number and the second INSERT fails with SQLSTATE 23505 on tasks_org_identity_owner_repo_number_key.
Measured (independent verification of archie-core-32ae, a fresh probe against pgstore with a throwaway postgres:18): 2 goroutines on one caller, 4/20 rounds failed; two callers in one repo, 1/20 failed. Reachable from a supported configuration, not only from calls: workflow.call is explicitly allowed in parallel branches (parallelSafe), and any two chat or binding dispatches can land together. Pre-existing: the allocator is unchanged by the workflow.call key work and is shared by InsertChatTask (queries/tasks.sql) and EnqueueCallTask (queries/call_tasks.sql). The FOR UPDATE does not close it because the snapshot is fixed at statement start.
Smallest producer-side fix: allocate the number from a sequence seeded past max(issue_number) per repo (a migration plus the two queries) instead of reading MAX in the insert. A retry-on-23505 loop would paper over it at the consumer. Done when two concurrent chat enqueues in one repo both commit, and an idempotency test covers it.
### Close reason
Verified: fixed in code or doc/file no longer exists (see burndown 2026-10-13)
---
_Imported from beads `archie-core-mo0x` · GitHub #1563 · type bug · priority P2 · created 2026-10-08 · closed 2026-10-12_
sam
added the mediumbug labels 2026-10-27 13:40:27 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
InsertChatTask and EnqueueCallTask both allocate the synthetic chat issue_number as COALESCE(MAX(issue_number) ...) + 1 in a single statement. Under READ COMMITTED the second concurrent statement computes MAX from the snapshot taken before it blocked on the CTE's SELECT ... FOR UPDATE, so both pick the same number and the second INSERT fails with SQLSTATE 23505 on tasks_org_identity_owner_repo_number_key.
Measured (independent verification of archie-core-32ae, a fresh probe against pgstore with a throwaway postgres:18): 2 goroutines on one caller, 4/20 rounds failed; two callers in one repo, 1/20 failed. Reachable from a supported configuration, not only from calls: workflow.call is explicitly allowed in parallel branches (parallelSafe), and any two chat or binding dispatches can land together. Pre-existing: the allocator is unchanged by the workflow.call key work and is shared by InsertChatTask (queries/tasks.sql) and EnqueueCallTask (queries/call_tasks.sql). The FOR UPDATE does not close it because the snapshot is fixed at statement start.
Smallest producer-side fix: allocate the number from a sequence seeded past max(issue_number) per repo (a migration plus the two queries) instead of reading MAX in the insert. A retry-on-23505 loop would paper over it at the consumer. Done when two concurrent chat enqueues in one repo both commit, and an idempotency test covers it.
Close reason
Verified: fixed in code or doc/file no longer exists (see burndown 2026-10-13)
Imported from beads
archie-core-mo0x· GitHub #1563 · type bug · priority P2 · created 2026-10-08 · closed 2026-10-12