Repository navigation
feat(runtime): end a stopped run as stopped, and stop a run on a debug quit - #171
Open
robert-ursu wants to merge 11 commits into
Open
robert-ursu wants to merge 11 commits into
robert-ursu wants to merge 11 commits into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Debug quit can restart a cancellation-swallowing delegate and remains ignored by the non-streaming fallback.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Adds stopped-run reporting and makes debug quit interrupt active streaming executions.
Changes:
- Introduces the
STOPPEDstatus and host stop-request probe. - Detects cancellation-related stops and delivers stopped results.
- Watches streaming delegates for debug termination.
| File | Description |
|---|---|
src/uipath/runtime/stop.py |
Adds the stop-request probe. |
src/uipath/runtime/result.py |
Adds STOPPED status. |
src/uipath/runtime/context.py |
Classifies requested cancellations as stopped. |
src/uipath/runtime/debug/runtime.py |
Adds debug-quit monitoring. |
tests/test_stop.py |
Tests stopped-result behavior. |
tests/test_debugger.py |
Tests debug termination handling. |
pyproject.toml |
Bumps package version. |
uv.lock |
Updates the locked project version. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
A run cancelled because its host asked it to stop was reported as faulted with ERROR_CancelledError, indistinguishable from a crash. A host can now install a stop-requested probe (uipath.runtime.stop). When the run ends in a cancellation, or in an error raised because of one, and the probe says a stop was requested, the context writes the new stopped status with no error, and the result sink receives it like any final result. Without a probe, or when the probe says no, nothing changes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The debug runtime looked at the bridge's terminate signal only while it was waiting: before the first resume, at a breakpoint, or while polling a trigger. A Quit from Studio Web while the agent was running was logged and then ignored, and the run went on to completion. The delegate's stream is now watched for a quit. One that arrives while the delegate is working cancels it where it waits, as a stop would; one that arrives while an event is being handled ends the stream before the next. The delegate is closed either way and the run ends with the result a quit has always produced. A cancellation from anywhere else still propagates. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…in execute() A stopped run is now told apart from a failure by Task.cancelling() on the task that entered the context: a cancel() someone called keeps it above zero through cleanup, and a stray CancelledError leaves it at zero. This replaces the host-installed stop-requested probe and the walk of the exception chain, so uipath.runtime.stop goes away and hosts install nothing. The debug quit is watched in execute(), which runs the stream in its own task and races it against wait_for_terminate(). A quit cancels that task instead of the caller's, so no uncancel() bookkeeping or in-delegate tracking is needed, and the execute() fallback for a delegate that cannot stream is covered too. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011be41L1VE33oixHNnJRPhw
robert-ursu
force-pushed
the
feat/stopped-status
branch
from
November 24, 2026 14:08
4477dc9 to
1a8ed92
Compare
radu-mocanu
reviewed
Nov 24, 2026
radu-mocanu
reviewed
Nov 24, 2026
radu-mocanu
reviewed
Nov 24, 2026
radu-mocanu
reviewed
Nov 24, 2026
Before Python 3.13, a TaskGroup whose child fails after the group's body has ended cancels the parent task and never takes that back, so the task still reads cancelling() == 1 when the group's ExceptionGroup reaches the context. The context took that for a stop, wrote stopped and dropped the error. A run now ends as stopped only when its task is being cancelled and the exception is the CancelledError, or was raised while handling one or because of one. For an exception group, every error in it must be. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fmj9j6BHFgyskAHtyrUX7i
A quit that arrived while the debug runtime awaited a bridge call between events, such as a state update, left the delegate's stream suspended at its yield. Nothing closed it, so its cleanup ran later from the event loop's finalizer, after execute() had reported the run as completed. Every stream the debug runtime iterates is now closed when it stops iterating, so cancelling the run closes and awaits the delegate's stream before execute() reports the quit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fmj9j6BHFgyskAHtyrUX7i
… meanwhile A host cancellation while execute() waited for the quit's cleanup made it raise at once, while the run's task was still closing the delegate. It now waits for that task through any cancellation and then re-raises the cancellation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fmj9j6BHFgyskAHtyrUX7i
The testcase from uipath-langchain-python now checks the LLM Gateway's spans and needs the key of the folder the Gateway publishes them to. It fails its setup without it. Pass it the way uipath-python's copy of this workflow does, from the <ENV>_GATEWAY_FOLDER_KEY secrets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fmj9j6BHFgyskAHtyrUX7i
- _wait_out re-raises the caller's cancellation from its handler, after waiting again for the task, instead of keeping it for after the loop. - Each pytest.raises block in test_stop.py holds a single call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fmj9j6BHFgyskAHtyrUX7i
ionut-mihalache-uipath
approved these changes
Nov 24, 2026
A cancellation on its own does not say the host stopped the run. On Python 3.11 and 3.12, a TaskGroup whose child fails after the group's body has ended leaves the parent's cancelling() count raised, and a child whose asyncio.timeout() expires fails with a TimeoutError chained to a CancelledError. Such a run was written as stopped with its error cleared. The host now confirms the stop through a probe in uipath.runtime.stop, read from the context the run entered. uipath 2.15.8 already installs one that answers whether its stop reached the still-running root task. The run ends as stopped when that probe says yes and the exception is the cancellation or was raised because of one. Without a probe, a cancelled run faults as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fmj9j6BHFgyskAHtyrUX7i
…ellation The console bridge catches the CancelledError while it waits for a resume and returns a continue command, so a Ctrl+C at a breakpoint cancelled the run and then resumed the delegate's next segment. Python 3.11's asyncio.wait_for can swallow the cancellation the same way during the initial resume wait. Once execute() stops the run, the debug runtime raises the cancellation again before it starts a delegate segment and after it handles each event. The chat test's debug bridge returned from wait_for_terminate at once, which is a quit before the run starts. It now blocks like a real bridge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fmj9j6BHFgyskAHtyrUX7i
A quit at a breakpoint makes the resume wait raise and sets the bridge's terminate signal. stream() then reports the quit's result, and execute()'s watcher could cancel the run while that send was awaited and report completion again. A run that has started reporting its completion now owns it: a quit that lands meanwhile waits for the run instead of cancelling it. A run the quit cancels before that point still gets its completion from execute(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fmj9j6BHFgyskAHtyrUX7i
|
This branch has not been deployed
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.




