Repository navigation
Commit 40359d4
feat(opencode): fail-fast per-session subagent concurrency cap (nested-agents Issue 1)
Phase-2 Issue 1: bound how many subagents a SINGLE session may have running
concurrently as its direct children. Implements design-final §10 variant (b)
(fail-fast breadth cap per session) — explicitly NOT a tree-wide semaphore over
foreground chains, which the design note proves deadlocks (two parallel L2
foreground parents each hold a permit and wait on an L3 child that can never get
one).
- subagent-limits.ts: SubagentConcurrencyError (TaggedErrorClass, mirrors
SubagentTreeLimitError) + concurrencyError() with a model-directed message
naming the limit; DEFAULT_SUBAGENT_CONCURRENCY = 8 (conservative; tree limit
and depth limit stay the tree-wide ceilings); __testHooks.concurrency seam.
- task.ts: per-SPAWNER running counter (keyed by ctx.sessionID, independent of
the tree-root tree cap). Synchronous fail-fast gate before sessions.create
(coordinated with the existing tree-cap/budget gates, none weakened); slot
reserved synchronously, released on create failure via the existing onExit and
on child-run end via a one-shot Effect.ensuring — robust against success,
error and abort, so the abort cascade never hangs on a permit and the counter
never leaks. Resumes/extends reuse a still-running child and never re-reserve.
- test/session/nested-concurrency.test.ts: the deadlock counterexample (cap 2,
two parallel L2 foreground tasks each with an L3 child → completes, no
deadlock), fail-fast over-cap rejection, decrement-after-finish and
decrement-on-abort (no leak), and per-spawner budget independence.
- subagent-limits.test.ts: pins the constant, the error text, and the seam.
Co-Authored-By: Claude Fable 5 <[email protected]>1 parent 81ea40c commit 40359d4
4 files changed
Lines changed: 584 additions & 9 deletions
File tree
- packages/opencode
- src
- session
- tool
- test/session
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
31 | 51 | | |
32 | 52 | | |
33 | 53 | | |
| |||
96 | 116 | | |
97 | 117 | | |
98 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
99 | 142 | | |
100 | 143 | | |
101 | 144 | | |
| |||
150 | 193 | | |
151 | 194 | | |
152 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
153 | 202 | | |
154 | 203 | | |
155 | 204 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
117 | 128 | | |
118 | 129 | | |
119 | 130 | | |
| |||
183 | 194 | | |
184 | 195 | | |
185 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
186 | 201 | | |
187 | 202 | | |
188 | 203 | | |
| |||
194 | 209 | | |
195 | 210 | | |
196 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
197 | 223 | | |
198 | 224 | | |
199 | 225 | | |
| |||
206 | 232 | | |
207 | 233 | | |
208 | 234 | | |
209 | | - | |
| 235 | + | |
210 | 236 | | |
211 | | - | |
212 | | - | |
| 237 | + | |
| 238 | + | |
213 | 239 | | |
214 | | - | |
215 | | - | |
216 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
217 | 245 | | |
| 246 | + | |
218 | 247 | | |
219 | 248 | | |
220 | 249 | | |
| |||
238 | 267 | | |
239 | 268 | | |
240 | 269 | | |
241 | | - | |
242 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
243 | 274 | | |
244 | 275 | | |
245 | 276 | | |
| |||
364 | 395 | | |
365 | 396 | | |
366 | 397 | | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
367 | 415 | | |
368 | 416 | | |
369 | 417 | | |
| |||
376 | 424 | | |
377 | 425 | | |
378 | 426 | | |
379 | | - | |
| 427 | + | |
380 | 428 | | |
381 | 429 | | |
382 | 430 | | |
| |||
0 commit comments