Skip to content

fix(agent-runtime): propagate cancellation from isolated agent runners - #87

Open
Linxiushen wants to merge 1 commit into
dtyq:masterfrom
Linxiushen:fix/subagent-cancellation-propagation
Open

fix(agent-runtime): propagate cancellation from isolated agent runners#87
Linxiushen wants to merge 1 commit into
dtyq:masterfrom
Linxiushen:fix/subagent-cancellation-propagation

Conversation

@Linxiushen

Copy link
Copy Markdown

Summary

  • persist the terminal INTERRUPTED state before isolated-agent cancellation exits
  • re-raise CancelledError from both tool-driven and service-driven sub-agent runners
  • cover synchronous delegation, Cron timeout handling, cleanup ordering, and background interruption compatibility

Problem

Both isolated-agent runners caught asyncio.CancelledError, saved an interrupted state, and then returned that state normally.

Returning from the cancellation handler converts a control-flow cancellation into normal completion:

  • synchronous call_subagent can wrap an interrupted child in an ok=True ToolResult, allowing the parent Agent loop to process work after its run was stopped or superseded
  • Cron's asyncio.wait_for(run_isolated_agent(...)) can return normally after its timeout, causing a timed-out job to remain recorded as ok

This leaves persisted state, scheduler state, and caller control flow with conflicting terminal outcomes.

Approach

Cancellation persistence and cancellation propagation serve separate purposes, so the runners now preserve both:

  1. mark and persist the sub-agent session as INTERRUPTED
  2. re-raise the original CancelledError
  3. keep the existing finally cleanup for Agent closure and session-handle clearing

Background status queries remain compatible because wait_for_subagents reads the persisted runtime state rather than calling task.result(). SubagentSessionManager.interrupt_run() already handles cancelled tasks.

Tests

  • tests/tools/test_subagent_cancellation.py: 3 passed
  • tests/service/test_cron_model_payload.py: 1 passed
  • runnable service test suite on the local platform: 95 passed
  • Ruff checks, Ruff format check, py_compile, and git diff --check: passed

Fixes #86

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.

fix(agent-runtime): preserve cancellation through isolated agent runners

1 participant