fix(snowflake): dedup model buffer by hash before flush#11
Merged
Conversation
A single Ledger.add() pass buffers the same new model twice (register() saves it, then update_model() saves it again). The flush MERGE is idempotent only once the target row exists; for a brand-new model the empty-target INSERT fires per source row, so an undeduped buffer writes duplicate rows. Dedup the buffer by model_hash (last write wins) in _flush_models before the MERGE. Surfaced by a first-time bulk insert of ~500 new nodes, which produced exactly 2x rows. Existing nodes were unaffected (register() early-returns from cache, so only update_model() buffers them, and MERGE updates in place). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Ledger.add()buffers the same new model twice in one pass —register()saves it, thenupdate_model()(which is justsave_modelagain) saves it a second time. The flushMERGEis idempotent only once the target row exists; for a brand-new model the empty-targetWHEN NOT MATCHED → INSERTfires per source row, so an undeduped buffer writes duplicate rows.Fix: dedup
_model_bufferbymodel_hash(last write wins) in_flush_models()before the MERGE. Existing models were never affected (register()early-returns from cache, so onlyupdate_modelbuffers them and the MERGE updates in place).Linear
Consumer PR
Test Plan
test_flush_dedups_model_buffer_by_hash— saves the same model twice, asserts it reaches the MERGE source exactly once (fails before fix: 2×)🤖 Generated with Claude Code