Repository navigation
Conversation
MLA82
force-pushed
the
fm/werft-herdr-detached-session-public
branch
from
September 20, 2026 17:18
812bfe7 to
992e082
Compare
Closed
2 of 3 tasks
MLA82
added a commit
to MLA82/firstmate
that referenced
this pull request
Sep 28, 2026
…guid#4366 and PR kunchenguid#4683 - tests/fm-control-relaunch.test.sh: read the whole recorded launch command instead of the retired inline 'encode launch-brief' grep shape (needed by PR kunchenguid#5288's own new test). - tests/fm-backend-herdr-launcher-workspace-e2e.test.sh: pass FM_HOME to the teardown call explicitly, kept as a precaution. Dropped: the 10s->20s Herdr server poll-budget widening in bin/backends/herdr.sh. It was PR kunchenguid#4683's own fix for its own setsid-wrapped server launch; without kunchenguid#4683, bin/backends/herdr.sh reverts to the original, unmodified 10s poll and needs no widening.
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.
Intent
A herdr server started from an interactive shell inherits that shell's POSIX session. When the
shell goes away the server is no longer a session leader, and from herdr 0.9.1 on a remote client
refuses such a host for saved machines with "remote server is not ready for saved machines",
because
capabilities.detached_server_daemonis false.Today a long-running server only satisfies that requirement by accident, when it happens to have
been started in a way that left it leading its own session. After a reboot, an unattended start
brings the server back without that property, and saved machines stop working until somebody
restarts it by hand.
This makes the server start as its own session leader, so the capability holds after an
unattended restart rather than depending on how it was launched.
What Changed
fm_backend_herdr_server_ensurenow launches the named Herdr server throughsetsidwhen that utility is available, so the server leads its own POSIX session and Herdr advertisescapabilities.detached_server_daemon(required before it accepts saved machines). Becausesetsidneeds an executable rather than thefm_backend_herdr_clishell helper, the detached launch resolves the session-selected client binary and reproduces the helper'sHERDR_SESSIONplus trailing--session <name>routing; hosts withoutsetsidkeep the previous backgrounded helper launch.docs/herdr-backend.mddocuments the detached launch as the one path that bypassesfm_backend_herdr_cli, why the session leadership matters, and the unchanged fallback.server_ensuretest's fake Herdr client records its ownsid/pid, and the existing environment-scrubbing test asserts they match whensetsidis present, while still checking the scrubbed environment and session routing.Risk Assessment
✅ Low: The change is a narrow, guarded launch-path fix that preserves existing behavior on hosts without setsid, routes through the single shared server-start boundary used by every Linux caller, and is covered by a behavioral test asserting the launched process leads its own POSIX session; the only finding is a mechanical duplication of an existing selection rule.
Testing
Drove the real product: on this host (herdr 0.9.1, setsid present)
fm_backend_herdr_server_ensurewas run from an isolated XDG_CONFIG_HOME against a private fm-lab session, and the resulting server leads its own POSIX session and reports capabilities.detached_server_daemon=true; the same driver against the base commit's herdr.sh on the same host reproduces the reported failure (sid!=pid, capability false), so the regression fails before and passes after. Adversarial variants all passed live: launcher already a session/process-group leader still yields a session-leading server, a PATH without setsid(1) still starts a working server via the retained fallback, a session-selected client binary is used even with noherdron PATH, and re-ensuring reuses the same server PID without restart. The environment-scrub/session-routing behaviour was only exercised by the unit suite, not driven against the live product, so it is reported as untested. The existing adapter unit suite was run targeted and passes in full (207 checks) once the shell locale is pinned to C — an unrelated de_DE decimal-comma artifact made one wait_for_working sleep-timing assertion fail in my ambient locale, untouched by this change. The doctor/systemd reboot path could not be driven because it hardcodes the live fm-remote session the intent forbids touching. No UI surface exists for this change, so evidence is CLI transcripts of the live server capability state.setsid: server pid=349173 sid=349173, detached_server_daemon=trueherdrexists on PATHLC_ALL=C bash tests/fm-backend-herdr.test.sh, test_server_ensure_scrubs_home_and_harness_identity), which stubs the herdr client; the prior payload records no live…Evidence: Live herdr 0.9.1 capability transcript (before fix / after fix / session-leader launcher)
Source: Live herdr 0.9.1 capability transcript (before fix / after fix / session-leader launcher)
--- BEFORE the fix (base 795e5e4) --- server_ensure: ok status: {"running":true,"version":"0.9.1","capabilities":{"detached_server_daemon":false,...}} server pid=346841 sid=346794 --- AFTER the fix (this branch) --- server_ensure: ok status: {"running":true,"version":"0.9.1","capabilities":{"detached_server_daemon":true,...}} server pid=348323 sid=348323 --- launcher already a session/process-group leader --- server pid=349173 sid=349173 detached_server_daemon=trueEvidence: Adversarial variants: no setsid(1) on PATH, and session-selected client with no herdr on PATH
Source: Adversarial variants: no setsid(1) on PATH, and session-selected client with no herdr on PATH
--- host WITHOUT setsid(1) --- setsid on PATH: no server_ensure: ok status: running=true, detached_server_daemon=false --- session-selected client, no 'herdr' on PATH --- selected client: ~/.local/bin/herdr server_ensure: ok status: running=true, detached_server_daemon=true server pid=353748 sid=353748Evidence: Idempotence: re-ensure reuses the running detached server
Source: Idempotence: re-ensure reuses the running detached server
first ensure: ok second ensure: ok server pids after first ensure: 362518 server pids after second ensure: 362518 idempotent: same single server reused, no restart capabilities: truePipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/backends/herdr.sh:1669- bin/backends/herdr.sh:1669-1671 re-implements the session-scoped client-binary rule that fm_backend_herdr_cli already defines once at bin/backends/herdr.sh:388-392 (client_bin=herdr, overridden by fm_backend_herdr_bin only when FM_BACKEND_HERDR_CLIENT_SESSION equals the session). The two copies agree today, but the setsid branch bypasses fm_backend_herdr_cli entirely, so a later change to client selection (for example a new selection input alongside the existing protocol_mismatch re-selection at herdr.sh:404-415) would apply only to the non-setsid fallback, and the server would launch with a different client than every other call for that session. Smallest mechanical remedy: extract the rule into a helper (e.g. fm_backend_herdr_client_bin <session>) and call it from both sites, keeping behavior identical.✅ **Test** - passed
✅ No issues found.
setsid: server pid=349173 sid=349173, detached_server_daemon=trueherdrexists on PATHLC_ALL=C bash tests/fm-backend-herdr.test.sh, test_server_ensure_scrubs_home_and_harness_identity), which stubs the herdr client; the prior payload records no live…bash /tmp/fm-live-real.sh <worktree> fixed— real herdr 0.9.1 server started throughfm_backend_herdr_server_ensurein an isolated XDG_CONFIG_HOME/private fm-lab session; asserted sid==pid and.server.capabilities.detached_server_daemonsame live driver againstgit show 795e5e4:bin/backends/herdr.sh(before-fix baseline) — reproduces sid!=pid and detached_server_daemon=falsesetsid /tmp/fm-live-real.sh <worktree> pgleader— launcher already a session/process-group leaderlive driver variant with a restricted PATH that omitssetsid(1)— fallback launch still brings the server uplive driver variant with noherdron PATH and FM_BACKEND_HERDR_CLIENT_SESSION/FM_BACKEND_HERDR_BIN set to the absolute clientlive driver callingfm_backend_herdr_server_ensuretwice against the same running server (idempotence, same PID)LC_ALL=C bash tests/fm-backend-herdr.test.sh— 207 checks pass, includingtest_server_ensure_scrubs_home_and_harness_identitywith its new sid==pid assertionherdr session list --json+ps -o pid=,sid= -p 2790299before/after — confirmed the pre-existing fm-remote server untouched and no leftover test servers✅ **Document** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.