fix(server): bound Claude subagent usage - #7520
Ivorisnoob wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR introduces runtime behavior changes affecting resource usage control (subagent spawn limits with explicit subscription/billing implications) and task lifecycle management. The scope of behavioral changes warrants human review. You can add or adjust custom eligibility rules. Learn more. |
|
Thanks for the PR. We're not taking changes to the orchestration and provider layers right now: that part of the server is being rewritten for V2, and merging into the current code would either conflict with or be thrown away by that work. Closing for now. If this is still an issue once V2 lands, please reopen (or open a fresh PR against the new code) and we'll take a proper look. |
What Changed
Why
Claude sessions could delegate into a large tree of concurrent subagents, while some background tasks could survive session shutdown paths and continue consuming subscription usage.
This adds conservative default bounds and makes task cleanup consistent across shutdown paths. It preserves the existing streaming and session-resume architecture so the change does not intentionally disrupt prompt caching or steering.
Checklist
Note
Bound Claude subagent spawn depth and concurrency with default guardrails
withClaudeSubagentGuardrailsin ClaudeAdapter.ts to inject default env vars (CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH=1,CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS=5) unless already set by the process environment.background_tasks_changedSDK messages and stops all live tasks viastopLiveTasksbefore closing a session or replacing a turn.informationalandmodel_refusal_no_fallbackSDK system subtypes, emitting runtime warnings instead of silently ignoring them.stopSessionnow stops background tasks before closing the SDK transport and emitstask.completed(status:stopped) events for each stopped task.Macroscope summarized de22df2.
Note
Medium Risk
Touches Claude session lifecycle, background task teardown, and SDK integration paths that affect token usage and shutdown behavior; changes are bounded by tests but affect production agent orchestration.
Overview
Claude sessions get default subagent guardrails (max depth 1, max 5 concurrent) via
withClaudeSubagentGuardrails, with provider env vars overriding when set. User docs describe the defaults and overrides.Background task cleanup is unified:
stopLiveTasksruns before closing the SDK query onstopSession(and is shared withinterruptTurn). Live task IDs are reconciled frombackground_tasks_changedsnapshots so missed lifecycle events do not leave agents running.Claude Agent SDK bumps from
0.3.170to0.3.235; tests passrequestIdintocanUseToolmocks. New system subtypes (informational,model_refusal_no_fallback, etc.) are handled or surfaced as warnings instead of unknown-subtype noise.Reviewed by Cursor Bugbot for commit de22df2. Bugbot is set up for automated code reviews on this repo. Configure here.