Skip to content

Plan Viewer: guard clipboard writes and hand back the captured query on a truncated single-statement copy #4582

Closed

Description

@erikdarlingdata

Part of #4511, plan viewer parity with PerformanceStudio (PS). The viewer control is shared by the Darling Viewer and Lite, so the fix lands in both. This also covers the half of erikdarlingdata/PerformanceStudio@35249e2 that #4548 left out.

PS hardened all viewer clipboard writes against a busy Windows clipboard (erikdarlingdata/PerformanceStudio@7cd9218, issue #415: unguarded SetTextAsync in an async-void handler crashes the app when another process holds the clipboard) and separately fixed Copy Query Text to fall back to the query the plan was captured from when the plan's own copy hit SQL Server's 4,000-char showplan cap, but only for single-statement plans, counted the way the grid counts — not Batches.Sum (@35249e2, corrected by @fdd3d22 after a stored-procedure-body miscounted as single-statement). PM has the truncation flag already (PlanModels.cs:68-78 TruncationLengthThreshold/IsTextTruncated, Rule 39 warning in PlanAnalyzer.cs:568) but CopyStatementText_Click (PlanViewerControl.xaml.cs:341-349) still calls bare Clipboard.SetText and never uses the captured query fallback, and the node context-menu copies in PlanViewerControl.Interaction.cs:118-138 call bare Clipboard.SetDataObject. Port: add a guarded-write helper (mirror ClipboardText.TryRead's retry shape for writes) and route all Copy sites through it; add the single-statement-by-grid-count fallback to CopyStatementText_Click, leaving any parameterized-copy entry (if/when PM adds one) untouched per @fdd3d22's correction. Lite/Darling share this control, so the fix reaches both automatically.

PM today: CopyStatementText_Click (PerformanceMonitor.Ui/PlanViewerControl.xaml.cs ~341) calls Clipboard.SetText unguarded, and the node context-menu copies do the same (PlanViewerControl.Interaction.cs ~118–138). PM has a guarded clipboard READ helper (ClipboardText.cs) but no guarded write. For the truncated-copy fallback, the host has to pass the full query text it holds (the Darling Viewer and Lite load plans next to stored query text), the way PS's session passes the captured query.

At 08f3e3c4e. PS reference: its dev branch at 85492a1.

Activity

  1. added a commit that references this issue on Sep 28, 2026
    30e93e8
  2. erikdarlingdata commented on Sep 28, 2026

    @erikdarlingdata
    OwnerAuthor

    Closed by the watcher: delivered in PR #4593, merged to dev.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions