[Platform][Cache] Key MessageBag inputs on their message content - #2388
Open
lazerg wants to merge 1 commit into
Open
[Platform][Cache] Key MessageBag inputs on their message content#2388lazerg wants to merge 1 commit into
lazerg wants to merge 1 commit into
Conversation
lazerg
force-pushed
the
fix/issue-2192-messagebag-cache-key
branch
from
August 7, 2026 14:32
88daa42 to
4a8aaf6
Compare
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.
MessageBagCacheKeyGeneratorreturned$input->getId()->toString(), andMessageBaggenerates a freshUuid::v7()in its constructor. Every request builds a new bag, so every request produced a new cache key andCachePlatformnever returned a cached result for a conversation.The generator now hashes the messages themselves: their class, their content and their order. The identifiers and the metadata of the bag and of its messages stay out of the hash, since they describe the instance rather than the conversation. Identifiers a provider assigns to a content part, a tool call id for instance, are kept, because they are sent along with it. Binary content is keyed on a hash of its bytes, the way
FileCacheKeyGeneratoralready does, so a lazily read file does not leak its closure into the key.template_varsnow goes into the key as well. Templates are rendered inside the inner platform, afterCachePlatformhas built the key, so without that a bag of templates would serve the first render to every later set of variables.The existing test for two separate bags with the same messages asserted the current behaviour (two calls to the inner platform), so it now asserts the cache hit, and further tests cover two bags with different messages and two calls with different template variables.