Repository navigation
fix(context): never stash or serve offload previews as originals (py + ts) - #5626
Merged
lizradway merged 2 commits intoOct 28, 2026
Merged
Conversation
Backfill after a session restore onto a stash lacking the originals wrote the restored previews under the originals' keys, so retrieve_context served the preview as the original. store_message now skips offload placeholders, and retrieve_context reports a placeholder entry as no longer available. Fixes strands-agents#5620
Seeding an agent with already-offloaded messages stashed the previews under the originals' keys, overwriting the originals in a shared stash. storeMessage now skips offload placeholders, and retrieve_context reports a placeholder entry as no longer available. Refs strands-agents#5620
lizradway
marked this pull request as ready for review
October 28, 2026 16:59
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
8 of 9 tasks
opieter-aws
approved these changes
Oct 28, 2026
Contributor
|
Assessment: Approve Focused, well-scoped bug fix for #5620 with parallel Python/TS implementations and the detection logic coupled to the same Review notes
Clear write-up and repro script made this easy to verify — thanks. |
lizradway
enabled auto-merge (squash)
October 28, 2026 17:05
6 of 9 tasks
lizradway
added a commit
to lizradway/harness-sdk
that referenced
this pull request
Oct 29, 2026
Resolves the strands-agents#5626 conflicts in favor of the typed offload placeholder check, which replaces the TS ref regex guard.
6 of 8 tasks
gautamsirdeshmukh
pushed a commit
to gautamsirdeshmukh/harness-sdk
that referenced
this pull request
Nov 2, 2026
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.
Human Overview
Description
When a conversation holding offloaded previews lands on a stash that doesn't have the originals, the stash write path files each preview under its original's key, because a truncated tool result keeps its
toolUseId.retrieve_contextthen serves the preview as the original, and the model reports "No matches found" for content that exists. In Python this happens through backfill after a session restore onto an empty stash (new host, expired store, failed write). In TS it happens when an agent is seeded vianew Agent({ messages })with already-offloaded messages, and since TSstorealways overwrites, a shared durable stash loses its real originals.Both SDKs now skip offload placeholders when stashing, recognized by the trailing
[ref: …]/[refs: …]token that_format_stash_refs/formatStashRefsadds to every offload marker. When any item of a tool result is a placeholder, the whole result is skipped, because truncation re-indexes the remaining items.retrieve_contextalso refuses entries that are placeholders, which covers stashes 1.62.0 already polluted. A lost original now surfaces as an error instead of a confident wrong answer.Related Issues
Fixes #5620
Documentation PR
N/A
Type of Change
Bug fix
Testing
Ran the Python and TS context-manager unit suites. The new tests fail on
mainand pass with the fix. End to end in Python: host A truncates a 5,000-row tool result, and host B gets A's conversation with an empty stash.retrieve_context(reference="tu-1_0", pattern="row-4321")returnssuccess: No matches found for pattern 'row-4321'onmainanderror: reference not found: tu-1_0with this change. TS was exercised throughContextManager.initAgentwith seeded messages over a stash that holds the original, not with a live model.hatch run prepare(ranhatch run format,hatch run lint, and the context-manager tests separately; the fullpreparewas killed locally for memory)Additional Details
Risks and repro script
False positive: a genuine tool output or text block that ends with the literal
" [ref: x]"is no longer eagerly stashed, so if it's offloaded later, retrieval reports "not found". The match is anchored to the end of the string with a leading space, so mid-text mentions are still stored.Not in scope: skipping backfill after restore was considered and rejected. It couples the session manager to context-manager internals and misses the seeded-messages path.
Repro, run from
strands-py/:Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
🤖 Generated with Claude Code