Repository navigation
fix(harness): preserve tool result metadata and state when pruning - #3326
Conversation
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
pruneToolResults rebuilt the pruned ToolResultBlock from id/name/output only, so the eviction/suspension markers in metadata and the execution state were silently dropped, and the rebuilt Msg dropped usage. The fix restores all three and the new ConversationCompactorPruneTest pins each preserved field plus the below-minimum / excluded-tool / multi-block paths. Correctness-wise I have no objection to the change itself.
The only blocker is CI: build (ubuntu-latest) fails in service-dataplane on a test unrelated to this diff (windows cancelled). Rebase or re-run CI and this is good to go.
Automated review by github-manager-bot
…ning pruneToolResults rebuilt each pruned ToolResultBlock with only id and name, silently discarding metadata and resetting the execution state to RUNNING (the constructor default). Eviction markers (agentscope.tool_result_evicted), suspension markers (agentscope_suspended) and error states were wiped, so a pruned block no longer matched the consumers that branch on them (ToolResultEvictionMiddleware.isEvicted, ToolResultBlock.isSuspended). The carrying message also lost its usage. Copy metadata and state from the original block and keep usage on the rebuilt Msg, mirroring the lossless rebuild discipline of ToolResultEvictionMiddleware (agentscope-ai#2319). Only the output text is replaced with the head+tail preview.
d616466 to
cfcd421
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Re-review at cfcd4214. I diffed this head against the head I reviewed before (d6164667): the only change is the javadoc note that a preserved marker describes the pre-prune payload, so consumers must not assume the block text is the full payload — exactly the caveat I would have asked for, and it makes the agentscope.tool_result_evicted pointer semantics explicit instead of leaving them to be discovered.
The code itself is unchanged and still correct: ToolResultBlock's constructor defensive-copies metadata (Map.copyOf) and defaults a null state, so sharing tr.getMetadata() / tr.getState() with the pruned copy is safe, and Msg now carries usage through the rebuild. ConversationCompactorPruneTest pins every preserved field plus the excluded-tool, below-minimum and multi-block paths.
CI is green at this head (build (ubuntu-latest), build (windows-latest), codecov/patch, license/cla), which was the only open blocker in my previous pass. Approving.
Findings
None.
Automated review by github-manager-bot
…3326) Backport the verified fix to the 2.0.x implementation and retain its existing public contracts where the upstream kernel differs. (cherry picked from commit d87c96d) Backport-review-patch: 7dc81b5b90e0d06917f913aa09dbcaeea70dd88f Constraint: No AgentScope Service or SDK migration Confidence: high Not-tested: Whole-repository verification pending after lane integration
AgentScope-Java Version
2.0.4-SNAPSHOT (based on
main@9c8b10d4e)Description
ConversationCompactor.pruneToolResultstrims old oversized tool results to a head+tail preview. When rebuilding the trimmed block it copies onlyidandname, which silently discards the rest of the block's identity:agentscope.tool_result_evicted(written byToolResultEvictionMiddleware, fix: preserve skill isolation and tool result history #2319) and the suspension markeragentscope_suspended(consumed byToolResultBlock.isSuspended()and ReActAgent's suspend/resume matching), plus any integrator-supplied metadata.RUNNING(theToolResultBlockconstructor default for null), so a prunedERRORresult is rewritten asRUNNING.MessageUtilsresult-state maps and event-side state reporting observe the corrupted value.Msg.usage— dropped by the message rebuild.The eviction middleware already follows a lossless rebuild discipline (
withPlaceholderpreserves metadata and adds its own marker). This PR applies the same discipline to prune: the rebuilt block now copiesmetadataandstatefrom the original block, and the rebuiltMsgkeepsusage. Only the output text is replaced with the preview.Context size is strictly reduced, never grown — the preserved fields were already in the conversation before pruning, and formatters do not render block metadata into the model prompt. This matters once lightweight pruning results reach the working
AgentState(e.g. once #2970/#2971 is addressed): a persisted-and-replayed pruned block currently loses every field downstream consumers branch on.Compatibility
metadata,state,usageare existing@JsonPropertyfields ofToolResultBlock/Msg.Tests
New
ConversationCompactorPruneTest(5 cases). The preservation case was red-verified against pre-fix code — verbatim failure output:pruneToolResults_preservesMetadataStateAndUsageWhenTrimmingisSuspended(),state=ERROR, block id/name andMsgid/metadata/timestamp/usage all survive; preview actually trimmedpruneToolResults_multiBlockMessagePrunesOnlyOversizedBlockassertSame, so the rebuild is surgical rather than destructive)pruneToolResults_skipsExcludedToolspruneToolResults_returnsOriginalWhenBelowMinimumpruneToolResults_handlesBlockWithoutMetadataOrStateRegression:
ConversationCompactorTest7/7,ToolResultEvictionMiddlewareTestgreen, fullagentscope-harnesssuite green,spotless:checkclean.Out of scope
The
truncateArgsrebuilds in the same class keep even less (truncateToolUseArgsdrops the message id/metadata/usage;truncateToolUseBlockdropsToolUseBlockmetadata). They are masked by the same #2970 discard path and left for a follow-up to keep this change single-purpose.One pre-existing interaction edge is worth recording: an eviction placeholder larger than prune's
maxOutputCharsis itself prunable, and the head+tail preview may cut the embeddedread_filepointer text. This PR preserves the eviction marker through that rewrite, but cannot recover the pointer text itself; in practice the default placeholder (~4K chars) only hits this under a custommaxOutputCharsat or above that size.Checklist
mvn spotless:applymvn test)