You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by ak...@apache.org on 2026/06/05 07:37:36 UTC
(tooling-gofannon) 12/25: actually bind the cancel token so check_should_stop sees it
This is an automated email from the ASF dual-hosted git repository.
andrewmusselman pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-gofannon.git
commit 8c3134a14b610bce45a9ae57a14da6183d3b1b61
Author: Andrew Musselman <ak...@apache.org>
AuthorDate: Thu Jun 4 15:56:34 2026 -0700
actually bind the cancel token so check_should_stop sees it
ISSUE-007 follow-up #2. The cancel-token primitive's check sites in data_store_service and llm_service have been polling _token.get() since 007 landed, but no production code called bind_token() to put anything in the contextvar. /runs/{id}/stop correctly set _stopped=True on the registry entry; the agent's checks saw None and silently passed. One bind_token(_cancel_token) call in the streaming endpoint after registry publish closes the loop.
---
webapp/packages/api/user-service/routes.py | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/webapp/packages/api/user-service/routes.py b/webapp/packages/api/user-service/routes.py
index 45c4704..056a1e3 100644
--- a/webapp/packages/api/user-service/routes.py
+++ b/webapp/packages/api/user-service/routes.py
@@ -714,15 +714,15 @@ async def run_agent_code_stream(
queue: asyncio.Queue = asyncio.Queue()
trace.attach_queue(queue)
- # ISSUE-007 follow-up: register this run with the registry + cancel
- # registry so the client can address it for stop. Stream's runId is
- # emitted as the first SSE event ("run_id") so RunsScreen can capture
- # it and enable the Stop button. The streaming endpoint still pins
- # its worker (we haven't moved to the start-then-subscribe model
- # here), but the runId binding makes stop wiring possible.
+ # Register this run with the registry + cancel registry so the client
+ # can address it for stop. Stream's runId is emitted as the first SSE event
+ # ("run_id") so RunsScreen can capture it and enable the Stop button. The
+ # streaming endpoint still pins its worker (we haven't moved to the
+ # start-then-subscribe model here), but the runId binding makes stop
+ # wiring possible.
from services.run_registry import get_run_registry
from services.run_cancel_registry import publish as register_cancel_token
- from services.cancel_token import CancelToken
+ from services.cancel_token import CancelToken, bind_token
_registry = get_run_registry()
_run_record = _registry.new_record(
@@ -731,6 +731,7 @@ async def run_agent_code_stream(
)
_cancel_token = CancelToken()
register_cancel_token(_run_record.run_id, _cancel_token)
+ bind_token(_cancel_token)
# Sentinel posted to the queue when the agent finishes (success
# or error) so the streaming generator knows to stop pulling.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org