Skip to content

Commit 97f48c8

Browse files
committed
fix: move mode switch before child task creation in delegateParentAndOpenChild
- Move handleModeSwitch() call BEFORE createTask() to ensure child task initializes with the correct mode's system prompt - Remove redundant second handleModeSwitch() that was called after child creation - This ensures the child's first API call uses the correct mode configuration
1 parent c15cc38 commit 97f48c8

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,7 +3002,21 @@ export class ClineProvider
30023002
// Non-fatal: proceed with child creation even if parent cleanup had issues
30033003
}
30043004

3005-
// 3) Create child as sole active (parent reference preserved for lineage)
3005+
// 3) Switch provider mode to child's requested mode BEFORE creating the child task
3006+
// This ensures the child's system prompt and configuration are based on the correct mode.
3007+
// The mode switch must happen before createTask() because the Task constructor
3008+
// initializes its mode from provider.getState() during initializeTaskMode().
3009+
try {
3010+
await this.handleModeSwitch(mode as any)
3011+
} catch (e) {
3012+
this.log(
3013+
`[delegateParentAndOpenChild] handleModeSwitch failed for mode '${mode}': ${
3014+
(e as Error)?.message ?? String(e)
3015+
}`,
3016+
)
3017+
}
3018+
3019+
// 4) Create child as sole active (parent reference preserved for lineage)
30063020
const child = await this.createTask(message, undefined, parent as any, { initialTodos })
30073021

30083022
// 4) Persist parent delegation metadata
@@ -3032,17 +3046,6 @@ export class ClineProvider
30323046
// non-fatal
30333047
}
30343048

3035-
// 6) Switch provider mode to child's requested mode and focus child (already focused by addClineToStack)
3036-
try {
3037-
await this.handleModeSwitch(mode as any)
3038-
} catch (e) {
3039-
this.log(
3040-
`[delegateParentAndOpenChild] handleModeSwitch failed for mode '${mode}': ${
3041-
(e as Error)?.message ?? String(e)
3042-
}`,
3043-
)
3044-
}
3045-
30463049
return child
30473050
}
30483051

0 commit comments

Comments
 (0)