refactor(task): reimplement environment_details block appending with cache control support#11268
refactor(task): reimplement environment_details block appending with cache control support#11268hannesrudolph wants to merge 1 commit intomainfrom
Conversation
…ing bloc…" This reverts commit dd6e32e.
Reviewed the new
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| const contentWithoutEnvDetails = removeEnvironmentDetailsBlocks( | ||
| lastUserMsg.content as ( | ||
| | Anthropic.Messages.TextBlockParam | ||
| | Anthropic.Messages.ImageBlockParam | ||
| | Anthropic.Messages.ToolResultBlockParam | ||
| )[], | ||
| ) | ||
| // Add fresh environment details | ||
| lastUserMsg.content = [...contentWithoutEnvDetails, { type: "text" as const, text: environmentDetails }] | ||
| lastUserMsg.content = appendEnvironmentDetails(contentWithoutEnvDetails, environmentDetails) |
There was a problem hiding this comment.
removeEnvironmentDetailsBlocks only strips standalone text blocks that are entirely <environment_details>...</environment_details>. Now that env details are appended into existing blocks, this function won't find them on a second pass through the same content. Concretely, in the delegation resume path here: after the first call, the last user message in history has env details appended (e.g. "Tool result\n\n<environment_details>...") -- removeEnvironmentDetailsBlocks won't detect that, so appendEnvironmentDetails adds a second copy.
stripAppendedEnvironmentDetails was written to handle exactly this (it calls removeEnvironmentDetailsBlocks and regex-strips appended env details from the last block), but it's only tested and never used in production. Both this call site and the one at line 2750 should use stripAppendedEnvironmentDetails instead.
Fix it with Roo Code or mention @roomote and request a fix.
Summary
Re-applies #11198 (reverted in #11256) and extends it with cache control support.
Appends
<environment_details>onto the last user text block or tool result instead of adding a standalone trailing text block, avoiding message shapes that can break interleaved-thinking models.Changes
appendEnvironmentDetails()and comprehensive unit coverage (appendEnvironmentDetails.spec.ts).Taskto use the helper when constructing the next user message content.Problem
Task messages currently append
<environment_details>as a standalone trailing text block. Some interleaved-thinking models are sensitive to message content "shape" and can fail when an extra trailing block is introduced.Desired behavior
Append
<environment_details>into the final existing user text block (or tool result block) rather than adding a new standalone block.Acceptance criteria
<environment_details>to that block.<environment_details>to that tool result text.<environment_details>.What's coming next on this branch
Cache control support will be added to this PR. The environment_details appending behavior is a prerequisite for proper cache breakpoint placement -- provider-level cache controls (ephemeral breakpoints via
providerOptions) need to target the correct message parts. With environment_details merged into existing blocks, cache breakpoints can be placed accurately on the final content part rather than on an unintended standalone block.Context
The original implementation was merged and then reverted. This reimplementation restores that work as a foundation for the cache control additions that will follow in subsequent commits on this branch.
Relates to EXT-749.
Important
Reintroduces and enhances
appendEnvironmentDetailsto append<environment_details>to existing message blocks, with comprehensive testing for various scenarios.appendEnvironmentDetails()inappendEnvironmentDetails.tsto append<environment_details>to the last text or tool result block.TaskinTask.tsto useappendEnvironmentDetails()for constructing user message content.appendEnvironmentDetails.spec.tsto cover various scenarios, including empty content, text block handling, tool result handling, and mixed content.<environment_details>blocks before appending new ones to avoid duplicates.This description was created by
for 19c02e1. You can customize this summary. It will automatically update as commits are pushed.