BrowserCollectionCoordinator: per-collection schemaVersions cause reset loops, and sync-ingested writes bypass leadership
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- sqlite, typescript
調査の方向性
まず createBrowserWASQLitePersistence、coordinator.setAdapter、ensureCollectionReadyInternal を追跡し、adapter と schema のバージョンがどのように選択されるかを確認します。次に sourceSyncConfig.sync、persistAndBroadcastExternalSyncTransactionUnsafe、requestEnsureRemoteSubset、wrappedOnUpdate を調べ、報告された 2 ページの Chromium probe を再現手順として使用します。完了条件は、コレクション単位の schema 処理によって reset や初期化の race が発生しなくなり、sync の書き込みが調整され、subset オプションが RPC を安全に通過し、coordinator の RPC retry が timeout になることだけを理由に受理済みの書き込みが失敗しないことです。
索引モデルが issue の本文から書いたものです。
説明
Findings from an adoption attempt of BrowserCollectionCoordinator (@tanstack/browser-db-sqlite-persistence 0.2.12, @tanstack/db-sqlite-persistence-core 0.2.12, @tanstack/db 0.7.2, Electric collections). Verified empirically with two pages in one Chromium context (shared storage partition) plus source reading. Happy to share probe scripts.
1. The coordinator holds one adapter, so per-collection schemaVersions destroy each other's tables
createBrowserWASQLitePersistence creates one adapter per distinct (schemaMismatchPolicy, schemaVersion) and calls coordinator.setAdapter(...) for each — the coordinator keeps whichever was created last. The schema check runs in ensureCollectionReadyInternal, which every adapter method reaches, and ensureCollectionState fires acquireLeadership → getStreamPosition for every subscribed collection through that single adapter. With per-collection versions (we compute one per Electric shape) the wrong-version adapter touches every other collection: under sync-present-reset we observed collection_reset_epoch climb 0→5 during one run, a 9,475-row table wiped to 0, every reload re-syncing cold, and the registry's schema_version flipping between two collections' hashes.
A second failure appears even with matching versions: two adapter instances race ensureCollectionReadyInternal for the same collection on a fresh registry (UNIQUE constraint failed: collection_registry.tombstone_table_name, then no such table: t_… when the loser tries to reset a table the winner has not created yet). Leadership is never acquired for those collections.
One global schemaVersion (all adapters collapse to one instance) avoids all of this, at the cost that any schema change resets the whole database. Suggestion: key leader-side adapter access by collection — e.g. requireAdapter(collectionId) with a resolver passed to the constructor — instead of a single setAdapter slot.
2. Sync-ingested transactions bypass leadership entirely
sourceSyncConfig.sync() runs unconditionally in every tab, and externally-synced transactions go straight to disk (persistAndBroadcastExternalSyncTransactionUnsafe → adapter.applyCommittedTx) with no leadership check. N same-partition tabs therefore write the same stream to the same file concurrently, each minting its own term/seq, and the applied_tx dedupe on (collection_id, term, seq) silently returns on a hit — two tabs minting the same pair for different transactions means the second is dropped. We did not observe corruption in the probe, but the hazard is structural, and it means adopting the coordinator does not remove the need for an app-level single-writer election for sync-sourced collections.
3. requestEnsureRemoteSubset fails structuredClone on real LoadSubsetOptions
The follower→leader RPC posts LoadSubsetOptions over BroadcastChannel verbatim. Ours carry a subscription object with a callback: DataCloneError: (event) => options.onUnsubscribe(event) could not be cloned, ~70 occurrences per tab, retried forever by scheduleRemoteEnsureRetry. Follower-side subset widening never reaches the leader. Suggestion: serialize a wire-safe projection of the options.
4. (Minor) coordinator RPC failure lands in the user write path after the server accepted
wrappedOnUpdate runs the app's own mutation handler first and the coordinator RPC after; a wedged leader stalls the write ~30 s (RPC timeout × retries) and then rejects, rolling optimistic state back for a write the backend already accepted.
- 主要言語
- TypeScript
- スター
- 3.9k
- フォーク
- 272
- 平均マージ
- 1日 1時間
- マージ済み PR(30日)
- 210
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/db のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 5/100
メンテナーはふだん 1 日以内に返信
-
browser-db-sqlite-persistence: option to load the wa-sqlite WASM by URL instead of inlined base64オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
electric-db-collection: on-demand + persistence fails after relaunch with "Snapshot requests are not supported in full mode"対応中かも @KyleAMathews が 3 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
TanStack/db#2056 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
bug go
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
genkit-ai/genkit#6761 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
NousResearch/hermes-agent#136483 ·
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
facioquo/stock-indicators-dotnet#2316 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
vercel-labs/skills#2460 ·
メンテナーはふだん 1 日以内に返信