Skip to content

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

Draft
edelauna wants to merge 3 commits into
mainfrom
issue/560
Draft

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

Conversation

@edelauna

@edelauna edelauna commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Related GitHub Issue

Closes: #560

Description

When a delegated subtask was cancelled mid-execution, cancelTask() immediately severed the parent–child link — parent transitioned 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.

How it works

Before: cancel child → parent: delegated→active, awaitingChildId→undefined
        → child resumes → falls through to standalone "Start New Task"

After:  cancel child → child: active→interrupted, parent stays delegated
        → child resumes → delegates back to parent → parent completes

Changes

Core fix:

  • packages/types/src/history.ts — Add "interrupted" to HistoryItem 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.ts#cancelTask — Mark cancelled delegated child as "interrupted" instead of severing parent link; await abortTask() promise before writing "interrupted" to prevent a late saveClineMessages write from downgrading the status back to "active"
  • src/core/webview/ClineProvider.ts#removeClineFromStack — Skip parent auto-repair when child history shows "interrupted" (parent must stay "delegated" for resume)
  • src/core/tools/AttemptCompletionTool.ts — Accept "interrupted" alongside "active" so resumed children can delegate back to parent

CLI/session type sync:

  • packages/core/src/task-history/index.ts — Add "interrupted" to session reader allow-list so persisted interrupted sessions are not silently dropped
  • apps/cli/src/ui/types.ts, apps/cli/src/ui/components/autocomplete/triggers/HistoryTrigger.tsx — Add "interrupted" to status unions; display interrupted tasks with ⏸ icon and cyan color

Test Procedure

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

  • src/core/webview/__tests__/ClineProvider.flicker-free-cancel.spec.ts — Updated existing cancel tests; added tests asserting child is marked "interrupted" and parent stays "delegated"
  • src/__tests__/removeClineFromStack-delegation.spec.ts — Added test asserting parent is not auto-repaired when child is "interrupted"
  • src/core/tools/__tests__/attemptCompletionTool.spec.ts — Added test for interrupted child delegating back to parent
  • apps/cli/src/ui/components/autocomplete/triggers/__tests__/HistoryTrigger.test.tsx — Added test asserting ⏸ icon renders for interrupted status

E2E test:

  • apps/vscode-e2e/src/suite/subtasks.test.ts — New test: interrupt child mid-execution → resume → asserts child reports back to parent and parent completes with expected result

All unit tests pass: pnpm vitest run (408/408 files).

Pre-Submission Checklist

@coderabbitai

coderabbitai Bot commented Jul 2, 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: 8d74f235-6d60-4039-ac89-a74807f980c8

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.

@edelauna edelauna changed the title Issue/560 fix(task-lifecycle): preserve parent-child link when delegated subtask is interrupted (#560) Jul 2, 2026
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/extension/api.ts 0.00% 2 Missing ⚠️
src/core/tools/AttemptCompletionTool.ts 0.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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