Skip to content

fix(prompt-cache): drain shutdown sentinels after active refreshes - #2020

Open
passionworkeer wants to merge 1 commit into
langfuse:mainfrom
passionworkeer:fix/prompt-cache-shutdown-drain-20261018
Open

passionworkeer wants to merge 1 commit into
langfuse:mainfrom
passionworkeer:fix/prompt-cache-shutdown-drain-20261018

Conversation

@passionworkeer

@passionworkeer passionworkeer commented Oct 18, 2026 •

Copy link
Copy Markdown

What does this PR do?

When every prompt-cache refresh worker is busy, shutdown() pauses the workers before enqueueing their shutdown sentinels. The workers finish their callbacks and exit without consuming those sentinels. shutdown() returns, but the queue retains unfinished tasks and a subsequent wait_for_idle() never returns.

Let the existing sentinel path stop the workers after queued refreshes finish. The change preserves broadcasting all sentinels before joining workers. This is a fix for the prompt-cache task manager's queue accounting; it does not claim that every public Langfuse.shutdown() call hangs.

Related prior work: the author-closed #1670 and #1671 proposed removing the same pause step. This focused patch credits those attempts and adds a deterministic regression that checks the unfinished queue, rather than only checking whether shutdown returns. It does not include the separate invalidation change from #1671.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Verification

Four new cases use real workers and a real queue, with barriers/events holding all workers busy until shutdown has queued the sentinels. They cover 1 and 3 workers, with both successful and raising refresh callbacks. All four fail on current main (35f8e7ee) with 1 or 3 unfinished tasks, then pass with the fix. They also verify worker exit, cleared active task keys, and wait_for_idle() returning.

Python 3.12.15, dependencies from uv sync --locked:

# Same test-only environment as the upstream unit-test workflow
LANGFUSE_BASE_URL=http://localhost:3000 \
LANGFUSE_PUBLIC_KEY=pk-lf-test LANGFUSE_SECRET_KEY=sk-lf-test \
OPENAI_API_KEY=test-openai-key \
uv run --frozen python -m pytest tests/unit -q
# 926 passed, 2 skipped

uv run --frozen pre-commit run --all-files
# uv-lock, ruff-check, ruff-format, mypy: all passed

The complete unit run includes the prompt-cache subprocess/atexit tests and resource-manager tests. No backend or external-provider integration result is claimed.

Checklist

  • Reviewed against code_review.md, including an independent review.
  • Added regression tests that fail on the unmodified implementation.
  • No generated API files, dependencies, or public signatures changed.
  • No credentials or secrets added; the values above are upstream CI test placeholders.

AI assistance: implemented, tested, and reviewed with Codex.

RetriggerView in GreptileConfidence Score: 5/5

This PR appears safe to merge.

Summary

Removes pause() from prompt-cache shutdown so busy workers finish queued refreshes and consume their stop markers.

  • Busy prompt-cache workers finish queued refreshes before exiting.

Diagram

sequenceDiagram
    participant Shutdown
    participant Queue
    participant Worker
    Shutdown->>Queue: Add one stop marker per worker
    Worker->>Worker: Finish current refresh
    Worker->>Queue: Mark refresh done
    Worker->>Queue: Take remaining work, then stop marker
    Worker->>Queue: Mark stop marker done
    Worker->>Worker: Exit
    Shutdown->>Worker: Join after all markers are queued
Loading

Reviews (1) · Last reviewed commit: "fix(prompt-cache): drain shutdown sentin..." · Reviewed by Greptile

Copilot AI balanced review requested due to automatic review settings October 18, 2026 05:00

@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.

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants