Skip to content

Commit 9f2e99a

Browse files
committed
chore: address delegation review cleanup
1 parent e82b18c commit 9f2e99a

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/core/tools/AttemptCompletionTool.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export class AttemptCompletionTool extends BaseTool<"attempt_completion"> {
8686
// to prevent duplicate tool_results when user revisits from history
8787
const provider = task.providerRef.deref() as DelegationProvider | undefined
8888
if (provider) {
89+
let historyLookupTaskId = task.taskId
8990
try {
9091
const { historyItem } = await provider.getTaskWithId(task.taskId)
9192
const status = historyItem?.status
@@ -96,6 +97,7 @@ export class AttemptCompletionTool extends BaseTool<"attempt_completion"> {
9697
// This shows the user the completion result and waits for acceptance
9798
// without injecting another tool_result to the parent
9899
} else if (status === "active") {
100+
historyLookupTaskId = task.parentTaskId
99101
const { historyItem: parentHistory } = await provider.getTaskWithId(task.parentTaskId)
100102

101103
if (parentHistory.status === "delegated" && parentHistory.awaitingChildId === task.taskId) {
@@ -110,6 +112,9 @@ export class AttemptCompletionTool extends BaseTool<"attempt_completion"> {
110112
this.emitTaskCompleted(task)
111113
}
112114
if (delegation !== "continue") return
115+
} else {
116+
// Parent already detached, such as when the user cancelled this child.
117+
// Fall through to the normal completion ask flow.
113118
}
114119
} else {
115120
// Unexpected status (undefined or "delegated") - log error and skip delegation
@@ -124,7 +129,7 @@ export class AttemptCompletionTool extends BaseTool<"attempt_completion"> {
124129
} catch (err) {
125130
// If we can't get the history, log error and skip delegation
126131
console.error(
127-
`[AttemptCompletionTool] Failed to get history for task ${task.taskId}: ${(err as Error)?.message ?? String(err)}. ` +
132+
`[AttemptCompletionTool] Failed to get history for task ${historyLookupTaskId}: ${(err as Error)?.message ?? String(err)}. ` +
128133
`Skipping delegation.`,
129134
)
130135
// Fall through to normal completion ask flow

src/core/tools/__tests__/attemptCompletionTool.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ describe("attemptCompletionTool", () => {
534534
expect(mockPushToolResult).toHaveBeenCalledWith("")
535535
})
536536

537-
it("does not delegate a lineage-preserving subtask when the parent is no longer awaiting it", async () => {
537+
it("does not resume the parent when the parent is no longer awaiting this child", async () => {
538538
const block: AttemptCompletionToolUse = {
539539
type: "tool_use",
540540
name: "attempt_completion",

src/core/webview/ClineProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,6 +2972,9 @@ export class ClineProvider
29722972
awaitingChildId: undefined,
29732973
})
29742974

2975+
this.log(
2976+
`[cancelTask] Detached delegated parent ${task.parentTaskId}: delegated → active (child ${task.taskId} cancelled)`,
2977+
)
29752978
parentTask = undefined
29762979
rootTask = undefined
29772980
}

0 commit comments

Comments
 (0)