-
Notifications
You must be signed in to change notification settings - Fork 344
fix(cache): prevent over-invalidation of similarly named prompt prefixes in PromptCache - #1829
fix(cache): prevent over-invalidation of similarly named prompt prefixes in PromptCache #1829Xayar145 wants to merge 4 commits into
Conversation
...xes in PromptCache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude Code Review
This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.
CLAassistant
commented
Aug 22, 2026
CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2 Hyphen-delimited names still collide
For cached prompts named summary and summary-detailed, invalidating summary also matches summary-detailed-version:1, unnecessarily evicting the distinct sibling and forcing another API fetch on its next access. The added underscore case does not cover this collision because prompt names accept hyphens and cache metadata uses the same delimiter.
Knowledge Base Used: Utils and Support Types
Prompt To Fix With AI
This is a comment left during a code review. Path: langfuse/_utils/prompt_cache.py Line: 186 Comment: **Hyphen-delimited names still collide** For cached prompts named `summary` and `summary-detailed`, invalidating `summary` also matches `summary-detailed-version:1`, unnecessarily evicting the distinct sibling and forcing another API fetch on its next access. The added underscore case does not cover this collision because prompt names accept hyphens and cache metadata uses the same delimiter. **Knowledge Base Used:** [Utils and Support Types](https://app.greptile.com/personal-org-4986/-/custom-context/knowledge-base/langfuse/langfuse-python/-/docs/utils-support.md) --- For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Uh oh!
There was an error while loading. Please reload this page.
Summary
Fixes cache invalidation in
PromptCache.invalidate():{prompt_name}-instead of bare substring prefix matching (key.startswith(prompt_name)).test_prompt_cache_invalidate_exact_prefix_match.Motivation
Previously,
PromptCache.invalidate("summary")would unintentionally evict other prompt keys sharing the same name prefix (for example"summary_detailed-version:1"or"summary_qa-label:production"). Checking exact key match or hyphen-delimited prefix ensures only the target prompt is evicted.Changes
langfuse/_utils/prompt_cache.py: Refactoredinvalidate()to matchkey == prompt_name or key.startswith(f"{prompt_name}-").tests/unit/test_prompt.py: Added test ensuring sibling prompts with similar prefixes are not accidentally evicted.Tests
test_prompt_cache_invalidate_exact_prefix_matchverifying selective invalidation.Greptile Summary
The PR narrows prompt-cache invalidation to exact keys and hyphen-delimited prefixes and adds a regression test for similarly prefixed names. The delimiter remains ambiguous for valid prompt names containing hyphens.
PromptCache.invalidate()to avoid bare prefix matching.summarypreservessummary_detailed.summary-detailed.Confidence Score: 4/5
The PR is safe to merge with a non-blocking cache-correctness improvement recommended for hyphen-prefixed sibling prompt names.
The change fixes underscore-style prefix collisions, but the shared hyphen delimiter still causes distinct names such as
summary-detailedto be evicted whensummaryis invalidated.Files Needing Attention: langfuse/_utils/prompt_cache.py, tests/unit/test_prompt.py
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "test(prompt): add unit test for exact pr..." | Re-trigger Greptile
Context used: