Skip to content

feat(a2a): name Squadrons in the address book and remote senders in the timeline - #198

Merged
Jacksondr5 merged 5 commits into
j5/peering-6-pairing-scopesfrom
j5/peering-7-names
Sep 30, 2026
Merged

Jacksondr5 merged 5 commits into
j5/peering-6-pairing-scopesfrom
j5/peering-7-names

Conversation

@Jacksondr5

@Jacksondr5 Jacksondr5 commented Sep 21, 2026 •

Copy link
Copy Markdown
Owner

Stack 8/8. Depends on #197. Merge in order, retargeting to j5/main as predecessors land.

Full stack:

Testing: scripts/j5/pr-env.sh <pr> --peer (#255) serves this PR's build as two peered servers, Local and Remote. Rebased onto j5/main on 2026-09-30, after the Effect rc.115 upstream sync and the Playbooks and Crews migrations landed; peer migrations are now 023–027 and the FORK.md case is 48. A test state directory that ran an earlier cut of this stack recorded the peer tables under other ids, so rerun pr-env.sh with --fresh for such environments.


Stack 7 of the cross-server peering build. Base: #197. Fixes two things the first real two-server test surfaced.

Problems

  1. Agents saw Squadron ids, never names. list_participants rows carried squadron_id only, and a peer's Squadron never appears in list_squadrons, so an agent could not tell "Remote Squad" from an opaque id, nor confirm its own Squadron's name from its self row.
  2. A remote sender rendered as "Unnamed participant". The web resolves sender labels through the client identity read on the receiving server, which knows local thread titles and machine names. A sender homed on a peer has neither there.

What this does

  • squadron_name on every address-book row, local and peer-homed, from the ledger's Squadron list and the peer roster respectively. The tool description now says the self row's Squadron is the one the caller belongs to. No server is named anywhere; the existing assertion that no row reveals an environment still holds.
  • Names travel with a peer delivery. The origin adds originSquadronName and senderLabel (the sender's thread title) to the delivery request, best-effort. The receiving server keeps both on its message.received payload.
  • Client identity lookup falls back to the delivered label. After local thread titles and machine names, the latest senderLabel a peer sent for that participant id stands in, so the timeline and inbox name a remote sender as they name a local one.
  • Docs: agent-tools.md result rows and description; cross-device.md AC17 gains the name, new AC23 states the label carriage.
  • After review: the fallback runs only for ids nothing local named, through one statement whose probes run on the peer route index from feat(a2a): route platform notices back to a waiter on a peer server #176 (migration 26), and migration 27 adds the label-recency index. A query-plan test requires both ledger reads to be index searches, so local-only identity reads never scan received history.

Deliberately not added: a server or environment name on any agent-facing row, per the 2026-09-16 ruling that agents never see servers. The envelope text is unchanged in this PR; naming the origin Squadron there is a possible follow-up.

Verification

  • 14 A2A and MCP test files, 131 tests, pass: handlers, outbound (asserts both names in the posted body), inbound (asserts both names on the received row), client reads (new case: latest peer label wins, local names take precedence), envelope contract, round trip, peer HTTP, delivery transport, worker, silence, lifecycle, ledger, production MCP registration.
  • Scoped typechecks of apps/server, packages/contracts, apps/web: clean. Lint on changed files: clean.

After the 2026-09-30 Astra review: a remote sender's latest label is chosen by the time this server recorded it, not by seq, which is allocated per Squadron. Migration 27 indexes labeled received rows by sender and receipt time so each lookup is one backward index seek.

Built by Claude Fable 5.1 in Claude Code.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Peer-delivered messages now include the sender’s display name when available, helping recipients identify who sent them.
    • Participant listings now show each participant’s Squadron name, including the caller’s own.
    • Peer message text can contain up to 256,000 characters.
  • Documentation
    • Updated participant-listing and cross-device documentation to describe Squadron names and sender names on peer deliveries.

@Jacksondr5

Copy link
Copy Markdown
Owner Author

Astra review (gpt-6-astra, 2026-09-24) of this PR after the rebase onto current j5/main. Findings and what changed:

  • Confirmed: the identity fallback scanned received history for every participant batch, local ones included, with no index to seek by sender. Fixed: the fallback runs only for ids nothing local named, through a statement whose probes use a new partial index on received rows by sender (migration 21), with a query-plan test.
  • Everything else checked out: optional name fields, no labels in agent envelopes, bound SQL parameters, sender label rendered as React text, receipt replay before label persistence, and the rebase seams in the delivery worker, runtime layer, send service, handler tests, and client-runtime modules.

Built by Claude Fable 5.1 in Claude Code.

@github-actions github-actions Bot added size:L 100-499 effective changed lines (test files excluded in mixed PRs). and removed size:M 30-99 effective changed lines (test files excluded in mixed PRs). labels Sep 24, 2026
@Jacksondr5
Jacksondr5 marked this pull request as ready for review September 24, 2026 07:08
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Peer deliveries now support sender display labels, which receiving services retain and identity lookup can use. Participant directory rows now include Squadron names for local and remote participants. The peer delivery contract also limits message text length.

Changes

A2A labels

Layer / File(s) Summary
Peer sender-label delivery
packages/contracts/src/j5.ts, apps/server/src/j5/a2a/contracts.ts, apps/server/src/j5/a2a/DeliveryTransport.ts, apps/server/src/j5/a2a/PeerInboundService.ts, apps/server/src/j5/a2a/PeerOutbound.test.ts, apps/server/src/j5/a2a/PeerInboundService.test.ts, docs/j5/product/cross-device.md
Peer delivery requests accept an optional bounded senderLabel. The transport adds a trimmed, length-limited sender name when available, and the inbound service stores a supplied label in the received event. Tests and product criteria cover the label.
Resolve identities from received labels
apps/server/src/j5/a2a/ClientReadsService.ts, apps/server/src/j5/a2a/ClientReadsService.test.ts
Identity lookup uses the highest-sequence labeled received event for unresolved participant IDs. The test checks sequence selection and the received-sender index in the query plan.
Squadron names in participant directory
apps/server/src/j5/a2a/mcp/tools.ts, apps/server/src/j5/a2a/mcp/handlers.ts, apps/server/src/j5/a2a/mcp/handlers.test.ts, apps/server/src/j5/a2a/envelopes.v1.json, apps/server/src/j5/a2a/EnvelopeFormatter.test.ts, apps/server/src/mcp/toolkits/worktree/registration.test.ts, docs/j5/product/a2a/agent-tools.md, docs/j5/product/cross-device.md, FORK.md
Participant directory rows include nullable squadron_name. Local names come from the Squadron ledger, and remote names come from peer data. The envelope version and descriptions, tests, documentation, and peering inventory are updated.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant DeliveryTransport
  participant participantIdentityRows
  participant PeerInboundService
  participant message_received
  DeliveryTransport->>participantIdentityRows: Look up sender identity
  DeliveryTransport->>PeerInboundService: Send peer delivery with senderLabel
  PeerInboundService->>message_received: Store senderLabel in received payload
Loading

Suggested reviewers: bryantderosier

Merge Risk: 🟡 Moderate · up to 3b143

Oversized peer messages can remain undelivered, and a Squadron-name lookup failure can hide an otherwise available address book. Align send validation with the wire limit before merging; address the narrower label and test gaps as well.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the two primary changes: naming Squadrons in the address book and naming remote senders in the timeline.
Description check ✅ Passed The description is detailed and covers the problems, implementation, tests, documentation, scope, upstream impact, and verification results. It also identifies the model and harness used. It does not …
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@bryantderosier bryantderosier left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sending the sender's name with each peer delivery is the right idea, but one of the new fields has no reader, the name lookup is duplicated, and the peer-supplied names need limits.

Should fix

  • originSquadronName gets sent, validated and persisted, but nothing reads it. The contract comment and AC23 describe a reader that doesn't exist. (inline, contracts.ts)
  • DeliveryTransport.ts: the sender-label query is a second definition of a participant's display name, alongside ClientReadsService.participantIdentityRows. (inline)
  • The peer-supplied names have no length cap and text has no max. The label lookup is keyed by sender id alone, and a future-dated createdAt pins a label for good. (inline, ClientReadsService.ts)

Nits

  • DeliveryTransport.ts: squadronRows isn't wrapped in orElseSucceed the way labelRows is, so despite the "best-effort" comment an SQL error there still fails the delivery. (inline)
  • ClientReadsService.ts: the unresolved filter is quadratic; a Set fixes it. (inline)
  • PeerRegistryService.ts: the reasonOf cause-chain change is unrelated to names and belongs in its own PR. (inline)
  • Docs: cross-device.md adds AC23 and edits AC17 without a History line, and the agent-tools.md description change has no History entry either. (inline, on AC23)

Comment thread apps/server/src/j5/a2a/contracts.ts Outdated
@@ -150,6 +150,9 @@ const NonMembershipCommEvent = Schema.Struct({
export const MessageReceivedPayload = Schema.Struct({
originSquadronId: SquadronId,
originEnvironmentId: Schema.optional(Schema.String.check(Schema.isNonEmpty())),
/** From a peer delivery: the names its server sent, read by the client identity lookup. */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only senderLabel feeds ClientReadsService. originSquadronName is sent by DeliveryTransport.ts, validated in both contracts and persisted by PeerInboundService.ts, but nothing reads it, so this comment isn't accurate. AC23 describes the same reader, and also mentions the inbox, which doesn't apply because people are server-local. I'd either wire it into the timeline now or drop the field until something reads it, then fix this comment and AC23 to match.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ff33fdc6f1: originSquadronName is dropped from the wire, the payload and the inbound service; the comment and AC23 say only what the timeline shows (the sender's label).

const squadronRows = yield* sql<{ readonly name: string }>`
SELECT name FROM j5_a2a_squadron WHERE id = ${input.originSquadronId} LIMIT 1
`;
const labelRows = yield* Effect.orElseSucceed(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a second definition of a participant's display name. ClientReadsService.participantIdentityRows uses the thread title from the first participant.joined, while this joins the membership threadId to orchestration_v2_projection_threads. The two can disagree, so a peer could see a different name than we do locally. It also reads an upstream projection table from a new place, and orElseSucceed would hide it if that schema drifted. I'd export participantIdentityRows and reuse it here.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ff33fdc6f1: participantIdentityRows is exported and the transport uses it, wrapped in orElseSucceed.

FROM j5_a2a_comm_event AS event
WHERE event.kind = 'message.received'
AND json_extract(event.payload, '$.senderLabel') IS NOT NULL
AND event.sender IN ${sql.in(participantIds)}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These labels are peer-controlled, and there are a few problems with trusting them as-is. senderLabel and originSquadronName only check isNonEmpty (and text has no max), so a peer can send a megabyte of name. This lookup matches on sender alone, not (originEnvironmentId, sender). And "newest" is ordered by the peer-supplied createdAt, so a single delivery dated in the future pins its label permanently. I'd cap names at around 200 chars and put a max on text in the contract, key this lookup and the NOT EXISTS probe by originEnvironmentId, and order by local seq rather than created_at. A peer can also name its Squadron after one of ours, so it may be worth showing the peer's environment label next to remote senders.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ff33fdc6f1: senderLabel is capped at 200 and text at 256k in the wire contract, the lookup and its NOT EXISTS probe are keyed by originEnvironmentId, and newest is by local seq (the test dates the older row in 2099). Showing the peer's environment label beside remote senders is a client concern I would take separately.

// Names travel with the message for the peer's people, so its timeline
// can name the sender as it names a local one. Best-effort: a name the
// origin cannot read never holds a delivery.
const squadronRows = yield* sql<{ readonly name: string }>`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the comment above says a name the origin can't read never holds up a delivery, but only labelRows is wrapped in orElseSucceed. An SQL error here still fails the send. I'd wrap this one too. The (): ReadonlyArray<{ readonly title: string | null }> => [] annotation on line 476 isn't needed either; () => [] infers.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ff33fdc6f1: the squadron read is gone and the one remaining read is wrapped; the annotation went with it.

// A sender homed on a peer has no thread here; the label its server
// sent with its latest delivery stands in, and only for ids nothing
// local named, so local-only reads never touch received history.
const unresolved = participantIdBatch.filter(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this scans every accumulated row for each id in the batch, so it's quadratic in the batch size. I'd build a Set of the resolved participant_ids first and filter against that.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ff33fdc6f1: a Set of resolved ids.

@@ -138,7 +138,17 @@ const recordFromRow = (row: PeerRow): PeerRecord => ({

const decodeHello = Schema.decodeUnknownEffect(PeerHelloResponse);

const reasonOf = (cause: unknown) => (cause instanceof Error ? cause.message : String(cause));
/** The message plus the cause chain: a transport error alone never says why the socket failed. */
const reasonOf = (cause: unknown): string => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: walking the cause chain is a useful change, but it's unrelated to carrying names. I'd move it to its own small PR so this one stays about one thing.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: moved to its own branch, j5/peer-unreachable-reason (844ba9d0ae), based on #173's branch. I have not opened the PR yet.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened as #288, stacked on #173.

Comment thread docs/j5/product/cross-device.md Outdated
18. A message to a participant on a peer is recorded in the sender's Squadron ledger before the call returns; the peer records its own received row before delivering to the agent's thread; the peer's acknowledgement is the sender's delivery receipt; failure to reach the peer retries and alarms as any delivery does.
19. Retrying one message to a peer never yields a second received row or a second delivery.
20. A reply, silence notice or lifecycle closure for an Exchange across peers travels the peer path back to the origin server and closes or notifies the origin Exchange exactly as a local one would.
21. A person is never addressed across peers: an ask to a person is delivered on the sender's own server.
22. Peers reach each other directly at the recorded origin; no relay or tunnel is required for peering.
23. A delivery to a peer carries the sender's display name and its Squadron's name; the receiving server keeps them with its received row so the client names a remote sender in the timeline and the inbox as it names a local one, and no agent verb needs them.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: AC23 is new and AC17 changed, but there's no History line for either, and the list_participants description change in agent-tools.md has no History entry. I'd add both. If originSquadronName stays unread, this AC should also drop the inbox and say only what the timeline actually shows.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ff33fdc6f1: History lines for AC17/AC23 in cross-device.md and for the list_participants description in agent-tools.md; AC23 drops the inbox and the Squadron name.

@vercel

vercel Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
j5-code Ready Ready Preview Sep 30, 2026 2:37pm UTC

Request Review

Jacksondr5 and others added 5 commits September 30, 2026 10:36
…he timeline

Two-server testing showed agents could see only Squadron ids in
list_participants, and the timeline showed a remote sender as "Unnamed
participant" because its display name lives on the other server.

list_participants rows now carry squadron_name beside squadron_id, for local
and peer-homed rows alike, and the tool description says the self row's
Squadron is the caller's own. A peer delivery carries the sender's thread
title and its Squadron's name; the receiving server keeps them on its
received row, and the client identity lookup falls back to that label after
any local name, so the web names a remote sender as it names a local one.
Agents keep addressing by participant id and still see no server.

Built by Claude Fable 5.1 in Claude Code.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ne definition of a display name

Review of #198. The origin Squadron's name was sent, validated and
persisted but read by nothing, so it goes; AC23 and the payload comment
now say what the timeline actually shows. The sender's label comes from
the same statement the client identity read uses, so a peer sees the
name we see, and the wire bounds it and the message text so a peer
names a sender rather than filling the ledger.

The client's label lookup is keyed by the server the label came from
and ordered by this ledger's sequence, so a delivery the origin dated
in the future cannot pin a name, and it runs on the peer route index
from migration 21, so the extra index migration goes. The unresolved
set is a Set. The cause-chain change to peer errors moves to its own
branch. History lines cover AC17, AC23 and the list_participants
description.

Built by Claude Fable 5.1 in Claude Code.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…st-effort, and let the plan test see a scan

CodeRabbit on #198. The wire capped message text but nothing stopped a
local send from recording a longer message that the peer would then
refuse on every retry until the alarm; the cap is now the platform's
(A2A_MESSAGE_TEXT_MAX_CHARS) and the send service refuses it before
anything is written. list_participants no longer loses the whole
address book when the Squadron-name read fails; names are enrichment
and fall back to null. The query-plan assertion matched the table name,
which a SCAN under the query's aliases never contains; it now requires
both ledger reads to be index searches.

Built by Claude Fable 5.1 in Claude Code.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…er numbering

The peering migrations moved above main's Playbooks and Crews
migrations to 23–26 in this rebase. The client identity read's comment
names the route index by its new id, and FORK.md case 48 says that
development databases that ran either earlier numbering are disposable.

Built by Claude Opus 5.5 in Claude Code.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…und with one index seek

Astra review of #198. The label lookup took the row with the highest seq
as newest, but seq is allocated per Squadron, so a stale label received
in one Squadron at a high seq hid a renamed sender's later label in
another. Received rows carry this server's own clock, stamped at
receipt, so the lookup orders by that, with Squadron id then seq as the
tie-break so exactly one row wins.

Ordering by time on the seq-ordered route index made the "nothing newer"
check walk a sender's history, so migration 27 indexes labeled received
rows by sender, receipt time, Squadron and seq, and the statement takes
each asked id's latest row with one backward seek on it. A sender id
belongs to one peer, since the inbound ownership check refuses a second
origin, so that row is its peer's latest label. The test spans two
Squadrons and a same-instant tie, and the plan test rejects a scan or a
sort. FORK.md case 48 names migration 27, and the round-trip fake says
why it carries no sender label.

Built by Claude Opus 5.5 in Claude Code.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Jacksondr5
Jacksondr5 merged commit 0d2b37d into j5/main Sep 30, 2026
36 checks passed
@Jacksondr5
Jacksondr5 deleted the j5/peering-7-names branch September 30, 2026 15:01
bryantderosier added a commit that referenced this pull request Sep 30, 2026

This branch was successfully deployed

1 active deployment
Preview — c2997298 Deployed Sep 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 effective changed lines (test files excluded in mixed PRs). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants