fix(delegate-task): align metadata with opencode core task tool
Match opencode core 'task' tool behavior for metadata consistency: 1. Model fallback: When categoryModel/task.model/resumeModel is undefined, fall back to parentContext.model so subagent metadata always includes model info. Thread parentContext into executeSyncContinuation for parity. 2. Task ID consistency: unstable-agent-task was missing taskId and backgroundTaskId in metadata. background_output used inconsistent snake_case 'task_id' vs camelCase 'taskId' elsewhere. Standardize on camelCase: taskId = sessionID (resume id), backgroundTaskId = bg task id. Update text output blocks to use buildTaskMetadataBlock helper. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -161,7 +161,7 @@ describe("metadata model unification", () => {
|
||||
prompt: async () => ({}),
|
||||
},
|
||||
},
|
||||
} as any, deps)
|
||||
} as any, parentContext, deps)
|
||||
|
||||
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
|
||||
expect(meta).toBeDefined()
|
||||
@@ -169,4 +169,179 @@ describe("metadata model unification", () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given categoryModel is undefined but parent.model is set", () => {
|
||||
describe("#when executors publish metadata", () => {
|
||||
test("#then sync-task metadata falls back to parent.model", async () => {
|
||||
const { executeSyncTask } = require("./sync-task")
|
||||
const ctx = makeMockCtx()
|
||||
const deps = {
|
||||
createSyncSession: async () => ({ ok: true, sessionID: "ses_sync" }),
|
||||
sendSyncPrompt: async () => null,
|
||||
pollSyncSession: async () => null,
|
||||
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
|
||||
}
|
||||
const args: DelegateTaskArgs = {
|
||||
description: "test", prompt: "do it",
|
||||
subagent_type: "explore", load_skills: [], run_in_background: false,
|
||||
}
|
||||
|
||||
await executeSyncTask(args, ctx, {
|
||||
client: { session: { create: async () => ({ data: { id: "ses_sync" } }) } },
|
||||
directory: "/tmp",
|
||||
onSyncSessionCreated: null,
|
||||
}, parentContext, "explore", undefined, undefined, undefined, undefined, deps)
|
||||
|
||||
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
|
||||
expect(meta).toBeDefined()
|
||||
expect(meta.metadata.model).toEqual(MODEL)
|
||||
})
|
||||
|
||||
test("#then background-task metadata falls back to parent.model", async () => {
|
||||
const { executeBackgroundTask } = require("./background-task")
|
||||
const ctx = makeMockCtx()
|
||||
const args: DelegateTaskArgs = {
|
||||
description: "test", prompt: "do it",
|
||||
load_skills: [], run_in_background: true, subagent_type: "explore",
|
||||
}
|
||||
|
||||
await executeBackgroundTask(args, ctx, {
|
||||
manager: {
|
||||
launch: async () => ({
|
||||
id: "bg_1", description: "test", agent: "explore",
|
||||
status: "pending", sessionID: "ses_bg",
|
||||
}),
|
||||
getTask: () => undefined,
|
||||
},
|
||||
} as any, parentContext, "explore", undefined, undefined)
|
||||
|
||||
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
|
||||
expect(meta).toBeDefined()
|
||||
expect(meta.metadata.model).toEqual(MODEL)
|
||||
})
|
||||
|
||||
test("#then unstable-agent-task metadata falls back to parent.model", async () => {
|
||||
const { executeUnstableAgentTask } = require("./unstable-agent-task")
|
||||
const ctx = makeMockCtx()
|
||||
const args: DelegateTaskArgs = {
|
||||
description: "test", prompt: "do it",
|
||||
category: "quick", load_skills: [], run_in_background: false,
|
||||
}
|
||||
|
||||
const launchedTask = {
|
||||
id: "bg_unstable", description: "test", agent: "explore",
|
||||
status: "completed", sessionID: "ses_unstable",
|
||||
}
|
||||
|
||||
await executeUnstableAgentTask(
|
||||
args, ctx,
|
||||
{
|
||||
manager: {
|
||||
launch: async () => launchedTask,
|
||||
getTask: () => launchedTask,
|
||||
},
|
||||
client: {
|
||||
session: {
|
||||
status: async () => ({ data: { ses_unstable: { type: "idle" } } }),
|
||||
messages: async () => ({
|
||||
data: [{
|
||||
info: { role: "assistant", time: { created: 1 } },
|
||||
parts: [{ type: "text", text: "done" }],
|
||||
}],
|
||||
}),
|
||||
},
|
||||
},
|
||||
syncPollTimeoutMs: 100,
|
||||
} as any,
|
||||
parentContext, "explore", undefined, undefined, "anthropic/claude-sonnet-4-6",
|
||||
)
|
||||
|
||||
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
|
||||
expect(meta).toBeDefined()
|
||||
expect(meta.metadata.model).toEqual(MODEL)
|
||||
})
|
||||
|
||||
test("#then background-continuation metadata falls back to parent.model when task.model missing", async () => {
|
||||
const { executeBackgroundContinuation } = require("./background-continuation")
|
||||
const ctx = makeMockCtx()
|
||||
const args: DelegateTaskArgs = {
|
||||
description: "continue", prompt: "keep going",
|
||||
load_skills: [], run_in_background: true, task_id: "ses_resumed",
|
||||
}
|
||||
|
||||
await executeBackgroundContinuation(args, ctx, {
|
||||
manager: {
|
||||
resume: async () => ({
|
||||
id: "bg_2", description: "continue", agent: "explore",
|
||||
status: "running", sessionID: "ses_resumed",
|
||||
}),
|
||||
},
|
||||
} as any, parentContext)
|
||||
|
||||
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
|
||||
expect(meta).toBeDefined()
|
||||
expect(meta.metadata.model).toEqual(MODEL)
|
||||
})
|
||||
|
||||
test("#then sync-continuation metadata falls back to parent.model when resume model missing", async () => {
|
||||
const { executeSyncContinuation } = require("./sync-continuation")
|
||||
const ctx = makeMockCtx()
|
||||
const args: DelegateTaskArgs = {
|
||||
description: "continue", prompt: "keep going",
|
||||
load_skills: [], run_in_background: false, task_id: "ses_cont",
|
||||
}
|
||||
|
||||
const deps = {
|
||||
pollSyncSession: async () => null,
|
||||
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
|
||||
}
|
||||
|
||||
await executeSyncContinuation(args, ctx, {
|
||||
client: {
|
||||
session: {
|
||||
messages: async () => ({ data: [] }),
|
||||
prompt: async () => ({}),
|
||||
},
|
||||
},
|
||||
} as any, parentContext, deps)
|
||||
|
||||
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
|
||||
expect(meta).toBeDefined()
|
||||
expect(meta.metadata.model).toEqual(MODEL)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given both categoryModel and parent.model are undefined", () => {
|
||||
test("#when sync-task runs #then metadata.model is undefined without crashing", async () => {
|
||||
const { executeSyncTask } = require("./sync-task")
|
||||
const ctx = makeMockCtx()
|
||||
const deps = {
|
||||
createSyncSession: async () => ({ ok: true, sessionID: "ses_sync" }),
|
||||
sendSyncPrompt: async () => null,
|
||||
pollSyncSession: async () => null,
|
||||
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
|
||||
}
|
||||
const args: DelegateTaskArgs = {
|
||||
description: "test", prompt: "do it",
|
||||
subagent_type: "explore", load_skills: [], run_in_background: false,
|
||||
}
|
||||
|
||||
const parentContextWithoutModel: ParentContext = {
|
||||
sessionID: "ses_parent",
|
||||
messageID: "msg_parent",
|
||||
agent: "sisyphus",
|
||||
}
|
||||
|
||||
await executeSyncTask(args, ctx, {
|
||||
client: { session: { create: async () => ({ data: { id: "ses_sync" } }) } },
|
||||
directory: "/tmp",
|
||||
onSyncSessionCreated: null,
|
||||
}, parentContextWithoutModel, "explore", undefined, undefined, undefined, undefined, deps)
|
||||
|
||||
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
|
||||
expect(meta).toBeDefined()
|
||||
expect(meta.metadata.model).toBeUndefined()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user