Repository navigation
fix(template): wait for an interrupted execution to end before the next one - #372
Merged
Merged
Conversation
…xt one When a client abandons a long-running execution, the server interrupts the kernel. Starlette keeps cancelling the request task, so the shielded interrupt returned at once and the next execution's code reached the kernel first; ipykernel then aborted it with the interrupted cell. The interrupt now runs in its own task that waits for the interrupted execution to end, and the next execution waits for that task. Aborted execute replies (status "aborted", not "abort") now end the execution instead of hanging it. Co-Authored-By: mish@e2b.dev <mish@e2b.dev>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…disconnects Co-Authored-By: mish@e2b.dev <mish@e2b.dev>
mishushakov
approved these changes
Nov 25, 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
Fixes the interrupt-after-client-timeout tests that have failed in E2B SDK CI since 2026-11-19 (SDK-452). When a client abandons a run (
run_code(..., timeout=3)thenrun_code("1 + 1")), the follow-up run hung until it timed out.The server log in a real
code-interpreter-v1sandbox showed the cause. The proxy now closes the connection about 9 s after the client does, so the server notices the disconnect after the next request has arrived. The next request then got its code to the kernel ~20 ms before the interrupt. ipykernel interruptssleep(300)and aborts the queued1 + 1along with it.Two bugs made that a hang:
await asyncio.shield(self.interrupt())returned at once and releasedself._lockbefore the interrupt was sent. Now the disconnect handler starts_interrupt_execution(message_id)as its own task. That task interrupts the kernel and waits for the run'sEndOfExecution(at mostINTERRUPT_TIMEOUT= 10 s).execute()waits for it under the lock, the same way it already waits for_cleanup_task.status: "aborted", but the handler checked for"abort". So an aborted run never gotEndOfExecution.Verified with a test template built from this branch:
tests/test_interrupt.pypasses (it fails on prodcode-interpreter-v1).tests/suite passes (91).20.6 s after the follow-up call.SDK CI goes green once this template ships to prod. The
xfailmarks from e2b-dev/E2B#2175 can be removed then.Link to Devin session: https://app.devin.ai/sessions/a7f462b4bda74774b229bdfe9da39dc0
Open in Devin Desktop: https://app.devin.ai/desktop/session/a7f462b4bda74774b229bdfe9da39dc0?variant=devin
Requested by: @mishushakov
🟢 Devin Review found nothing to fix · View findings · Follow Devin's work