refactor(sync): extract submitLocalBatch as the single local intake - #259
Merged
Conversation
Local batches enter the sync coordinator through two paths today — the store-commit path (attachSync.sendBatch → rebase set + pump) and a direct oplog write (getBoardPersistenceRef().record) that skips the rebase set and send trigger, desyncing synced boards. Extract `submitLocalBatch(batch)` as the one sync-correct intake (track for rebase + trigger a pump), route the store producer through it, and publish it via `getBoardSyncRef()` so a headless/off-scene producer can enter the same path instead of writing the oplog directly. Behavior-neutral: the store path is unchanged; the ref + seam are additive groundwork for the headless producer (S7b).
… injection A headless / off-scene batch's ops are not in the loaded store, so adding it to the rebase set would make applyRemote replay those ops into the current scene on the next remote op. Gate rebase tracking behind `scene` (default true for store commits); `scene: false` batches are pumped but not rebased. Strengthen the seam test to drive a remote op after a headless submit and assert the off-scene node is never injected into the submitter's store.
Contributor
Author
Review response (code-review high)Addressed the seam-contract findings in a7fb33e:
Bonus — this de-risks S7b. Since off-scene batches never enter |
This was referenced Aug 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
First, behavior-neutral step of S7 (headless sync-correct emit). Extracts the single local-batch intake that the headless producer (S7b) will call, without changing any current behavior.
Why
Local batches reach the sync coordinator two ways today:
attachSync.sendBatchregisters the batch in thependingrebase set and schedules a pump (correct);getBoardPersistenceRef().record(...)in the deep-cascade delete (subtree.ts) lands in the oplog but never joinspending, never triggers a pump, and never gets aserverSeqon ack. On a synced board that batch ships opportunistically and is never rebased against concurrent remote ops — the "bypasses the outbox -> desyncs" hazard.S7b needs one correct place for an off-scene / cross-layer producer to enter. This PR creates it.
How
board-sync.ts: extractsubmitLocalBatch(batch)= register in thependingrebase set +schedulePump().attachSync.sendBatchnow routes through it (identical behavior). Exposed onBoardSyncHandle.board-sync-ref.ts(new): module singleton mirroringboard-persistence-ref, so code outside the harness can reachsubmitLocalBatch.nullon a purely local board (no relay) — callers fall back to the persistence ref, which is sync-correct there.use-board-sync-v2.ts: publish the handle viasetBoardSyncRefon mount, clear on detach (beforehandle.detach()).No producer is rewired onto the headless path in this PR — the store path is untouched, and the
subtree.tsbypass is left as-is (fixed in S7b, where the durable-only rebase handling and ack/serverSeq stamping land with their own tests).Test plan
handle.submitLocalBatch(...); it ships as one relay message and the peer converges — proving the exposed seam takes the outbox/rebase path, not a bypass.npm run check-allpasses.Follow-ups (rest of S7)
subtree.ts(and the future headlessBoardMutator) throughsubmitLocalBatchinto a durable-only rebase set (off-layer batches must be excluded from the in-scene undo/replay loop, since their inverse would re-add nodes into the wrong layer's store), with ack/serverSeqstamping.