fix(background): use parent session variant in notifyParentSession instead of child task variant
This commit is contained in:
@@ -1059,7 +1059,18 @@ describe("BackgroundManager.notifyParentSession - aborted parent", () => {
|
|||||||
prompt: promptMock,
|
prompt: promptMock,
|
||||||
promptAsync: promptMock,
|
promptAsync: promptMock,
|
||||||
abort: async () => ({}),
|
abort: async () => ({}),
|
||||||
messages: async () => ({ data: [] }),
|
messages: async () => ({
|
||||||
|
data: [{
|
||||||
|
info: {
|
||||||
|
agent: "explore",
|
||||||
|
model: {
|
||||||
|
providerID: "anthropic",
|
||||||
|
modelID: "claude-opus-4-6",
|
||||||
|
variant: "high",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const manager = new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput)
|
const manager = new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput)
|
||||||
@@ -1219,6 +1230,58 @@ describe("BackgroundManager.notifyParentSession - variant propagation", () => {
|
|||||||
manager.shutdown()
|
manager.shutdown()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("should prefer parent session variant over child task variant in parent notification promptAsync body", async () => {
|
||||||
|
//#given
|
||||||
|
const promptCalls: Array<{ body: Record<string, unknown> }> = []
|
||||||
|
const client = {
|
||||||
|
session: {
|
||||||
|
prompt: async () => ({}),
|
||||||
|
promptAsync: async (args: { path: { id: string }; body: Record<string, unknown> }) => {
|
||||||
|
promptCalls.push({ body: args.body })
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
abort: async () => ({}),
|
||||||
|
messages: async () => ({
|
||||||
|
data: [{
|
||||||
|
info: {
|
||||||
|
agent: "explore",
|
||||||
|
model: {
|
||||||
|
providerID: "anthropic",
|
||||||
|
modelID: "claude-opus-4-6",
|
||||||
|
variant: "max",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const manager = new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput)
|
||||||
|
const task: BackgroundTask = {
|
||||||
|
id: "task-parent-variant-wins",
|
||||||
|
sessionID: "session-child",
|
||||||
|
parentSessionID: "session-parent",
|
||||||
|
parentMessageID: "msg-parent",
|
||||||
|
description: "task with mismatched variant",
|
||||||
|
prompt: "test",
|
||||||
|
agent: "explore",
|
||||||
|
status: "completed",
|
||||||
|
startedAt: new Date(),
|
||||||
|
completedAt: new Date(),
|
||||||
|
model: { providerID: "anthropic", modelID: "claude-opus-4-6", variant: "high" },
|
||||||
|
}
|
||||||
|
getPendingByParent(manager).set("session-parent", new Set([task.id]))
|
||||||
|
|
||||||
|
//#when
|
||||||
|
await (manager as unknown as { notifyParentSession: (task: BackgroundTask) => Promise<void> })
|
||||||
|
.notifyParentSession(task)
|
||||||
|
|
||||||
|
//#then
|
||||||
|
expect(promptCalls).toHaveLength(1)
|
||||||
|
expect(promptCalls[0].body.variant).toBe("max")
|
||||||
|
|
||||||
|
manager.shutdown()
|
||||||
|
})
|
||||||
|
|
||||||
test("should not include variant in promptAsync body when task has no variant", async () => {
|
test("should not include variant in promptAsync body when task has no variant", async () => {
|
||||||
//#given
|
//#given
|
||||||
const promptCalls: Array<{ body: Record<string, unknown> }> = []
|
const promptCalls: Array<{ body: Record<string, unknown> }> = []
|
||||||
|
|||||||
@@ -1783,6 +1783,7 @@ export class BackgroundManager {
|
|||||||
let agent: string | undefined = task.parentAgent
|
let agent: string | undefined = task.parentAgent
|
||||||
let model: { providerID: string; modelID: string } | undefined
|
let model: { providerID: string; modelID: string } | undefined
|
||||||
let tools: Record<string, boolean> | undefined = task.parentTools
|
let tools: Record<string, boolean> | undefined = task.parentTools
|
||||||
|
let promptContext: ReturnType<typeof resolvePromptContextFromSessionMessages> = null
|
||||||
|
|
||||||
if (this.enableParentSessionNotifications) {
|
if (this.enableParentSessionNotifications) {
|
||||||
try {
|
try {
|
||||||
@@ -1796,7 +1797,7 @@ export class BackgroundManager {
|
|||||||
tools?: Record<string, boolean | "allow" | "deny" | "ask">
|
tools?: Record<string, boolean | "allow" | "deny" | "ask">
|
||||||
}
|
}
|
||||||
}>)
|
}>)
|
||||||
const promptContext = resolvePromptContextFromSessionMessages(
|
promptContext = resolvePromptContextFromSessionMessages(
|
||||||
messages,
|
messages,
|
||||||
task.parentSessionID,
|
task.parentSessionID,
|
||||||
)
|
)
|
||||||
@@ -1840,7 +1841,7 @@ export class BackgroundManager {
|
|||||||
const isTaskFailure = task.status === "error" || task.status === "cancelled" || task.status === "interrupt"
|
const isTaskFailure = task.status === "error" || task.status === "cancelled" || task.status === "interrupt"
|
||||||
const shouldReply = allComplete || isTaskFailure
|
const shouldReply = allComplete || isTaskFailure
|
||||||
|
|
||||||
const variant = task.model?.variant
|
const variant = promptContext?.model?.variant
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.client.session.promptAsync({
|
await this.client.session.promptAsync({
|
||||||
|
|||||||
Reference in New Issue
Block a user