fix: propagate control-flow exceptions from async helper thread - #1868
Open
Bortlesboat wants to merge 1 commit into
Open
fix: propagate control-flow exceptions from async helper thread#1868Bortlesboat wants to merge 1 commit into
Bortlesboat wants to merge 1 commit into
Conversation
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?
run_async_safelynow propagates cancellation and exit exceptions when it runs a coroutine in its helper thread. Previously,CancelledError,SystemExitandKeyboardInterruptescaped the worker while the caller receivedNone, unlike the directasyncio.runpath.The original exception object reaches the caller in both contexts.
Type of change
Verification
python -m pytest tests/unit/test_utils.py -q python -m pytest tests/unit -q python -m ruff check . python -m ruff format --check langfuse/_client/utils.py tests/unit/test_utils.py python -m mypy langfuse --no-error-summaryAll 22 utility tests pass on Python 3.13; the three new threaded cases fail before the fix. Ruff and mypy pass, and the changed files pass formatting.
The full unit suite produced 673 passes, 2 skips, 3 failures and 18 fixture errors on native Windows. A separate untouched checkout of the same base produced the same failures/errors and 667 passes: the failures are two prompt atexit subprocess tests and a Windows path assertion; the errors are prompt-client initialization fixtures. Whole-tree format checking also reports an existing discrepancy in
test_media.py. Server and live-provider suites were not run because this bridge behavior is covered without external services.Checklist
code_review.md..env.template; the existing exception contract already describes the intended behavior.No service deployment or new telemetry is involved in this SDK fix.
Agent-assisted: Codex prepared the patch and ran the local checks listed above.
Greptile Summary
This PR fixes
run_async_safelyso control-flow exceptions raised in its helper thread reach the caller, consistent with its direct execution path.BaseExceptionrather than onlyException.Confidence Score: 5/5
The PR appears safe to merge, with the implementation matching the existing exception contract and direct execution behavior.
No actionable failures remain; the worker is joined before the original captured exception is re-raised, and the new tests cover all control-flow exceptions targeted by the fix.
Reviews (1): Last reviewed commit: "fix: propagate control-flow exceptions f..." | Re-trigger Greptile