fix(session): cache messages across prompt loop to preserve prompt cache byte-identity#36852
Closed
BYK wants to merge 1 commit into
Closed
fix(session): cache messages across prompt loop to preserve prompt cache byte-identity#36852BYK wants to merge 1 commit into
BYK wants to merge 1 commit into
Conversation
…che byte-identity filterCompactedEffect(sessionID) reloads all messages from the DB at the start of every prompt loop iteration. Between reloads, the DB returns rows with new object identity, breaking Anthropic's prompt cache which relies on byte-identical prefixes. Cache messages across loop iterations — first iteration does a full load, subsequent iterations only append new messages by ID. Full reload is flagged after subtask, compaction, or overflow operations.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found one potentially related PR: Related PR:
However, this is a related but distinct fix. PR #36852 is a re-filed version of the earlier #31527 (which was auto-closed by the cleanup bot), so it's not a duplicate—it's a rebased continuation of previous work. No duplicate open PRs found addressing the exact same message caching mechanism across prompt loop iterations. |
Contributor
Author
|
Closing this. After a deeper look, the original rationale doesn't hold and the patch isn't worth the risk:
|
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.
Issue for this PR
Closes #31525
Type of change
What does this PR do?
filterCompactedEffect(sessionID)reloads all messages from the DB at the start of every prompt loop iteration. Between reloads, the DB returns rows with new object identity, breaking Anthropic's prompt cache which relies on byte-identical prefixes.This PR caches messages across loop iterations:
needsFullReloadto get a fresh loadThis preserves object identity for existing messages across iterations, improving prompt cache hit rates.
Re-filing of #25367 which was auto-closed by the cleanup bot.
How did you verify your code works?
Tested locally with multi-turn sessions. Verified via logs that message count stays stable across iterations and only new messages are appended after tool calls.
Screenshots / recordings
N/A — backend performance improvement.
Checklist