Skip to content

fix(agent-runtime): report subagent output token truncation as failure - #1193

Merged
vastsa merged 3 commits into
vastsa:mainfrom
Totopo27:fix/subagent-truncated-output-status
Sep 28, 2026
Merged

vastsa merged 3 commits into
vastsa:mainfrom
Totopo27:fix/subagent-truncated-output-status

Conversation

@Totopo27

Copy link
Copy Markdown
Contributor

Summary

Ensures subagent runs whose response hits the model output token limit (stopReason: "length" / "max_tokens") settle as failed with error code SUBAGENT_OUTPUT_TRUNCATED rather than falsely reporting completed.

Motivation & Root Cause

Resolves issue #1190.

In packages/agent-runtime/src/subagent.ts, SubagentRun.run() evaluated completion purely on whether lastReportText was non-empty:

if (!this.lastReportText.trim()) {
  return this.result("failed", "", { code: "SUBAGENT_NO_REPORT", ... });
}
return this.result("completed", this.lastReportText);

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 as completed, handing the parent agent an incomplete report cut off mid-generation with no indication of truncation.

Key Changes

  • Error Taxonomy (packages/shared/src/errors.ts):
    • Added SUBAGENT_OUTPUT_TRUNCATED to ErrorCodes.
  • Subagent Runtime (packages/agent-runtime/src/subagent.ts):
    • Added outputTruncated?: boolean to SubagentRunResult.
    • Tracked lastReportTruncated on message_end when stopReason === "length" || stopReason === "max_tokens".
    • Settle run() as failed with SUBAGENT_OUTPUT_TRUNCATED whenever lastReportTruncated is true, surfacing the explanatory failure message while preserving the partial output under Its last output was:.
  • Unit Tests (packages/agent-runtime/src/subagent.test.ts):
    • Added test verifying that a subagent ending on a truncated message reports status: "failed", code: "SUBAGENT_OUTPUT_TRUNCATED", and outputTruncated: true.
    • Added test verifying that a subsequent turn completing with stopReason: "stop" clears the truncated state and completes cleanly.

Verification

@Totopo27
Totopo27 force-pushed the fix/subagent-truncated-output-status branch from e12f6af to 6785eaa Compare September 28, 2026 20:11
Treat delegates truncated by the model output token limit as failed with SUBAGENT_OUTPUT_TRUNCATED rather than clean completions.

Addresses vastsa#1190
@Totopo27
Totopo27 force-pushed the fix/subagent-truncated-output-status branch from 6785eaa to 5fa60e0 Compare September 28, 2026 20:27
Register the shared error code and document the visible failed outcome so the subagent truncation fix matches the runtime contract.
@vastsa
vastsa merged commit 8fcca3d into vastsa:main Sep 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants