Repository navigation
fix(herdr): exec the server launch so no forked shell waits on it - #1
Merged
Merged
Conversation
Backgrounding the long-lived `herdr server` launch through fm_backend_herdr_cli forked a shell that then did nothing but wait on the server, so every session carried a stray `bash` as the server's parent for the server's whole lifetime. Route that launch through the new fm_backend_herdr_server_exec, which exec's the server in the forked child so nothing is left behind, and drop the fm_backend_herdr_cli comment that called the old shape an exec when it was not one. The wrapper held no caller file descriptor: bash assigns a non-interactive asynchronous command's stdin from /dev/null, and the caller already redirects stdout/stderr. This is process hygiene, not the channel-leak the discarded comment claimed. Pin the shape in tests/fm-backend-herdr.test.sh with a parent-observing herdr stub: after fm_backend_herdr_server_ensure returns, the server must not be left parented to a forked shell. The case fails on the old launch shape and passes on the new one.
The document step's commit committed an unreferenced three-line stub named fake_server at the repository root; it was a leftover from the pipeline agent's own parent-process probing and nothing in the tree refers to it. Remove it, keeping that commit's docs/herdr-backend.md correction.
onyx-space
force-pushed
the
fm/herdr-server-exec
branch
2 times, most recently
from
September 10, 2026 10:08
f35de9f to
9dff146
Compare
This was referenced Sep 11, 2026
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
队长原话:「先评估,确定就提 pr」——指的是他工作区里那份未提交的 herdr 改动。
背景:那份改动是本 home 工作区当时唯一的未提交改动(文件时间 2026-09-10 14:50,早于本次会话)。我按队长先前的指示把它原样保存在本地分支
fm/herdr-server-exec-preserve(commit 1f36d88,未推送),才把 main 快进到上游最新(b1ad702)。现在队长要求:评估后确认就提 PR。firstmate 的评估结论(作为本次 PR 的依据,不代替你在管线里的验证):
fm_backend_herdr_server_ensure启动 server 那一行,从fm_backend_herdr_cli "$session" server >/dev/null 2>&1 &改成新函数fm_backend_herdr_server_exec "$session" >/dev/null 2>&1 &(新函数 exec herdr,不再留一个等待 server 的 bash 包裹 shell)。其余两处是新函数本体与注释订正。bin/fm-remote-herdr-guard.sh:69正是exec "$HERDR_BIN" server --session "$SESSION",bin/fm-remote-herdr-owner-lib.sh还专门处理 server 的 “birth” 归属。这份改动把server_ensure的启动形态对齐到同一形态。What Changed
fm_backend_herdr_server_ensure现在通过新的fm_backend_herdr_server_exec启动命名服务器,该函数直接execherdr,因此在服务器生命周期内不再有 fork 出来的bashshell 作为其父进程等待它。bin/backends/herdr.sh中添加了fm_backend_herdr_server_exec,镜像fm_backend_herdr_cli的客户端选择逻辑,使同一 session 继续使用已选择的客户端。herdr-backend.md的传输描述,并添加了一个 regression test,断言在server_ensure之后服务器不再以 fork 出来的 shell 作为父进程。Risk Assessment
✅ Low: The change is a single, well-bounded behavior change with a matching behavioral test and an accurate, intent-satisfying comment correction; no correctness, conformance, or reachable-failure issues were found.
Testing
围绕用户意图(验证 exec 启动改动的真实机制、以及更正后注释是否准确)做了聚焦验证:运行了新增回归测试与相邻的 scrubs 测试(均通过),并把 herdr.sh 临时回退到 base 后确认新测试会失败(证明它是真回归测试);再用 fake herdr 做进程树对比和 fstat/stdin 实证,确认『遗留 bash 父进程(进程卫生)』才是真实机制、且后台 shell 三个 fd 均为 /dev/null(即确非 fd/ssh 通道问题)。结论:改动正确、注释准确,无需改写,无发现项。
Evidence: 进程树对比(旧 vs 新启动形态)
Source: 进程树对比(旧 vs 新启动形态)
OLD (fm_backend_herdr_cli ... server &): server parent_comm=bash → 遗留 fork shell 空等 server NEW (fm_backend_herdr_server_exec ... &): server parent=1 (/sbin/launchd) → 无遗留 bashEvidence: fd 实证(后台启动 shell 的 0/1/2 均为 /dev/null)
Source: fd 实证(后台启动 shell 的 0/1/2 均为 /dev/null)
fd0=CHR ino=336 /dev/null fd1=CHR ino=336 /dev/null fd2=CHR ino=336 /dev/nullEvidence: stdin 重定向实证(非交互异步命令 stdin 被 bash 置为 /dev/null)
Source: stdin 重定向实证(非交互异步命令 stdin 被 bash 置为 /dev/null)
async cmd fd0: CHR ino=336 /dev/nullPipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-backend-herdr.test.sh (focused) → test_server_ensure_leaves_no_forked_shell_waiting_on_the_server — 通过bash tests/fm-backend-herdr.test.sh (focused) → test_server_ensure_scrubs_home_and_harness_identity — 通过回归验证:将 bin/backends/herdr.sh 临时回退到 base b1ad702 后重跑新测试 → 失败(『left parented to a forked shell (bash)』),随后恢复目标版本并确认工作树干净手动进程树对比(旧 vs 新启动形态,fake herdr server 记录 PPID)→ 旧:parent_comm=bash(遗留 fork shell);新:parent=1(重父到 init/launchd)fd 实证:后台启动 subshell 内 fstat(0/1/2) → 三者均为 CHR ino=336 /dev/null(无 caller 描述符)stdin 重定向实证:父进程 stdin 为真实管道时,非交互异步命令 fd0 仍为 /dev/null(印证『bash 分配非交互异步命令 stdin 自 /dev/null』)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.