From 2d82b658baefdd6dbd634a73ba50ad78c692cc3a Mon Sep 17 00:00:00 2001 From: Chinesezjc Date: Thu, 20 Aug 2026 18:31:09 +0800 Subject: [PATCH] fix(code-runtime-python): bind RuntimeError inside the module-level _pump_replies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous commit bound _RuntimeError in _run, but _pump_replies is a separate module-level function, so its except _RuntimeError referenced an out-of-scope local and raised NameError instead of catching the closed-loop failure — killing the pump and timing out the run. Bind _RuntimeError at the top of _pump_replies too. The closed-loop pump test now passes. --- packages/code-runtime/code-runtime-python/py/bootstrap.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/code-runtime/code-runtime-python/py/bootstrap.py b/packages/code-runtime/code-runtime-python/py/bootstrap.py index 1833489eea..90f108b4e2 100644 --- a/packages/code-runtime/code-runtime-python/py/bootstrap.py +++ b/packages/code-runtime/code-runtime-python/py/bootstrap.py @@ -1122,6 +1122,12 @@ async def _pump_replies( pending: dict[int, tuple[asyncio.AbstractEventLoop, asyncio.Future[Any]]], pending_lock: "threading.Lock", ) -> None: + # The exception class the closed-loop catch below resolves is bound into a + # LOCAL here. This bootstrap IS `__main__`, so `__main__.RuntimeError = ...` + # would otherwise rebind the module global the `except RuntimeError` clause + # resolves at runtime, and a closed-loop scheduling failure would then escape + # the catch, killing the pump and stranding every later reply. + _RuntimeError = RuntimeError """Background task: read reply frames and settle pending futures. Cancelled after ``done`` is posted. Unknown ids and post-settlement replies