Repository navigation
fix(prompt-cache): drain shutdown sentinels after active refreshes - #2020
Open
passionworkeer wants to merge 1 commit into
Open
passionworkeer wants to merge 1 commit into
passionworkeer wants to merge 1 commit into
Conversation
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?
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 subsequentwait_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
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, andwait_for_idle()returning.Python 3.12.15, dependencies from
uv sync --locked: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
code_review.md, including an independent review.AI assistance: implemented, tested, and reviewed with Codex.


Confidence 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.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 queuedReviews (1) · Last reviewed commit: "fix(prompt-cache): drain shutdown sentin..." · Reviewed by Greptile