Skip to content

fix(project): prevent lost global diagnostics push notifications - #6

Draft
robertpenner wants to merge 1 commit into
mainfrom
fix/session-global-diag-push
Draft

robertpenner wants to merge 1 commit into
mainfrom
fix/session-global-diag-push

Conversation

@robertpenner

Copy link
Copy Markdown
Owner

Closes #4

Summary

Fixes a lost-notification race in project.Session.EnqueuePublishGlobalDiagnostics / publishGlobalDiagnostics (tsc/internal/project/session.go), where global diagnostics accumulated while a previous PublishDiagnostics RPC was in flight were dropped because globalDiagPublishPending was cleared in a defer on function exit.

Root Cause

publishGlobalDiagnostics previously cleared globalDiagPublishPending via defer s.globalDiagPublishPending.Store(false). If a diagnostics checker merged new global diagnostics after TakeNewGlobalDiagnostics() / GetProjectDiagnostics() and before publishGlobalDiagnostics returned, EnqueuePublishGlobalDiagnostics() saw CompareAndSwap(false, true) == false and discarded the request.

Fix

Replace the single boolean with a three-state atomic latch (idle, running, rerun):

  • EnqueuePublishGlobalDiagnostics transitions idle -> running (enqueueing one background task) or running -> rerun (coalescing updates arriving during an active pass).
  • publishGlobalDiagnostics runs one pass and attempts CAS(running, idle) to exit; if the state became rerun, it resets to running and performs a follow-up pass.

This guarantees both zero dropped notifications and at most one concurrent publish goroutine (preventing out-of-order PublishDiagnostics RPC delivery).

Verification

  • TLA+ model (SessionGlobalDiag_Fixed.cfg on tla-concurrency-verification): 0 errors across 72 distinct states (98 generated), verifying NoLostGlobalDiagnostics, NoOutOfOrderPublish, and EventuallyAllPublished.
  • go -C ./tsc test -race -count=1 ./internal/project/...: all 5 packages pass (including new TestSessionEnqueuePublishGlobalDiagnosticsDuringInFlightPublish).
  • gofmt and go vet ./internal/project/...: clean.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant