From 7874669de07685a9ab0977eb51d1b40318887c1f Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sun, 8 Mar 2026 02:22:22 +0900 Subject: [PATCH] feat(call-omo-agent): block sync subagent depth overflows Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- src/tools/call-omo-agent/tools.test.ts | 23 +++++++++++++++++++++++ src/tools/call-omo-agent/tools.ts | 8 ++++++++ 2 files changed, 31 insertions(+) diff --git a/src/tools/call-omo-agent/tools.test.ts b/src/tools/call-omo-agent/tools.test.ts index a560c8bea..11af01a9a 100644 --- a/src/tools/call-omo-agent/tools.test.ts +++ b/src/tools/call-omo-agent/tools.test.ts @@ -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") + }) }) diff --git a/src/tools/call-omo-agent/tools.ts b/src/tools/call-omo-agent/tools.ts index c2a169e64..5f5b5d319 100644 --- a/src/tools/call-omo-agent/tools.ts +++ b/src/tools/call-omo-agent/tools.ts @@ -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) }, })