Skip to content

[Platform][Cache] Key MessageBag inputs on their message content - #2388

Open
lazerg wants to merge 1 commit into
symfony:mainfrom
lazerg:fix/issue-2192-messagebag-cache-key
Open

[Platform][Cache] Key MessageBag inputs on their message content#2388
lazerg wants to merge 1 commit into
symfony:mainfrom
lazerg:fix/issue-2192-messagebag-cache-key

Conversation

@lazerg

@lazerg lazerg commented Aug 7, 2026

Copy link
Copy Markdown
Contributor
Q A
Bug fix? yes
New feature? no
Docs? no
Issues Fix #2192
License MIT

MessageBagCacheKeyGenerator returned $input->getId()->toString(), and MessageBag generates a fresh Uuid::v7() in its constructor. Every request builds a new bag, so every request produced a new cache key and CachePlatform never 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 FileCacheKeyGenerator already does, so a lazily read file does not leak its closure into the key.

template_vars now goes into the key as well. Templates are rendered inside the inner platform, after CachePlatform has 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.

@carsonbot carsonbot added Status: Needs Review Bug Something isn't working Platform Issues & PRs about the AI Platform component labels Aug 7, 2026
@lazerg
lazerg force-pushed the fix/issue-2192-messagebag-cache-key branch from 88daa42 to 4a8aaf6 Compare August 7, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Platform Issues & PRs about the AI Platform component Status: Needs Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Platform][Cache] CachePlatform never hits cache when input is a MessageBag

2 participants