Skip to content

fix: make observation additive and reference-counted per webview (#54) - #55

Merged
velocitysystems merged 1 commit into
silvermine:masterfrom
jjhafer:fix-observation-issue
Jul 30, 2026
Merged

fix: make observation additive and reference-counted per webview (#54)#55
velocitysystems merged 1 commit into
silvermine:masterfrom
jjhafer:fix-observation-issue

Conversation

@jjhafer

@jjhafer jjhafer commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Observation was destructive: any observe() call dropped the existing broker, and with it the sole broadcast sender, ending every current subscriber's stream with no error and no attributable cause. Since observe() is exposed over IPC, one window could silently kill another window's change stream just by observing the same database, which made multi-window use impossible.

Observation is now shared rather than replaced. The broker is created once per database and reused, requested tables are merged into it, and each window holds its own registration so teardown waits for the last one to be released.

Correctness depends on the registrations and the broker staying in step, so the lock order protecting them is enforced by the compiler rather than by convention - the registration methods require proof that the caller holds the database lock. The same ordering defect had been reintroduced four times while the rule lived only in a comment.

Fixes issue #54.

BREAKING CHANGE: DatabaseWrapper::enable_observation() no longer tears down the existing broker. Callers who re-called it to shed subscribers, or to change channel_capacity/capture_values on a live database, must now call disable_observation() first.

@jjhafer
jjhafer requested review from a team, velocitysystems and yokuze July 30, 2026 15:55
@jjhafer

jjhafer commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@velocitysystems @yokuze This attempts to resolve this issue: #54

Comment thread src/commands.rs Outdated
Comment thread crates/sqlx-sqlite-toolkit/src/wrapper.rs
Comment thread src/commands.rs Outdated
Comment thread src/subscriptions.rs Outdated
Comment thread README.md Outdated
Comment thread src/commands.rs
Comment thread crates/sqlx-sqlite-toolkit/Cargo.toml
Comment thread src/commands.rs Outdated
Comment thread src/lib.rs
Comment thread crates/sqlx-sqlite-observer/src/broker.rs
Comment thread crates/sqlx-sqlite-toolkit/src/wrapper.rs
Comment thread src/commands.rs Outdated
Comment thread CHANGELOG.md
Comment thread src/commands.rs Outdated
Comment thread src/subscriptions.rs Outdated
Comment thread src/subscriptions.rs
Comment thread guest-js/index.ts
…vermine#54)

Observation was destructive: any observe() call dropped the existing broker,
and with it the sole broadcast sender, ending every current subscriber's
stream with no error and no attributable cause. Since observe() is exposed
over IPC, one window could silently kill another window's change stream just
by observing the same database, which made multi-window use impossible.

Observation is now shared rather than replaced. The broker is created once per
database and reused, requested tables are merged into it, and each window
holds its own registration so teardown waits for the last one to be released.

Correctness depends on the registrations and the broker staying in step, so
the lock order protecting them is enforced by the compiler rather than by
convention - the registration methods require proof that the caller holds the
database lock. The same ordering defect had been reintroduced four times while
the rule lived only in a comment.

Fixes issue silvermine#54.

BREAKING CHANGE: DatabaseWrapper::enable_observation() no longer tears down
the existing broker. Callers who re-called it to shed subscribers, or to
change channel_capacity/capture_values on a live database, must now call
disable_observation() first.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jjhafer
jjhafer force-pushed the fix-observation-issue branch from 208b57f to abb8001 Compare July 30, 2026 19:40
@jjhafer
jjhafer requested a review from velocitysystems July 30, 2026 19:40
@jjhafer

jjhafer commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@velocitysystems Updated, can you review again?

@velocitysystems
velocitysystems merged commit a5a4364 into silvermine:master Jul 30, 2026
1 check 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.

2 participants