refactor(task): reimplement environment_details block appending with cache control support #11268
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.
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.