fix(session): cache messages across prompt loop to preserve prompt cache byte-identity#31527
Open
BYK wants to merge 1 commit into
Open
fix(session): cache messages across prompt loop to preserve prompt cache byte-identity#31527BYK wants to merge 1 commit into
BYK wants to merge 1 commit into
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found. (The search returned PR #31527 which is the current PR itself, but no other related/duplicate PRs addressing the same issue.) |
…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.
810aaff to
f6cf0be
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.
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