Skip to content

fix(spawn): refuse herdr task ids over the 32-char agent-name cap - #8231

Open
LorenzoMinghini wants to merge 3 commits into
kunchenguid:mainfrom
LorenzoMinghini:fm/herdr-name-cap-guard-upstream
Open

LorenzoMinghini wants to merge 3 commits into
kunchenguid:mainfrom
LorenzoMinghini:fm/herdr-name-cap-guard-upstream

Conversation

@LorenzoMinghini

@LorenzoMinghini LorenzoMinghini commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Re-raise the Herdr agent-name-cap guard against the upstream firstmate repository as a clean, minimal pull request.

Context: Herdr caps agent names at 32 characters. When a firstmate task id exceeds that cap, the relaunch path reports success while the replacement agent never boots - a silent death that firstmate has hit in practice. A guard for this was written and merged on our fork (fork PR #1, "fm-spawn/fm-control: refuse task ids over 32 chars on herdr backend (silent relaunch death)"), but that pull request carries 434 files of unrelated drift, because the fork's main is an upstream mirror taken at a different commit; the fork also force-wipes fork-only commits, so nothing that lives only on the fork is a durable home. Upstream main today has no such guard in bin/fm-spawn.sh or bin/fm-control.sh and no tests/fm-spawn-herdr-name-cap.test.sh.

The captain ruled on 2026-11-06 to re-raise it upstream cleanly, and to keep the pull request free of everything except the guard itself.

Acceptance: one upstream pull request that changes only the guard and its test, ported onto current upstream main, with the guard's behaviour proven by a test that fails without it.

What Changed

  • Add a Herdr agent-name-cap guard (FM_HERDR_AGENT_NAME_MAX=32 and fm_herdr_agent_name_within_cap) in bin/fm-control-lib.sh, and enforce it fail-closed on all three spawn/relaunch paths — bin/fm-spawn.sh fresh spawn and --relaunch, and bin/fm-control.sh relaunch — before any pane, tab, workspace, or old agent is created/stopped, so an over-cap task id is refused with an explicit error instead of reporting success while Herdr's agent start rejects the name (invalid_agent_name) and the replacement never boots.
  • Add tests/fm-spawn-herdr-name-cap.test.sh covering the exact 32/33-character boundary on the fresh-spawn, spawn --relaunch, and control-relaunch paths, including herdr-specific refusal messages, 32-char pass-through at the cap, and non-herdr (tmux) negative controls proving the cap does not apply elsewhere.
  • Register the new test in bin/fm-test-run.sh and docs/fm-test-portable-shards.md (provisional 25000 ms serial hint), and document the cap refusal in docs/herdr-backend.md.

Risk Assessment

✅ Low: The change is a small, well-bounded guard: one shared predicate, three fail-closed call sites placed before any side effect, plus behavioral boundary tests; prior findings were resolved correctly and no new defects were found.

Testing

Drove the change live end-to-end: real herdr 0.9.5 in an isolated fm-lab-capg2 lab session confirmed the 32/33 agent-name boundary (33-char agent start returns invalid_agent_name; 32-char boots a real agent), and the real fm-spawn.sh/fm-control.sh entry points were run in a disposable marked lab home where all three guard paths (fresh spawn, fm-spawn --relaunch, fm-control relaunch) refused a 33-char herdr task id with the cap message before any endpoint or old agent was touched, while 32-char and tmux cases passed through the cap. The focused 9-test suite passes with the guard and demonstrably fails without it in a guard-stripped disposable copy. Lab and disposable homes were torn down and the worktree left clean; all scenarios passed.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Oracle: real herdr agent start rejects a 33-char agent name with invalid_agent_name and accepts a 32-char name ✅ pass live herdr-name-cap-live-validation.md: herdr 0.9.5 returned invalid_agent_name rc=1 for the 33-char name; the 32-char name started a real pi agent rc=0 in the lab workspace pane w1:p1
Live fm-spawn fresh spawn with --backend herdr refuses a 33-char task id before any pane/tab/workspace is created ✅ pass live herdr-name-cap-live-validation.md scenario 1: refusal message names cap, id, and length; exit rc=1; lab tab count stayed 1 (no endpoint created)
Live fm-spawn fresh spawn lets a 32-char id pass the cap (inclusive boundary) and fails downstream instead ✅ pass live herdr-name-cap-live-validation.md scenario 2: failure is downstream (missing brief), no cap message
Live fm-spawn fresh spawn with --backend tmux does not apply the herdr-only cap to a 33-char id ✅ pass live herdr-name-cap-live-validation.md scenario 3: failure is downstream (missing brief), no cap message
Live fm-spawn --relaunch with a herdr meta refuses a 33-char task id before inspecting or touching the endpoint ✅ pass live herdr-name-cap-live-validation.md scenario 4: cap refusal with actionable hint, rc=1
Live fm-control relaunch refuses a 33-char herdr task id BEFORE stopping the old agent or mutating durable records ✅ pass live herdr-name-cap-live-validation.md scenario 5: refusal 'recreate the task under a shorter id before relaunching', rc=1; no herdr call was made (tab count unchanged)
Regression: tests/fm-spawn-herdr-name-cap.test.sh fails without the guard and passes with it (9/9 ok) ✅ pass live herdr-name-cap-guardless-regression.log: 'not ok - fresh herdr refusal must name the 32-char cap' with the downstream cd failure in the output
Evidence: Live validation report: real herdr 0.9.5 oracle + live guard scenarios on fm-lab-capg2

Source: Live validation report: real herdr 0.9.5 oracle + live guard scenarios on fm-lab-capg2

# Live validation: herdr agent-name-cap guard (fm/herdr-name-cap-guard-upstream)

Environment: real herdr 0.9.5 on this host; isolated lab session `fm-lab-capg2`
via bin/fm-herdr-lab.sh (prepare/provision/teardown contract), disposable marked
lab home via bin/fm-lab-home.sh. Teardown confirmed only the default session
remains. Worktree clean afterwards.

## Oracle: real herdr `agent start` cap (herdr 0.9.5)
- 33-char name -> `{"error":{"code":"invalid_agent_name","message":"agent name must
  start with a lowercase letter and contain only lowercase letters, digits, '-' or
  '_' (1-32 characters)"},"id":"cli:agent:start"}`, rc=1
- 32-char name -> agent started successfully (rc=0) in the lab workspace/pane.

## Guard scenarios driven live against bin/fm-spawn.sh / bin/fm-control.sh
1. fresh spawn, 33-char id, --backend herdr:
   `error: herdr caps agent names at 32 characters ... task id 'aaa...' (33 chars);
   pick a shorter id before spawning`, rc=1. No herdr tab/pane created (tab count
   stayed 1).
2. fresh spawn, 32-char id, --backend herdr: no cap refusal; fails downstream on
   missing brief (cap is inclusive at 32).
3. fresh spawn, 33-char id, --backend tmux: no cap refusal (guard is
   herdr-only); fails downstream on missing brief.
4. fm-spawn --relaunch, herdr meta, 33-char id: cap refusal before any endpoint
   inspection, rc=1.
5. fm-control relaunch, herdr meta, 33-char id: cap refusal BEFORE stopping the
   old agent or mutating durable records, rc=1.

## Regression proof (test fails without the guard)
Copied the worktree to a disposable temp dir, removed the guard blocks from
bin/fm-control-lib.sh, bin/fm-spawn.sh, bin/fm-control.sh (bash -n OK, no guard
refs remained), ran tests/fm-spawn-herdr-name-cap.test.sh there: first 33-char
assertion fails — without the guard the spawn falls past the cap check into an
unrelated downstream failure (`cd: .../projects/none: No such file or directory`),
the silent-stranding shape the guard exists to prevent. See
herdr-name-cap-guardless-regression.log.

## Focused suite with the guard (worktree as-is)
`bash tests/fm-spawn-herdr-name-cap.test.sh` -> 9/9 ok, FM_TEST_COMPLETE.
Evidence: Regression proof: focused suite run against a disposable copy with the guard stripped (first 33-char assertion fails; spawn falls through to an unrelated downstream cd failure)

Source: Regression proof: focused suite run against a disposable copy with the guard stripped (first 33-char assertion fails; spawn falls through to an unrelated downstream cd failure)

1..9 not ok - fresh herdr refusal must name the 32-char cap (missing: 'herdr caps agent names at 32 characters') --- output --- .../bin/fm-spawn.sh: cd: .../projects/none: No such file or directory

1..9
not ok - fresh herdr refusal must name the 32-char cap (missing: 'herdr caps agent names at 32 characters')
--- output ---
/tmp/fm-cap-noguard.MdEcMP/bin/fm-spawn.sh: line 4168: cd: /tmp/fm-spawn-herdr-name-cap.Odcs3F/fresh-herdr-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/home/projects/none: No such file or directory
  • Outcome: ⚠️ 1 info across 1 run (7m14s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ⚠️ bin/fm-spawn.sh:995 - Simplification: the guard introduces the concept 'herdr agent-name cap' as a second definition. FM_HERDR_AGENT_NAME_MAX=32 and fm_herdr_agent_name_within_cap() are defined independently in bin/fm-spawn.sh:995-1000 and bin/fm-control.sh:232-237, yet both scripts already source the same shared library (bin/fm-spawn.sh:949 sources bin/fm-control-lib.sh, which fm-control.sh also uses). No intent requirement forces duplication; the strictly narrower form is one definition of the constant plus predicate in bin/fm-control-lib.sh (or another lib both entry points source), with three call sites unchanged. The change's own comments argue for locality ('it is a one-line length comparison'), so this is a deliberate-intent question, not an auto-fix: the smallest honest remedy would move the definition into the shared lib, touching a third file beyond 'only the guard and its test'.
  • ℹ️ docs/herdr-backend.md:67 - Intent says the PR changes 'only the guard and its test'; this change also adds a one-line behavioral doc to docs/herdr-backend.md:67 and registers the test in bin/fm-test-run.sh:916 + docs/fm-test-portable-shards.md:32. The test registration is required for the test to exist in the suite; the herdr-backend.md line documents the new refusal in the section that already enumerates spawn preflight refusals, so it reads as part of delivering the guard rather than unrelated drift. Flagging for awareness only; no action recommended.

🔧 Fix applied.
2 infos still open:

  • ℹ️ docs/herdr-backend.md:67 - Intent says the PR changes 'only the guard and its test'; this change also adds a one-line behavioral doc to docs/herdr-backend.md:67 and registers the test in bin/fm-test-run.sh:916 + docs/fm-test-portable-shards.md:32. The test registration is required for the test to exist in the suite; the herdr-backend.md line documents the new refusal in the section that already enumerates spawn preflight refusals, so it reads as part of delivering the guard rather than unrelated drift. Flagging for awareness only; no action recommended.
  • ℹ️ tests/fm-spawn-herdr-name-cap.test.sh:27 - Stale comment left by the fix round that consolidated the guard into bin/fm-control-lib.sh: the suite header still says "The cap predicate is defined locally in each of the two scripts (it is a one-line length comparison)" (tests/fm-spawn-herdr-name-cap.test.sh:25-27), which is now false — the predicate lives once in bin/fm-control-lib.sh:409-413. Comment-only accuracy fix; no behavior change.

🔧 Fix applied.
1 info still open:

  • ℹ️ docs/herdr-backend.md:67 - Intent says the PR changes 'only the guard and its test'; this change also adds a one-line behavioral doc to docs/herdr-backend.md:67 and registers the test in bin/fm-test-run.sh:916 + docs/fm-test-portable-shards.md:32. The test registration is required for the test to exist in the suite; the herdr-backend.md line documents the new refusal in the section that already enumerates spawn preflight refusals, so it reads as part of delivering the guard rather than unrelated drift. Flagging for awareness only; no action recommended.
⚠️ **Test** - 1 info
  • ℹ️ bin/fm-herdr-lab.sh:596 - bin/fm-herdr-lab.sh provision's else-branch calls fm_herdr_lab_prepare, which refuses with 'tripwire already exists' when the caller ran prepare first as its documented usage suggests (prepare then provision in sequence fails; provision alone works). Pre-existing helper behavior unrelated to this change; noted only because it surfaced during lab setup.
  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Oracle: real herdr agent start rejects a 33-char agent name with invalid_agent_name and accepts a 32-char name ✅ pass live herdr-name-cap-live-validation.md: herdr 0.9.5 returned invalid_agent_name rc=1 for the 33-char name; the 32-char name started a real pi agent rc=0 in the lab workspace pane w1:p1
Live fm-spawn fresh spawn with --backend herdr refuses a 33-char task id before any pane/tab/workspace is created ✅ pass live herdr-name-cap-live-validation.md scenario 1: refusal message names cap, id, and length; exit rc=1; lab tab count stayed 1 (no endpoint created)
Live fm-spawn fresh spawn lets a 32-char id pass the cap (inclusive boundary) and fails downstream instead ✅ pass live herdr-name-cap-live-validation.md scenario 2: failure is downstream (missing brief), no cap message
Live fm-spawn fresh spawn with --backend tmux does not apply the herdr-only cap to a 33-char id ✅ pass live herdr-name-cap-live-validation.md scenario 3: failure is downstream (missing brief), no cap message
Live fm-spawn --relaunch with a herdr meta refuses a 33-char task id before inspecting or touching the endpoint ✅ pass live herdr-name-cap-live-validation.md scenario 4: cap refusal with actionable hint, rc=1
Live fm-control relaunch refuses a 33-char herdr task id BEFORE stopping the old agent or mutating durable records ✅ pass live herdr-name-cap-live-validation.md scenario 5: refusal 'recreate the task under a shorter id before relaunching', rc=1; no herdr call was made (tab count unchanged)
Regression: tests/fm-spawn-herdr-name-cap.test.sh fails without the guard and passes with it (9/9 ok) ✅ pass live herdr-name-cap-guardless-regression.log: 'not ok - fresh herdr refusal must name the 32-char cap' with the downstream cd failure in the output
  • bash tests/fm-spawn-herdr-name-cap.test.sh (9/9 ok, FM_TEST_COMPLETE)
  • bin/fm-herdr-lab.sh prepare/provision/teardown of fm-lab-capg2; herdr agent start 33-char vs 32-char oracle in the lab
  • live ./bin/fm-spawn.sh <33-char-id> ... --backend herdr with marked lab home (refusal, no endpoint created)
  • live ./bin/fm-spawn.sh <32-char-id> --backend herdr and <33-char-id> --backend tmux (no cap refusal, downstream failure)
  • live ./bin/fm-control.sh <33-char-id> relaunch and ./bin/fm-spawn.sh <33-char-id> --relaunch with herdr meta (refusal before endpoint/old-agent touch)
  • guard-stripped disposable copy: tests/fm-spawn-herdr-name-cap.test.sh fails at the first 33-char assertion (regression proof)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

CI note and full-ci label request

The only red check on this pull request is the Full suite job, which is this repository's documented maintainer-label gate, not a code failure: in its run (42331229101) the job started and finished within two seconds, executed exactly two steps ("Set up job" and "Require the full-ci go-ahead and passing lanes"), and ran no project code at all. The eight lane jobs were skipped for the same label reason (their names carry the "Not run for label" prefix), and the fast tiers that do run for outside pull requests - "Test coverage guard" and "Repo invariants" - both pass. FM_CI_LANES_FAILED=false: no actual lane failed.

Per CONTRIBUTING.md, the full suite runs for an outside pull request once a maintainer adds the full-ci label. We cannot apply labels from this fork, so: please add the full-ci label if you want the full suite executed here; the check will then report real lane results. We have made no workflow, gate, threshold, or test changes to work around the gate, and will not.

What the guard fixes, in one paragraph

Herdr caps agent names at 32 characters. Before this change, a task id longer than that cap made spawn or relaunch report success while Herdr's inner agent start rejected the name (invalid_agent_name) and the replacement agent never booted - a silently dead endpoint that still looked alive to supervision. With this change, all three entry points (fresh spawn, fm-spawn --relaunch, fm-control relaunch) refuse an over-cap id before any pane, tab, workspace is created or any old agent is stopped, naming the cap, the offending id and length, and the shorter-id hint. Ids within the cap and every non-herdr backend are untouched, and tests/fm-spawn-herdr-name-cap.test.sh proves the refusal at the exact 32/33 boundary (it fails without the guard).

Herdr's `agent start <NAME>` caps agent names at 32 characters and
rejects over-cap names with `invalid_agent_name`. A task id past the
cap therefore reported a successful spawn or relaunch while the
replacement agent's inner agent-start silently errored and never
booted: the endpoint looked alive, the worker did not exist, and the
relaunch path reported success on a silently dead agent.

fm-spawn.sh now refuses an over-cap id on the fresh spawn path (before
any pane, tab, workspace, or agent is created) and on the --relaunch
path (before the recorded endpoint is inspected or touched), and
fm-control.sh refuses on its relaunch path before stopping the old
agent or mutating any durable record. The refusal names the cap, the
offending id and its length, and the shorter-id hint; ids within the
cap and every non-herdr backend are untouched. The one-line length
predicate is defined locally in each script and cross-referenced,
since a shared home in bin/fm-backend.sh would grow this change's
file surface.

tests/fm-spawn-herdr-name-cap.test.sh pins the exact 32/33 boundary
and the 40-char live-failure shape through the three entry points,
with tmux cases proving the cap stays herdr-only. A herdr stub keeps
the pass-through cases hermetic: a real CLI could answer a
nonexistent session by starting a real server. Without the guard the
refusal assertions fail, which is what makes the suite a guard.

The new suite carries a provisional serial duration hint in
bin/fm-test-run.sh's hint table (provenance in
docs/fm-test-portable-shards.md) so the coverage guard's 15 percent
unhinted bound stays satisfied, and docs/herdr-backend.md names the
new preflight refusal alongside the tool and protocol-floor refusals.
@greptile-apps

greptile-apps Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Reviews (1) · Last reviewed commit: "no-mistakes(review): Fix stale comment a..." · Reviewed by Greptile

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @LorenzoMinghini. I read tip 1b8211d9 against main bf05a4fc.

What I checked: the shared FM_HERDR_AGENT_NAME_MAX / fm_herdr_agent_name_within_cap guard in bin/fm-control-lib.sh, the three fail-closed call sites (fresh spawn, fm-spawn --relaunch, fm-control relaunch) before any pane/tab/workspace is created or any old agent is stopped, the 32/33 boundary suite, and the herdr-backend refusal note. No workflow, credential, installer-checksum, or network changes.

Contract-class: restore. Herdr already rejects names over 32 with invalid_agent_name. Before this change, spawn/relaunch could report success while the replacement never booted. The guard restores an honest refusal on that hard cap; non-herdr backends and ids within the cap are untouched.

VISION: One captain aligns (no silent-dead endpoints) · Authority aligns (no new autonomy) · Scripts own the mechanics aligns (length predicate, fail-closed) · Restart is a non-event aligns · Delegation aligns (field incident → regression) · Vendor aligns (Herdr adapter honors vendor limit) · Scope aligns (spawn/control only).

Gates: no-mistakes binds 1b8211d9 with no skipped steps; live go 7/7 against real herdr 0.9.5; Greptile 5/5, 0 threads; coverage + invariants PASS; Full suite FAILURE is the unlabelled label-gate only (not red). MERGEABLE, behind_by=0. Rockets: none.

Next: author work is done. The next step is ours — run the full suite; if green this can land as a restore. Nothing more needed from you for the label-gate red.

@kunchenguid kunchenguid added full-ci Maintainer go-ahead: run the full CI suite on this outside pull request and removed full-ci Maintainer go-ahead: run the full CI suite on this outside pull request labels Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Maintainer go-ahead: run the full CI suite on this outside pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants