Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow state watch to debug mode #1975

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

glopesdev
Copy link
Member

@glopesdev glopesdev commented Aug 15, 2024

Understanding the runtime state of each operator in the workflow can be one of the most confusing aspects of learning visual reactive programming. Here we aim to assist this learning and debugging process by introducing a "watch" feature to the editor debug mode.

There are two main components to the feature:

  • New Diagnostics namespace introducing components and types for counting the number of notifications, subscriptions and cancellations to each operator.
  • Rendering pipeline for periodically overlaying the live watch state on the workflow, currently refreshing at 10 Hz.

Watch infrastructure

There are five main stages in the life of a subscription to an observable sequence:

  • Subscribe: the observable receives a subscription from a downstream operator
  • OnNext: the observable emits a new value notification
  • OnCompleted: the observable terminates successfully
  • OnError: the observable terminates exceptionally
  • Unsubscribe: the subscription is disposed, either following termination or cancellation

These stages can all run in parallel for each observable. The new diagnostics infrastructure introduces components to count all these events in a thread-safe manner using the InspectBuilder output streams.

A new Watch stream had to be introduced to reliably materialize cancellation. In general cancellation is not part of the Rx grammar and should not be relied upon for operator composition, but it can be invaluable to materialize these events for tracing and runtime monitoring.

Since each operator can have an arbitrary number of multiple parallel subscriptions, we adopt a strategy for combining or aggregating the state of each sequence into a single value using the following rules:

  enum WorkflowElementStatus
  {
      Ready, // no subscriptions have yet been made
      Active, // at least one active subscription but no values have been emitted yet
      Notifying, // at least one active subscription and emitted at least one value in the last period
      Completed, // no active subscriptions and at least one subscription terminated successfully
      Error, // no active subscriptions and at least one subscription terminated exceptionally
      Canceled // no active subscriptions and at least one subscription was canceled without termination
  }

The Error status has precedence over Completed, and both have precedence over Canceled. Each of the status values is mapped into a visual annotation which is updated and overlaid periodically on top of each operator. The Notifying status will actively spin as long as values continue to be emitted.

Status Annotation
Ready ready
Active ready
Notifying ready
Completed ready
Error ready
Canceled ready

Watch Example

watch-example

Caveats and limitations

  • Since the live watch refreshes at a maximum rate of 10 Hz this feature should not be relied upon for debugging race conditions, high-frequency streams, or any other aspects of the workflow behavior depending on precise timing.
  • When overlaying multiple parallel subscriptions some of the indicators may be misleading as to the true state, as there is currently no way of visually tracking the state of individual subscriptions and there are precedence rules for the visual annotations.
  • This feature should not be relied upon if knowing how many subscriptions are running over each operator is important.

Fixes #1859

@glopesdev glopesdev added the feature New planned feature label Aug 15, 2024
@glopesdev glopesdev added this to the 2.9 milestone Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New planned feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the ability to inspect the state of observable sequences
1 participant