Skip to content

DYN-9151: Trust warning popup delayed by 20+ seconds on large graph open from untrusted folder #17103

@johnpierson

Description

@johnpierson

Problem

When a user opens a .dyn file from an untrusted folder, the "untrusted location" warning popup does not appear until after the entire graph has finished loading. On large graphs this is 20+ seconds. The popup should appear immediately, before the heavy deserialization work begins.

Regression from Dynamo 3.5 → 3.6. The popup-after-load ordering existed in 3.5 too, but graph open was fast enough that the delay was imperceptible. 3.6 perf refactors made other parts of open faster but did not move the popup display, so the gap grew visible.

Tracked in Jira: DYN-9151.

Reproduction

  1. Add a folder to Preferences → Security → Trusted Locations and then remove it (or use any folder not on the trusted list).
  2. Place a large .dyn file (≥1000 nodes, or any graph that takes >5s to open) in that untrusted folder.
  3. File → Open the graph.
  4. Observed: App processes for 20+ seconds. UI is laggy. Only after deserialization completes does the trust warning popup appear.
  5. Expected: Popup appears within ~100ms of clicking Open, before deserialization runs.

Root cause

In src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs, method Open(object parameters) (~L2192-2287) executes in this order:

Line Action Cost
L2224 Path.GetDirectoryName(filePath) fast
L2227-2231 displayTrustWarning = !PreferenceSettings.IsTrustedLocation(directoryName) && ... fast
L2232 RunSettings.ForceBlockRun = displayTrustWarning; fast
L2234 ExecuteCommand(new DynamoModel.OpenFileCommand(...)) — synchronous on UI thread; routes through DynamoModel.OpenFileFromPathOpenJsonFileFromPathOpenJsonFile + OpenWorkspace + OnComputeModelDeserialized + SetPeriodicEvaluation 20+ s on large graphs
L2237 RefreshAnnotationDescriptions() slow
L2240-2247 FileTrustViewModel.ShowWarningPopup = true — this is what flips IsOpen on the WPF popup popup finally appears here

The trust check itself is not the bottleneck. The defect is ordering: the popup is set after ExecuteCommand returns.

Same wrong-order pattern is duplicated in Insert(object parameters) at L2297-2371.

Prior attempt

PR #16947 ("DYN-9151: Add null-safety and caching") tried to defer ExecuteCommand via UIDispatcher.BeginInvoke so the popup could render first. The deferral was reverted — likely because the currentWorkspaceViewModel?.IsHomeSpace guard at L2240 fails: the new home workspace isn't swapped in until ExecuteCommand completes, so the guard skips showing the popup. Read the review comments on #16947 before re-attempting.

Acceptance criteria

  • Opening a large graph (≥1000 nodes) from an untrusted folder shows the trust warning popup within 500 ms of the user clicking Open.
  • After the graph finishes loading, the popup state is correct: visible if the folder is still untrusted, hidden if the user added it to trusted locations mid-load.
  • Same fix applied to DynamoViewModel.Insert (L2297-2371).
  • No regression to the .dyf exclusion (custom node definitions should not trigger the popup).
  • Existing tests pass; add a regression test that asserts popup-show ordering relative to OpenFileCommand execution.

Suggested implementation

Primary fixsrc/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs Open (L2192-2287):

Move the FileTrustViewModel block from L2240-2247 to before L2234's ExecuteCommand call. To avoid the regression that killed #16947, drop reliance on currentWorkspaceViewModel?.IsHomeSpace (the new workspace isn't loaded yet at this point) and either:

  • Option A (preferred): Show popup pre-emptively keyed on the file path. After load completes, call the existing ShowHideFileTrustWarningIfCurrentWorkspaceTrusted at L4200 to reconcile (hide popup if the loaded workspace turned out to be trusted, e.g., a custom node def or the user mid-load whitelisted the folder).
  • Option B: Guard on file extension only (already excludes .dyf) + null check on FileTrustViewModel. Drop the IsHomeSpace guard.

Secondary fixes:

  1. src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs Insert (L2297-2371) — duplicate of the bug, apply the same fix.
  2. src/DynamoCoreWpf/Views/FileTrust/FileTrustWarning.xaml.cs (L71-87) — ViewModel_PropertyChanged calls mainWindow.Dispatcher.Invoke(DispatcherPriority.Background, ...). If the popup is moved earlier (before heavy work), this synchronous pump may need to be BeginInvoke to avoid re-blocking the UI thread during the popup-render → ExecuteCommand transition.

Optional cleanup (in the same area):

  • src/DynamoCore/Configuration/PreferenceSettings.cs L637-639: TrustedLocations getter calls .ToList() on every access. L1466 IsTrustedLocation iterates that copied list per entry. Not the bottleneck, but trivial to fix while in the file.

Files to read first

  • src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.csOpen (~L2192), Insert (~L2297), ShowHideFileTrustWarningIfCurrentWorkspaceTrusted (~L4200)
  • src/DynamoCoreWpf/Views/FileTrust/FileTrustWarning.xaml.csViewModel_PropertyChanged (~L71)
  • src/DynamoCoreWpf/ViewModels/FileTrust/FileTrustWarningViewModel.csShowWarningPopup setter
  • src/DynamoCoreWpf/Views/FileTrust/FileTrustWarning.xaml — popup IsOpen binding
  • src/DynamoCore/Models/DynamoModel.csOpenFileFromPath (~L2175), OpenJsonFileFromPath (~L2304) for context on what runs synchronously inside ExecuteCommand
  • PR DYN-9151: Add null-safety and caching #16947 review comments — explains why the prior deferral attempt regressed

Out of scope

  • Making OpenFileCommand itself async — separate, larger effort.
  • Reworking TrustedLocations storage. (Trivial getter cleanup OK; full refactor is out.)

Notes

Line numbers are approximate to current master as of this writing.

Metadata

Metadata

Type

No type

Projects

Status

Triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions