[BUG] TS TruncateStrategy appends a [Stashed] marker to text blocks it did not truncate
Checks
- [x] I have searched issues and there are no duplicates
SDK Language
TypeScript
Strands Version
main (a642b4177), also present on #4228 head 70cefbd12
Steps to Reproduce
Offload.truncate('assistantText').when({ threshold: 500 })with a ContextManager stash enabled.- Have an assistant text block of ~2,500 chars (fits the 1,000-token preview budget, so
truncateTextBlockreturns the same block). - Run two offload passes.
Expected Behavior
A block that isn't reduced is returned unchanged (acted false), as Python does at strands-py/src/strands/_context_manager/strategies/offload/truncate.py:147-148 (if result is block: return block) and as TS's own tool-result branch does at strands-ts/src/context-manager/strategies/offload/truncate.ts:95-98.
Actual Behavior
strands-ts/src/context-manager/strategies/offload/truncate.ts:104 appends \n\n[Stashed] [ref: K] unconditionally when refs exist, so the strategy reports acted with no token reduction and another marker is appended on every pass.
Suggested fix
Mirror the tool-result branch: if (truncated === block) return block before appending refs.
Found while reviewing #4228 (pre-existing, not introduced there). Filed by strandly-the-agent.
I will take this issue. Please assign it to me.
The problem is in strands-ts/src/context-manager/strategies/offload/truncate.ts at line 104. The code appends a [Stashed] marker even when the text block is not truncated. I will first check if truncated is the same as block before appending the marker. This should align with the behavior in the Python version and the tool-result branch. I will test the fix by running the offload passes and ensuring no marker is added when no truncation occurs.
Hi! I had already reproduced this issue and prepared a focused fix with a regression test before the latest claim, but I have not opened a PR yet.
The change is limited to TruncateStrategy and its stash integration test. I am happy to coordinate and avoid duplicate work. Maintainers, please let me know how you would prefer us to proceed.
hey! i can review prs for this if you create one, please make sure to keep change minimal for the fix.
would be curious to know your use case and feedback for using context manager as well. Set this issue as ready for contribution
cc: @modelpath-dev @97Three
Hi! Thanks for confirming that a focused PR would be welcome. I prepared a minimal local patch and regression test on my side, but I see @modelpath-dev offered to take this and @97Three already prepared a focused fix. To avoid duplicating work, I haven't opened a PR. Could you let me know whether one of them is actively preparing the PR? If so, I'll defer; if not, I can submit mine for review.
Thanks for checking, @z2Ace0107. Yes, I have completed the focused fix and regression test and am actively preparing the PR. I’ll link it here once it is opened.
@modelpath-dev, please let me know if you already have a PR in progress so we can avoid duplicate work.