#4806·herdr

machine reconnect: managed control socket refuses the session, probe falls back to BatchMode=yes and spends an MFA passcode (follow-up to #4490)

Author: nickboyCreated Sep 30, 2026Updated Sep 30, 2026
Labelsmaintainer-neededp2macosremotetriaged

Summary

PR #4490 reuses the authenticated managed SSH transport across setup, saved machines and API requests, fixing the case #4276 described: an endpoint-capability probe opening a separate BatchMode=yes bridge that cannot answer an MFA prompt.

There is an unhandled branch. When the managed control socket exists but refuses the session, reuse fails, OpenSSH disables multiplexing, and the probe falls back to exactly the BatchMode=yes bridge #4276 identified as the original defect. MFA has already succeeded by that point, so the passcode is spent and the authenticated connection is discarded.

Both halves of #4490's fix live in src/remote/attach.rs and both assume the managed ControlPath is either free or reusable:

  • ssh_authentication_command() builds ssh -o BatchMode=no -o NumberOfPasswordPrompts=3 -T <target> exit. BatchMode=no is deliberate and correct, and MFA does succeed. But the command's only product is the master it leaves behind on the managed ControlPath — it runs exit and nothing else. When that path is already held by a master that refuses sessions, OpenSSH prints already exists, disabling multiplexing, the exit runs over a throwaway direct connection, and no master is installed. Nothing checks for this, so reconnect reports the authentication it performed rather than the master it failed to leave.
  • RemoteSsh::new_noninteractive() now derives manage from multiplexing && config.remote.manage_ssh_config and goes through the same managed config. It therefore meets the same occupied socket, is refused, and falls back — this time with BatchMode=yes, which is the fallback #4276 was written to eliminate.

So the two paths fail in sequence and the second one reports the error, which is why the visible symptom (remote platform detection failed) names the probe rather than the recovery step that actually went wrong.

Versions

client:        0.9.3
local server:  0.9.3
remote server: 0.9.3
client OS:     macOS 15 (arm64)
server OS:     Linux x86_64
sshd:          AuthenticationMethods publickey,keyboard-interactive

(Quote herdr status, not herdr --version — they disagree while a server predates its binary, which herdr status reports as server_binary_stale.)

Reproduction

With a saved machine whose managed control socket is already present:

bash
$ herdr machine reconnect devvm
mux_client_request_session: session request failed: Session open refused by peer
(user@host) Duo two-factor login for user
Enter a passcode:
Passcode: ********
Success. Logging you in...
ControlSocket /tmp/hssh-501/<hash> already exists, disabling multiplexing
Error: remote platform detection failed: mux_client_request_session: session
request failed: Session open refused by peer ... Permission denied (keyboard-interactive).

Line 1: reuse attempted, refused. Line 5: MFA succeeded. Line 6: OpenSSH cannot install the new connection as master. Line 7: the probe (remote platform detection) falls back to the BatchMode bridge, which by construction cannot answer the second factor.

herdr machine status fails the same way permanently, because it opens the same extra session.

It is not sshd's MaxSessions

Counted rather than assumed. Twelve sessions opened one at a time against the blocking master:

Master running (pid=45686)
[1]  refused by peer
[2..12] refused by peer

Refused 12 for 12 starting with the first. MaxSessions defaults to 10, so a server-side cap would have let roughly nine through. A master created by hand with ssh -M -N -f against the same host accepts concurrent sessions normally.

Workaround

Close the blocking master first; reconnect then succeeds in about nine seconds.

bash
shopt -s nullglob
for s in "/tmp/hssh-$(id -u)"/*; do ssh -S "$s" -O exit "$HOST" 2>/dev/null; done
rm -f "/tmp/hssh-$(id -u)"/*
herdr machine reconnect "$LABEL"

Suggested direction

Three options, roughly in order of how cheap they look from outside:

  1. Verify the product, not the act. After ssh_authentication_command() returns success, check that the managed ControlPath now answers (ssh -O check). If it does not, the authentication bought nothing and the user should be told that, not handed a later probe failure.
  2. Treat Session open refused by peer on the managed socket as recoverable. Retire the refusing master (-O exit, then unlink) and let the freshly authenticated connection take the path. This is exactly what the workaround above does by hand, and it succeeds in about nine seconds every time.
  3. Refuse the BatchMode=yes fallback once interactive auth has already run. That fallback cannot answer a second factor by construction, so in an MFA environment reaching it is always a failure. Failing loudly beats spending a passcode silently.

Option 1 alone would have turned a day of misdiagnosis into one clear error message, even without fixing the underlying refusal.

Questions

  1. Does this reproduce without mandatory two-factor auth? If the BatchMode fallback can authenticate unaided, the refusal is invisible and only affects MFA users.
  2. Is machine status ever reachable for a saved machine, given it opens the extra session that gets refused?
  3. Since 0.9.2 open clients recheck failed machines every 30 s. Are those rechecks what occupies the master? #4721 reports a 30 s reconnect delay after a lid open, which may be the same loop.

Related

  • #4490 (merged 2026-09-22) — the transport-reuse fix this follows up
  • #4276 (closed, superseded) — Root Cause describes this exact BatchMode-probe failure at machine add
  • #3763 (closed) — the MFA machine add bug behind both
  • #4582 — saved machine stuck in Attention after the SSH agent refuses to sign during reconnect; same stuck-state shape
  • #4721 — saved machine takes 30 s+ to reconnect after a lid open
  • #4350 — machine add fails when the user's ssh config declares RemoteForward/ExitOnForwardFailure; same root shape of herdr's ssh invocation colliding with user ssh config
  • #4496 — Tailscale login URL hidden, stuck Reconnecting

Caveat

The exact OpenSSH interaction is inferred from its stderr (already exists, disabling multiplexing) plus the observed outcome, not from instrumenting herdr. If the master should in fact have been replaced there, that reconstruction is the part to doubt first. The code claims come from reading the merged #4490 diff.