Repository navigation
fix(project/dirty): unify canonical entry locking and lifecycle in SyncMap - #9
Draft
robertpenner wants to merge 2 commits into
Draft
robertpenner wants to merge 2 commits into
robertpenner wants to merge 2 commits into
Conversation
This was referenced Nov 26, 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.
Closes #5
Summary
Fixes 5 verified concurrency and state-machine defects in
dirty.SyncMap(tsc/internal/project/dirty/syncmap.go) by unifying canonical-entry promotion and locking under a single invariant:SyncMapEntry.Delete(): On a raced clean handle that lostm.dirty.LoadOrStore, line 151 previously sete.delete = trueinstead ofentry.delete = trueand omittede.proxyFor = entry, silently dropping deletions.SyncMap.Delete(key)+ concurrentSyncMapEntry.Change():m.Deleteinserted a tombstone withvalue: zero (nil), dirty: false, delete: true, causing concurrent clean handles to panic inentry.value.Clone()and causingFinalizeWith'sOnDeletehook to receivenil.ChangeIf/DeleteIf: Predicates were evaluated against stale clean handles before proxying to the winning dirty entry without re-checking underentry.mu.changeLockedcloned and ranapplyeven whenentry.deletewas alreadytrue.SyncMapEntry.Locked(): After a firstv.Change()proxied a clean handle and unlockedentry.mu, subsequentv.Change()orv.Delete()calls in the sameLocked(fn)skippede.proxyFor, causing a-racedata race and lost deletion.Fix
lockCanonicalLocked()so every mutating path resolves the canonical entry inm.dirty, bindse.proxyFor, and lockscanonical.muin strictloser.mu -> canonical.muorder (depth-1 DAG, deadlock-free).if c.delete { return }) and re-checkChangeIf/DeleteIfpredicates underc.muafter proxying (while preserving zero-allocation clean fast paths when untouched andcondis false).value: baseValalongsideoriginal: baseValinSyncMap.Delete(key)soFinalizeWithOnDeletereceives the base value.lockedEntryretain the canonical lock for the remainder ofSyncMapEntry.Locked(fn)once promoted or bound, keeping multi-operationLockedcallbacks mutually excluded oncanonical.mu.Verification
DirtySyncMapFixed.tla/.cfgontla-concurrency-verification): 0 errors across 4,164 distinct states (2 workers) and 261,232 distinct states (3 workers) with deadlock checking enabled, verifyingNoNilClonePanic,NoDataRace,NoMutateBase,NoMutateDeleted,NoChangeIfTOCTOU, andNoLostDelete.dirty_syncmap_repro_test.go) now pass under-race.go -C ./tsc test -race -count=1 ./internal/project/... ./internal/ls/autoimport/...: all 6 packages pass (dirty,project,ata,background,logging,autoimport), includingTestSyncMapEntryLifecycleSafety.gofmtandgo vet ./internal/project/dirty/...: clean.