Skip to content

refactor(relay): stop creating three tables nothing writes - #25354

Merged
Jinwoo-H merged 2 commits into
mainfrom
relay-step0-dead-tables
Oct 5, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
relay-step0-dead-tables

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​83 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​77
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4 $\color{#cf222e}{\Huge{\mathbf{−}}}$​35 $\color{#cf222e}{\Huge{\mathbf{−}}}$​31

ELI5

The relay creates three database tables at every boot that nothing has ever written to or read from. This stops creating them. It does not delete them yet, because an older relay version that is still running, or that we roll back to, would re-create them and could trip over a concurrent delete.

What Changed

  • SCHEMA no longer creates relay_confirmable_splices, relay_cell_drain_attempts or relay_migration_leases.
  • Their two entries in the transaction-phase table are removed. relay_cell_drain_ still covers the live drain tables.
  • Test references are removed: the SQLite table list, and one cleanup DELETE in postgres-drain-send-locking.test.ts.
  • One comment beside SCHEMA records why existing databases keep the empty tables.

Nothing changes at runtime. New databases simply do not get the three tables.

Why

Zero non-test references on main. git grep across the repo finds them only in database.ts (the CREATEs and phase entries) and the two test files above.

  • relay_cell_drain_attempts is distinct from the live relay_cell_drain_attempt_states.
  • relay_migration_leases is distinct from the live relay_assignments.migration_leases column.

Zero rows and zero use in production (read-only session, 2026-10-04/05):

  • count(*) = 0 for all three.
  • pg_stat_user_tables shows n_tup_ins = 0, seq_scan = 0 and idx_scan = 0 since the 2026-09-28 stats reset.
  • Each table is 16 kB (empty heap plus primary key).

Why not DROP TABLE now. Cells and directors on older images still run CREATE TABLE IF NOT EXISTS for these at boot. During a mixed-version rollout, or a rollback, a DROP on one instance can race:

  • another instance re-creating the table;
  • or two old instances creating it at once, which can fail with a pg_type unique violation.

Either fails that boot's schema step. The tables cost nothing while empty. A follow-up can add DROP TABLE IF EXISTS once no image that creates them can be rolled back to.

Linked Issue

N/A. Relay redesign step 0 (internal).

Visual Proof

N/A. Schema code only; there is no UI or client-visible change.

Testing

  • Automated tests added/updated
  • New dead-relay-tables-postgres.test.ts (local Postgres 16, port 55440):
    • A fresh database has none of the three tables.
    • A database an older image created (tables present) still boots, and the tables are left alone.
  • database.test.ts, relay-schema-lock-targets.test.ts (golden list unchanged; CREATE TABLE takes no relation lock) and relay-schema-catalog-precheck-postgres.test.ts pass.
  • From cloud/apps/relay: pnpm typecheck passes, and the full relay suite with Postgres passes.

Review

Notes

  • Backwards compatible in both directions. Old images keep creating the (empty) tables; new images ignore them.
  • Security, cross-platform, SSH, mobile: not affected.

relay_confirmable_splices, relay_cell_drain_attempts and
relay_migration_leases are created at every boot and referenced nowhere
else on main except tests. In production all three hold 0 rows and
pg_stat_user_tables shows 0 inserts, 0 sequential and 0 index scans since
the 2026-09-28 stats reset.

This removes them from the schema and the transaction-phase table, and
drops the test references. It does not drop them: an older image still
runs CREATE TABLE IF NOT EXISTS at boot, and a drop racing that create can
fail the older boot's schema step. A follow-up can drop them once no image
that creates them can be rolled back to.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Drops three never-written tables from SCHEMA — relay_confirmable_splices, relay_cell_drain_attempts, and relay_migration_leases are no longer created at boot on either the SQLite or Postgres path.
  • Removes their two POSTGRES_TRANSACTION_PHASES entries — error-phase attribution only; the relay_cell_drain_ prefix still covers the live drain tables.
  • Updates tests — the SQLite table-list assertion and the relay_migration_leases cleanup DELETE are pruned.
  • Adds dead-relay-tables-postgres.test.ts — a fresh database has none of the three, and a database with them still boots and leaves them in place.

Verified independently: a repo-wide grep finds no non-test reference to any of the three names (migration_leases elsewhere is the relay_assignments column; relay_cell_drain_attempt_states is a distinct live table). relayPostgresSchemaStatements() and POSTGRES_SCHEMA_MIGRATIONS contain none of them, the lock-target golden list holds only indexes/columns/constraints, and nothing pins POSTGRES_TRANSACTION_PHASES. Both new test cases are falsifiable, and the deferral of DROP TABLE is documented and correctly reasoned.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 76400aef-ae39-41be-ae4b-cf5131cd6408
📥 Commits

Reviewing files that changed from the base of the PR and between 0fefdbb and e5e340e.

📒 Files selected for processing (1)
  • cloud/apps/relay/src/database.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • cloud/apps/relay/src/database.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The relay schema no longer creates relay_confirmable_splices, relay_cell_drain_attempts, or relay_migration_leases. The transaction-phase mappings no longer include dedicated entries for confirmable splices or migration leases. Tests update the expected table list and check that fresh databases lack the three tables while existing databases retain them.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to e5e34

No actionable issue is established for this schema change. It appears mergeable after the reported database and PostgreSQL checks are confirmed.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to 0fefd

The change stops creating three unused tables without deleting existing tables or changing live drain and migration storage. No new production entrypoint, privilege, or materially weakened security control was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The production effect is confined to the schema emitted for databases initialized by the relay. Existing legacy objects and retained live state are not migrated or deleted. The inspected delta introduces no new tenant input, credential authority, or cross-service access path.

Trust Boundaries and Controls

  • observed — The new tests obtain database identity and credentials from ORCA_RELAY_TEST_POSTGRES_URL, not a production request. They use a constant test schema, a scoped search_path for initialization, static DDL identifiers, and a parameterized metadata query. Their CREATE and DROP authority comes from the configured test credential; that credential's actual permissions are external to the repository evidence.

Resilience and Maintainability Implications

  • observed — Production startup retains its existing statement-by-statement schema application, lock and retry handling, and concurrent-create collision handling. Schema-pool cleanup runs in finally, and later database-initialization failure closes the serving database before rethrowing. Partial application remains possible as before; removing legacy CREATE statements adds no new transition, recovery obligation, or rollback cleanup.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: the relay stops creating three unused tables. It is concise and specific.
Description check ✅ Passed The description covers the change, rationale, compatibility considerations, testing, and visual-proof exception. It marks the linked issue as not applicable for an internal change. The Review section …
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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

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

@Jinwoo-H
Jinwoo-H merged commit 52bd9af into main Oct 5, 2026
24 checks passed
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