html: auto-reconnect on socket close with exponential backoff - #1536
Open
hndrewaall wants to merge 1 commit into
Open
html: auto-reconnect on socket close with exponential backoff#1536hndrewaall wants to merge 1 commit into
hndrewaall wants to merge 1 commit into
Conversation
…ff (#1) * feat: autoreconnect with visibilitychange handler + exponential backoff The stock client only reconnects immediately on non-1000 close codes and disables reconnect entirely on the websocket `error` event. That makes the terminal die on a single network blip (laptop sleep/wake, VPN flap, brief WiFi drop) -- the user comes back to a dead overlay and has to manually reload the page. This patch keeps the existing `reconnect` and `closeOnDisconnect` client-settings semantics but changes the reconnect strategy: - Always schedule a reconnect on `close` when `reconnect` is enabled, including close code 1000. - Don't disable reconnect on `error` -- the browser fires `close` after `error` anyway, so onSocketClose handles it. - Exponential backoff: 1s -> 2s -> 4s -> ... capped at 30s. - `visibilitychange` listener: when the tab becomes visible AND the socket is CLOSED/CLOSING, cancel any pending backoff timer and reconnect immediately. This covers the laptop-wake / VPN-flap case where the user returns to a dead session and would otherwise wait out the backoff. - A successful (re)open resets the backoff delay. - `closeOnDisconnect` and the !reconnect ("Press Enter to Reconnect") paths are unchanged. Caveats: - In-place reconnect resets terminal scrollback (same as the existing reconnect-overlay path). - Typed-but-unsent input is lost on disconnect, matching existing behaviour (sendData early-returns when the socket isn't OPEN). Co-Authored-By: Claude <noreply@anthropic.com> * style: register visibilitychange listener via addEventListener helper; clear reconnect timer on dispose --------- Co-authored-by: Claude <noreply@anthropic.com>
Merged
4 tasks
hndrewaall
added a commit
to hndrewaall/claude-watch
that referenced
this pull request
May 13, 2026
The ttyd web console previously consumed the upstream tsl0922/ttyd:1.7.7 image's embedded HTML directly. That HTML's WebSocket-client logic only reconnects on non-1000 close codes and bails entirely on a single socket error, so laptop sleep / VPN flap / brief network drops stick the in-browser terminal at "Press Enter to Reconnect" until the user notices. Switch the frontend build to clone our ttyd fork (https://github.com/hndrewaall/ttyd) and run yarn build + gulp inline against it, producing a single self-contained HTML file that ships an exponential-backoff auto-reconnect plus a visibilitychange handler (cancels the backoff + reconnects immediately when the tab becomes visible). The autodark CSS + theme-swap injection still runs on top of the fork-built HTML via inject-autodark.py. The upstream C binary is unchanged; we still copy it out of tsl0922/ttyd:1.7.7. Once the upstream PR (tsl0922/ttyd#1536) merges, the TTYD_FORK_REF pin can move back to tsl0922/ttyd:main (or a future tag). Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
hndrewaall
added a commit
to hndrewaall/claude-watch
that referenced
this pull request
Aug 11, 2026
The ttyd web console previously consumed the upstream tsl0922/ttyd:1.7.7 image's embedded HTML directly. That HTML's WebSocket-client logic only reconnects on non-1000 close codes and bails entirely on a single socket error, so laptop sleep / VPN flap / brief network drops stick the in-browser terminal at "Press Enter to Reconnect" until the user notices. Switch the frontend build to clone our ttyd fork (https://github.com/hndrewaall/ttyd) and run yarn build + gulp inline against it, producing a single self-contained HTML file that ships an exponential-backoff auto-reconnect plus a visibilitychange handler (cancels the backoff + reconnects immediately when the tab becomes visible). The autodark CSS + theme-swap injection still runs on top of the fork-built HTML via inject-autodark.py. The upstream C binary is unchanged; we still copy it out of tsl0922/ttyd:1.7.7. Once the upstream PR (tsl0922/ttyd#1536) merges, the TTYD_FORK_REF pin can move back to tsl0922/ttyd:main (or a future tag). Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
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.
Closes #808, #1134, #1397; helps #911, #1016, #1156.
Currently the web client only reconnects on non-1000 close codes
and disables reconnect after a single socket
error, so anylaptop sleep / VPN flap / brief network drop sticks the terminal
at "Press Enter to Reconnect" until the user notices.
This change:
while
reconnectis on, not just non-1000 codeserrorevents (theclosethat always follows drives the retry)
visibilitychangelistener that cancels the backoffand reconnects immediately when the tab becomes visible
closeOnDisconnect=trueanddisableReconnect=truepaths arepreserved (the original window.close() / Press-Enter branches
still fire when those options are set).