0b9cc80ecf
Sub-agent sessions created via the task tool or call_omo_agent tool were
being created without a model. The resolved model was only passed as a
promptAsync body override, which opencode core ignores, causing fallback
to the client's system default model (often a reasoning model that hangs).
OpenCode's session.create API supports model: { id, providerID, variant }
at creation time. This fix ensures the resolved category/agent model is
passed during session creation across all paths:
- createSyncSession() (delegate task / category-based)
- createOrGetSession() (call_omo_agent / direct agent calls)
- BackgroundManager.startTask() (background tasks)
This guarantees each sub-agent session is created with the correct model
regardless of whether promptAsync honors its model override.
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
import type { OpencodeClient } from "./types"
|
|
import type { DelegatedModelConfig } from "../../shared/model-resolution-types"
|
|
import { QUESTION_DENIED_SESSION_PERMISSION } from "../../shared/question-denied-session-permission"
|
|
|
|
export async function createSyncSession(
|
|
client: OpencodeClient,
|
|
input: {
|
|
parentSessionID: string
|
|
agentToUse: string
|
|
description: string
|
|
defaultDirectory: string
|
|
categoryModel?: DelegatedModelConfig
|
|
}
|
|
): Promise<{ ok: true; sessionID: string; parentDirectory: string } | { ok: false; error: string }> {
|
|
const parentSession = client.session.get
|
|
? await client.session.get({ path: { id: input.parentSessionID } }).catch(() => null)
|
|
: null
|
|
const parentDirectory = parentSession?.data?.directory ?? input.defaultDirectory
|
|
|
|
const createResult = await client.session.create({
|
|
body: {
|
|
parentID: input.parentSessionID,
|
|
title: `${input.description} (@${input.agentToUse} subagent)`,
|
|
permission: QUESTION_DENIED_SESSION_PERMISSION,
|
|
...(input.categoryModel
|
|
? {
|
|
model: {
|
|
id: input.categoryModel.modelID,
|
|
providerID: input.categoryModel.providerID,
|
|
...(input.categoryModel.variant ? { variant: input.categoryModel.variant } : {}),
|
|
},
|
|
}
|
|
: {}),
|
|
} as Record<string, unknown>,
|
|
query: {
|
|
directory: parentDirectory,
|
|
},
|
|
})
|
|
|
|
if (createResult.error) {
|
|
return { ok: false, error: `Failed to create session: ${createResult.error}` }
|
|
}
|
|
|
|
return { ok: true, sessionID: createResult.data.id, parentDirectory }
|
|
}
|