Skip to content

fill the diff before draining buffered head updates - #776

Merged
cheggaaa merged 1 commit into
mainfrom
cheggaaa/fix-filldiff-order
Sep 1, 2026
Merged

fill the diff before draining buffered head updates#776
cheggaaa merged 1 commit into
mainfrom
cheggaaa/fix-filldiff-order

Conversation

@cheggaaa

@cheggaaa cheggaaa commented Sep 1, 2026

Copy link
Copy Markdown
Member

Follow-up to #772.

FillDiff bulk-Sets the diff from a storage snapshot. With the drain goroutine started first, a RemoveId the drain had just applied got undone by that older snapshot — resurrecting a deleted tree in the diff and persisting a space hash for a tree the space no longer has. Nothing corrected it afterwards, so head sync kept advertising the tree until the next unrelated update for that id.

The race predates #772, but #772 made it reachable: subscribing from Init means updates buffer for the whole Run phase (~13 components) instead of being dropped, so the drain flushes a burst at exactly the moment FillDiff runs. Previously the window was microseconds and nothing was pending.

Filling first makes the storage snapshot the baseline and lets buffered updates apply on top, where they converge — the last queued event for an id always matches storage. The reverse order could not converge, because the bulk Set had no later event to correct it.

FillDiff stays in Run: it is ctx-bound I/O that can fail, and Init has no context. Only the two statements swap — no component lifecycle changes.

go test -race ./... green (58 packages).

🤖 Generated with Claude Code

https://claude.ai/code/session_01HXNxMzxa6rK3bAwcULTt4x

FillDiff bulk-Sets the diff from a storage snapshot. Draining first let a
just-applied RemoveId be undone by that older snapshot, resurrecting a deleted
tree in the diff and persisting a space hash for a tree the space no longer
has; nothing corrected it afterwards.

Subscribing from Init made this reachable: updates now buffer for the whole Run
phase instead of being dropped, so the drain flushes a burst exactly when
FillDiff runs. Filling first makes the snapshot the baseline and lets buffered
updates apply on top, where they converge.
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

New Coverage 61.8% of statements
Patch Coverage 80.0% of changed statements (4/5)

Coverage provided by https://github.com/seriousben/go-patch-cover-action

@cheggaaa
cheggaaa merged commit ea6736f into main Sep 1, 2026
4 checks passed
@cheggaaa
cheggaaa deleted the cheggaaa/fix-filldiff-order branch September 1, 2026 17:08
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants