fix(core): limit subagent nesting depth (#37124)

Co-authored-by: Dax <mail@thdxr.com>
This commit is contained in:
opencode-agent[bot] 2026-07-15 09:53:52 -05:00 committed by GitHub
commit 285d315b4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 99 additions and 1 deletions

View file

@ -101,6 +101,21 @@ export const TaskTool = Tool.define(
)
}
const parent = yield* sessions.get(ctx.sessionID)
let current = parent
let depth = 0
while (current.parentID) {
depth++
current = yield* sessions.get(current.parentID)
}
if (depth >= (cfg.subagent_depth ?? 1)) {
return yield* Effect.fail(
new Error(
`Subagent depth limit reached (${cfg.subagent_depth ?? 1}). Increase "subagent_depth" to allow nested subagents.`,
),
)
}
if (!ctx.extra?.bypassAgentCheck) {
yield* ctx.ask({
permission: id,
@ -121,7 +136,6 @@ export const TaskTool = Tool.define(
const session = params.task_id
? yield* sessions.get(SessionID.make(params.task_id)).pipe(Effect.catchCause(() => Effect.succeed(undefined)))
: undefined
const parent = yield* sessions.get(ctx.sessionID)
const childPermission = deriveSubagentSessionPermission({
parentSessionPermission: parent.permission ?? [],
subagent: next,