Repository navigation
fix(cache): scope exact invalidations - #2142
Open
stussysenik wants to merge 1 commit into
Open
stussysenik wants to merge 1 commit into
stussysenik wants to merge 1 commit into
Conversation
Comment on lines
+185
to
+188
| prefixes = (f"{prompt_name}-version:", f"{prompt_name}-label:") | ||
| with self._lock: | ||
| for key in list(self._cache): | ||
| if key.startswith(prompt_name): | ||
| if key.startswith(prefixes): |
Contributor
There was a problem hiding this comment.
Some names still lose cache. Invalidating
foo still removes the generated key foo-label:bar-label:production for a different prompt named foo-label:bar. Prompt names are plain strings, and the documented name rules do not exclude this case. This leaves the exact-name fix incomplete and causes unnecessary fetches. Store the prompt name separately, or use an unambiguous key format, and add a test for names containing these separators.
Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/_utils/prompt_cache.py
Line: 185-188
Comment:
**Some names still lose cache.** Invalidating `foo` still removes the generated key `foo-label:bar-label:production` for a different prompt named `foo-label:bar`. Prompt names are plain strings, and the documented name rules do not exclude this case. This leaves the exact-name fix incomplete and causes unnecessary fetches. Store the prompt name separately, or use an unambiguous key format, and add a test for names containing these separators.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.This branch has not been deployed
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.
What does this PR do?
PromptCache.invalidate(prompt_name)deleted any cached key starting with thegiven name. Since cache keys are
f"{name}-version:{v}"orf"{name}-label:{l}", invalidatingfooalso evictedfoobar-label:production(and
my-promptevictedmy-prompt-extra). Invalidation now matches those twoexact key shapes, so only the named prompt is evicted.
No issue:
langfuse/langfuse-pythonrestricts issue creation to collaborators(GraphQL
CreateIssuepermission error, REST POST 404). The bug and a runnablerepro are reproduced here:
Type of change
Verification
Focused: 2 passed. Ruff: pass. Mypy: exit 0. Full unit suite: 1027 passed /
168 failed / 32 errors, the same failures present on clean
main.Checklist
code_review.md..env.templateif needed.The PR appears safe to merge, with a non-blocking edge case that can cause extra prompt fetches.
Summary
This PR narrows prompt cache invalidation and adds tests for overlapping names.
One edge case remains: names containing
-label:or-version:can still lose unrelated cache entries.Reviews (1) · Last reviewed commit: "fix(cache): scope exact invalidations" · Reviewed by Greptile