fix(delegate-task): add subagent turn limit and model routing transparency#2575
Merged
code-yeongyu merged 1 commit intocode-yeongyu:devfrom Mar 25, 2026
Conversation
…rency 原因: - subagent 无最大步数限制,陷入 tool-call 死循环时可无限运行,造成巨额 API 费用 - category 路由将 subagent 静默切换到与父 session 不同的模型,用户完全无感知 改动: - sync-session-poller: 新增 maxAssistantTurns 参数(默认 300),每检测到新 assistant 消息 计数一次,超限后调用 abortSyncSession 并返回明确错误信息 - sync-task: task 完成时在返回字符串中显示实际使用的模型;若与父 session 模型不同, 加⚠️ 警告提示用户发生了静默路由 影响: - 现有行为不变,maxAssistantTurns 为可选参数,默认值 300 远高于正常任务所需轮次 - 修复 code-yeongyu#2571:用户一个下午因 Sisyphus-Junior 死循环 + 静默路由到 Gemini 3.1 Pro 烧掉 $350+,且 OpenCode 显示费用仅为实际的一半
There was a problem hiding this comment.
No issues found across 2 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Auto-approved: Critical cost-protection circuit breaker and model transparency. Defensive design with high defaults ensures no impact on normal operations.
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
Fixes #2571 — a subagent infinite tool-call loop burned $350+ in one afternoon due to two missing safeguards.
Changes
Bug 1: Subagent infinite loop — no circuit breaker
File:
src/tools/delegate-task/sync-session-poller.tsAdded a
maxAssistantTurnsparameter (default: 300) topollSyncSession. Each time a new assistant message is detected, a counter increments. When the limit is reached, the session is aborted and a clear error message is returned to the parent.The default of 300 is well above any normal task's requirements while still preventing runaway loops. The parameter is optional and backward-compatible.
Bug 2: Silent model routing — no user visibility
File:
src/tools/delegate-task/sync-task.tsWhen a task completes, the return string now includes the actual model used. If the subagent was routed to a different model than the parent session (via category resolution), a⚠️ warning is shown:
Root Cause (from issue)
A Sisyphus-Junior subagent was silently routed to
google/gemini-3.1-pro-previewvia thevisual-engineeringcategory, despite the parent session using GPT-5.4. The subagent then entered an infinitetool-callsloop (809 turns, 3.5 hours) with no safeguard to stop it. Gemini 3.1 Pro has zero prompt caching, so each of the 809 turns sent880K input tokens at full price ($1.76/turn displayed, ~$3.52/turn actual due to >200K context tier).Testing
All existing delegate-task tests pass. No breaking changes —
maxAssistantTurnsis an optional parameter with a safe default.Related
Summary by cubic
Adds a turn-limit circuit breaker for subagents and makes model routing visible in task results to prevent infinite loops and surprise model costs. Addresses #2571.
Bug Fixes
Migration
Written for commit f2b26e5. Summary will update on new commits.