Skip to content

Conversation

jakubno
Copy link
Member

@jakubno jakubno commented Sep 20, 2025

Handle connection error between the server and kernel gracefully
Add reconnect logic


Note

Adds WebSocket reconnect with retries and ping timeout, conditionally sets auth header in Python clients, and surfaces connection-loss errors to prevent hangs.

  • Server runtime (template/server/messaging.py):
    • WebSocket resilience: Add reconnect() with MAX_RECONNECT_RETRIES and PING_TIMEOUT; wrap send in retry loop catching ConnectionClosedError/WebSocketException and reconnecting.
    • Error propagation: On receiver teardown, enqueue Error and UnexpectedEndOfExecution for ongoing executions to avoid hangs.
    • Execution flow: Create per-execution message_id and Execution right before send; serialize request with _get_execute_request.
  • Python client (python/e2b_code_interpreter/*):
    • Auth header handling: Set headers with X-Access-Token only if token present for both async and sync run_code and create_code_context.
  • Changesets: Patch releases for @e2b/code-interpreter-template (add retry) and @e2b/code-interpreter-python (fix header issue).

Written by Cursor Bugbot for commit e51313b. This will update automatically on new commits. Configure here.

@jakubno jakubno self-assigned this Sep 20, 2025
@jakubno jakubno added the bug Something isn't working label Sep 20, 2025
@jakubno jakubno marked this pull request as ready for review September 21, 2025 06:22
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@jakubno jakubno changed the title Handle websocket error gracefully Handle websocket error gracefully + add retry logic Sep 22, 2025
cursor[bot]

This comment was marked as outdated.

@jakubno jakubno removed their assignment Sep 22, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@jakubno jakubno force-pushed the handle-websocket-error-gracefully branch from 87a0b15 to 1950089 Compare September 22, 2025 12:23
cursor[bot]

This comment was marked as outdated.

@jakubno jakubno requested a review from mishushakov September 23, 2025 13:41
@jakubno jakubno requested a review from mishushakov September 26, 2025 13:32
jakubno and others added 2 commits September 26, 2025 06:35
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Reconnect Hangs on Blocked Receive Task

The reconnect method awaits self._receive_task without cancelling it first. If the receive task is blocked waiting for WebSocket messages, this can cause the reconnect process to hang indefinitely, unlike the close() method's approach.

template/server/messaging.py#L70-L78

async def reconnect(self):
if self._ws is not None:
await self._ws.close(reason="Reconnecting")
if self._receive_task is not None:
await self._receive_task
await self.connect()

Fix in Cursor Fix in Web


@jakubno jakubno requested a review from mishushakov October 7, 2025 15:37
@mishushakov mishushakov merged commit be28fb7 into main Oct 7, 2025
9 checks passed
@mishushakov mishushakov deleted the handle-websocket-error-gracefully branch October 7, 2025 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants