fix(experiments): await future and custom awaitable results - #1869
Open
Bortlesboat wants to merge 2 commits into
Open
fix(experiments): await future and custom awaitable results#1869Bortlesboat wants to merge 2 commits into
Bortlesboat wants to merge 2 commits into
Conversation
Address review feedback on langfuse#1869 and preserve composite scores from Future, Task and custom awaitable callbacks. Note: pre-existing failures in prompt, prompt atexit, and Windows path tests are not addressed by this PR.
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?
Experiments now resolve
Future,Taskand custom awaitable results before recording task output or evaluating scores. Previously, task output could contain the awaitable object itself, and evaluator scores could be dropped, even though the callback protocols allowAwaitableresults.Direct values and coroutines retain their existing behavior. Item evaluators and run evaluators both use the corrected result handling.
Type of change
Verification
python -m pytest tests/unit/test_experiment.py -q python -m pytest tests/unit -q python -m ruff check . python -m ruff format --check langfuse/experiment.py tests/unit/test_experiment.py python -m mypy langfuse --no-error-summaryAll 30 experiment tests pass on Python 3.13, including ten public
run_experimentcases covering values, coroutines, pending Futures, Tasks and custom awaitables. Six cases fail before the fix. Ruff and mypy pass; the changed files pass formatting.The full unit suite produced 677 passes, 2 skips, 3 failures and 18 fixture errors on native Windows. The untouched base produced 667 passes with the same failures/errors: two prompt atexit subprocess tests, a Windows path assertion, and 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; these cases use the existing in-memory fixture.Checklist
code_review.md..env.template; callback protocols already document awaitable results.No service deployment or new monitoring is needed for this SDK result-handling fix.
Agent-assisted: Codex prepared the patch and ran the local checks listed above.
Greptile Summary
This PR broadens experiment callback result handling from coroutine-only detection to all Python awaitables.
Confidence Score: 4/5
The PR is not yet safe to merge because composite evaluators can still silently lose valid Future, Task, and custom-awaitable results.
Item and run evaluator results are now resolved correctly, but the third supported experiment evaluation layer bypasses the corrected helper and retains the same coroutine-only behavior this PR is intended to fix.
Files Needing Attention: langfuse/experiment.py and langfuse/_client/client.py
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(experiments): await future and custo..." | Re-trigger Greptile
Context used: