Skip to content

fix(platform): queue a comment's retry on the audit chain it ends on - #3980

Merged
yannickmonney merged 1 commit into
mainfrom
fix/task-comment-retry-audit-queue
Sep 30, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
fix/task-comment-retry-audit-queue

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

Summary

A burst of comment writes across one organization's tasks could lose a comment: its writer ran out of its five serializable attempts and failed with 40001. I found this while running the whole backend:integration suite for TALE-382. The tasks: a burst of serializable commenters across one org's tasks all land check was red or flaky on main.

Root cause. A comment write can fail before its audit append, on a read/write dependency with the org's other comment writes. Postgres reports these as Canceled on identification as a pivot wherever it finds one. Such a failure carried only the task's retry-queue key, so the retry queued on the task alone and then lost a second time at the org's audit-chain head, a write-write conflict. A writer could spend three attempts or more. Only a loss at the head carried both keys.

Change. addTaskComment and deleteTaskComment now go through queuedCommentWrite. It marks a serialization failure anywhere in the write with the chain head's key too (auditChainQueueKey). The retry then takes both session locks before its snapshot and wastes at most one attempt, which is what the lane and the queue's own doc claim. Refusals and other errors pass through unmarked.

Checklist

  • bun run check passes — N/A locally: the sandbox's 4 GiB cap cannot hold the platform-wide gates. The changed files and their importers were checked as listed under Test plan, and CI runs the full gate.
  • bun run lint:sast passes — the pre-commit hook ran Opengrep on the staged files; CI's Opengrep job runs it in full.
  • Translations — N/A: no user-visible string.
  • Docs in docs/{en,de,fr}/ — N/A: no user-visible change.
  • README.md — N/A.

Test plan

  • Probe: real PG 16.13 with pg_search 0.22.6 and pgvector 0.8.1; 12 concurrent commenters on 12 tasks of one fresh organization per round, logging every failed attempt's SQLSTATE and queue keys.
    • Before: round 1 took 33 attempts and 1 comment was rejected. Several first attempts were aborted as SSI pivots, carrying [task-comment] only, and their retries then lost again at audit_chain_heads.
    • After: 23 attempts in each of 6 rounds, 0 rejected, and no retry carried the task key alone.
  • ITEST_LANES=checkTaskCommentBurst,checkTaskCommentCrossTaskBurst:
    • Before: landed=11/12 rejected=1 (could not serialize access due to read/write dependencies among transactions) attempts=27.
    • After: 12/12 landed, attempts=23, both lanes pass.
  • Unit: backend/domains/tasks/comments.queue.test.ts has 3 new cases: an add loss and a delete loss both carry [task, chain], and a refusal stays unmarked. The two marking cases fail on main's comments.ts.
  • Local checks:
    • vitest --project server over the 19 files that import the module: 253 tests pass.
    • A scoped tsc over the changed files: clean.
    • oxlint --type-aware and oxfmt --check: clean.

A comment write that lost before its audit append, on a read/write
dependency with the org's other comment writes, carried the task's
queue key alone. Its retry then lost again at the org's audit chain
head. A burst of commenters across one org's tasks spent up to three
attempts a writer, and now and then one ran out of attempts and the
comment failed.

Adding and deleting a comment now mark a serialization failure with
the chain head's key as well, so the retry holds both queues from
before its snapshot and wastes at most one attempt.
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent review at 417b8136371c6556b7e927caea235017058ff3b8 accepts the narrow source change: both add/delete statement failures tagged 40001 or 40P01 carry the task and organization audit-chain queue keys, while ordinary refusals pass through unchanged. Sixteen focused local tests pass; the parent implementation fails exactly the two new marking regressions. The completed normal CI has all five workflows successful; the affected platform Unit task actually executed on a cache miss, including the eight queue tests.

The raw source-bound real-Postgres burst receipts requested on TALE-382 remain the last evidence handoff before merge. Please qualify the PR body’s “at most one attempt” statement to the observed burst/covered statement-failure path: this wrapper does not establish a universal bound for failures raised at transaction commit or every possible source of contention. No broader retry guarantee is claimed by this review.

@yannickmonney
yannickmonney merged commit c276da3 into main Sep 30, 2026
60 checks passed
@yannickmonney
yannickmonney deleted the fix/task-comment-retry-audit-queue branch September 30, 2026 10:01
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