Repository navigation
Cancel a running flow: flow_cancel and POST /flows/runs/:id/cancel stop the step a run is on (1.9.0) - #65
Merged
Conversation
…op the step a run is on (1.9.0) A run could not be stopped. The runner had a per-run AbortController that nothing aborted, and only custom steps received its signal. - Runs executing in a process are kept in one registry per process (on globalThis, like the step registry), so a cancel finds a run whichever FlowRunner started it: the flow server keeps the runner it started with, while flow_run and the scheduler use the newest one. - FlowRunner.cancel(instanceId, reason) aborts a live run. Every step gets the signal of its attempt: an agent step's openclaw process gets SIGTERM, on which the CLI aborts its turn in the gateway; exec kills its shell; http and ai abort their request; sleep and wait-for-event stop; a custom step gets ctx.abortSignal and is abandoned if it ignores it. The run ends "cancelled", the interrupted step's trace entry too, and nothing after it runs or retries. - A run not executing in this process (paused at an approval gate, or left "running" by a restart) is marked cancelled and its approval dropped. A runner in another process that still holds a run stops before its next step and keeps the cancel. - flow_cancel tool, and POST /:basePath/runs/:instanceId/cancel on the flow server (404 run_not_found, 409 run_finished). - Each attempt is also stopped when it times out, before a retry starts, instead of running on in the background. An agent step with no timeout now gets 120 s per attempt, the timeout its openclaw process always had; with 30 s the step failed while its turn ran on to 120 s. - The flow_run guard now catches a step that names only an agent (it runs in agent:<agent>:<session.mainKey>, "main" by default, read from the host config), and agent steps inside loops, branches and conditions.
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.
What changes
A run could not be stopped. The runner had a per-run
AbortControllerthat nothing aborted, and only custom steps received its signal. This adds cancelling, and makes each step's timeout stop the step's work.FlowRunner.cancel(instanceId, reason?), theflow_canceltool, andPOST /:basePath/runs/:instanceId/cancelon the flow server. The route answers 200{ ok, instanceId, status }, 404run_not_found, or 409run_finished.cancelled, the interrupted step's trace entry too. Nothing after it runs or retries. What the step gets:openclaw agentprocess gets SIGTERM, which the CLI answers by aborting its turn in the gateway;ctx.abortSignal, and are abandoned if they ignore it.globalThis, like the step registry. A host may callregister()more than once, and the flow server keeps the runner of the first call, so a cancel has to cross runners.runningby a restart) is marked cancelled and its approval dropped. A runner in another process that still holds the run stops before its next step and keeps the cancel.timeoutnow gets 120 s per attempt, the timeout itsopenclaw agentprocess always had. With 30 s, the step failed while its turn ran on to 120 s.flow_runguard now resolves a step that names only an agent. Such a step runs inagent:<agent>:<session.mainKey>, "main" by default; the plugin reads the main key from the host config. The guard also covers agent steps inside loops, branches and conditions.Version 1.9.0, and the manifest version is brought level with the package.
Tests
271 pass, 19 of them new (
tests/cancel.test.ts,tests/plugin-cancel.test.ts). They cover:openclawCLI receiving SIGTERM;flow_cancelregistered and declared incontracts.tools.