feat(subagent): add session-wide cumulative spawn cap - #6669
Merged
Conversation
Zeph's existing subagent guardrails bound recursion depth and in-flight concurrency but not the cumulative total spawned over a session's lifetime, leaving a shallow, low-concurrency but high-frequency sequential delegation loop unprotected. Adds a configurable, default-on SessionSpawnBudget shared between SubAgentManager::spawn/resume and the ACP /subagent spawn chokepoint, so both spawn paths enforce the same session-wide cap. Closes #6545
bug-ops
force-pushed
the
feat/issue-6545/parity-subagent-no-cumulative
branch
from
July 28, 2026 00:13
290034b to
3f0ebc0
Compare
bug-ops
enabled auto-merge (squash)
July 28, 2026 00:13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Zeph's
zeph-subagentcrate guards runaway spawning along two axes only: recursion depth (max_spawn_depth) and in-flight concurrency (max_concurrent). Neither bounds the cumulative total number of subagents spawned over a session's lifetime, leaving a shallow, low-concurrency but high-frequency sequential delegation loop unprotected. This mirrors a guardrail Claude Code shipped default-on in the same release wave (CLAUDE_CODE_MAX_SUBAGENTS_PER_SESSION), and follows the same "default-on, not opt-in" precedent set by #6469/PR #6528 for the tool-call rate limiter and cost cap.SessionSpawnBudget(crates/zeph-subagent/src/budget.rs): a plainAtomicUsizenewtype, noArc/Cloneby design.SubAgentManagerowns the origin instance;OrchestrationStateowns an independent fallback used only when no manager is wired (serve/daemon/acp). Both are reached through a single accessor that cannot desynchronize by construction.SubAgentManager::spawn/resume, and the ACP/subagent spawnexternal-process chokepoint, which never touchesSubAgentManagerat all and would otherwise bypass the cap entirely.NotFound, a retriedConcurrencyLimit, a failed ACP launch) never burns budget it never used. On the ACP path specifically, the commit point is unconditional after the process launch attempt returns (bothOkandErr), since the underlyingzeph_acp::run_sessioncan launch a real child process and then time out or fail post-launch — undercounting that case would leave a real bypass.SubAgentConfig.max_spawns_per_session(default 100,0= unlimited sentinel), newSubAgentError::SessionSpawnLimitvariant, a--migrate-configstep, and/agent status//agent listnow surfaceSession spawns: N/max.SessionSpawnLimitclassifies into the orchestration scheduler's terminalFailedbranch (bounded retries only underFailureStrategy::Retry, permax_retries), not the transientConcurrencyLimit-style retry branch.Closes #6545
Test plan
cargo +nightly fmt --checkcargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing" -- -D warningscargo nextest run --config-file .github/nextest.toml --workspace --features "desktop,ide,server,chat,pdf,scheduler" --lib --bins(15128 passed, 0 failed)RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links") clean workspace-widecargo test --doc --workspacecleangitleaks protect --stagedclean0-unlimited sentinel, check/consume split (rejected spawns don't consume),resume()parity, priority overConcurrencyLimit, ACP-path launch-then-fail still consumes, config default/migration (both serde round-trip and directSubAgentConfig::default()), fullMIGRATIONSregistry migration test, schedulerFailed-not-retried classification (plus bounded-retry case underFailureStrategy::Retry), rendered status-line tests.local/testing/)