feat(call-omo-agent): block sync subagent depth overflows
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -4,12 +4,14 @@ import type { BackgroundManager } from "../../features/background-agent"
|
||||
import { createCallOmoAgent } from "./tools"
|
||||
|
||||
describe("createCallOmoAgent", () => {
|
||||
const assertCanSpawnMock = mock(() => Promise.resolve(undefined))
|
||||
const mockCtx = {
|
||||
client: {},
|
||||
directory: "/test",
|
||||
} as unknown as PluginInput
|
||||
|
||||
const mockBackgroundManager = {
|
||||
assertCanSpawn: assertCanSpawnMock,
|
||||
launch: mock(() => Promise.resolve({
|
||||
id: "test-task-id",
|
||||
sessionID: null,
|
||||
@@ -99,4 +101,25 @@ describe("createCallOmoAgent", () => {
|
||||
//#then
|
||||
expect(result).not.toContain("disabled via disabled_agents")
|
||||
})
|
||||
|
||||
test("should return a tool error when sync spawn depth validation fails", async () => {
|
||||
//#given
|
||||
assertCanSpawnMock.mockRejectedValueOnce(new Error("Subagent spawn blocked: child depth 4 exceeds background_task.maxDepth=3."))
|
||||
const toolDef = createCallOmoAgent(mockCtx, mockBackgroundManager, [])
|
||||
const executeFunc = toolDef.execute as Function
|
||||
|
||||
//#when
|
||||
const result = await executeFunc(
|
||||
{
|
||||
description: "Test",
|
||||
prompt: "Test prompt",
|
||||
subagent_type: "explore",
|
||||
run_in_background: false,
|
||||
},
|
||||
{ sessionID: "test", messageID: "msg", agent: "test", abort: new AbortController().signal },
|
||||
)
|
||||
|
||||
//#then
|
||||
expect(result).toContain("background_task.maxDepth=3")
|
||||
})
|
||||
})
|
||||
|
||||
@@ -57,6 +57,14 @@ export function createCallOmoAgent(
|
||||
return await executeBackground(args, toolCtx, backgroundManager, ctx.client)
|
||||
}
|
||||
|
||||
if (!args.session_id) {
|
||||
try {
|
||||
await backgroundManager.assertCanSpawn(toolCtx.sessionID)
|
||||
} catch (error) {
|
||||
return `Error: ${error instanceof Error ? error.message : String(error)}`
|
||||
}
|
||||
}
|
||||
|
||||
return await executeSync(args, toolCtx, ctx)
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user