Skip to content

fix(template): wait for an interrupted execution to end before the next one - #372

Merged
mishushakov merged 2 commits into
mainfrom
devin/1795628707-interrupt-before-next-run
Nov 25, 2026
Merged

mishushakov merged 2 commits into
mainfrom
devin/1795628707-interrupt-before-next-run

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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) then run_code("1 + 1")), the follow-up run hung until it timed out.

The server log in a real code-interpreter-v1 sandbox 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 interrupts sleep(300) and aborts the queued 1 + 1 along with it.

Two bugs made that a hang:

  • The interrupt didn't wait. With uvicorn's ASGI spec 2.3, Starlette cancels the request task through an anyio cancel scope, which cancels every await. So await asyncio.shield(self.interrupt()) returned at once and released self._lock before 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's EndOfExecution (at most INTERRUPT_TIMEOUT = 10 s). execute() waits for it under the lock, the same way it already waits for _cleanup_task.
  • Aborted runs never ended. ipykernel replies with status: "aborted", but the handler checked for "abort". So an aborted run never got EndOfExecution.

Verified with a test template built from this branch:

  • tests/test_interrupt.py passes (it fails on prod code-interpreter-v1).
  • The full tests/ suite passes (91).
  • The E2B SDK repro now returns 2 0.6 s after the follow-up call.

SDK CI goes green once this template ships to prod. The xfail marks 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

Devin Review

…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>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@cla-bot cla-bot Bot added the cla-signed label Nov 25, 2026
@mishushakov
mishushakov marked this pull request as ready for review November 25, 2026 18:09
@mishushakov
mishushakov self-requested a review as a code owner November 25, 2026 18:09
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T18:11:23.124659Z 30aedd1 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

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>

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment thread template/server/messaging.py Resolved
@mishushakov
mishushakov merged commit a76593b into main Nov 25, 2026
11 checks passed
@mishushakov
mishushakov deleted the devin/1795628707-interrupt-before-next-run branch November 25, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant