fix(agent-runtime): report subagent output token truncation as failure - #1193
Merged
vastsa merged 3 commits intoSep 28, 2026
Merged
Conversation
Totopo27
force-pushed
the
fix/subagent-truncated-output-status
branch
from
September 28, 2026 20:11
e12f6af to
6785eaa
Compare
Treat delegates truncated by the model output token limit as failed with SUBAGENT_OUTPUT_TRUNCATED rather than clean completions. Addresses vastsa#1190
Totopo27
force-pushed
the
fix/subagent-truncated-output-status
branch
from
September 28, 2026 20:27
6785eaa to
5fa60e0
Compare
Register the shared error code and document the visible failed outcome so the subagent truncation fix matches the runtime contract.
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
Ensures subagent runs whose response hits the model output token limit (
stopReason: "length"/"max_tokens") settle asfailedwith error codeSUBAGENT_OUTPUT_TRUNCATEDrather than falsely reportingcompleted.Motivation & Root Cause
Resolves issue #1190.
In
packages/agent-runtime/src/subagent.ts,SubagentRun.run()evaluated completion purely on whetherlastReportTextwas non-empty:When a subagent's response exceeded the model's output token limit without issuing tool calls, the stream terminated with
stopReason: "length". Because the message contained partial report text, the subagent silently settled ascompleted, handing the parent agent an incomplete report cut off mid-generation with no indication of truncation.Key Changes
packages/shared/src/errors.ts):SUBAGENT_OUTPUT_TRUNCATEDtoErrorCodes.packages/agent-runtime/src/subagent.ts):outputTruncated?: booleantoSubagentRunResult.lastReportTruncatedonmessage_endwhenstopReason === "length" || stopReason === "max_tokens".run()asfailedwithSUBAGENT_OUTPUT_TRUNCATEDwheneverlastReportTruncatedis true, surfacing the explanatory failure message while preserving the partial output underIts last output was:.packages/agent-runtime/src/subagent.test.ts):status: "failed",code: "SUBAGENT_OUTPUT_TRUNCATED", andoutputTruncated: true.stopReason: "stop"clears the truncated state and completes cleanly.Verification
errors.ts,subagent.ts,subagent.test.ts).fix:contribution addressing verified upstream issue [Bug] 被输出上限截断的子智能体仍被报成completed#1190).