Skip to content

[proposal] make run flows cancellable if coroutine scope is cancelled #2488

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

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

Conversation

herval
Copy link
Collaborator

@herval herval commented May 15, 2025

The goal here is to make a Maestro Orchestra coroutine-cancellable - if the context where it's running is cancelled, it'll skip heavy setup steps (eg initializing the js engine). It'll still go through all the commands on the flow, but marking them all as SKIPPED instead of executing them.

logger.info("Flow cancelled, skipping command...")
onCommandSkipped(index, command)
return@forEachIndexed
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say if coroutine context is cancelled where should we be releasing resources that got acquired during execution?

There are bunch already that could be acquired: There is insights listener, leaveScope on jsEngine, there is global screenRecording field which would have risk of just keep running.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say if coroutine context is cancelled where should we be releasing resources that got acquired during execution?

on the same place they get released without cancellation?

is there anything on this PR not being released with this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I see some funkiness with the jsEngine thing being a lateinit. I'll keep it being initialized even if the routine is cancelled to avoid some unexpected behavior

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verified that screenrecording.close will be called regardless of cancellation, so that one seems safe?

Copy link
Collaborator

@amanjeetsingh150 amanjeetsingh150 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direction looks great, I'm trying to think what would be best way to add a test for this to ensure, cancelling coroutine:

  1. Skips rest of commands
  2. Expect to release resources which were acquired


commands
.forEachIndexed { index, command ->
if (!coroutineContext.isActive) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking how this should look like for cli, should there be any controls there? I believe not useful, because users usually press control + c to break from flows.

Although I'm not sure about CI

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctrl+c kills the entire Java process, so it's not gonna impact any of this. Coroutine cancellation is for when you have a process still running and you want to cancel it

@herval herval force-pushed the cancellation-support branch from 7163212 to 924909b Compare May 16, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants