Skip to content

fix(subagents): fixed subagents returning empty responses#3125

Merged
taciturnaxolotl merged 6 commits into
charmbracelet:mainfrom
taoeffect:issue-3118
Jun 16, 2026
Merged

fix(subagents): fixed subagents returning empty responses#3125
taciturnaxolotl merged 6 commits into
charmbracelet:mainfrom
taoeffect:issue-3118

Conversation

@taoeffect

Copy link
Copy Markdown
Contributor

Closes #3118

This PR appears to fix a bug where the agent tool (and maybe agentic_fetch too) would sometimes fail to return any response.

I've tested it and it appears to work.

AI Disclosure

The investigation is described in #3118 and was done as 3 separate independent investigations by GLM-5.2, Opus 4.8, and GPT-5.5. GPT-5.5 and Opus 4.8 both reached the same conclusion. GLM-5.2 found a separate possibility that Opus 4.8 said was valid. Both bugs were fixed by Opus 4.8 (planning, max thinking) and GPT-5.5 (implementation, x-high thinking).

1 round of review was done with Opus 4.8.

  • I have read CONTRIBUTING.md.
  • I have created a discussion that was approved by a maintainer (for new features).

Copilot AI review requested due to automatic review settings June 14, 2026 19:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR makes runSubAgent more resilient by ensuring sub-agent output is preserved even when parent cost updates fail, and improves output extraction by aggregating text from multiple sources (final response blocks, step outputs, or persisted assistant messages).

Changes:

  • Make parent session cost update best-effort (log warning instead of failing the tool response).
  • Add subAgentOutput logic to derive text output from final response content, step outputs, or stored assistant messages.
  • Expand coordinator tests to cover new output/fallback behaviors and update recover tests to use context-aware requests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
internal/server/recover_test.go Uses context-aware request creation in recover handler tests.
internal/agent/coordinator_test.go Adds helper constructors and multiple new test cases validating sub-agent output/fallback scenarios.
internal/agent/coordinator.go Makes cost update best-effort and introduces output aggregation / fallback logic for sub-agent responses.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/agent/coordinator.go Outdated
Comment thread internal/agent/coordinator.go Outdated
…test

Return the sub-agent diagnostic fallback as an error response (IsError=true,
nil Go error) so the parent LLM can distinguish "no usable output" from a
real answer; subAgentOutput now returns (text, ok) with ok=false only for
the last-resort diagnostic. Also replace the brittle 100ms wall-clock
assertion in TestJQ_CtxCancel_PreCancel with an invariant-based reader that
fails if read, fixing flaky Windows CI under -race.
@taciturnaxolotl

Copy link
Copy Markdown
Member

i believe we can simplify this a bit by making a change upstream in fantasy charmbracelet/fantasy#283

@taoeffect

Copy link
Copy Markdown
Contributor Author

Nice, I like simplifications and when things are made more elegant 👍

Collapse agentResultWithTextBlocks into agentResultWithText and fix
subAgentOutput doc to match actual fantasy behavior.
@taciturnaxolotl taciturnaxolotl enabled auto-merge (squash) June 16, 2026 17:31
@taciturnaxolotl taciturnaxolotl merged commit 1cfa9a1 into charmbracelet:main Jun 16, 2026
15 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.

Agent tool sometimes fails to return any output

3 participants