Fix background task result retrieval so an agent can read a subagent's final answer#5459
Open
andrescera wants to merge 3 commits into
Open
Fix background task result retrieval so an agent can read a subagent's final answer#5459andrescera wants to merge 3 commits into
andrescera wants to merge 3 commits into
Conversation
… to completed results
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.
Fix background task result retrieval so an agent can read a subagent's final answer
The problem. When an agent delegates work to run in the background and later asks for the result, it frequently can't get the one thing it needs: the subagent's final answer. Asking for the result returns the entire background conversation — including very large intermediate output like full build and test logs — instead of the recent, relevant part. The option meant to return "just the most recent message" doesn't actually narrow anything, so even when the agent explicitly asks for the ending, it still receives everything, and the final answer at the very end gets dropped before the agent can see it. In practice the agent asks again and again, never receives the conclusion, and its own working memory fills with noise it never wanted.
When it started. The "most recent message" option was added in v4.10.0 (commit 6092c8e), on top of result formatting that had never limited large intermediate output.
The solution. Make result retrieval honor what the caller asks for. A request for the most recent part of a background task returns a bounded slice from the end that reliably contains the final answer, whether the task is finished or still running, and the final answer is shown first so it can't be cut off. Bulky intermediate output no longer crowds out that answer, and a caller's choice to leave heavy detail out is respected even while the task is still in progress. Lightweight status checks stay small and cheap; only an explicit request for full detail returns more.
Summary by cubic
Fixes background task result retrieval so agents reliably get a subagent’s final answer without being buried by logs. Adds bounded tail slicing and truncation for smaller, cheaper status checks.
from_endfor bothfull_sessionand completed results; when no limit is given, return the last 20 messages.message_limit, default 20).include_thinkingandinclude_tool_results: explicit values are honored; defaults are on only while the task is active.tool_resultblocks to 2000 chars with an ellipsis to avoid log bloat.Written for commit 3ebb341. Summary will update on new commits.