Skip to content

Commit 91d1b74

Browse files
committed
feat: auto-reject permission requests in subagent sessions
OpenCode continue_loop_on_deny only works in the main processor loop. Task/subtask permissions use Effect.orDie which converts RejectedError into a fatal defect, crashing the task instead of letting it continue. As a workaround, the subagent plugin now watches for permission.updated events on tracked subagent sessions and immediately rejects them via permission.reply(). This makes the task fail fast and return to the parent, rather than hanging for the full permission timeout. Uses the v1 SDK permission.updated event type (not permission.asked which only exists in the v2 event union). Upstream issue: anomalyco/opencode#31108 Session: ses_168857bfeffekY8bru6UmFg8NO
1 parent 83551d5 commit 91d1b74

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'kimaki': patch
3+
---
4+
5+
Auto-reject permission requests in task/subagent sessions.
6+
7+
OpenCode's `continue_loop_on_deny` only works in the main agent loop, not in tasks.
8+
Task permissions use `Effect.orDie` which turns rejections into fatal crashes
9+
(see https://github.com/anomalyco/opencode/issues/31108). As a workaround, the
10+
subagent plugin now watches for `permission.updated` events on tracked subagent
11+
sessions and immediately rejects them so the task fails fast and returns to the
12+
parent, rather than hanging for the full permission timeout.

‎cli/src/subagent-rate-limit-plugin.ts‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// OpenCode plugin that aborts task-created subagent sessions after rate limits.
1+
// OpenCode plugin that guards task-created subagent sessions:
2+
// - Auto-rejects permission requests so tasks don't hang waiting for user input
3+
// - Aborts subagent sessions after rate limits so the parent task can recover
24

35
import type { Hooks, Plugin } from '@opencode-ai/plugin'
46

@@ -171,6 +173,35 @@ export const subagentRateLimitPlugin: Plugin = async ({ serverUrl, directory })
171173
return
172174
}
173175

176+
// Auto-reject permission requests for subagent sessions.
177+
// OpenCode's continue_loop_on_deny only works in the main processor
178+
// loop. Task/subtask permissions use Effect.orDie which turns rejections
179+
// into fatal defects, crashing the task. We reject immediately so the
180+
// task fails fast and returns to the parent, rather than hanging for
181+
// the full permission timeout waiting for a user who isn't watching.
182+
if (event.type === 'permission.updated') {
183+
const perm = event.properties
184+
const subagent = subagentSessions.get(perm.sessionID)
185+
if (subagent) {
186+
await client.permission.reply({
187+
requestID: perm.id,
188+
directory,
189+
reply: 'reject',
190+
message:
191+
'This task does not have interactive permission approval. ' +
192+
'Work around this restriction or report to the parent task ' +
193+
'that you need a different approach.',
194+
}).catch((error) => {
195+
logger.warn(`Failed to auto-reject subagent permission: ${formatPluginErrorWithStack(error)}`)
196+
})
197+
const patterns = Array.isArray(perm.pattern) ? perm.pattern.join(', ') : perm.pattern || ''
198+
logger.info(
199+
`Auto-rejected permission ${perm.id} for subagent ${perm.sessionID} (${perm.type}: ${patterns})`,
200+
)
201+
return
202+
}
203+
}
204+
174205
const rateLimitReason = extractRateLimitReason(event)
175206
if (!rateLimitReason) {
176207
return

0 commit comments

Comments
 (0)