cd0e2e5190
Child session creation was injecting permission: { question: 'deny' } which
conflicted with OpenCode's child session permission handling, causing subagent
sessions to hang with 0 messages after creation (zombie state).
Remove the permission override from all session creators (BackgroundManager,
sync-session-creator, call-omo-agent) and rely on prompt-level tool restrictions
(tools.question=false) to maintain the intended policy.
Closes #1711
70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
import type { PluginInput } from "@opencode-ai/plugin"
|
|
import { log } from "../../shared"
|
|
import { subagentSessions } from "../../features/claude-code-session-state"
|
|
import type { CallOmoAgentArgs } from "./types"
|
|
import type { ToolContextWithMetadata } from "./tool-context-with-metadata"
|
|
|
|
export async function resolveOrCreateSessionId(
|
|
ctx: PluginInput,
|
|
args: CallOmoAgentArgs,
|
|
toolContext: ToolContextWithMetadata,
|
|
): Promise<{ ok: true; sessionID: string } | { ok: false; error: string }> {
|
|
if (args.session_id) {
|
|
log(`[call_omo_agent] Using existing session: ${args.session_id}`)
|
|
const sessionResult = await ctx.client.session.get({
|
|
path: { id: args.session_id },
|
|
})
|
|
if (sessionResult.error) {
|
|
log("[call_omo_agent] Session get error", { error: sessionResult.error })
|
|
return {
|
|
ok: false,
|
|
error: `Error: Failed to get existing session: ${sessionResult.error}`,
|
|
}
|
|
}
|
|
return { ok: true, sessionID: args.session_id }
|
|
}
|
|
|
|
log(`[call_omo_agent] Creating new session with parent: ${toolContext.sessionID}`)
|
|
const parentSession = await ctx.client.session
|
|
.get({ path: { id: toolContext.sessionID } })
|
|
.catch((err) => {
|
|
log("[call_omo_agent] Failed to get parent session", { error: String(err) })
|
|
return null
|
|
})
|
|
const parentDirectory = parentSession?.data?.directory ?? ctx.directory
|
|
|
|
const body = {
|
|
parentID: toolContext.sessionID,
|
|
title: `${args.description} (@${args.subagent_type} subagent)`,
|
|
}
|
|
|
|
const createResult = await ctx.client.session.create({
|
|
body,
|
|
query: { directory: parentDirectory },
|
|
})
|
|
|
|
if (createResult.error) {
|
|
log("[call_omo_agent] Session create error", { error: createResult.error })
|
|
const errorStr = String(createResult.error)
|
|
if (errorStr.toLowerCase().includes("unauthorized")) {
|
|
return {
|
|
ok: false,
|
|
error: `Error: Failed to create session (Unauthorized). This may be due to:
|
|
1. OAuth token restrictions (e.g., Claude Code credentials are restricted to Claude Code only)
|
|
2. Provider authentication issues
|
|
3. Session permission inheritance problems
|
|
|
|
Try using a different provider or API key authentication.
|
|
|
|
Original error: ${createResult.error}`,
|
|
}
|
|
}
|
|
return { ok: false, error: `Error: Failed to create session: ${createResult.error}` }
|
|
}
|
|
|
|
const sessionID = createResult.data.id
|
|
log(`[call_omo_agent] Created session: ${sessionID}`)
|
|
subagentSessions.add(sessionID)
|
|
return { ok: true, sessionID }
|
|
}
|