Skip to content

fix(cloud): retry the committed-winner collision codes in relay schema startup - #18553

Merged
Jinwoo-H merged 2 commits into
mainfrom
fix/relay-schema-startup-duplicate-codes
Sep 4, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
fix/relay-schema-startup-duplicate-codes

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​39
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​35 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​29

Why

postgres-schema-concurrency-postgres.test.ts is red on main (since #18537's run) and on every relay PR (#18547 twice). It is not a flake.

CREATE TABLE IF NOT EXISTS only checks the name before the catalog inserts. The loser of a concurrent CREATE therefore fails in one of two ways depending on timing:

  • on the catalog unique index: 23505 on pg_type_typname_nsp_index (already retried), or
  • when the winner has committed by the time the loser reaches TypeCreate / heap_create_with_catalog, on the repeated name check: 42710 (duplicate type) / 42P07 (duplicate relation).

The startup retry predicate treated the second shape as fatal, so a director could fail startup on a table it was about to find present. A throwaway diagnostic run in CI (#18552, closed) reported exactly those two codes as the only rejection reasons.

What

  • postgres-schema-startup.ts: 42710/42P07 retryable for CREATE TABLE IF NOT EXISTS, 42P07 for CREATE [UNIQUE] INDEX IF NOT EXISTS. Every other statement shape still fails fast.
  • database-postgres-timeout.test.ts: retry / no-retry cases for each new code × statement shape.
  • postgres-schema-concurrency-postgres.test.ts: ten rounds, and the failure now carries the loser's SQLSTATE instead of expected false to be true.

Verified

  • Local Postgres 16 on 127.0.0.1:55440 pinned to 0.2 CPU to make the race lose: unfixed predicate fails (42P07), fixed predicate passes 18/18 runs.
  • tsc clean for apps/relay.

Production impact: startup only; a director that lost this race would have crashed and been restarted by Cloud Run / the MIG. No wire or data change.

Also carried

cloud/.gitleaks.toml: the RFC 6455 example Sec-WebSocket-Key allowlist from #18547. Cloud Verify's Secret scan runs gitleaks over --all refs, so #18547's test nonce fails every cloud PR's scan until the allowlist is on main. Landing it here first; #18547 rebases onto it.

…a startup

`CREATE TABLE IF NOT EXISTS` only checks the name before the catalog inserts, so
the loser of a concurrent CREATE fails in one of two ways depending on timing:
on the catalog unique index (23505, which the startup retry already handled) or,
when the winner has committed by the time the loser reaches TypeCreate /
heap_create_with_catalog, on the name check those routines repeat (42710
duplicate type, 42P07 duplicate relation). The predicate treated the latter as
fatal, so a director could fail startup on a table it was about to find present.

This is what turned `postgres-schema-concurrency-postgres.test.ts` red on main
and on every relay PR (CI's shared runner loses the race more often than a dev
box): a throwaway diagnostic run in CI reported 42710 from TypeCreate and 42P07
from heap_create_with_catalog as the only rejection reasons.

Treat 42710/42P07 as retryable for `CREATE TABLE IF NOT EXISTS` and 42P07 for
`CREATE [UNIQUE] INDEX IF NOT EXISTS`; every other statement shape still fails
fast. The concurrency test now runs ten rounds and reports the loser's SQLSTATE
instead of a bare boolean.
@pullfrog

pullfrog Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

This run was cancelled 🛑

The workflow was cancelled before completion. Please check the link below for details.

Pullfrog  | View workflow run | via Pullfrog | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: d353115e-7727-4430-9a58-42e27d5f1c43

📥 Commits

Reviewing files that changed from the base of the PR and between 0fb169a and 2e1ed68.

📒 Files selected for processing (1)
  • cloud/.gitleaks.toml

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

PostgreSQL schema startup now retries 42710 and 42P07 collisions for idempotent table and index creation statements. Tests verify retries for idempotent DDL, propagation for non-idempotent DDL, and repeated concurrent openRelayDatabase execution with rejection details and cleanup. Gitleaks now allowlists the RFC 6455 example WebSocket handshake nonce used by raw-socket upgrade tests.

Merge Risk: ⚪ Minimal · up to 2e1ed

This change prevents relay startup failures when concurrent PostgreSQL schema creation races have already committed the same table or index. The retry behavior is scoped to idempotent DDL and is covered by targeted and concurrency tests, with no remaining merge-blocking risk.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the problem, implementation, testing, and production impact. However, it omits several required template sections, including ELI5, a populated Linked Issue, Visual Proof with … Complete the required template sections. Add a simple ELI5 summary, populate Fixes # with the issue reference, add N/A with a reason under Visual Proof, complete the Testing and other checklist items, and provide any required AI Disclos…
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the primary change: retrying committed-winner PostgreSQL schema collision codes during relay startup.
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)

Full details: Description check

Explanation

The description explains the problem, implementation, testing, and production impact. However, it omits several required template sections, including ELI5, a populated Linked Issue, Visual Proof with an explicit N/A justification, the Testing checklist, and the remaining checklist sections.

Resolution

Complete the required template sections. Add a simple ELI5 summary, populate Fixes # with the issue reference, add N/A with a reason under Visual Proof, complete the Testing and other checklist items, and provide any required AI Disclosure and review information.

  • Fix all pre-merge checks with AI

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

Comment @coderabbitai help to get the list of available commands.

…grade tests

Cloud Verify's Secret scan runs gitleaks over --all refs, so the raw-socket
upgrade test on fix/relay-upgrade-malformed-uri (#18547) trips every cloud PR's
scan until its allowlist reaches main. Land the allowlist here first.
@Jinwoo-H
Jinwoo-H merged commit dd9eaa9 into main Sep 4, 2026
24 checks passed
@Jinwoo-H
Jinwoo-H deleted the fix/relay-schema-startup-duplicate-codes branch September 4, 2026 01:20
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…a startup (stablyai#18553)

* fix(cloud): retry the committed-winner collision codes in relay schema startup

`CREATE TABLE IF NOT EXISTS` only checks the name before the catalog inserts, so
the loser of a concurrent CREATE fails in one of two ways depending on timing:
on the catalog unique index (23505, which the startup retry already handled) or,
when the winner has committed by the time the loser reaches TypeCreate /
heap_create_with_catalog, on the name check those routines repeat (42710
duplicate type, 42P07 duplicate relation). The predicate treated the latter as
fatal, so a director could fail startup on a table it was about to find present.

This is what turned `postgres-schema-concurrency-postgres.test.ts` red on main
and on every relay PR (CI's shared runner loses the race more often than a dev
box): a throwaway diagnostic run in CI reported 42710 from TypeCreate and 42P07
from heap_create_with_catalog as the only rejection reasons.

Treat 42710/42P07 as retryable for `CREATE TABLE IF NOT EXISTS` and 42P07 for
`CREATE [UNIQUE] INDEX IF NOT EXISTS`; every other statement shape still fails
fast. The concurrency test now runs ten rounds and reports the loser's SQLSTATE
instead of a bare boolean.

* chore(cloud): allowlist the RFC 6455 example Sec-WebSocket-Key for upgrade tests

Cloud Verify's Secret scan runs gitleaks over --all refs, so the raw-socket
upgrade test on fix/relay-upgrade-malformed-uri (stablyai#18547) trips every cloud PR's
scan until its allowlist reaches main. Land the allowlist here first.
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