Repository navigation
fix: keep the original error when a curator run fails inside a running event loop - #750
TanishGudise wants to merge 1 commit into
Conversation
…g event loop When an event loop was already running (Jupyter, Colab), run_in_event_loop called asyncio.run inside a try block that caught RuntimeError. If the coroutine raised a RuntimeError, the handler swallowed it and asyncio.run was called again with the same, already finished coroutine, so the user saw "RuntimeError: cannot reuse already awaited coroutine" instead of the real error (for example batch mode's "None of the submitted batches completed successfully"). Only catch the RuntimeError from get_running_loop() and run the coroutine once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Strix Security ReviewNo security issues found. Review summaryReviewed the two changed files: the Updated for Reviewed by Strix |
EntelligenceAI PR SummaryUpdated flowchart TD
classDef newBehavior fill:#dcfce7,stroke:#16a34a,color:#14532d;
A["run_in_event_loop"] --> B["Check for running event loop"]
B --> C{"Loop already running?"}
C -->|No| D["Call asyncio.run once"]
C -->|Yes| E["Apply nest_asyncio"]
E --> D
D --> F["Coroutine executes once"]
F --> G["Return result or propagate original error"]
class A,B,C,D,E,F,G newBehavior;
Review Scorecard
Safe to merge with a low blast radius; code quality rated Excellent (5/5): the review found nothing to flag. Key Findings:
Evaluated against
|
WalkthroughRefines ChangesFiles
Updated Files
Added coverage for exception propagation and unchained original errors when invoked with and without a running event loop. Tests also verify successful coroutine execution and forwarding of the result |
Closes #746
When an event loop was already running (Jupyter, Colab),
run_in_event_loopcalledasyncio.run(coroutine)inside atrythat caughtRuntimeError. If the coroutine raised aRuntimeError, the handler swallowed it andasyncio.runwas called again with the same finished coroutine, so the user sawRuntimeError: cannot reuse already awaited coroutineinstead of the real error (for example batch mode's "None of the submitted batches completed successfully").Now only the
RuntimeErrorfromasyncio.get_running_loop()is caught.nest_asyncio.apply()runs in theelsebranch, and the coroutine runs once, after thetryblock, so its errors aren't chained to the "no running event loop" error (the case #99 fixed).Tests (
tests/unittests/test_event_loop.py)RuntimeErrorreaches the caller and the coroutine runs once (fails on main with "cannot reuse already awaited coroutine").The tests also catch two regressions: moving
asyncio.runback into theexceptblock fails the no-loop test, and droppingnest_asyncio.apply()fails both in-loop tests.Manual check: in a real Jupyter kernel (ipykernel 7.4.0), the cell gets
RuntimeError('cannot reuse already awaited coroutine')on main and the original message with this change.Without network access, the full test suite has no new failures compared with main: the offline failures are tests that need the network, plus
test_simple_code_execution_local, which also fails locally on main.CI note: CI on main is currently red for reasons unrelated to this PR:
test_basic_reasoningandtest_batch_reasoningfail because litellm 1.83.7 doesn't mapclaude-3-7-sonnet-20250219, and total coverage is 78%, under--cov-fail-under=80(run 37956501158 on 31abdb7). Once CI runs here (first-time contributor runs wait for approval), those failures will show on this PR too until main is fixed.🤖 Generated with Claude Code