Skip to content

parity(subagent): no cumulative session-wide cap on total subagent spawns #6545

Description

@bug-ops

Description

Zeph's zeph-subagent crate has two existing runaway-spawn guardrails: max_spawn_depth (recursion-depth guard, SubAgentError::MaxDepthExceeded, crates/zeph-subagent/src/manager/spawn.rs:617-620) and max_concurrent (in-flight concurrency guard, SubAgentError::ConcurrencyLimit, crates/zeph-subagent/src/manager/spawn.rs:641-644/:1157-1160). Neither bounds the cumulative total number of subagents spawned over a session's lifetime — a session could sequentially spawn an unbounded number of subagents (shallow depth, low concurrency, high total count) with no default protection, e.g. a misbehaving orchestration loop spawning-and-completing subagents in a tight sequential cycle.

This is the subagent-spawning analog of #6469 ("core: no default-on runaway tool-call / cost protection"), which found Zeph's tool-call rate limiter and daily cost budget both shipped disabled/unlimited by default, corroborated by Claude Code's session-wide CLAUDE_CODE_MAX_WEB_SEARCHES_PER_SESSION cap. #6469 was fixed by PR #6528 (rate limiting + cost cap now enabled by default).

This cycle found a second, structurally distinct guardrail from the same Claude Code release wave (v2.1.207-212, week of 2026-07-13): CLAUDE_CODE_MAX_SUBAGENTS_PER_SESSION (default 200, session-wide absolute cap on total subagent spawns, "to stop runaway delegation loops"). Zeph has no equivalent cumulative counter or config field.

Reproduction Steps

  1. rg -n "max_spawn_depth|max_concurrent|ConcurrencyLimit|MaxDepthExceeded" crates/zeph-subagent/src — only depth and concurrency guards exist.
  2. Inspect SubAgentConfig (crates/zeph-config/src/agent.rs) — no max_spawns_per_session-style field.
  3. Observe: a session that spawns, awaits completion, then spawns again in a loop is unbounded by either existing guard.

Expected Behavior

A session should have a configurable, default-on cap on the cumulative number of subagents spawned over its lifetime, independent of depth and concurrency, to stop runaway sequential delegation loops.

Actual Behavior

No cumulative session-wide spawn cap exists; only depth and concurrency are bounded.

Environment

  • Version: HEAD c63e321
  • Config: default SubAgentConfig
  • Features: n/a (config-level)

Evidence / Competitive Corroboration

Spec

.local/specs/077-subagent-session-spawn-cap/spec.md

Metadata

Metadata

Assignees

Labels

P3Research — medium-high complexityresearchResearch-driven improvementsub-agentsSub-agent orchestration

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions