Repository navigation
Run scenarios on the thread pool, queue System Log entries - #13
Merged
Merged
Conversation
A scenario ran entirely on the WPF UI thread: RunOnceAsync called the engine on the dispatcher, and the engine awaits without ConfigureAwait(false). The time between two nodes depended on the UI's load, and a blocking node froze the window. Every log call also waited for the UI thread (Dispatcher.Invoke). - Services/ScenarioRun.RunAsync takes a snapshot of the graph on the UI thread and starts the engine with Task.Run. RunOnceAsync continues on the UI thread after the await. - The snapshot is a copy nothing else refers to: opening a scenario during a run clears TransactionJson of the stored nodes. A node from an older file that only names its transaction gets a copy of the library transaction, so the engine does not read or write the UI-bound library for it. The copy is written with the invariant culture; the SecsGemBase converter otherwise turns 1,5 into 15 on a decimal-comma system. - ObservableLogger queues entries with Dispatcher.InvokeAsync, like SecsMessageLogger, takes an optional dispatcher provider and drops the entry when there is no dispatcher. ScenariosViewModel writes its own lines through the logger, so they keep their place between the engine's lines. - Runs enter the engine one at a time (it keeps the run's cancellation source in a field while it starts), and an And node's late "1/2 branches" report no longer replaces its Succeeded state. Both were harmless on a single thread. - specification/features.md: new section. New tests: ScenarioRunTests and ObservableLoggerTests. Internal board: secsgem/evencoolerfastsim issue 26. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A scenario ran entirely on the WPF UI thread (internal board, issue 26).
ScenariosViewModel.RunOnceAsynccalled the SecsGemBase engine on the dispatcher, and the engine awaits withoutConfigureAwait(false), so every node continued there.ILoggercall waited for the UI thread (Dispatcher.Invoke), also from the receive loop.Changes
Services/ScenarioRun.RunAsync(new): takes a snapshot of the graph on the UI thread and starts the engine withTask.Run.RunOnceAsynccontinues on the UI thread after the await; theProgress<T>for the canvas is created there.ScenarioRun.Snapshot: a copy of graph, nodes and edges that nothing else refers to.TransactionJsonof its nodes. The engine reads a node only when it reaches it.Logging/ObservableLogger: queues entries withDispatcher.InvokeAsync, likeSecsMessageLogger. It takes an optional dispatcher provider and drops the entry when there is no dispatcher (unit tests, shutdown); before, such a call threw.ScenariosViewModel.LogInfo/LogError: go through the logger instead of adding to the collection directly. A direct add overtook engine entries that were still queued: after a cancel, "cancelled by the user" came before the engine's "was cancelled". The unusedILogServiceconstructor parameter is gone.specification/features.md: new section.Known limits
ScenarioNodeViewModel.ToModel). That is issue 68, which also affects saved libraries and the item editor, and it is not changed here.RunOnceAsynccallingRunAsyncandIsStaleis not covered by a unit test. The view model needs the whole DI graph and reads the user's profile in its constructor. It is covered by the smoke run below.CLAUDE.mdrewrite: the local, uncommitted rewrite ofCLAUDE.mdin the main checkout saysObservableLoggerthrows in tests. After this PR it drops the entry.Verification
ScenarioRunTests: the caller is a thread with a realDispatcher; the engine sees no context, at start and after its first await. Also: the snapshot is independent of the stored graph, name-only nodes get their copy, floats survive underde-DE, node, edge and graph properties are all copied, starts are serialized, stale reports are dropped.ObservableLoggerTests: a log call returns while the UI thread is busy, entries arrive in call order on the UI thread, and without a dispatcher the entry is dropped.Task.RunDispatcher.Invokein the loggerIsStalenever trueIsStalefor every Waiting reportwindows-latest.🤖 Generated with Claude Code