From 30c44c755500bbc9b8979733b7d219f4525d1f44 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 26 Sep 2026 23:19:42 +0530 Subject: [PATCH] fix(code-kernel): make post-result cell cleanup best-effort The rm of the cell result file runs after the runner has executed the cell. A transport failure there propagated out of _run_remote_cell, so _run_attached_cell evicted the kernel and re-raised, and the caller's per-call fallback then ran the same code a second time. Catch and debug-log that failure (a leftover cell_res_* is harmless because seq is monotonic), so the atomic ship is the only remote call that can raise inside the discard scope and the handler's "runs exactly once" comment holds. --- tools/code_kernel_remote.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/code_kernel_remote.py b/tools/code_kernel_remote.py index 2e86b476ab..e8065e3a69 100644 --- a/tools/code_kernel_remote.py +++ b/tools/code_kernel_remote.py @@ -321,7 +321,13 @@ def _run_remote_cell(kernel: RemoteKernel, code: str, timeout: int) -> Tuple[str status = payload.get("status", "error") except ValueError: payload, status = {}, "protocol-error" - kernel.sh(f"rm -f {q_cells}/{q_res}", timeout=10) + try: + kernel.sh(f"rm -f {q_cells}/{q_res}", timeout=10) + except Exception: + # Best-effort: the cell already ran, so raising here would send + # the caller to its per-call fallback and run the code twice. + # A leftover result file is harmless (seq is monotonic). + logger.debug("remote kernel: cell result cleanup failed", exc_info=True) return status, payload time.sleep(_CELL_POLL_INTERVAL) return "timeout", {} @@ -381,7 +387,8 @@ def _run_attached_cell(kernel: RemoteKernel, key: Tuple, code: str, *, env, task try: cell_status, cell_payload = _run_remote_cell(kernel, code, timeout) except Exception: - # The request never reached the runner (the atomic ship failed), so the + # The atomic ship is the only remote call here that can raise (the poll + # and result cleanup are best-effort), so the request never reached the runner and the # caller's per-call fallback runs the code exactly once. Kill the # kernel as the timeout path does: leaving it registered would let the # next call reuse a kernel whose state silently missed this cell.