Repository navigation
In progress
In progress
Copy link
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 A Fix dropped $/cancelRequest for queued LSP requests (tsc/internal/lsp/server.go) #2, Pattern 1) andverification/tla/FINDINGS.md(fix(api): retain snapshot across concurrent queries and reject post-close registration #8) on branchtla-concurrency-verification(3421f17). - Existing failing spec and reproducer:
verification/tla/specs/LspServerCancel/LspServerCancel.tla(NoDroppedCancellation, 7-state counterexample)verification/tla/reproducers/lsp_cancel_repro_test.go(reproduces on attempt 1 in 0.02s vialsptestutil.NewLSPClient)
What to build
Ensure $/cancelRequest notifications received by lsp.Server are never silently dropped while their target request is still waiting in s.requestQueue (before dispatchLoop dequeues it into s.pendingClientRequests).
Required observable behavior:
- If a client sends request
Rfollowed by$/cancelRequest(R)whileRis still queued ins.requestQueue, the server must not executeRwith an uncanceled context and must respond withlsproto.ErrorCodeRequestCancelled(or honor cancellation before running the handler). - Existing cancellation behavior for requests already dispatched and executing asynchronously must remain intact.
- Cancellation tracking must not leak memory for completed requests, out-of-order cancels for unknown IDs, or duplicate cancel notifications.
$/cancelRequestmust continue to cancel in-flight requests without blocking behind slow synchronous notifications ins.requestQueue.
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 LSP message ordering for non-cancel requests and notifications passing through
s.requestQueue. - Leave internal representation choices (for example registering
pendingClientRequestsinreadLoopvs tracking queued-cancel IDs) to the implementer, provided the green TLA+ model verifies no dropped cancellation, no deadlock, and bounded state cleanup.
Acceptance criteria
- Green TLA+ model: Add a fixed configuration (and updated spec transitions on
tla-concurrency-verification) checked bytla2tools.jar/ TLC that verifiesNoDroppedCancellation, deadlock freedom, and quiescent map cleanup (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/lsp/server.goand add in-package regression test(s) covering:$/cancelRequestarriving while the target request is queued behind synchronous notifications ins.requestQueue(returnsErrorCodeRequestCancelled, does not run hover/handler).$/cancelRequestarriving for an already-executing async request.$/cancelRequestfor a nonexistent or already-completed request ID (no panic, no leaked map entry).
- Verification:
go -C ./tsc test -race -timeout=60s ./internal/lsp/...passes (including the new regression tests), 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/lsp/server.go:937-1075(readLoop,cancelRequest,dispatchLoop)tsc/internal/lsp/dynamic_queue.goverification/tla/specs/LspServerCancel/LspServerCancel.tlaverification/tla/reproducers/lsp_cancel_repro_test.go
Activity
robertpenner commentedon Nov 26, 2026
Just-in-Time Agent Brief (#2)
e0fce98(main),3c1c901(tla-concurrency-verification).tsc/internal/lsp/server.go:994-1064puts incoming client requests intos.requestQueueinreadLoopwithout inserting them intos.pendingClientRequests, whilereadLoophandles$/cancelRequestimmediately againsts.pendingClientRequests. Any cancellation arriving beforedispatchLoopdequeues the request is silently dropped.pendingClientRequestwithcanceled bool(cancelremainsnilwhile queued).req.ID != nilins.pendingClientRequestsinsidereadLoopbefores.requestQueue.Put(ctx, req)(removing it onPuterror).cancelRequest: if found withcancel != nil, callcancel()and delete; if found withcancel == nil, markcanceled = true; if absent, no-op (prevents unbounded growth on unknown or late cancels).dispatchLoop: after poppingreq, lockpendingClientRequestsMu; if markedcanceled, delete, respond withErrorCodeRequestCancelled, and skip running the handler; otherwise attachcancelto the entry. BecauserequestCtxis still created indispatchLoop,s.GetLocale()remains ordered after preceding notifications.LspServerCancel_Fixed.cfg, 0 errors onNoDroppedCancellation,NoLeakedPendingEntries, and deadlock freedom), TDD regression tests undergo -C ./tsc test -race ./internal/lsp/..., andgofmt/go vet.robertpenner commentedon Nov 26, 2026
Slice Complete: Red-to-Green Verified (#2)
fix/lsp-queued-cancel(based onmaine0fce98)robertpenner/TypeScript(Closes #2)LspServerCancel_Fixed.cfgpassed with 0 errors (30 distinct states, 45 generated, deadlock checking enabled) onNoDroppedCancellation,NoLeakedPendingEntries, andCanceledRequestRespondsCancelled.go -C ./tsc test -race -count=1 ./internal/lsp/...passed (3/3 packages, includingTestCancelRequestWhileQueuedInRequestQueueandTestCancelActiveRequestCancelsContext);gofmtandgo vetclean.Draft Upstream Bug Report (for
microsoft/TypeScript)Title: LSP
$/cancelRequestis silently dropped when target request is still queued inServer.requestQueueDescription:
In
tsc/internal/lsp/server.go,readLoopenqueues incoming client requests intos.requestQueuewithout adding them tos.pendingClientRequests, whiledispatchLoopregisters them ins.pendingClientRequestsonly after dequeuing. However,readLoopintercepts$/cancelRequestimmediately (bypassings.requestQueue) and looks up the ID ins.pendingClientRequests. During typing bursts whendispatchLoopis busy processing edits, queued requests sit ins.requestQueue, so$/cancelRequestmissess.pendingClientRequests, is silently discarded, anddispatchLoopsubsequently executes the stale request with an uncanceled context.Registering queued request IDs in
s.pendingClientRequestsinsidereadLoop(withcancel == nil, markedcanceled = trueif canceled before dispatch) and short-circuiting withErrorCodeRequestCancelledindispatchLoopeliminates dropped cancellations without leaking unknown/duplicate cancel IDs or disturbings.GetLocale()ordering.(Clean fix branch ready at
robertpenner/TypeScript:fix/lsp-queued-cancelonce an upstream issue is milestoned.)test(verification): verify LspServerCancel green TLA+ model (#2)