Skip to content

Auto-reconnect with backoff when pycodeloop serve crashes #4

Description

@FernandoCelmer

Problem

When pycodeloop serve exits unexpectedly (crash, OOM, network error), the extension posts a processExit note and sets this.client = undefined, but takes no further action. The user must manually click "Reload Connection" from the settings menu (⚙ → Reload Connection) or run CodeLoop: Open Chat. This is disruptive during long agent runs where the CLI may restart cleanly on its own.

Steps to reproduce / context

  1. Start a long agent turn.
  2. Kill pycodeloop serve from outside (or let it crash on a bad provider response).
  3. The UI shows "Disconnected" and a system note. No automatic recovery occurs.
  4. User must manually reload to continue.

Expected behavior

After an unexpected exit (non-zero code, or signal), the extension should attempt to reconnect automatically using exponential backoff (e.g. 2s, 4s, 8s, max 30s), up to a configurable number of attempts. If reconnection succeeds, it should restore the current session by calling loadHistory(). If all attempts fail, it should surface the error clearly and stop retrying.

Deliberate reloads triggered by the user (provider switch, settings toggle) should bypass the reconnect logic.

Suggested fix

Add a reconnect(attempt: number) method to ChatController that is called from the exit handler only when code !== 0 and !this.disposing. Back off with setTimeout(2000 * 2 ** attempt) up to a maximum retry count (e.g. 5).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions