You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c8101e7
Browse filesBrowse the repository at this point in the historyBrowse files
feat(opencode): per-task timeout for foreground subagents (nested-agents Issue 5)
Optional per-task timeout for foreground `task` spawns, set via the new
`timeout` tool-param (milliseconds, wins) or the `experimental.subagent_task_timeout`
config default. On expiry the subtree is aborted through the SAME cancel path as
an explicit cancel (ops.cancel seeds Session.descendants into
SessionRunState.cancel; background.cancel closes the job scope and awaits its
interrupt finalizers), so the release-race fix (5582da5) stays intact, no
orphan job survives, and the foreground parent surfaces a typed
SubagentTimeoutError in its transcript instead of hanging. Background tasks are
unaffected (decoupled, notified out-of-band). Without a timeout, behavior is
byte-identical to before.
The timeout arm only sleeps then fails: with raceFirst the loser is interrupted
the moment the winner settles, so failing first interrupts the wait arm before
background.cancel could flip the job to "cancelled" and let that branch win the
race (which would surface "Task cancelled" instead of the typed timeout); the
catchIf then runs the abort and re-fails.
Single-source clamp helper SubagentLimits.taskTimeout(cfg, override) and a typed
SubagentTimeoutError live in subagent-limits.ts alongside maxDepth/the existing
typed errors. Tests in test/session/nested-timeout.test.ts.
Co-Authored-By: Claude Fable 5 <[email protected]>
Copy file name to clipboardExpand all lines: packages/core/src/v1/config/config.ts
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -218,6 +218,10 @@ export const Info = Schema.Struct({
218
218
description:
219
219
"Maximum subagent nesting depth (the root session is depth 1; clamped to 1..10). Default 5. Set 2 to restore the previous spawn behavior (the root spawns, subagents do not) — additionally the workflow tool is removed at the limit (security fix) and custom agents that previously nested without limit are bounded; 1 is the kill switch that removes the task and workflow tools entirely.",
"Default timeout in milliseconds for foreground subagent tasks (the `task` tool). When it elapses the subtree is aborted via the same cancel path as an explicit cancel (no orphan job) and the spawn fails with a typed timeout error in the parent's transcript. Overridable per call via the task tool's `timeout` parameter. Unset (default) means no timeout.",
message: `Subagent task timed out after ${input.timeout}ms and was aborted. The delegated work did not finish in time; do the remaining work directly in this session or retry with a larger timeout.`,
165
+
})
166
+
129
167
/**
130
168
* Raised when the parent-chain walk exceeds LINEAGE_ITERATION_CAP (corrupt or
131
169
* cyclic session parents). Callers treat this like "depth ≥ limit": spawning
Copy file name to clipboardExpand all lines: packages/opencode/src/tool/task.ts
+41-3Lines changed: 41 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -68,6 +68,10 @@ const BaseParameterFields = {
68
68
"This should only be set if you mean to resume a previous task (you can pass a prior task_id and the task will continue the same subagent session as before instead of creating a fresh one)",
69
69
}),
70
70
command: Schema.optional(Schema.String).annotate({description: "The command that triggered this task"}),
"Optional timeout in milliseconds for this foreground task. When it elapses the subagent (and its whole subtree) is aborted and this call fails with a timeout error; do the work yourself or retry with a larger value. Overrides experimental.subagent_task_timeout. Ignored for background tasks.",
Copy file name to clipboardExpand all lines: packages/opencode/src/tool/task.txt
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -19,3 +19,4 @@ Usage notes:
19
19
7. If the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement.
20
20
8. Agents may themselves delegate to deeper sub-agents. Nesting is allowed up to a configured maximum depth (your own session counts as one level; the root session is depth 1). On the deepest level this tool is not available — an agent there must do the remaining work itself and report results in its final message.
21
21
9. task_id can only resume tasks that THIS session started itself (its own direct children). Passing the id of a parent, sibling, or unrelated session fails; an unknown id starts a fresh session.
22
+
10. You may set an optional timeout (milliseconds) for a foreground task. If the subagent does not finish within it, the whole subtree is aborted and the call returns a timeout error — then do the remaining work yourself or retry with a larger timeout. The timeout is ignored for background tasks.
0 commit comments