Skip to content

fix(prompts): invalidate only cache entries of the given prompt name - #2133

Open
Mo0nl19ht wants to merge 1 commit into
langfuse:mainfrom
Mo0nl19ht:fix/prompt-cache-invalidate-exact-name
Open

Mo0nl19ht wants to merge 1 commit into
langfuse:mainfrom
Mo0nl19ht:fix/prompt-cache-invalidate-exact-name

Conversation

@Mo0nl19ht

@Mo0nl19ht Mo0nl19ht commented Nov 17, 2026 •

Copy link
Copy Markdown

What does this PR do?

create_prompt and update_prompt call PromptCache.invalidate(name), which deletes every cache key that starts with the prompt name. Updating summary therefore also evicts cached prompts such as summary_detailed and summary-v2, and their next get_prompt call goes back to the server.

invalidate() now compares the name of each cached prompt instead of the key prefix. The cache key format and the public API are unchanged.

Related PRs

Supersedes #1829 and #1671, which match on key prefixes. #1829 checks key.startswith(f"{name}-"), which still evicts summary-detailed and summary-v2, because prompt names can contain hyphens (as Greptile noted there). #1671 was closed by its author.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Documentation update
  • Tooling, CI, or repo maintenance

Verification

List the main commands you ran:

uv run --frozen ruff check .                                  # All checks passed!
uv run --frozen ruff format --check .                         # 595 files already formatted
uv run --frozen mypy langfuse --no-error-summary              # no issues
uv run --frozen pytest -n auto --dist worksteal tests/unit    # 1016 passed, 2 skipped

The new tests/unit/test_prompt.py::test_invalidate_only_evicts_entries_of_the_given_prompt_name caches summary (production, staging, version 3) next to summary_detailed, summary-detailed, summary-v2 and summary/nested, then invalidates summary. On main it fails with all 4 other prompts evicted; with the change from #1829 it still fails with summary-detailed and summary-v2 evicted; with this change it passes.

The comparison relies on the fetched prompt's name being the requested name, which tests/e2e/test_prompt.py::test_update_prompt_in_folder already asserts for folder prompts. I did not run the e2e suite locally.

Checklist

  • I self-reviewed the diff using code_review.md.
  • I added or updated tests for behavior changes.
  • I updated docs, examples, or .env.template if needed. (Not needed; no public API change.)
  • I did not hand-edit generated files; if generated files changed, I used the upstream regeneration path.
  • I did not commit secrets or credentials.

RetriggerView in GreptileConfidence Score: 5/5

This change appears safe to merge.

Summary

PromptCache.invalidate now checks each stored prompt’s name instead of matching the start of its cache key.

  • Prompt updates clear only cache entries with the same name.

Reviews (1) · Last reviewed commit: "fix(prompts): invalidate only cache entr..." · Reviewed by Greptile

@claude claude Bot left a comment

Copy link
Copy Markdown

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.

PromptCache.invalidate() deleted every key starting with the prompt name,
so create_prompt("summary") or update_prompt(name="summary") also evicted
cached prompts such as "summary_detailed" and "summary-v2". Matching on
"{name}-" is not enough, because prompt names can contain hyphens. Compare
the name of each cached prompt instead of the key prefix.
@Mo0nl19ht
Mo0nl19ht force-pushed the fix/prompt-cache-invalidate-exact-name branch from 68178f1 to f0c2495 Compare November 17, 2026 02:14

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant