fix(mcp): fold parent snapshot id into rescan purge cursor hash - #248
Merged
Conversation
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.
Closes #247.
Problem
The background rescan purge path (
pkg/mcp/rescan/rescan.goreconcileDeleted) emitted its deleted-file snapshot with a content-onlydiff.CursorHashFlat(synthetic).snapshots.cursor_hashisCHAR(16) NOT NULL UNIQUE, so a sequence that purges the same file set twice with an identical recreate in between (delete → purge → recreate+compile → delete same files → purge) reproduces the earlier purge hash and collides. The failure is swallowed (r.logger.Error+return false), so the purge snapshot is silently dropped rather than surfaced.This is the last
emitter.Emit*call site that was still on a parent-unaware digest — follow-up to #238 (write/summarize) and #244/#246 (compile/forget).Fix
Route the purge through parent-folded hashing, the model #238 adopted:
prevHeadIDviaGetHeadSnapshotID— already inside theOpMucritical section, so the head-id read and theemitter.Emit(which advances HEAD) stay atomic.diff.CursorHashFlat(synthetic)→diff.CursorHashForChange(prevHeadID, deltas).synthetic []*parser.ContextNodescaffold (it existed only to feedCursorHashFlat) and the orphanedparserimport.Tests
pkg/mcp/rescan:TestRescanLoop_RepeatedDeleteOfSameFileSet— delete the same file set twice with an identical recreate in between; asserts two distinct purge snapshots. Confirmed to fail pre-fix (purge snapshots = 1, want 2— second purge swallowed by theUNIQUEcollision) and pass after.go vet, 1186 tests, gofmt, golangci-lint (0 issues).Audit (closes the #247 follow-up note)
All five
emitter.Emit*snapshot sites now fold the parent id:compiler→CursorHashForCompile,rollback→CursorHashForRollback, write/summarize+forget+rescan→CursorHashForChange.CursorHashFlat/CursorHashremain only for non-snapshot, diff-internal uses. No further emit path on a bare content/delta hash.Reviewers
go-style and Codex reviews both clean.
🤖 Generated with Claude Code