Skip to content

Persist backoff for PostgreSQL local handler retries on every dispatch path - #827

Closed
thomhurst wants to merge 1 commit into
mainfrom
issue-823-uniform-retry-policy
Closed

thomhurst wants to merge 1 commit into
mainfrom
issue-823-uniform-retry-policy

Conversation

@thomhurst

@thomhurst thomhurst commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

A PostgreSQL local handler failure classified Retry now gets one policy, whichever path ran the attempt: it counts against MaxDispatchAttempts, persists exponential backoff (1 s to 5 min) in deliver_at, and dead-letters at the limit. An ordered row parks its key at the limit.

What the code did before: the issue says commit-triggered dispatch retried forever. That's not quite right. Local consumption always sets admission, so commit, recovery and ordered dispatch all went through the counted Failure statement. Every path had the poison budget, but none of them had backoff, so a failing handler was retried on each recovery or lane pass until it was poisoned. The local transport page promised backoff without a poison budget, which matched neither the code nor the reference pages (postgres-store.md, direct-dispatch.md, postgres-maintenance.md and docs/decisions.md), which all describe the budget. I kept the budget, since that's what the decision record and the issue's expected behaviour ask for, and added the backoff.

Changes:

  • PostgreSqlPoisonSql.Failure takes an optional clock expression. When it's set, a row that stays pending gets the same backoff expression as Retry, which now shares it.
  • The direct store's _failDirect (used only for local handler failures, on the commit and recovery paths) and a new ordered-lane _failLocal use it. Ordered preparation errors and the public explicit-time RecordFailureAsync are unchanged.
  • New test LocalTransportTests.Retry_failures_back_off_and_dead_letter_at_the_limit_on_every_dispatch_path covers the direct, recovery and ordered paths: the first failure gives attempts = 1 with deliver_at one second after the failure, and the second due attempt dead-letters. Before the fix it failed on all three paths with a null deliver_at.
  • Docs: transports/postgresql-local.md corrected; the three reference pages note the backoff.

Builds on: the existing fenced poison transition and the native-retry backoff from #672. No native client feature is involved; this is store SQL. Nothing duplicated.

Per-message cost: none on the success path. A local handler failure runs the same single statement with one extra column assignment, 0 B.

Validation (net10.0 and net11.0): LocalTransportTests, PoisonTests, DispatchBackoffTests, OrderedDispatchTests, MaintenanceTests, LocalTransportConformanceTests, ChangeCaptureTests, SharedMaintenanceContractTests, TransactionalCompletionTests, SagaTimeoutTests and SchedulingRequirementTests all pass. npm run build in website/ passes.

Per-consumer schedules stay in #804.

Closes #823

@coderabbitai

coderabbitai Bot commented Nov 15, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@thomhurst

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T12:45:32.747440Z 198769f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

Review of PR 827: persist backoff for local handler retries

No blocking issues found.

  • Correctness: Failure(..., backoffFrom) assigns deliver_at only when the row stays pending (attempts + 1 < limit). Rows at the limit still go to dead storage, or park their ordered key, as before. The backoff text is now shared with Retry, so the two statements can't drift apart.
  • Ordered path: local: preparedForSend && !nativeSend limits the new _failLocal command to local handler failures. Ordered preparation errors keep the plain _fail, and native sends keep _retry.
  • Direct path: _failDirect is now the backoff variant. It is reached only with now == null, which is internal dispatch. The public explicit-time RecordFailureAsync still uses _fail, so its caller-controlled clock contract is unchanged.
  • Tests: the new parameterised test covers direct, recovery and ordered dispatch. It checks the first-failure backoff window against the database clock, then checks dead-lettering at the limit and rollback of the business write.
  • Docs and performance: all four affected pages are updated, and the PR states the per-message cost (a failure-path-only column assignment, 0 B). That matches AGENTS.md, so no benchmark is needed.

One non-blocking note: a direct-path preparation failure with now == null would also get backoff. That seems harmless and arguably desirable.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 198769f7ec

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@thomhurst

Copy link
Copy Markdown
Owner Author

Closing as superseded by #819, which merged after this was reviewed and conflicts with it.

#819 already sends local handler failures through one counted statement (PostgreSqlPoisonSql.LocalFailure) on the direct, recovery and ordered paths, so they all share the same budget and dead-letter at the limit. It also made "due again at once" the documented default, with per-consumer RedeliveryDelays and MaxAttempts. A built-in 1 s to 5 min backoff here would undo that new default and break #819's no-delay tests, so I'm not rebasing this onto it. The branch stays available if we want a default backoff later.

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.

PostgreSQL local handler retries: backoff and poison limit depend on which dispatch path claimed the row

1 participant