Skip to content

vscode: terminal reconnect budget exhausts during laptop sleep — permanent 'unable to reconnect' banner while Tower is healthy #1681

Closed

Description

@amrmelsayed

Symptom

After a laptop sleep, VS Code terminal tabs show [Codev: Connection lost. unable to reconnect after 6 attempts. Click here to reconnect] and stay dead until manually reconnected — while Tower is perfectly healthy.

Field specimen 2026-09-14 ~9:41 PM: tab died with the 6/6 banner; diagnosis showed Tower up continuously for 5 days (uptime 433,612s at check, healthy, 39 terminals). The disconnect was purely client-side: the machine slept, and the extension's reconnect attempts fired against a suspended network stack — each fails instantly, so the whole 6×30s budget burns before full wake. The agent itself (detached shellper) was unaffected throughout; only the view died.

Defect

The reconnect policy is a fixed, exhaustible budget with no awareness of why attempts fail. Sleep/wake — the single most common disconnect cause on a laptop — reliably consumes it, converting a transient OS event into a permanent-looking failure banner across every open terminal tab.

Fix shape (lane's judgment)

  • Reset the retry budget on wake signals: window focus, online network event, or visibility change — any of these arriving should re-arm a parked client.
  • And/or replace the hard 6-attempt death with capped exponential backoff (e.g. 30s → 5m cap) that never fully terminates while the tab is visible; the "Click here" affordance stays as the immediate manual path.
  • Cheap discriminator worth adding: on final failure, probe /health once and word the banner honestly — "Tower unreachable" vs "reconnect failed (Tower is up — click to retry)". Tonight's specimen shows the second case wearing the first case's message.

Related: #1052 (window-reactivation terminal corruption — same wake window, different layer); the #1047 resume machinery already makes reattach cheap, so aggressive auto-reconnect is safe.

Activity

  1. added
    area/terminal
    on Sep 14, 2026
  2. amrmelsayed commented on Sep 14, 2026

    @amrmelsayed
    CollaboratorAuthor

    History for the fix lane (traced via git -S MAX_RECONNECT_ATTEMPTS): this is long-standing designed behavior, not a regression. The finite budget shipped 2026-06-02 in PIR #936, which fixed the OPPOSITE defect - a tight retry loop with no backoff/no give-up spamming '[Connection lost, reconnecting...]' dozens of times per second, typically against a stale terminal id Tower no longer had. #939 added the manual reconnect link for the parked state. The #936 threat model was 'session is gone, stop hammering' - correct for that case - and never covered 'session is fine, laptop slept', where a finite budget burns entirely inside the wake window. Constraint for this fix: keep #936's protections intact (the 4xx fast-give-up already discriminates Tower-says-no from network-says-nothing; wake-re-arm must not resurrect the stale-id spam loop). The synthesis: re-arm on wake/focus/online signals for network-class failures only, finite give-up stays for 4xx/session-gone.

  3. added
    area/vscode
    and removed
    area/terminal
    on Sep 14, 2026
  4. amrmelsayed commented on Sep 14, 2026

    @amrmelsayed
    CollaboratorAuthor

    On it! Working on a fix now.

  5. added 9 commits that reference this issue on Sep 15, 2026
    13126d3
    deee898
    60578ca
    646c3fe
    f921484
    0e70d5c
    1cbb6c0
    be1b852
    79a6c29
  6. added 3 commits that reference this issue on Sep 16, 2026
    58abd2b
    8746445
    964d777
  7. amrmelsayed commented on Sep 16, 2026

    @amrmelsayed
    CollaboratorAuthor

    Outcome

    Shipped in PR #1682, merged to main 2026-09-16T23:57Z as 58abd2b. Rides the next VS Code extension release, not the npm 3.3.4 release.

    What changed (apps/vscode/src/terminal-adapter.ts, terminal-manager.ts, extension.ts)

    • A window refocus, the extension host's only wake signal, re-arms every managed terminal's reconnect budget. A tab that gave up for a transient reason reconnects on its own; an already-connected tab and a terminal-adapter: WebSocket close-handler spams 'Connection lost' in a tight loop with no backoff, no give-up, no actual reconnect #936 permanent give-up ("session no longer exists on Tower") are no-ops, so the pre-June retry-spam loop cannot return.
    • Before wording the exhausted-budget banner, the adapter probes Tower's health once (via the sdk's existing getHealth), so the banner distinguishes "Tower unreachable" from "reconnect failed, Tower is up, click to retry". A generation token stops a stale probe from overwriting a banner after a successful reconnect.
    • Found in human testing at the gate: the old banner left a remnant on the composer line after automatic recovery. It is now wiped in place.

    Process

    • BUGFIX lane; pr gate approved by the owner 2026-09-16T23:52Z on head 79a6c29; merged by the main architect on the green post-gate head b2ad48f.
    • Three consultation rounds: round 1 raised a stale-probe race and test coverage (fixed); round 3, after the recovery-render fix, was two approvals and one comment on the throttle follow-up.
    • CI green throughout. A physical sleep-and-wake is the real end-to-end confirmation and cannot run in CI.

    Follow-ups, not filed yet

    • No throttle on the re-arm when the window is refocused repeatedly.
    • Refocus is the only wake signal available; there is no online or visibility event in the extension host.
    • The web dashboard's terminal component may have the same sleep gap; unaudited.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/vscode

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions