Skip to content

fix(task-lifecycle): preserve parent-child link when delegated subtask is interrupted (#560)#613

Closed
edelauna wants to merge 6 commits into
mainfrom
issue/560
Closed

fix(task-lifecycle): preserve parent-child link when delegated subtask is interrupted (#560)#613
edelauna wants to merge 6 commits into
mainfrom
issue/560

Conversation

@edelauna

@edelauna edelauna commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Related GitHub Issue

Closes: #560

Description

When a delegated subtask is interrupted mid-execution (user hits stop), cancelTask immediately severed the parent-child link — parent went from "delegated""active" with awaitingChildId cleared. When the user resumed the child and it called attempt_completion, the parent no longer awaited it, so it fell through to the standalone "Start New Task" flow instead of reporting back.

Changes

Core fix — 4 files:

  • packages/types/src/history.ts — Add "interrupted" to status enum
  • packages/types/src/task.ts / src/core/task/Task.ts / src/core/task-persistence/taskMetadata.ts — Propagate "interrupted" through initialStatus types
  • src/core/webview/ClineProvider.tscancelTask and removeClineFromStack now mark the child as "interrupted" instead of detaching the parent. Parent stays "delegated" with awaitingChildId intact.
  • src/core/tools/AttemptCompletionTool.ts — Accept "interrupted" alongside "active" so resumed children can still delegate back to parent

CLI type sync — 2 files:

  • apps/cli/src/ui/types.ts / apps/cli/src/ui/components/autocomplete/triggers/HistoryTrigger.tsx — Add "interrupted" to CLI status types to prevent type drift

Test flake fix — 1 file:

  • src/services/mcp/__tests__/McpHub.spec.ts — Replace 20 instances of setTimeout(resolve, 100) with mcpHub.waitUntilReady() to fix a pre-existing timing race that surfaces under thread-pool pressure in the full test suite

How it works

Before: cancel child → parent: delegated→active, awaitingChildId→undefined → child resumes → falls through to standalone
After:  cancel child → child: active→interrupted, parent stays delegated → child resumes → delegates back to parent

Test Procedure

Unit tests (3 files updated, 1 new test added):

  • src/__tests__/removeClineFromStack-delegation.spec.ts — Updated to assert child marked interrupted (not parent detached)
  • src/core/webview/__tests__/ClineProvider.flicker-free-cancel.spec.ts — Updated for new cancel behavior
  • src/core/tools/__tests__/attemptCompletionTool.spec.ts — Added test for interrupted child delegating back to parent; added test for unexpected child status branch

E2E test (1 test updated):

  • apps/vscode-e2e/src/suite/subtasks.test.ts — Updated "cancelled child" test to assert the new behavior: interrupted child resumes → reports back to parent → parent completes. Validated locally via xvfb-run.

All tests pass: pnpm exec vitest run (unit), xvfb-run pnpm --filter @roo-code/vscode-e2e test:ci:mock (e2e).

Pre-Submission Checklist

Additional Notes

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f61b104c-feef-451d-aacc-ac48202c203b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue/560

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.41176% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/core/webview/ClineProvider.ts 80.00% 9 Missing and 3 partials ⚠️
...omponents/autocomplete/triggers/HistoryTrigger.tsx 66.66% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@edelauna edelauna changed the title fix(task-lifecycle): preserve parent-child link when delegated subtas… fix(task-lifecycle): preserve parent-child link when delegated subtask is interrupted (#560) Jun 14, 2026
@edelauna edelauna force-pushed the issue/560 branch 3 times, most recently from 775a5d4 to 6afd917 Compare June 14, 2026 16:48
@edelauna

Copy link
Copy Markdown
Contributor Author

Closing in favor of landing #355 Epic 1+2 foundation first.

The multi-agent code review surfaced 3 blocking concurrency bugs from unserialized delegation-state mutations — a structural problem that the transition guards (Story 2.3, #366) and atomicReadAndUpdate() from #355 are designed to eliminate. See comments on #560 and #559 for the full rationale.

The behavioral design, test coverage (39 unit + 4 E2E tests), and review fixes on this branch are preserved for reuse when interrupted is re-implemented on top of the foundation.

@edelauna edelauna closed this Jun 14, 2026
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(task-lifecycle): preserve parent-child link when delegated subtask is interrupted

1 participant