Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

BrowserCollectionCoordinator: per-collection schemaVersions cause reset loops, and sync-ingested writes bypass leadership

クローズ
#1,753 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TanStack/db のほかの issue

TanStack/db の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。