You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Server crashes: TypeError in closeAttachment when attachment.pty is undefined #154
The server crashed with an unhandled TypeError in closeAttachment and did not come back up. The phone PWA was stuck on "reconnecting" until I restarted it by hand with herdr plugin action invoke devswha.herdr-web-ui.start.
herdr-web-ui listening on http://127.0.0.1:7317
Managed updates: automatic checks, install from Settings
374 | const retired = attachment.pty.exited.finally(() => {
^
TypeError: undefined is not an object (evaluating 'attachment.pty.exited')
at closeAttachment (server/index.ts:374:32)
at detach (server/index.ts:505:40)
at close (server/index.ts:1217:52)
Bun v1.4.2 (Linux x64)
Bridge exited unexpectedly (1).
Likely cause
In the attach path, the attachment is put in attachments with pty: undefined as unknown as PtySession (around line 422). attachment.pty = start() only runs after that (line 494). If new PtySession(...) throws, the placeholder stays in the map with no pty. It could also stay there if the constructor calls onExit synchronously. When the client later disconnects, close → detach → closeAttachment dereferences attachment.pty.exited and takes the whole process down.
I haven't confirmed which of those two paths happened. Around the time of the crash, a pane was opened and then closed in herdr (Ctrl+b x) while the phone was connected.
Suggested fix
Guard in closeAttachment: when attachment.pty is unset, delete the entry and return. Don't touch .exited or .kill().
Optionally, wrap start() in the attach path so that a failed spawn removes the placeholder attachment and reports pty-exit to its clients.
A crash in the bridge could also make the supervisor restart it, rather than leaving the server down.
Environment
herdr-web-ui 0.3.31 (installed via install.sh as a herdr plugin, checkout 7a45468)
herdr 0.9.1, Bun 1.4.2, Node 24
Linux Mint 22.3 (x64), served via tailscale serve, used from Chrome PWA on Android (Pixel 8a)
Thanks for the detailed report. I reproduced it, and the fix is in #155.
What happened. It's your first path. new PtySession() threw synchronously, because Bun.spawn throws when it can't start the node sidecar (node not on PATH, or fd/process limits). That first attach got an in-band command_failed, but the placeholder record stayed in attachments. The next attach to the same pane, your phone reconnecting, joined that dead record and got nothing. When it disconnected, closeAttachment dereferenced the missing pty and the process died. The supervisor then exits along with the bridge, so it stayed down. The second theory, a synchronous onExit, can't happen: onExit always runs asynchronously.
Closing a pane with Ctrl+b x doesn't trigger this by itself. A missing pane is rejected with pane_not_found before the placeholder is created. So what failed on your machine was the sidecar spawn. The failure was never written to the server log, which is why yours shows no cause.
A failed spawn removes the placeholder and reports the error in-band. The pane can then be opened again.
The same failure during the "read in progress" attach retry no longer throws uncaught. It ends that pane's terminal with pty-exit and leaves the server running.
Spawn failures are written to the server log (terminal attach for pane <id> failed to start: ...). If this happens again, server.log will say why, for example if node went missing from the plugin's PATH.
There are contract tests for both paths. They fail on main with the exact TypeError from your log and pass with the fix.
I didn't add a guard in closeAttachment. With the placeholder removed at its source, a record without a pty can't exist any more. Automatic bridge restart from the supervisor is a separate design question and isn't included here.
Activity
devswha commentedon Sep 29, 2026
Thanks for the detailed report. I reproduced it, and the fix is in #155.
What happened. It's your first path.
new PtySession()threw synchronously, becauseBun.spawnthrows when it can't start thenodesidecar (nodenot on PATH, or fd/process limits). That first attach got an in-bandcommand_failed, but the placeholder record stayed inattachments. The next attach to the same pane, your phone reconnecting, joined that dead record and got nothing. When it disconnected,closeAttachmentdereferenced the missing pty and the process died. The supervisor then exits along with the bridge, so it stayed down. The second theory, a synchronousonExit, can't happen:onExitalways runs asynchronously.Closing a pane with
Ctrl+b xdoesn't trigger this by itself. A missing pane is rejected withpane_not_foundbefore the placeholder is created. So what failed on your machine was the sidecar spawn. The failure was never written to the server log, which is why yours shows no cause.The fix (#155):
pty-exitand leaves the server running.terminal attach for pane <id> failed to start: ...). If this happens again,server.logwill say why, for example ifnodewent missing from the plugin's PATH.There are contract tests for both paths. They fail on
mainwith the exact TypeError from your log and pass with the fix.I didn't add a guard in
closeAttachment. With the placeholder removed at its source, a record without a pty can't exist any more. Automatic bridge restart from the supervisor is a separate design question and isn't included here.chore(release): prepare v0.3.32 (#160)
chore(release): prepare v0.3.39 (#246)
fix(server): drop the placeholder attachment when the pty cannot spawn (
fix(terminal): report a herdr the server cannot start instead of wait…
test(output): make breakPath() fail the spawn on both PTY hosts (#2364)