Repository navigation
Conversation
|
|
chrikrah
approved these changes
Nov 2, 2026
chrikrah
left a comment
There was a problem hiding this comment.
From my perspective this can be merged; it's the same await asyncio.to_thread(self.flush) the experiment runner already uses at client.py:2791.
$ sed -i 's/await asyncio.to_thread(self.client.flush)/self.client.flush()/' langfuse/batch_evaluation.py && .venv/bin/python -m pytest tests/unit/test_batch_evaluation.py tests/unit/test_score_consumer.py tests/unit/test_resource_manager.py -q -p no:cacheprovider # head ba1eb3b with the fix reverted
1 failed, 70 passed, 267 warnings in 6.36s
non-blocking: #2064 adds a bare self.client.flush() on the fetch-failure return at line 968, so that path would still block. If it lands first, would you switch that call to the same form when you rebase?
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?
BatchEvaluationRunner.run_async()calls the synchronousclient.flush()directly after evaluation. Waiting for the score queue or network uploads therefore blocks the caller's event loop, including unrelated tasks and callbacks.Await
asyncio.to_thread(self.client.flush), matching the existing experiment runner, so flushing finishes before a normal return while the event loop stays available. Update the method docstring and add a regression using the real SDK client, generated observations/score API clients, score queue and consumer thread withhttpx.MockTransport.The test schedules an event-loop callback from the score upload handler and checks that it runs during delivery. On unchanged main
1fc854dd2b241cf8e3dac38bfd5907ff2fe365e3, it fails because the callback cannot run until the upload wait times out. With the fix, it runs during the upload; both scores are delivered and the queue is empty before the result returns.Found during a source audit; no matching issue or PR was found. This is separate from #2064, which adds a missing flush on the fetch-failure path. This patch changes only the existing normal-completion flush.
Type of change
Verification
uv sync --locked uv run --frozen pytest tests/unit/test_batch_evaluation.py -k flush_keeps_event_loop -q uv run --frozen pytest tests/unit/test_batch_evaluation.py tests/unit/test_score_consumer.py tests/unit/test_resource_manager.py -q uv run --frozen ruff check . uv run --frozen mypy langfuse --no-error-summary uv run --frozen pre-commit run --files langfuse/batch_evaluation.py tests/unit/test_batch_evaluation.pyChecklist
code_review.md.AI assistance: Codex investigated, generated and reviewed the patch and ran the checks under the account owner's authorization. No independent human review is claimed.


Confidence Score: 5/5
The PR appears safe to merge.Summary
Moves the normal-completion flush in
BatchEvaluationRunner.run_async()to an awaited worker thread.Acknowledged scope:
6londeexplicitly leaves the existing fetch-failure flush issue to #2064. This patch changes only the normal-completion flush.Diagram
sequenceDiagram participant R as Batch runner participant L as Event loop participant W as Worker thread participant C as Score consumer R->>W: Await client.flush() W->>C: Wake consumer W->>W: Wait for queued work C->>C: Upload scores L->>L: Run unrelated callbacks C-->>W: Mark scores finished W-->>R: Flush finished R->>R: Return resultReviews (1) · Last reviewed commit: "fix(evaluations): flush scores without b..." · Reviewed by Greptile