Skip to content

Move cross-instance NOTIFY behind DBAdapter.notify#4672

Draft
lukemelia wants to merge 2 commits intomainfrom
cs-pg-notify-browser-guard
Draft

Move cross-instance NOTIFY behind DBAdapter.notify#4672
lukemelia wants to merge 2 commits intomainfrom
cs-pg-notify-browser-guard

Conversation

@lukemelia
Copy link
Copy Markdown
Contributor

@lukemelia lukemelia commented May 5, 2026

Summary

Realm.#notifyFileChange was issuing raw SELECT pg_notify(...) SQL against this.#dbAdapter. In the host/browser context the adapter is SQLite, which has no pg_notify function — every write logged SQLITE_ERROR: no such function: pg_notify. The host runs a single in-process realm with no peers to notify, so issuing the SQL was also semantically a no-op even when it didn't error.

This pushes the cross-instance broadcast capability down into the existing DBAdapter abstraction:

  • Add notify(channel, payload): Promise<void> to the DBAdapter interface, documented as best-effort cache-coherency.
  • PgAdapter implements via SELECT pg_notify($1, $2).
  • SQLiteAdapter implements as a no-op (no pub/sub primitive, no peers).
  • Realm.#notifyFileChange calls this.#dbAdapter.notify(...) and no longer embeds pg-specific SQL.
  • Update the realm-server listener test to drive notifications via the new method (also gives PgAdapter.notify direct CI coverage).
  • Add notify to the inline DBAdapter mocks in bot-runner / realm-server / runtime-common tests.

Surfaced as flaky test-log noise after PR #4660 (CS-10892: realm_file_changes NOTIFY channel) widened the call site without gating SQLite. Original diagnosis and the simpler kind === 'sqlite' guard fix were Hassan's, on cs-11036-indexer-resume-progress; this PR replaces that guard with the adapter-level abstraction.

Test plan

  • Host shard 16 runs cleanly with no no such function: pg_notify lines in the test log.
  • Realm-server realm-file-changes-listener-test.ts still passes end-to-end against real Postgres (now exercising PgAdapter.notify).
  • Full realm-server, bot-runner, and runtime-common test suites green (mock DBAdapter shapes updated).

🤖 Generated with Claude Code

Realm.#notifyFileChange was issuing raw `SELECT pg_notify(...)` SQL
against this.#dbAdapter. In the host/browser context the adapter is
SQLite, which has no pg_notify function — every write logged
`SQLITE_ERROR: no such function: pg_notify`. The host runs a single
in-process realm with no peers to notify, so issuing the SQL was
also semantically a no-op even when it didn't error.

Push the cross-instance broadcast capability down into the existing
DBAdapter abstraction:

- Add `notify(channel, payload): Promise<void>` to the DBAdapter
  interface, documented as best-effort cache-coherency.
- PgAdapter implements via `SELECT pg_notify($1, $2)`.
- SQLiteAdapter implements as a no-op (no pub/sub primitive, no peers).
- Realm.#notifyFileChange calls `this.#dbAdapter.notify(...)` and no
  longer embeds pg-specific SQL.
- Update the realm-server listener test to drive notifications via
  the new method (also gives PgAdapter.notify direct CI coverage).
- Add `notify` to the inline DBAdapter mocks in bot-runner /
  realm-server / runtime-common tests.

Surfaced as flaky test-log noise after PR #4660 (CS-10892:
realm_file_changes NOTIFY channel) widened the call site without
gating SQLite. Original diagnosis and the kind === 'sqlite' guard
fix from Hassan Abdel-Rahman on cs-11036-indexer-resume-progress.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lukemelia lukemelia force-pushed the cs-pg-notify-browser-guard branch from f9dcc47 to 8b212d8 Compare May 5, 2026 23:41
@lukemelia lukemelia marked this pull request as draft May 5, 2026 23:41
@lukemelia lukemelia changed the title Skip pg_notify in SQLite (host/browser) context Move cross-instance NOTIFY behind DBAdapter.notify May 5, 2026
…guard

# Conflicts:
#	packages/postgres/pg-adapter.ts
#	packages/realm-server/tests/realm-file-changes-listener-test.ts
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Preview deployments

Host Test Results

    1 files      1 suites   1h 41m 19s ⏱️
2 565 tests 2 550 ✅ 15 💤 0 ❌
2 584 runs  2 569 ✅ 15 💤 0 ❌

Results for commit 6ee8224.

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