fix: Replace done_callback with coroutine chain for judge tracking#147
Merged
jsonbailey merged 5 commits intomainfrom Apr 29, 2026
Merged
fix: Replace done_callback with coroutine chain for judge tracking#147jsonbailey merged 5 commits intomainfrom
jsonbailey merged 5 commits intomainfrom
Conversation
`_track_judge_results` previously used `add_done_callback` to fire `track_judge_result()` after evaluation completed, but callbacks run outside the asyncio task scheduler and can execute at unpredictable times. Replace with a single `_run_and_track` coroutine wrapped in a new `asyncio.create_task`, so that awaiting `response.evaluations` guarantees both evaluation and tracker calls complete in sequence. Add `test_managed_model.py` covering: invoke() returns before evaluations resolve; awaiting evaluations collects results; tracking fires inside the awaited chain (not before); failed judge results do not trigger tracking; noop evaluator returns an empty list. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
a2402ea to
381cf75
Compare
This was referenced Apr 28, 2026
a997b91 to
d0b3436
Compare
Wrap tracker.track_judge_result() in try/except inside _run_and_track so a tracking failure (e.g., shutdown LD client) does not propagate through the wrapper task and destroy the evaluation results that were successfully computed. Restores the resilience of the previous add_done_callback approach, which asyncio handled with isolation. Also log a warning when a judge evaluation fails (r.success is False) so failures are visible rather than silently skipped.
d0b3436 to
e56f69a
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2f0fd53. Configure here.
… tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
keelerm84
approved these changes
Apr 29, 2026
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.

Summary
add_done_callbackinManagedModel._track_judge_resultswith a proper_run_and_trackcoroutine wrapped inasyncio.create_task, so that awaitingresponse.evaluationsguarantees both evaluation andtracker.track_judge_result()calls complete in sequencetest_managed_model.pywith 5 tests covering: return-before-resolve, collect results, tracking fires inside the awaited chain, failed results skip tracking, noop evaluator returns empty listTest plan
test_managed_model.pytests added and passinghello-python-aiagent🤖 Generated with Claude Code
Note
Medium Risk
Changes async task orchestration for judge evaluation/tracking, which can affect ordering, exception propagation, and background task behavior. New tests reduce regression risk but subtle event-loop edge cases remain possible.
Overview
Fixes the judge-evaluation tracking chain so that awaiting
ModelResponse.evaluationsnow guarantees judge results are tracked in-sequence with evaluation completion.ManagedModel._track_judge_resultsreplaces the prioradd_done_callbackapproach with an awaited coroutine wrapper (_run_and_track) scheduled viaasyncio.create_task, adds warning logs for failed judge results and tracking exceptions, and introduces a focusedtest_managed_model.pysuite covering non-blockinginvoke(), result collection, tracking timing, and failure/noop behavior.Reviewed by Cursor Bugbot for commit 7ae2024. Bugbot is set up for automated code reviews on this repo. Configure here.