Skip to content

Validate hcoord spawn arguments before any effect and name the started agent again - #243

Merged
yansfil merged 5 commits into
mainfrom
fix/hcoord-spawn-fixes
Sep 28, 2026
Merged

yansfil merged 5 commits into
mainfrom
fix/hcoord-spawn-fixes

Conversation

@yansfil

@yansfil yansfil commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Related: #236, #237

Summary

Closes #236. Closes #237.

  • hcoord agent spawn fails lineage with identity_conflict because the spawned pane has no name #236: Herdr can report the agent hcoord started with no name, and the lineage step then refused it (identity_conflict) although the agent was running.
    • This happens after a confirmed start.
    • It also happens after an unconfirmed one: a prompt passed as a native argument keeps Claude Code working past readiness, agent start times out, and the pane's agent is unnamed.
    • Right after its own start, confirmed or not, hcoord records the pane's terminal and any session Herdr reports within 2 s as the started execution.
    • In that same call it renames an unnamed agent (herdr agent rename) when pane, kind and terminal (and any recorded session) match.
    • A later same-intent retry renames only when a recorded session exists and matches, because a pane keeps its terminal while agents are restarted in it.
    • --resume-start clears the recorded start of an agent that is gone before it launches a new one.
  • hcoord agent spawn validates its native arguments only after creating the worktree #237: name, kind and native arguments are checked before hcoord registers a --parent here pane, writes a letter, or reserves an intent.
    • A refused spawn creates no worktree, workspace or pane, and the daemon repeats the check at reserve.
    • An executable name followed by flags after -- (such as -- claude --dangerously-skip-permissions under the default codex kind) is refused, and the error names the --kind to pass.
  • hcoord agent spawn --help prints the spawn usage, including --kind and how claude and codex arguments are passed.
  • The README spawn example is corrected.

No screen changes.

before  $ hcoord agent spawn --parent here --name kid1 ... -- claude --dangerously-skip-permissions
        hcoord: invalid_argument: Codex task must be the final native argument   (worktree + workspace left behind)
after   hcoord: invalid_argument: arguments after -- go to the codex executable itself, so drop the leading "claude"
        and pass --kind claude to start claude; see hcoord agent spawn --help          (nothing created)

Review

  • Please judge: automatic renaming uses the terminal only in the call that started the agent; a retry needs a matching recorded session.
    So a codex start that timed out (no session yet) still needs a manual herdr agent rename on retry after a person checks the pane.
    An unnamed agent in another terminal or session is refused as a replacement and never renamed.
  • Please judge: hcoord agent spawn validates its native arguments only after creating the worktree #237's "same-intent retry reuses or cleans up" is covered by refusing first, since argument errors no longer leave anything partial.
    A retry with different arguments on the same intent remains intent_conflict.
  • Please judge: a lone word after -- (for example the prompt claude) is accepted as a prompt or task.
    So -- codex under the codex kind still sends codex as the task.
  • Files to review carefully:
    • plugins/hcoord/src/hcoord/transport.ts (spawn sequence): the failure path.
      An unconfirmed start now continues like a retry would, and only agent_pane_busy stops it.
    • plugins/hcoord/src/hcoord/herdr.ts (observeStartedAgent, nameSpawnedAgent, inspectSpawnedAgent): identity binding over the Herdr contract (agent.rename is in the pinned schema).
    • plugins/hcoord/src/hcoord/service.ts (agent.spawn.started, agent.spawn.start_reset): new ledger steps.
      The spawn event budget goes from 7 to 8 slots.
      started refuses a terminal or session that differs from the first observation, and start_reset clears it on --resume-start.
  • Follow-up: observeStartedAgent records nothing when agent get does not answer within 2 s, or when the daemon dies before the ledger write.
    Such an intent behaves like one saved before this change.
  • Known effect: saved native arguments are re-validated on --resume-start and at reserve.
    An intent reserved before this change with an executable name followed by flags now fails on rerun, even after its pane exists.

Evidence

  • Cause of hcoord agent spawn fails lineage with identity_conflict because the spawned pane has no name #236: a separate batch run on 2026-09-28 found it on this machine, with herdr 0.9.1.
    • herdr agent start ... -- --dangerously-skip-permissions --effort high "<prompt>" timed out ({"code":"timeout"}) because Claude Code went straight to work.
    • Afterwards, looking the agent up by its name returned agent_not_found until herdr agent rename was run.
    • Starting without the prompt argument and sending the prompt later kept the name, on 4 spawns.
  • Confirmed live, hcoord agent spawn fails lineage with identity_conflict because the spawned pane has no name #236 (isolated Herdr 0.9.1 server, private HOME and HCOORD_HOME, real Claude Code, this branch):
    • A wrapper reports a successful start as Herdr's timeout (exit 1) and clears the name.
      With it, the spawn exits 0, logs hcoord.spawn_name_restored, writes lineage written, and agent get shows the name and parent_pane.
    • A wrapper that only clears the name after a confirmed start gives the same result.
      On main, that case fails with the issue's identity_conflict.
    • Two real inline-prompt spawns were confirmed by Herdr before the prompt ran.
      I could not make a real start time out on demand.
  • Confirmed live, hcoord agent spawn validates its native arguments only after creating the worktree #237: refused spawns (an executable name plus flags under codex, and a misplaced codex task) exit 2.
    Worktrees, workspaces, intents, participants, the outbox and branches are all unchanged; on main the same command left a worktree and a workspace behind.
  • Confirmed (hcoord suites): typecheck, build, unit 30/30, e2e 26/26 (fake Herdr). New e2e cases:
    • Starts ending in timeout or agent_not_ready name and register the agent.
    • A retry with no recorded session (same terminal) refuses with the manual rename and does not rename; after a manual rename it binds.
    • With a session recorded at start, a refused rename ends as spawn_uncertain / name_agent, and a retry renames and binds.
    • An unnamed agent in a replaced terminal is refused and not renamed.
    • After the first agent exits, --resume-start binds the new session; without the reset this case fails.
    • A refusal with --repo --branch never calls worktree create.
    • --parent here validates before inspecting the pane, and --help prints the spawn usage.
  • Confirmed (other checks): repository structural checks and check-no-attribution.py.
  • CI: the clone.rs fixture flake is fixed on main by Keep background git maintenance and local object copies out of the clone test fixtures #245, which is merged into this branch.
    The last run failed desktop/e2e/add-project.spec.ts:134 in its cleanup (rmdir ENOTEMPTY), outside this diff.
  • Not confirmed:
    • A real Herdr start timing out on demand (simulated instead, as above).
    • Web, desktop and Rust lanes, which this diff does not touch.
    • No screenshot, because nothing on screen changed.

