Skip to content

feat(cli): surface resumable task_id when a subagent stops on error#11621

Merged
marius-kilocode merged 6 commits into
Kilo-Org:mainfrom
maoxin1234:feat/subagent-resumable-error-output
Jun 30, 2026
Merged

feat(cli): surface resumable task_id when a subagent stops on error#11621
marius-kilocode merged 6 commits into
Kilo-Org:mainfrom
maoxin1234:feat/subagent-resumable-error-output

Conversation

@maoxin1234

Copy link
Copy Markdown
Contributor

Problem

Closes #11620 (partially — backend slice).

When a subagent stops on an error (provider error, rate limit, timeout), the parent agent never sees the child session's task_id in a resumable form. The task tool already supports resuming a subagent by passing a prior task_id (it continues the same child session instead of creating a fresh one), but on the failure path that id is dropped, so a stopped subagent effectively becomes one-shot and its context is lost.

Change

Surface the resumable task_id whenever a subagent stops on an error, on both paths:

  • Foreground subagent failure: the error raised through the task-tool boundary now appends the child task_id and a hint that the session can be resumed.
  • Background subagent failure: the task_error message injected back into the parent session now includes the same resumable hint.

No new resume machinery is introduced — this only makes the already existing task_id resume capability discoverable to the parent agent on the error path.

Testing

  • bun test test/tool/task.test.ts → 23 pass / 0 fail
    • extended the existing "child assistant error" test to assert the failure message carries task_id="<id>" and the resume hint
    • added a background test asserting the injected task_error message surfaces the resumable task_id
  • tsgo --noEmit on @kilocode/cli → 0 errors
  • oxlint on the changed files → 0 errors

Changeset included.

Out of scope / follow-up

The issue also asks for UI affordances (a "Continue" button on stopped subagents, @subagent mentions). Those belong in the TUI subagent footer (subagent-data.ts) and are best done as a separate PR on top of this backend slice.

Foreground and background subagent failures now include the child
session's task_id and a hint that it can be resumed via the task tool,
so a stopped subagent can be continued instead of being lost (Kilo-Org#11620).
auto-merge was automatically disabled June 24, 2026 08:39

Head branch was pushed to by a user without write access

Comment thread packages/opencode/src/tool/task.ts
Comment thread packages/opencode/test/tool/task.test.ts
@kilo-code-bot

kilo-code-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/opencode/src/tool/task.ts
  • packages/opencode/test/tool/task.test.ts
Previous Review Summaries (2 snapshots, latest commit 0274b72)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 0274b72)

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/tool/task.ts 89 The duplicate-hint guard can still suppress the resumable task_id on unrelated background errors.

Fix these issues in Kilo Cloud

Files Reviewed (2 files)
  • packages/opencode/src/tool/task.ts - 1 issue
  • packages/opencode/test/tool/task.test.ts

Previous review (commit 2ac38d7)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/tool/task.ts 274 Background assistant-error failures append the resume hint twice.
packages/opencode/test/tool/task.test.ts 610 New background failure coverage can race the async parent-session injection and flake.

Fix these issues in Kilo Cloud

Files Reviewed (3 files)
  • .changeset/subagent-resumable-error.md
  • packages/opencode/src/tool/task.ts - 1 issue
  • packages/opencode/test/tool/task.test.ts - 1 issue

Reviewed by gpt-5.4-20260305 · Input: 56.3K · Output: 6.4K · Cached: 225.3K

Review guidance: REVIEW.md from base branch main

@marius-kilocode

Copy link
Copy Markdown
Collaborator

@maoxin1234 looks good. We can do this until we have all of the different issues fixed. (Related: #11585)

@marius-kilocode

Copy link
Copy Markdown
Collaborator

@maoxin1234 both bot comments seem valid. We should fix them.

@maoxin1234

Copy link
Copy Markdown
Contributor Author

Fixed both in 0274b72:

  • task.ts:274 (duplicate hint): the background assistant-error path already carries the resume hint from runTask(), and inject("error", ...) was appending it again. backgroundMessage() now only appends the hint when the error text does not already contain it, so the parent sees it exactly once. The defect/non-assistant-error path (which has no hint yet) still gets it.
  • task.test.ts (race): the parent-session injection is forked asynchronously, so jobs.wait() alone could read injected before it was populated. The test now resolves a Deferred inside the input.sessionID === chat.id branch and awaits it (1s timeout) before asserting.

Both new tests pass, typecheck and the annotation check are green.

Comment thread packages/opencode/src/tool/task.ts Outdated
@marius-kilocode marius-kilocode linked an issue Jun 29, 2026 that may be closed by this pull request
@marius-kilocode marius-kilocode merged commit 4a8f324 into Kilo-Org:main Jun 30, 2026
22 checks passed
@marius-kilocode

Copy link
Copy Markdown
Collaborator

Thanks @maoxin1234 , appreciate the contribution!

vkeerthivikram pushed a commit to vkeerthivikram/kilocode that referenced this pull request Jun 30, 2026
…able-error-output

feat(cli): surface resumable task_id when a subagent stops on error
NJ-2020 pushed a commit to NJ-2020/kilocode that referenced this pull request Jul 4, 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.

[Bug] Cannot Resume or Recover Sub-Agent Work After It Stops [FEATURE]: Option to force subagent continue on break, error or accident stop

2 participants