Repository navigation
In progress
Labels
Description
Parent / source
- Parent: End-to-end red-to-green TLA+ fixes and upstream PR prep for flagship TypeScript 7 concurrency bugs #1
- Authoritative analysis:
verification/tla/ANALYSIS.md(Tier B fix(lsp): preserve $/cancelRequest for queued client requests #7, Pattern 3) andverification/tla/FINDINGS.md(#1a–#1e) on branchtla-concurrency-verification(3421f17). - Existing failing spec and reproducers:
verification/tla/specs/DirtySyncMap/DirtySyncMap.tla(5 invariants violated in 6 to 15 states)verification/tla/reproducers/dirty_syncmap_repro_test.go(6/6 tests reproduce in 0.02s, including a liveWARNING: DATA RACEand nil-pointer panic)
What to build
Fix all 5 verified concurrency and state-machine defects in dirty.SyncMap (tsc/internal/project/dirty/syncmap.go) by establishing a sound entry lifecycle and proxy-forwarding invariant:
SyncMapEntry.Delete()lost delete: When a clean handle losesm.dirty.LoadOrStore(e.key, e), deletion must be applied to the winning canonical dirtyentry(underentry.mu) and proxy state updated, not written only to the losing handlee.SyncMap.Delete(key)tombstone vs concurrentChange/FinalizeWith: A tombstone created bym.Delete(key)must not cause a concurrent clean handle'sChange/ChangeIfto callClone()on a zero/nilvalue, andFinalizeWith'sOnDeletehook must receive the deleted entry's non-zero original value whenkeyexisted inbase.ChangeIfandDeleteIfTOCTOU acrossproxyFor: Predicatecondmust be evaluated against the current canonical entry's value under the canonical entry's lock (re-checking after proxying to a winning dirty entry), never deciding solely from a stale clean handle.- No mutation of deleted entries:
ChangeandChangeIfon a handle whose canonical dirty entry has already been deleted must not clone or runapplyon the deleted entry (define and test the refusal/no-op contract clearly). SyncMapEntry.Locked()proxy lock safety: Operations invoked onValue[V]insidee.Locked(fn)(including multiplev.Change()calls,v.Value(),v.ChangeIf(), andv.Delete()) must maintain mutual exclusion on the canonical dirty entry aftereproxies, eliminating both the unlocked-mutation data race and lostv.Delete().
Decisions and constraints
- Follow all shared constraints in End-to-end red-to-green TLA+ fixes and upstream PR prep for flagship TypeScript 7 concurrency bugs #1 (clean fix branch from
mainate0fce98, no unsolicited PR againstmicrosoft/TypeScript, officialtla2tools.jaronly). - Preserve the public
dirty.SyncMap,dirty.SyncMapEntry,dirty.Value[V],LoadClean,Range,Finalize, andFinalizeWithAPIs and lock-ordering deadlock freedom (no deadlock when two goroutines concurrently operate on clean/proxied/dirty handles for the same key). - Do not break existing callers in
project/snapshotfs.go,project/projectcollectionbuilder.go,project/configfileregistrybuilder.go, orls/autoimport/registry.go.
Acceptance criteria
- Green TLA+ model: Add a fixed model/configuration (on
tla-concurrency-verification) checked bytla2tools.jar/ TLC that satisfies all 6 safety invariants (NoNilClonePanic,NoDataRace,NoMutateBase,NoMutateDeleted,NoChangeIfTOCTOU,NoLostDelete) and deadlock freedom with 0 errors across all reachable states, wired intoverification/tla/scripts/run-tlc.sh. - Go fix and regression tests: On a clean fix branch off
main(e0fce98), fixtsc/internal/project/dirty/syncmap.goand add in-package regression tests covering all 6 scenarios fromdirty_syncmap_repro_test.goplusFinalizeWithOnDeletevalue preservation. - Verification:
go -C ./tsc test -race -timeout=120s ./internal/project/... ./internal/ls/autoimport/...passes with 0 data races, andnpx hereby check:formatandnpx hereby lintpass for touched files. - Upstream preparation: Include a concise ready-to-file upstream bug report and PR description (referencing the fix branch on
robertpenner/TypeScript) in an issue comment when done.
Dependencies
None. Independently executable.
Starting references
tsc/internal/project/dirty/syncmap.gotsc/internal/project/dirty/syncmap_test.gotsc/internal/project/snapshotfs.go:284-294,433-458(realLockedand concurrentSyncMapusage)verification/tla/specs/DirtySyncMap/DirtySyncMap.tlaverification/tla/reproducers/dirty_syncmap_repro_test.go
Activity
robertpenner commentedon Nov 26, 2026
Just-in-Time Agent Brief (#5)
e0fce98(main),78bed89(tla-concurrency-verification).tsc/internal/project/dirty/syncmap.go:SyncMapEntry.Delete()(line 151) setse.delete = trueinstead ofentry.delete = trueand omitse.proxyFor = entrywhen a clean handle losesLoadOrStore.SyncMap.Delete(key)(lines 253-259) inserts a tombstone withvalue: zero (nil), dirty: false, delete: true, causing concurrent clean handles callingchangeLockedto panic onentry.value.Clone(), and causingFinalizeWith'sOnDeleteto passnil.ChangeIf/DeleteIfevaluatecond(e.value)on the stale clean handle before proxying and apply/delete on the winning dirty entry without re-checkingcond.changeLockedmutates already-deleted dirty entries (entry.delete == true).SyncMapEntry.Locked()invokeslockedEntrymethods that callchangeLocked/deleteLockeddirectly; after the firstv.Change()proxiese(e.dirty = true,e.proxyFor = entry) and unlocksentry.mu, any subsequentv.Change()orv.Delete()inside the sameLocked(fn)skipse.proxyFor, causing a live Go-racedata race and lost deletion.e.proxyFor == nil && (e.dirty || e.delete)holds iffeis the canonical entry inm.dirty.lockCanonicalLocked()(called withe.muheld) that lockse.proxyFor.mu, returnseif already canonical, or performsm.dirty.LoadOrStore(e.key, e)and locks + bindse.proxyForon loss. Lock order is strictlyloser.mu -> canonical.mu(depth-1 DAG, deadlock-free).Change,Delete,ChangeIf, andDeleteIfthrough canonical helpers that refuse mutation on deleted entries (if c.delete { return }) and re-evaluatecond(c.value)underc.muafter proxying (while preserving zero-allocation clean fast paths whenm.dirty.Loadmisses andcondis false).SyncMap.Delete(key), populatevalue: baseValalongsideoriginal: baseValsoFinalizeWithOnDeletereceives the base value.SyncMapEntry.Locked(fn), track any acquired canonical lock inlockedEntryand keep it held untilLocked(fn)returns, so multi-op callbacks (Change; Change,Change; Delete,ValueafterChange) stay mutually excluded oncanonical.mu.DirtySyncMap_Fixed.tla/.cfg, 0 errors across all 6 safety invariants + deadlock freedom), TDD regression tests for all 6 reproducer scenarios +OnDeletepreservation undergo -C ./tsc test -race ./internal/project/... ./internal/ls/autoimport/..., andgofmt/go vet.robertpenner commentedon Nov 26, 2026
Slice Complete: Red-to-Green Verified (#5)
fix/dirty-syncmap-lifecycle(based onmaine0fce98)robertpenner/TypeScript(Closes #5)DirtySyncMapFixed.tlapassed with 0 errors across 4,164 distinct states (2 workers) and 261,232 distinct states (3 workers) with deadlock checking enabled on all 6 safety invariants (NoNilClonePanic,NoDataRace,NoMutateBase,NoMutateDeleted,NoChangeIfTOCTOU,NoLostDelete).-race;go -C ./tsc test -race -count=1 ./internal/project/... ./internal/ls/autoimport/...passed (6/6 packages, includingTestSyncMapEntryLifecycleSafety);gofmtandgo vetclean.Draft Upstream Bug Report (for
microsoft/TypeScript)Title:
dirty.SyncMapentry proxy races cause-racedata race inLocked, nil-pointer panic inClone, lost deletes, andChangeIfTOCTOUDescription:
In
tsc/internal/project/dirty/syncmap.go, five related concurrency bugs occur when two goroutines hold clean handles (or a clean handle racesSyncMap.Delete) for the same key:SyncMapEntry.Delete()(line 151) setse.delete = trueinstead ofentry.delete = truewhen losingLoadOrStore, silently dropping the deletion.SyncMap.Delete(key)(lines 253-259) inserts a tombstone withvalue: zero (nil), dirty: false, delete: true, so a concurrent clean handle'sChange()panics inentry.value.Clone()andFinalizeWithpassesniltoOnDelete.ChangeIfandDeleteIfevaluatecond(e.value)on the stale clean handle and do not re-checkcondafter proxying to the winning dirty entry.changeLockedclones and mutates entries withentry.delete == true.SyncMapEntry.Locked(fn), a firstv.Change()proxiese(e.dirty = true,e.proxyFor = entry) and unlocksentry.mu; any subsequentv.Change()orv.Delete()in the sameLocked(fn)skipse.proxyFor, triggering a Go data race under-raceand dropping deletes.Unifying canonical entry promotion/locking via
lockCanonicalLocked()and keeping the canonical lock held insidelockedEntryfor the duration ofLocked(fn)eliminates all five defects without deadlocks or unnecessary allocations on clean read-only paths.(Clean fix branch ready at
robertpenner/TypeScript:fix/dirty-syncmap-lifecycleonce an upstream issue is milestoned.)test(verification): verify DirtySyncMapFixed green TLA+ model and com…