AI tooling: mostly AI tools; the live runs above were checked by reading Herdr's agent get output, the hcoord ledger events and git worktree list directly.

… again

A spawn whose native arguments the chosen kind cannot take was refused only
after hcoord had created the worktree, the workspace and its shell pane, so
the same intent could not be retried and a person cleaned up by hand (#237).
The CLI now checks the name, kind and native arguments before it registers
a --parent here pane or writes a letter, and the daemon checks them again
before it reserves the intent. A leading executable name after -- (for
example `-- claude` under the default `codex` kind) is refused with the
--kind to pass, and `hcoord agent spawn --help` prints the usage.

Herdr can report the agent hcoord has just started without the name it was
started under, and the lineage step then refused it as a different
execution although the agent was running (#236). Directly after its own
start in the pane the intent owns, hcoord names an unnamed agent of the
intended kind again and logs that it did. A later retry cannot tell a lost
name from a replaced agent, so it still refuses and names the rename
command a person runs.

Closes #236
Closes #237
…ost-name retry

The spawn help showed --session as optional and said --machine always needs
--repo and --branch; it is required without --parent here, and only a
machine other than the parent's needs a worktree. A name must also start
with a letter. The README now says a retry that finds the child unnamed
refuses and how a person names it.
…d start or on retry

Naming ran only when agent start exited 0. A prompt passed as a native
argument can keep the agent working past readiness: agent start then times
out, the pane's agent has no name, and the same-intent retry refused it, so
one spawn still did not write the lineage (observed 2026-09-28). A name
Herdr dropped after the rename was also never repaired.

Right after its own start, confirmed or not (only Herdr's busy refusal
proves nothing started), hcoord records the pane's terminal and any
reported session as the started execution. Then, and again at the start of
every same-intent retry, it names an unnamed agent only when pane, kind,
terminal and recorded session match that execution. An unnamed agent in
another terminal or session is refused as a replacement and never renamed;
an intent saved before this record keeps the manual rename hint.

A lone word after -- is a prompt or task, so the leading-executable check
now refuses an executable name only when arguments follow it.
yansfil added a commit that referenced this pull request Sep 28, 2026
…one test fixtures (#245)

Related: 2a8e6d1 is on `feat/overview-lenses` (#238); the maintenance
guard was found while working on #242. This lands both on `main`.

## Summary

- The clone test fixtures (`hide-host/tests/clone.rs`,
`herdr-core/src/runtime/tests/repository_clone.rs`) commit, then run a
local `git clone --bare`.
- `git commit` starts a detached `git maintenance run --auto`, which can
pack and prune loose objects while the clone is still copying them.
- On macOS CI runners this fails a random clone test with "failed to
copy file ... No such file or directory" in the fixture, before the code
under test runs.
- Tonight it failed the `rust workspace` lane of #242 (twice), #243 and
#244, always at `clone.rs:24`.
- The fixtures' `git` calls now turn off auto maintenance and auto gc,
and the bare origin is cloned with `--no-local` (a pack through Git's
transport, no file copy). Test-only.

## Review

- **Please decide**: whether landing this on `main` before #238 is fine;
2a8e6d1 is identical to the commit on `feat/overview-lenses`, so #238
merges over it cleanly.
- **Files to watch**: `herdr-core/src/runtime/tests/repository_clone.rs`
- preventive: the same fixture shape, not observed failing.

## Evidence

- **Confirmed**: `cargo test -p hide-host --test clone` passes 5/5
locally; the hide-host race reproduced locally under forced background
gc before the maintenance guard and not after (measured while working on
#242).
- **Not confirmed**: the flake rate on CI after the change beyond this
PR's own runs; the herdr-core fixture never reproduced.

**AI tooling**: mostly AI tools; the diff is three cherry-picked
commits, compared by hand.
…rt replace the recorded start

A pane keeps its terminal while agents are restarted in it, so a retry that
matched the terminal alone could rename a replacement: a `codex` start that
timed out records no session, a person restarts the agent in that pane, and
the retry named it, sent the first turn and bound it as the child. The call
that started the agent still names it on the terminal match; a later retry
renames only when a recorded session exists and matches the agent's, and
otherwise refuses with the manual rename a person runs.

A --resume-start after the first agent exited launched a new agent and then
refused its new session against the recorded one, and every later retry
failed the same way. A deliberate --resume-start now clears the recorded
start before it launches.
@yansfil
yansfil merged commit 7774014 into main Sep 28, 2026
11 of 13 checks passed
@yansfil
yansfil deleted the fix/hcoord-spawn-fixes branch September 28, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant