Skip to content

Fix lost global-diagnostics push notification in project.Session (tsc/internal/project/session.go) #4

In progress

Description

@robertpenner

Parent / source

What to build

Fix the coalescing latch between Session.EnqueuePublishGlobalDiagnostics() and Session.publishGlobalDiagnostics() in tsc/internal/project/session.go so global diagnostics accumulated in any project's checkerPool while a previous publish task is scanning or sending PublishDiagnostics RPC are never dropped.

Required observable behavior:

  • Multiple rapid calls to EnqueuePublishGlobalDiagnostics() before the background task runs still coalesce into one publish pass.
  • If new global diagnostics arrive after TakeNewGlobalDiagnostics() / GetProjectDiagnostics() and before publishGlobalDiagnostics exits, a follow-up publish pass runs so the client eventually receives the latest global diagnostics.
  • At quiescence (no pending/running publish task), no configured project has globalDiagChanged == true left unpublished, and globalDiagPublishPending does not get stuck true if backgroundQueue.Enqueue drops a task on cancellation/close.

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 main at e0fce98, no unsolicited PR against microsoft/TypeScript, official tla2tools.jar only).
  • Do not hold snapshotMu or checkerPool.mu across s.client.PublishDiagnostics RPC calls.
  • Leave exact latch design (e.g., clear before scan + re-check, or a 3-state idle / running / rerun state machine) to the implementer, provided the green TLA+ model verifies both safety (NoLostGlobalDiagnostics) and absence of stuck-flag states.

Acceptance criteria

  1. Green TLA+ model: Add a fixed configuration (and updated spec transitions on tla-concurrency-verification) checked by tla2tools.jar / TLC that verifies NoLostGlobalDiagnostics (including across concurrent RPC delivery and background cancellation) with 0 errors across all reachable states, wired into verification/tla/scripts/run-tlc.sh.
  2. Go fix and regression test: On a clean fix branch off main (e0fce98), fix tsc/internal/project/session.go and add a deterministic in-package regression test proving that global diagnostics arriving while PublishDiagnostics RPC End-to-end red-to-green TLA+ fixes and upstream PR prep for flagship TypeScript 7 concurrency bugs #1 is in flight trigger a second publish call and leave globalDiagChanged == false at quiescence.
  3. Verification: go -C ./tsc test -race -timeout=120s ./internal/project/... passes, and npx hereby check:format and npx hereby lint pass for touched files.
  4. 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/session.go:196-200, 1998-2024 (globalDiagPublishPending, EnqueuePublishGlobalDiagnostics, publishGlobalDiagnostics)
  • tsc/internal/project/checkerpool.go:405-425 (mergeGlobalDiagnosticsFromCheckerLocked, TakeNewGlobalDiagnostics)
  • tsc/internal/project/background/queue.go
  • verification/tla/specs/SessionGlobalDiag/SessionGlobalDiag.tla
  • verification/tla/reproducers/project_repro_test.go

Activity

  1. added
    bug
    ready-for-agent
    on Nov 26, 2026
  2. robertpenner commented on Nov 26, 2026

    @robertpenner
    OwnerAuthor

    Just-in-Time Agent Brief (#4)

    • Codebase verified at: e0fce98 (main), 3421f17 (tla-concurrency-verification).
    • Root cause confirmed: tsc/internal/project/session.go:2004-2010 uses globalDiagPublishPending atomic.Bool cleared via defer s.globalDiagPublishPending.Store(false) on exit of publishGlobalDiagnostics. Any new global diagnostic merged into checkerPool after TakeNewGlobalDiagnostics() / GetProjectDiagnostics() and before publishGlobalDiagnostics returns sees CompareAndSwap(false, true) == false and is dropped.
    • Design for green model and fix: Replace the single boolean + defer with a 3-state atomic latch (idle = 0, running = 1, rerun = 2):
      • EnqueuePublishGlobalDiagnostics returns early if s.backgroundContext().Err() != nil; otherwise transitions idle -> running (enqueueing one background task) or running -> rerun (leaving rerun unchanged).
      • publishGlobalDiagnostics loops: runs one publish pass, then attempts CAS(running, idle) to exit; if state was rerun, resets to running (or idle if ctx.Err() != nil) and repeats.
      • This guarantees (1) zero lost notifications, (2) at most one concurrent publish goroutine (preventing out-of-order PublishDiagnostics RPC delivery), and (3) clean quiescent state.
    • Verification plan: Exhaustive TLC check (SessionGlobalDiag_Fixed.cfg, 0 errors on NoLostGlobalDiagnostics, NoOutOfOrderPublish, NoConcurrentPublishers), TDD regression test under go -C ./tsc test -race ./internal/project/..., and npx hereby check:format / lint.
  3. robertpenner commented on Nov 26, 2026

    @robertpenner
    OwnerAuthor

    Slice Complete: Red-to-Green Verified (#4)

    • Fix branch: fix/session-global-diag-push (8f416ad, based on main e0fce98)
    • Fork draft PR: opened on robertpenner/TypeScript (Closes #4)
    • Green TLA+ verification: SessionGlobalDiag_Fixed.cfg passed with 0 errors (72 distinct states, 98 generated) on NoLostGlobalDiagnostics, NoOutOfOrderPublish, and EventuallyAllPublished.
    • Go verification: go -C ./tsc test -race -count=1 ./internal/project/... passed (5/5 packages, including TestSessionEnqueuePublishGlobalDiagnosticsDuringInFlightPublish); gofmt and go vet clean.

    Draft Upstream Bug Report (for microsoft/TypeScript)

    Title: project.Session.publishGlobalDiagnostics drops global diagnostic updates arriving while a publish RPC is in flight

    Description:
    In tsc/internal/project/session.go, publishGlobalDiagnostics clears globalDiagPublishPending via defer s.globalDiagPublishPending.Store(false) on function return. If another diagnostics checker merges new global diagnostics into checkerPool after TakeNewGlobalDiagnostics() / GetProjectDiagnostics() and while s.client.PublishDiagnostics is in flight, EnqueuePublishGlobalDiagnostics() calls CompareAndSwap(false, true), observes true, and drops the enqueue. When the first publish returns, defer clears the flag, leaving checkerPool.globalDiagChanged == true unpublished until an unrelated future trigger.

    Replacing the single boolean with a three-state atomic latch (idle / running / rerun) preserves coalescing, prevents concurrent out-of-order PublishDiagnostics RPCs, and guarantees follow-up passes drain updates produced during an active publish.

    (Clean fix branch ready at robertpenner/TypeScript:fix/session-global-diag-push once an upstream issue is milestoned.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions