@@ -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
0 commit comments