Repository navigation
Reconnect the terminal after sleep, a network drop or an HA restart (2.5.3) - #84
Conversation
17b0f53 to
8301c64
Compare
…2.5.3) ttyd 1.7.7 retries a dropped connection once and then stops at "Press ⏎ to Reconnect". After sleep that try is refused (network not back, or an expired ingress session answered with 401 until HA's page creates a new one, up to a minute later), and during an HA restart the add-on answers 502. While ttyd shows that message, the panel checks /health after 1, 2, 5 and then every 10 s, and at once when the browser is back online or the tab is shown. When the add-on answers, it reloads the terminal frame, which reattaches to the same tmux session. So when Claude restarts Home Assistant itself (e.g. ha core restart after a config change), the terminal comes back by itself with Claude's session where it left off. Also remove --client-option reconnect=5, which ttyd 1.7.7 ignores. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018rxd5pKHfU3wFULG6yLDE6
8301c64 to
aca83b5
Compare
|
Thanks @nsleigh for this fix and for testing the sleep, network-drop and Home Assistant restart scenarios! The automatic recovery is a useful improvement. I added commit 43bb363 to cover two additional edge cases: health requests now time out and abort after 10 seconds, and recovery keeps retrying if the iframe navigation fails after a successful health check. Three new regression tests cover stalled requests, error pages and navigation that never finishes. Validation passed: all regression suites in a Linux container (including the image-service integration tests), metadata checks, ShellCheck, JavaScript syntax checks, and Chromium/WebKit browser tests. The reconnect suite now has 10 passing tests. The merge is currently blocked by the required GitHub Actions checks: GitHub rejects workflow dispatch with “Actions has been disabled for this repository”, despite the Actions settings reporting enabled. The new commit has no CI checks yet. Auto-merge is also disabled. Once Actions can run again, the required checks can validate the commit and unblock merging. |
|
Thanks for adding this. Both are real gaps: a hung I've pulled 43bb363 and the reconnect suite (10 tests) and the full One small thing, not blocking: if |
Problem
After the computer sleeps or the network drops, the terminal often stops at
"Press ⏎ to Reconnect", and pressing Enter fails again. Only leaving the
dashboard and coming back works.
ttyd 1.7.7 retries a dropped connection once, straight away, then gives up.
That one try usually comes too early:
request from the panel gets a 401 (the Supervisor log shows "No valid
ingress session") until Home Assistant's page creates a new session.
Fix
New
image-service/public/terminal-reconnect.js, installed byindex.html:/healthafter 1, 2, 5, thenevery 10 s. It also checks at once when the browser comes back online or
the tab is shown again.
/healthanswers, it reloads the terminal frame, which reattaches tothe same tmux session, so nothing running in it is lost.
[terminal-reconnect].Also removes
--client-option reconnect=5fromrun.sh. ttyd 1.7.7 hasno
reconnectoption (onlydisableReconnect), so it did nothing.Home Assistant restarts run by Claude
This helps most when Claude restarts Home Assistant itself, for example
after editing the configuration it checks it and runs
ha core restart.Before, the terminal dropped with "Press ⏎ to Reconnect" and you had to press
Enter (or reopen the panel) once Home Assistant was back, then see what
Claude had done meanwhile. Now the terminal comes back by itself as soon as
Home Assistant is up, showing Claude's session where it left off, so you can
watch it carry on and check the result. The same applies to a restart
started from Settings while the terminal is open.
Tests
tests/test-terminal-reconnect.js(7 tests, added torun-tests.sh) covers:spotting the overlay, the retry delays, checking at once on online or a
shown tab, no reload if Enter already reconnected, and watching the new
document after a reload.
Tested
On Home Assistant OS, through ingress:
then reloaded by itself. The released version needed Enter.
/healthgot 401 until HomeAssistant's page created a new session, then the terminal reloaded by
itself. This took between about 8 and 30 s: Home Assistant's page checks
its session once a minute (
ha-panel-app.ts), so the wait depends onwhen that check falls after waking.
new code doesn't act.
🤖 Generated with Claude Code
https://claude.ai/code/session_018rxd5pKHfU3wFULG6yLDE6