05. Runtime Sequences
Why This Page Matters
Static diagrams are useful, but this system is ultimately about motion over time:
- a command starts work
- services coordinate asynchronous operations
- state updates ripple into the UI
- terminal summaries and diagnostics record what happened
That is why sequence-style explanations are especially valuable in this repo.
This page focuses on two sequences a newcomer should understand early:
- start-run
- fault and recovery
Sequence 1: Start-Run
The Start Run button may look simple in the UI, but the underlying sequence is deliberately structured.
At a high level:
- the operator clicks
Start Run MainViewModelforwards the command toIWorkflowServiceWorkflowService.StartRunAsync()checks current state and claims the active run slot- the service updates canonical app state into
Preparing - the run loop begins on background work
- motion, camera, telemetry, and defect-result behavior advance during the run
- the service maps the termination reason to a terminal run summary
- the summary updates
LastRunSummaryandRunHistory - the UI reprojects the new state automatically
Relevant files:
src/InspectionPrototype.Presentation/ViewModels/MainViewModel.cssrc/InspectionPrototype.Application/Services/WorkflowService.cssrc/InspectionPrototype.Application/State/ActiveRunState.cssrc/InspectionPrototype.Domain/Contracts/RunSummary.cs
Quick Start-Run Sketch
Operator
|
v
MainViewModel -> WorkflowService -> AppState(Preparing)
|
v
Run loop starts
|
+---------------+----------------+
| | |
v v v
Motion Camera Pipelines / Results
\ | /
\ | /
+-------------+--------------+
|
v
RunSummary + RunHistory
|
v
UI reprojects stateWhy The Sequence Looks This Way
The code avoids a common mistake: leaving the workflow in a startable state while background work is only “about to” begin.
That is why the service claims the run slot and transitions state before the deeper runtime work unfolds. It reduces race conditions such as double-start behavior.
Sequence 2: Fault And Recovery
The fault path is equally important because it teaches the difference between:
- unsafe condition
- operator acknowledgment
- clearance of the underlying condition
- explicit recovery
At a high level:
- the operator injects a fault
- the fault injector raises an event
WorkflowServiceappends an alarm, transitions toFaulted, and cancels active work if needed- the UI shows the active alarm and blocked runtime state
- the operator acknowledges the fault
- the operator or engineer clears the underlying condition
- recovery remains blocked until the explicit
Recoveraction is used WorkflowService.RecoverAsync()returns the system to a usable non-faulted state
Relevant files:
src/InspectionPrototype.Infrastructure/Simulator/SimulatorFaultInjector.cssrc/InspectionPrototype.Application/Services/WorkflowService.cssrc/InspectionPrototype.Application/Guards/CommandGuards.cssrc/InspectionPrototype.Presentation/ViewModels/AlarmViewModel.cs
Quick Fault-Recovery Sketch
Inject Fault
|
v
FaultInjector -> WorkflowService -> AppState(Faulted)
|
+--> Active alarm added
+--> Active work canceled
+--> Commands blocked
Acknowledge
|
v
Alarm marked seen
|
v
Unsafe condition may still be active
Clear Fault Condition
|
v
Critical fault removed
|
v
Recover
|
v
WorkflowService -> AppState(Idle or Ready)Why These Sequences Matter Architecturally
These flows show the real value of the repo’s structure:
- the UI stays thin
- the application layer owns sequencing
- infrastructure raises events or satisfies abstractions
- the canonical app state remains the projection source
If these sequences were driven from the UI directly, the system would be much harder to test and much easier to desynchronize.
Trade-Offs
Benefits
- complex flows become inspectable
- concurrency issues are easier to reason about
- terminal behavior is centralized
- the system becomes more teachable
Costs
- runtime orchestration files grow in importance
- sequence reasoning requires learners to follow state plus async control flow
That complexity is worth showing, because it mirrors real production desktop systems more closely than a simplistic example would.
Suggested Hands-On Pairing
Read this page together with:
Those scenario pages let the learner see the sequence externally, while this page explains it internally.
Related Lessons
- 01. Async Await Deep Dive
- 04. CancellationToken in Production - Real World
- 11. Background Processing in .NET - Real World
- 12. Observability in .NET Systems - Real World
Diagram Brief: Start-Run Sequence
Title: Start-run sequencePurpose: Show how a run starts, claims ownership, progresses, and ends with a persisted summaryAudience: newcomer developer learning runtime orchestrationNodes: Operator, MainWindow, MainViewModel, WorkflowService, AppStateStore, MotionController, CameraController, TelemetryPipeline, FramePipeline, RunHistoryStoreEdges: operator triggers command; view model calls workflow service; service claims run slot and updates state; motion/camera/pipelines produce runtime activity; terminal summary is created and stored; UI reprojects the new stateGrouping: UI command path, application orchestration, background producers, persistenceCaption: A run is a coordinated sequence across services, not a direct UI-to-device shortcutDestination file path:docs/diagrams/source/architecture-05-start-run-sequence.drawio
Diagram Brief: Fault And Recovery Sequence
Title: Fault and recovery sequencePurpose: Show the transition from active fault to acknowledgment, clearance, and explicit recoveryAudience: newcomer developer or automation engineer learning safety-oriented state handlingNodes: Operator, MainViewModel, FaultInjector, WorkflowService, AppStateStore, Alarm List UI, CommandGuardsEdges: fault injection triggers event; workflow service appends active alarm and transitions to faulted; operator acknowledges; fault is cleared; command guards still block recovery-sensitive commands until explicit recover; recovery updates state and diagnosticsGrouping: Fault occurrence, operator acknowledgment, condition clearance, recoveryCaption: Recovery is intentionally stricter than acknowledgment so the system models unsafe conditions more honestlyDestination file path:docs/diagrams/source/architecture-05-fault-recovery-sequence.drawio