Skip to content

fix(prompts): honor cache expiry at fractional seconds - #2119

Open
Aafimalek wants to merge 1 commit into
langfuse:mainfrom
Aafimalek:fix/sdk-validation
Open

Aafimalek wants to merge 1 commit into
langfuse:mainfrom
Aafimalek:fix/sdk-validation

Conversation

@Aafimalek

@Aafimalek Aafimalek commented Nov 10, 2026 •

Copy link
Copy Markdown

What does this PR do?

Prompt cache expiry rounds timestamps down to whole seconds and considers an item expired only when the rounded time is greater than its expiry. As a result, a positive TTL can be treated as fresh for almost one additional second. For example, an item cached at 100.75 seconds with a one-second TTL is still considered fresh at 101.75 seconds, so the usual stale-while-revalidate refresh is not scheduled at the configured expiry.

Keep fractional timestamp precision and treat the item as expired once the TTL has elapsed. The stale-while-revalidate behavior remains unchanged: the first request after expiry can still receive stale data while the background refresh runs.

This addresses positive-TTL timing; #2114 separately addresses writing to the cache when the caller explicitly requests a zero TTL.

Type of change

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

Verification

  • A deterministic test for the exact TTL boundary failed before the fix and passes afterward. The complete prompt unit file passed: 27 tests.
  • ruff check ., ruff format --check ., mypy langfuse --no-error-summary, and the repository pre-commit hooks passed.
  • Linux unit suite: 1,008 passed, two skipped, eight failed when LANGFUSE_TRACING_ENVIRONMENT=unit was set for the run. Those eight environment-propagation cases all passed when rerun with that variable unset. The entire unit suite was not rerun after changing the environment.
  • No live provider or server E2E tests were run; this change affects local cache timing.

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. (No documentation change was needed.)
  • 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

The PR appears safe to merge.

Summary

Prompt cache entries now keep fractional timestamps and expire when their full TTL has elapsed.

  • Prompt entries expire as soon as their full TTL elapses.

Aafimalek explicitly deferred zero-TTL cache writes to #2114.

Reviews (1) · Last reviewed commit: "fix(prompts): honor cache expiry at frac..." · 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.

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