# Peer reference

[Documentation index](../README.md) · [Coordination](../concepts/coordination.md)

Peer communication connects live Coordinators of the same role without
creating a supervision or ownership relationship.

## Who can communicate?

| Participants                                            | Eligible scope                                                                                                                                  |
| ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| Ordinary Leads                                          | Local Lead-to-Lead communication across projects                                                                                                |
| Managed or assigned Leads                               | Local Lead-to-Lead communication within the same verified Herdr worktree group and socket, with current exact assignment evidence               |
| Managers                                                | Local Manager-to-Manager communication across projects                                                                                          |
| Ordinary Leads and Managers across saved Herdr machines | Same-role communication with federation enabled and eligibility verified. Only verified ordinary, unassigned Leads qualify for Lead federation. |
| Managed Agents and Chief                                | No peer communication                                                                                                                           |

If either Lead is assigned, both must meet the shared group and socket
requirements. Unavailable or retired Managed Leads do not become ordinary
global peers.

Eligible peers can be discovered once initialized, before their first
conversation. Communication settings and current identity checks still
determine whether discovery and messaging are permitted.

## Communication controls

The user-wide [communication settings](configuration.md#peer-communication)
apply only to horizontal peer coordination. Turning off **Peer communication**
blocks peer listing and new peer messages, and pauses delivery to Pi of all
pending peer messages in the local inbox, regardless of where they originated.
Turning off only **Peer federation** blocks cross-machine discovery and
transfers, including retries and replies through existing return correspondences.
Both endpoints must allow federation for a cross-machine transfer. An eligible
message already committed to the recipient's local inbox can still reach Pi
with federation off, as long as **Peer communication** remains on there.
Neither setting changes Agent delegation, Manager supervision, or Chief
coordination.

Running sessions check the current settings at communication boundaries,
including submission and delivery, without requiring a reload. A known target
or a previously published presence record does not bypass these checks.
Disabling communication does not delete queued messages, correspondence, or
delivery receipts. Eligible pending work can resume when the applicable controls
are enabled again, subject to existing identity and authorization checks.

The Herdsman federation setting is separate from Herdr's saved machine pairing
and enablement. Turning federation off does not remove or disable a Herdr
machine; turning it on does not pair a machine or configure SSH access.

## Presence and identity

### Live Coordinator presence

A healthy, eligible Lead or Manager publishes one private, generation-bound
Coordinator presence record in the user-global `runtime/peers-v2/peers/`
directory beneath the Herdsman data root. Publication is independent of peer
communication settings. Both peer discovery and hierarchical supervision
use verified live Coordinator information; initial discovery does not require
persisted conversation history.

The record immediately publishes the exact Pi session, Herdr pane, tab,
workspace, and current Coordinator cwd with the `{ pid, id }` claim for the
session's presence process lock. The current session name, repository,
branch, and workspace label are optional presentation metadata. Repository,
branch, and workspace label are enriched asynchronously without delaying
coordination startup. Peer cwd is always the session's current `ctx.cwd`,
never a Herdr provenance or source-checkout path.

The record is valid only while its claim matches the exact live process-lock
generation. Missing, malformed, duplicate, replaced, or dead-lock evidence
is ignored. Enumeration scans every canonical filename in the global
registry; one stale record does not hide later live peers. Chief and
suspended sessions do not publish these records. Unhealthy coordination
withdraws presence without discarding queued messages. Successful durable
recovery publishes a fresh generation rather than reviving the prior claim.
After an update, [reload sessions still using an older build](../guides/recovery.md#coordinator-is-missing).

### Identity and authorization

Presence is observation, not permission to communicate with or control
another session. The record and its exact live process-lock claim bind the
publisher's socket and verified project-group provenance to that generation.

Assignment mutations and peer authorization share a short-lived user-global
process lock. Under it, Herdsman validates every canonical assignment record
across socket namespaces. Immutable, exact-session-bound session kind and the
global exact assignment snapshot separately establish identity and project
eligibility. Incomplete, corrupt, ambiguous, or unavailable assignment
evidence fails closed; assignment absence does not change a Managed Lead's
session kind.

Presentation metadata, branch names, cwd, and checkout names are not authority.
Peer message submission makes a best-effort final
reread of the captured sender and target generations immediately before
writing. Presentation-only enrichment does not invalidate a message, and a
replacement process-lock claim observed by that reread rejects it. The target's
held presence lock and the inbox message lock are separate, so a replacement
can race after the reread. Submission rechecks eligibility after attachment
preparation and publishes under the assignment authority lock; exact session IDs do not bypass the policy. Queued peer messages
retain verified sender context across sender shutdown; discovery, submission,
and delivery revalidate managed eligibility and current assignment/group evidence.
Transient topology failures defer delivery, while definitive ineligibility
rejects it. Managed Agents, Chief sessions, display labels, and metadata are
never peer targets.

### Local and cross-socket verification

The user-global peer runtime is independent of the socket-scoped supervision
runtime. Same-role Coordinators on different local Herdr sockets share peer
discovery and transport, subject to the project eligibility rules above.

For a peer on the local Herdr socket, discovery and submission check its
placement and native session against the current agent inventory. Assigned
peer eligibility also checks current worktree topology. For a peer on another socket, Herdsman has no existing Pi
primitive to query that socket's live topology: discovery and submission use
the peer's generation-bound published group plus that socket's exact
assignment namespace. The receiving Lead always rechecks its own current
topology before delivery; this does not provide a cross-socket topology RPC.

## Peer tools

Leads (including eligible managed Leads) and active Managers have `list_peers` and `message_peer`.
Initiate a peer message for concrete, task-relevant coordination another eligible coordinator needs. Reply when asked or when a response resolves the exchange; avoid unsolicited routine broadcasts and unnecessary acknowledgments. Share useful evidence when it helps the peer act.

```json
{}
```

Returns this session separately from independently discovered eligible
same-role sessions. A Lead or Manager may also receive an optional
`reply_only` collection for originating sessions of its current role with an
existing authorized return correspondence. Target-bearing entries have this
form:

```json
{
  "peers": [
    {
      "target": "lead:7k3mp9qd2f",
      "name": "workspace/api",
      "cwd": "/work/api",
      "repo": "api",
      "branch": "feature/peer",
      "workspace_label": "api"
    }
  ],
  "reply_only": [
    {
      "target": "lead:4n8rx2c6ya",
      "name": "Research peer",
      "workspace_label": "project-alpha/main"
    }
  ]
}
```

`reply_only` is omitted when empty. Its targets are not independently
discovered peers. Optional `name` and `workspace_label` are last-known,
sender-provided presentation context; they may be absent, non-unique, or stale.
These labels do not verify identity, availability, machine
origin, project ownership, or permission to initiate an unrelated conversation.
Each peer is addressed by its stable `target`; the same role/session has the
same target whether discovered locally or through federation. Targets resolve
to exact coordinator sessions but are not authorization. `message_peer`
revalidates identity and authority when sending, including the existing
eligibility and correspondence checks. Missing reciprocal Herdr/SSH
configuration does not prevent replies through an existing correspondence;
reverse connectivity is needed only to independently initiate communication.
Therefore, an empty `peers` list does not necessarily mean communication with
known originating peers through current-role correspondences is impossible.

The current session is identified separately from `peers`. Peer targets are
caller-session-scoped bindings, not portable aliases. An unresolved target is
rejected; rediscover it with `list_peers` before messaging. Do the same when
identity or eligibility is uncertain. Names, paths, branches, and workspace
labels are descriptive metadata, not target handles. The model-facing list has
no `session_id`, `pane_id`, `tab_id`, or `workspace_id` fields.

With federation enabled, an active Manager can also discover live Managers on
enabled, reachable saved Herdr machines. An ordinary Lead similarly
discovers only remote Leads verified as ordinary and unassigned by the remote
machine's authoritative assignment scan. Managed or assigned Leads are not
remote federation targets. Those entries use the same stable target format and
include a `machine` display label. If remote Lead eligibility cannot be
verified, that machine does not contribute Lead results; an incomplete scan
does not mean that no eligible Leads exist. Labels are not authority. Remote
transport requires an independently working noninteractive OpenSSH target with
normal strict host-key verification. `ssh://` targets and SSH-config aliases
are supported; Herdr-only temporary authentication is not. For authorized
onboarding or reciprocal SSH setup, see the bundled
[machine-pairing skill](../../skills/machine-pairing/SKILL.md).

An eligible peer in `peers` has been verified for discovery, but
`message_peer` still revalidates identity and authority when sending. A peer in
`reply_only` has an existing authorized return correspondence: its reply can
be queued even though its current independent availability is unverified.
Neither display metadata nor a diagnostic observation makes a target
addressable. Discovery failures appear as an optional `remote_diagnostics`
array and do not hide peers discovered successfully elsewhere:

```json
{
  "remote_diagnostics": [
    {
      "machine": "base",
      "reason": "build_mismatch",
      "peer": "worker",
      "local_build": "v0.34.1 · 0123456789ab",
      "remote_build": "v0.34.0 · fedcba987654"
    }
  ]
}
```

Each diagnostic has one of these reasons:

- `machine_list_failed`: Herdr's saved machine list could not be read.
- `herdr_not_reachable`: Herdr did not confirm reachability for the saved
  machine; this does not establish that its physical host is offline.
- `probe_failed`: the remote peer probe failed before identity was established.
- `federation_disabled`: the remote bridge explicitly refused federation under
  its [communication settings](#communication-controls). That machine contributes
  no peer results; this is a policy refusal, not a network or probe failure.
- `build_mismatch`: an observed peer has valid build evidence that differs from
  this runtime. The affected peer is excluded from `peers`.
- `build_unverified`: an observed peer has missing or invalid build evidence
  and is excluded from `peers`.
- `eligibility_unverified`: a remote ordinary-Lead assignment scan was
  incomplete. That machine contributes no Lead results; this does not assert
  that it has no eligible Leads.

`machine` and optional `peer` values are bounded display hints, not target
handles. Build fields appear only for validated build mismatches. Diagnostics
contain no connection targets, credentials, or raw transport errors; they are
observations, never authorization records. A complete scan with no eligible
peers is a normal empty result and needs no diagnostic. A listing, reachability,
probe, or eligibility diagnostic means discovery is incomplete even when other
peers were found; build diagnostics report observed peers that were excluded.
`remote_diagnostics` contains at most 20 entries. If more were observed,
`remote_diagnostics_omitted` gives the exact additional count; total warnings
are the array length plus that count. Expanded Pi output also reports any
diagnostics it omits from display.

```json
{
  "target": "lead:7k3mp9qd2f",
  "message": "The integration is ready.",
  "files": ["result:researcher#1"]
}
```

`message_peer` accepts ordinary files, reusable direct-agent refs such as
`result:researcher#1`, and canonical `result:<request-id>` refs already supplied
as evidence. A semantic ref resolves on the sender's current branch and keeps
its model-facing name during attachment preparation. Its hidden canonical
binding travels with the durable peer message so the recipient can forward the
same semantic ref. Peer attachments must be complete supported UTF-8 text
within both configured byte limits or the handoff is rejected; a reference-only
attachment is not reported as delivered. The compact physical peer record
remains bounded by the internal 8 KiB limit, with larger accepted bodies
stored separately and verified before Pi delivery.

Targets do not all need to be independently discoverable and currently live:
a coordinator may reply to an exact `reply_only` target through its existing
return correspondence. This does not grant general initiation permission.

Remote sends are retained locally until the remote endpoint confirms durable
acceptance. Failed sends remain queued and retry automatically while the
coordinator inbox is active and federation is enabled; `list_peers` also
triggers reconciliation when federation is enabled. Acceptance is not delivery
to Pi or completion of the requested work. An accepted request establishes a
capability-scoped, durable return correspondence bound to the coordinator role.
The recipient can reply to the exact originating session with `message_peer`;
the reply is queued at the recipient and retrieved automatically while the
origin's inbox runtime is active and both endpoints allow federation. Replies
remain queued until acknowledged, including across temporary
disconnections; reverse SSH is not required. Recovery is allowed only for the
same exact Pi session after it re-establishes live authority for that role; a
replacement session or a different role is not substituted. Requests also
verify the endpoint's effective Herdsman data root against the discovered
route before recovery or reply transfer. Delivery to Pi and completion of the
requested work remain separate states.