A run that its host stops now ends as stopped instead of faulted, and a debug session that quits while the agent is running stops the run instead of letting it finish.
Why
CancelledErrorinto a faulted result withERROR_CancelledError, sooutput.jsonand the result sink could not tell a stop from a failure. Serverless reads that status and lets a faulted one win over the stop, so a stopped job would be reported as Faulted.What: a stopped status
UiPathRuntimeStatus.STOPPED("stopped").uipath.runtime.stop: a host installs a stop-requested probe withset_stop_requested_probe(). It is a contextvar, read when the run enters the context, so concurrent executions each see their own host's answer.UiPathRuntimeContext.__exit__writesstopped, with no error, when two things hold:CancelledError, or was raised while handling one or because of one. For an exception group, every error in it must be.cancelling()count raised, and a child whoseasyncio.timeout()expires fails with aTimeoutErrorchained to aCancelledError. Without the probe, such a run would look stopped.ERROR_CancelledErroras before.What: a debug quit while the run is going
execute()runs the stream in its own task and races it against the bridge'swait_for_terminate():CancelledErrorwhile it waits for a resume and returns a continue command, and Python 3.11'sasyncio.wait_forcan swallow it during the initial resume wait. Onceexecute()stops the run, the debug runtime raises the cancellation again before it starts a delegate segment and after it handles each event, so a Ctrl+C at a breakpoint does not resume the delegate.The quit cancels the run's own task, not the caller's, so no
uncancel()bookkeeping is needed. The same path covers a delegate that cannot stream.Worth a careful look
UiPathDebugFunctionsRuntimeruns a coded function on its own thread, which kept going after its stream was closed. UiPath/uipath-python#2025 makes it stop the function and wait for its thread. It should be released before this one, since uipath allowsuipath-runtime<0.14.wait_for_terminate()returning now ends a running session. The bridges in uipath (console and SignalR) and the detached bridge here block until the user quits. A bridge whosewait_for_terminatereturns at once would end every run at its first event. One test fake inuipath-claude-sdkdoes this.output.json. A coded agent can also run a newer runtime than its host, so switching the quit's status is left for when those handlers are gone.Compatibility
uipath.runtime.stop. It answers whether its stop reached the still-running root task, so uipath server's stops end as stopped with no change in uipath. Once uipath'suipath-runtimefloor is this release, its fallback for a missing module can go.CI
The
gateway-and-direct-modelstestcase from uipath-langchain-python now needs the key of the folder the LLM Gateway publishes its spans to. This PR passesGATEWAY_FOLDER_KEYto it the way uipath-python's copy of the workflow does. This repo still needs theALPHA_GATEWAY_FOLDER_KEY,STAGING_GATEWAY_FOLDER_KEYandCLOUD_GATEWAY_FOLDER_KEYsecrets before those jobs can pass.Testing
New
tests/test_stop.py:New in
tests/test_debugger.py:execute()and throughstream().The debug bridge mocks'
wait_for_terminatenow blocks like a real bridge, including the one intests/test_chat.py.End to end, uipath 2.15.8's
uipath serverran a job and was asked over HTTP to stop it after 5 s:output.jsonfaulted,ERROR_CancelledError{"output": {}, "status": "stopped"}A run that is not stopped still ends with exit 0 on this PR.
466 tests pass on Python 3.11, 3.12 and 3.13; ruff and mypy are clean.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Fmj9j6BHFgyskAHtyrUX7i