Repository navigation
Backlog
Labels
Description
Parent / source
- Parent: End-to-end red-to-green TLA+ fixes for Tier 3 TypeScript 7 concurrency & state-machine defects (7 findings across 3 packages) #20
- Authoritative findings:
verification/tla/FINDINGS-TIER3.md(End-to-end red-to-green TLA+ fixes and upstream PR prep for flagship TypeScript 7 concurrency bugs #1, Fix dropped $/cancelRequest for queued LSP requests (tsc/internal/lsp/server.go) #2, Fix api.Session snapshot use-after-deref and post-close leak (tsc/internal/api/session.go) #3 +cpuProfileraudit note) on branchtla-tier2-investigation(4f0e240). - Upstream status: Novel (distinct from Tier 1 Fix api.Session snapshot use-after-deref and post-close leak (tsc/internal/api/session.go) #3
ApiSessionSnapshot, which covereds.snapshotsonly). - Existing TLA+ spec, fixed proof, and Go reproducers:
verification/tla/specs/ApiSessionLifecycle/ApiSessionLifecycle.tlaApiSessionLifecycle_LspRefs.cfg:NoPostCloseLspRefLeakviolated (exit 12)ApiSessionLifecycle_SourceFileLease.cfg:NoPostCloseLeaseLeakviolated (exit 12)ApiSessionLifecycle_BatchPages.cfg:NoPostCloseBatchPageLeakviolated (exit 12)ApiSessionLifecycle_Fixed.cfg: verified 0 errors (360 states generated, 147 distinct)
verification/tla/reproducers/api_session_tier3_repro_test.go:TestReproApiSessionLspSnapshotAfterCloseLeaksRefs(FAIL)TestReproApiSessionSourceFileLeaseAfterCloseLeak(FAIL)TestReproApiSessionBatchResponsePagesAfterCloseLeak(FAIL)
What to build
Enforce a monotonic closed state across the three remaining resource tables in tsc/internal/api/session.go and stop any active CPU profiler in Session.Close():
- LSP reference leak (
NoPostCloseLspRefLeak):Session.Close()(session.go:5789-5810) callsreleaseLanguageServerRefs()(session.go:5812-5844) unders.languageServerUpdateMuwithout marking the session closed. A concurrenthandleGetCurrentLanguageServerSnapshot(session.go:1892-1929) acquirings.languageServerUpdateMuafterward callss.projectSession.APIUpdateand leaks open projects, files, or synthetic programs into the live shared LSPproject.Sessionpermanently (s.closeOncealready fired). - Source-file lease leak (
NoPostCloseLeaseLeak):registerSourceFileLease(session.go:2339-2345) acquiress.sourceFileLeasesMuand stores a lease without checking whetherreleaseSourceFileLeases()(session.go:2419-2430) already ran, pinning*ast.SourceFilerefcounts in the sharedparseCache. - Batch continuation page leak (
NoPostCloseBatchPageLeak):paginateBatchResponses(session.go:1349-1394) stores pages intos.batchResponsePages(session.go:1390) with no closed check or synchronization againsts.batchResponsePages.Clear()(session.go:5808). - Unstopped
cpuProfileron disconnect:Session.Close()never stopss.cpuProfiler(session.go:1448-1455) if a client disconnects mid-profile.
Required observable behavior:
- After
Session.Close()begins releasing each table, concurrent or subsequenthandleGetCurrentLanguageServerSnapshot,registerSourceFileLease, andpaginateBatchResponsescannot insert new entries or leak open LSP refs/leases/batch pages (releasing any newly acquired lease immediately if closed). Session.Close()stops an actives.cpuProfilerif present.
Decisions and constraints
- Soft merge overlap with Tier 1 Fix api.Session snapshot use-after-deref and post-close leak (tsc/internal/api/session.go) #3 (
s.snapshotsintsc/internal/api/session.go): keep edits cleanly scoped tolanguageServerUpdateMu,sourceFileLeasesMu,batchResponsePages, andcpuProfilerinClose().
Acceptance criteria
- Green TLA+ model: Already verified in
ApiSessionLifecycle_Fixed.cfg(exit 0). - Go fix and regression tests: On a clean fix branch off
main(e0fce98), fixtsc/internal/api/session.goand add in-package-raceregression tests porting all 3 reproducers (pluscpuProfilercleanup if testable cleanly). - Verification:
go -C ./tsc test -race -timeout=120s ./internal/api/...passes.
Starting references
tsc/internal/api/session.go:1349-1394(paginateBatchResponses)tsc/internal/api/session.go:1448-1465(cpuProfiler)tsc/internal/api/session.go:1892-1929(handleGetCurrentLanguageServerSnapshot)tsc/internal/api/session.go:2339-2345,2419-2430(registerSourceFileLease,releaseSourceFileLeases)tsc/internal/api/session.go:5789-5844(Session.Close,releaseLanguageServerRefs)verification/tla/specs/ApiSessionLifecycle/ApiSessionLifecycle.tlaverification/tla/reproducers/api_session_tier3_repro_test.go
Activity