Skip to content

feat(cloudflare): local plugin-replica worker with Postgres read subscriber#2619

Closed
riderx wants to merge 2 commits into
mainfrom
feat/plugin-replica-local-worker
Closed

feat(cloudflare): local plugin-replica worker with Postgres read subscriber#2619
riderx wants to merge 2 commits into
mainfrom
feat/plugin-replica-local-worker

Conversation

@riderx

@riderx riderx commented Jul 4, 2026

Copy link
Copy Markdown
Member

Summary (AI generated)

  • Added cloudflare_workers/plugin-replica/ worker that reuses the existing plugin routes
  • Added a Postgres 17 Docker subscriber that auto-applies read_replicate/schema_replicate.sql and subscribes to local Supabase logical replication
  • Added LOCAL_READ_REPLICA_DB_URL routing in pg.ts so read-only plugin queries hit the local replica
  • Added bun run plugin-replica:dev orchestration script and local replication helpers in read_replicate/

Motivation (AI generated)

Local Cloudflare plugin testing currently hits the primary Supabase database directly, while production plugin workers read from regional Postgres replicas. This change mirrors production read-replica behavior locally so plugin hot paths can be exercised against a subscriber database.

Business Impact (AI generated)

Improves local and CI fidelity for /updates, /stats, and /channel_self without changing production behavior. Reduces risk of shipping plugin changes that work on primary DB but fail on read replicas.

Test Plan (AI generated)

  • bun run supabase:start && bun run supabase:db:reset
  • bun run plugin-replica:dev and verify worker responds on http://127.0.0.1:8790/ok
  • Confirm read-only plugin requests use X-Database-Source: LOCAL_READ_REPLICA
  • bunx vitest run tests/pg-local-read-replica.unit.test.ts

Generated with AI

Made with Cursor

…riber

Introduce a plugin-replica worker stack that boots a local Postgres container,
applies the read-replica schema, subscribes to Supabase logical replication,
and routes read-only plugin queries through LOCAL_READ_REPLICA_DB_URL.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3125b55b-3c71-4bcf-942e-fdde035fc890

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

@codspeed-hq

codspeed-hq Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing feat/plugin-replica-local-worker (a01352f) with main (aa2f33b)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Replace invalid [db.config] keys that broke Supabase CLI config parsing in CI.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 4, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

container_name: capgo_plugin_read_replica
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres

@RobinWitch RobinWitch left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

read_replicate/common.sh currently embeds a literal 0x01 byte in the sed replacement at apply_local_subscription_source_connection, not the \1 capture-group reference.

That means the local replica path rewrites a valid source URL such as postgresql://postgres:postgres@127.0.0.1:54322/postgres?... into a URL whose password is the control character (postgresql://postgres:<0x01>@...). The next psql "$SOURCE_DB_URL" calls in replicate_setup_source.sh / replicate_to_replica.sh then authenticate with the wrong password, so bun run readreplicate:local and bun run plugin-replica:dev fail before the publication/subscription setup can run.

The extraction above uses \1, so this line should do the same instead of storing the literal control byte.

@riderx

riderx commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

Closing: superseded by colo-cache + targeted invalidation approach (new PR incoming).

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.

3 participants