Skip to content

Move cross-instance NOTIFY behind DBAdapter.notify#4672

Merged
lukemelia merged 2 commits intomainfrom
cs-pg-notify-browser-guard
May 6, 2026
Merged

Move cross-instance NOTIFY behind DBAdapter.notify#4672
lukemelia merged 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 57m 25s ⏱️
2 565 tests 2 550 ✅ 15 💤 0 ❌
2 584 runs  2 569 ✅ 15 💤 0 ❌

Results for commit 6ee8224.

Realm Server Test Results

    1 files      1 suites   16m 15s ⏱️
1 248 tests 1 248 ✅ 0 💤 0 ❌
1 326 runs  1 326 ✅ 0 💤 0 ❌

Results for commit 6ee8224.

@lukemelia lukemelia marked this pull request as ready for review May 6, 2026 02:12
@lukemelia lukemelia requested review from a team, Copilot and habdelra May 6, 2026 02:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR moves cross-instance invalidation notifications behind the DBAdapter abstraction so the host/browser (SQLite) environment no longer attempts to call pg_notify, eliminating SQLITE_ERROR: no such function: pg_notify noise while preserving Postgres behavior.

Changes:

  • Added notify(channel, payload): Promise<void> to the DBAdapter interface as a best-effort cross-instance broadcast primitive.
  • Implemented notify in PgAdapter (via SELECT pg_notify($1, $2)) and in SQLiteAdapter as an intentional no-op.
  • Updated Realm.#notifyFileChange and tests/mocks to use dbAdapter.notify(...) instead of embedding raw pg-specific SQL.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/runtime-common/db.ts Extends DBAdapter with a documented best-effort notify API.
packages/runtime-common/realm.ts Switches file-change broadcasting from raw pg_notify SQL to dbAdapter.notify.
packages/postgres/pg-adapter.ts Implements DBAdapter.notify using parameterized pg_notify.
packages/host/app/lib/sqlite-adapter.ts Implements DBAdapter.notify as a no-op for SQLite/host.
packages/realm-server/tests/realm-file-changes-listener-test.ts Drives notifications through dbAdapter.notify to cover PgAdapter.notify.
packages/realm-server/tests/screenshot-card-test.ts Updates DBAdapter test mock shape to include notify.
packages/realm-server/tests/prerender-proxy-test.ts Updates DBAdapter test mock shape to include notify.
packages/runtime-common/tests/run-command-task-shared-tests.ts Updates DBAdapter test mock shape to include notify.
packages/bot-runner/tests/command-runner-test.ts Updates DBAdapter test mock shape to include notify.
packages/bot-runner/tests/bot-runner-test.ts Updates DBAdapter test mock shape to include notify.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@backspace
Copy link
Copy Markdown
Contributor

This is unrelated to your PR, I’ll look more at how it escaped the colour-ignoring changes:

CleanShot 2026-05-06 at 06 49 54@2x

@lukemelia lukemelia merged commit 52f097e into main May 6, 2026
105 of 106 checks passed
habdelra added a commit that referenced this pull request May 6, 2026
PR #4672 added a `notify` method to the DBAdapter interface
but indexing-event-sink-test.ts (introduced in CS-10930) still
constructs mock adapters that don't implement it. Lint flagged
TS2741 on the merge of main into this branch.

Both mock adapters in this file are recording stubs for `execute`;
add a no-op `notify` so the type matches.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
habdelra added a commit that referenced this pull request May 6, 2026
The DBAdapter interface gained a notify() method (PR #4672, cs-pg-notify-
browser-guard) the same week tests/indexing-event-sink-test.ts was added
(CS-10930). Each PR was rebased on a main that didn't see the other, so
the merge of both leaves two DBAdapter literals in this test missing the
new required method, breaking lint:types in CI for any branch that
merges current main.

Add async notify() {} to both mock literals (line 18 and line 362).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
habdelra added a commit that referenced this pull request May 6, 2026
PR #4672 added a `notify` method to the DBAdapter interface
but indexing-event-sink-test.ts (introduced in CS-10930) still
constructs mock adapters that don't implement it. Lint flagged
TS2741 on the merge of main into this branch.

Both mock adapters in this file are recording stubs for `execute`;
add a no-op `notify` so the type matches.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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