← Back to Pull requests

[BACKPORT 2026.1][#38182] YSQL: Fix duplicate notifications from retried statements (#38183) #38358

Closed
unknown closed this pull request without merging on Nov 19, 2026 00:38 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 09:44 UTC
Author

Summary

A query-layer retry kept the discarded attempt's notifications in
pendingNotifies: the restart does not reset PG-side transaction state,
so the retried attempt queued its notifications again, and a
notification whose payload differed between attempts was delivered twice
(#38182).

The retry wrapper (yb_exec_query_wrapper_one_attempt) now takes a mark
of the pending notifications when the statement starts and rolls back to
it on retry:

  • It rolls back to the mark rather than clearing: in a pipelined batch

  • (e.g. JDBC executeBatch) a retry re-runs only the failing statement,
    and the notifications queued by earlier statements in the batch must
    survive.
  • The mark counts notifications under open subtransactions too. Under

  • READ COMMITTED, the previous statement's notifications move to the top
    level only when the next statement starts, so a mark of the top level
    alone would make the rollback drop them.

    Original commit: 40d627827b1b3499553a385443b447a5d29bdefb / #38183

    Test plan

  • testNotifyFromRetriedStatementDeliveredOnce. Without the fix it

  • fails with Notifications: [kept, attempt_..., attempt_..., sentinel]
    expected:<3> but was:<4>
    . It runs under REPEATABLE READ: under READ
    COMMITTED, the default in release builds, the retry rolls back the
    statement's internal subtransaction, which drops the attempt's
    notifications, so the test passed without the fix there.
  • testNotifyFromRetriedStatementInReadCommittedBlock: rolling back

  • to the mark keeps the notification queued by the previous statement of a
    READ COMMITTED block. It passes without the fix too, for the reason
    above.
  • TestPgListenNotify passes.
  • ./yb_build.sh debug --java-test 'org.yb.pgsql.TestPgListenNotify#testNotifyFromRetriedStatementDeliveredOnce'
    ./yb_build.sh debug --java-test 'org.yb.pgsql.TestPgListenNotify#testNotifyFromRetriedStatementInReadCommittedBlock'
    ./yb_build.sh debug --java-test org.yb.pgsql.TestPgListenNotify
    

    Run on a debug build on macOS arm64.

    Merge conflicts

    2026.2 --> 2026.1


  • src/postgres/src/backend/tcop/postgres.c:6261 — [adjacent-lines] kept 2026.1's retry_data->query_string and retry_data->command_tag lines and added the pending_notifies_mark line above them.
  • master --> 2026.2


  • java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgListenNotify.java:774 — [adjacent-lines] on master the new tests follow #37444's testNotifyAfterTableReadDeliveredOnce, which isn't on 2026.2; placed them after testNotifyInSubtransaction instead.
  • 🤖 Generated with Claude Code

    ---------

    Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>

    Diff: 332 lines (+249 / -83) across 4 files Reviewer: arpang Review duration: 893m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 332 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.347
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #38358"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.1% (MEDIUM) · Higher = larger blast radius
    42.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.7% · Safe to merge
    16.7%