Skip to content

fix(a2a): a reply to an ask from another Squadron is accepted - #428

Merged
Jacksondr5 merged 1 commit into
j5/mainfrom
fix/cross-squadron-reply
Oct 3, 2026
Merged

Jacksondr5 merged 1 commit into
j5/mainfrom
fix/cross-squadron-reply

Conversation

@Jacksondr5

Copy link
Copy Markdown
Owner

Problem

An agent could ask an agent in another Squadron a question, but the answer was refused with A2ACrossSquadronReplyInvariantError. The Exchange is recorded only in the asker's ledger, and the reply path would not write a closure there, so the ask stayed open until it was dropped or withdrawn.

What changed

A reply from another Squadron is now accepted, and the asker's ledger records the closure in the same transaction that accepts the reply.

When Replier's ledger Asker's ledger
Reply accepted message.sent (reply) exchange.closed
Reply delivered message.delivered message.received
  • One transaction. Both appends run under the ledger writer permit inside the reply's transaction. Each ledger allocates its own next sequence number, so both stay gap-free, and either both events land or neither does.
  • Closure command id. A command receipt binds a command id to one ledger, so the closure uses an id derived from the reply's command id.
  • Replay. A replayed reply command returns the original result and writes nothing to either ledger.
  • One reply. A second reply is refused with A2AExchangeNotOpenError, as it is inside one Squadron. The existing reply count and the unique index on reply deliveries remain as the backstop, and still answer A2AExchangeAlreadyAnsweredError if the closure is missing.
  • No migration. There is still one Exchange row per exchange id.

Closing at accept, not at delivery, matters for silence: if the Exchange stayed open until the delivery worker ran, a replier whose turn ended first would be reported to the asker as "turn ended without reply" for an Exchange it had answered.

A2ACrossSquadronReplyInvariantError is removed, along with the exchange.closed branch in DeliveryWorker.appendReceiverEntry. That branch only ran for a reply row whose ledger differs from the receiver's, and no other path produces one:

  • A person's answer (HumanInboxService.answer) writes the reply and its closure in the Exchange's own ledger.
  • A reply to a person resolves the person into the sender's Squadron, so the row is same-ledger.
  • A machine participant only sends plain messages and never receives, so it is never party to an Exchange.
  • A reply from a peer server is projected into the receiver's own ledger and closed by PeerInboundService; a reply to a peer server takes the peer transport and never reaches this function.

The peer path did not have this refusal: the receiving server opens its own copy of the Exchange, so the reply there is a same-Squadron reply. That approach can't be reused on one server, because several lookups find an Exchange by id alone and expect one row.

Tests:

  • SendService.test.ts: ask, follow-up, one reply closing the asker's Exchange, a second reply and a late follow-up refused, the events each ledger holds, gap-free sequences, replay writing nothing, and the one-reply backstop.
  • DeliveryWorker.test.ts: the reply is delivered to the asker and the Exchange closes once.
  • SilenceDetector.test.ts: the replier's turn ends after the reply is accepted and before the worker runs, and no silence notice is written.
  • DeliveryTransport.integration.test.ts: the cross-Squadron case now runs the same ask-and-reply assertions as the same-Squadron case.

Fixes #427

Checklist

  • One concern: the description has no "also"
  • Tests cover the changed behavior (backend changes ship with focused tests)
  • UI changes: before/after screenshots above, and a video for motion or interaction — not applicable, server-only
  • Upstream-owned files: each one is recorded in FORK.md (case text and file-table row) in this PR — not applicable, only apps/server/src/j5 is touched
  • Upstream product: any change to what upstream's product does has a human decision linked above and a register entry in docs/j5/product/upstream.md — not applicable
  • Surfaces: entry points, clients, providers, contracts, reverse states, connection modes (see AGENTS.md) — server-only; no contract change. The peer (cross-server) path was checked and is unchanged. Not verified in a running client.
  • Docs: definitions under docs/j5/product/ and user docs rewritten where this changes them — none needed; the A2A definition already describes this behavior

Claude Opus 5.5 (1M context), Claude Code in J5 Code.

🤖 Generated with Claude Code

An agent could ask an agent in another Squadron, but the answer was
refused: the Exchange lives only in the asker's ledger, and the reply
path would not record a closure there.

The reply is now accepted. Its message.sent goes in the replier's
ledger and the exchange.closed goes in the asker's ledger, both in the
transaction that accepts the reply, so the Exchange closes exactly once
and is never left open after it is answered. The closure has a command
id derived from the reply's, because a receipt binds a command to one
ledger. A replayed reply returns the original result and writes nothing.

The delivery worker no longer closes an Exchange when it delivers a
reply; no path reaches that branch now that closure happens at accept.

Fixes #427

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@vercel

vercel Bot commented Oct 3, 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 Oct 3, 2026 3:33am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 6 billable files and costs up to $1.50.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 15 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available. Your 52 included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: Jacksondr5/j5code/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: fecf0370-4aff-4ced-a1e1-e20f12aa35a1
📥 Commits

Reviewing files that changed from the base of the PR and between 9bd7e09 and 6c10e05.

📒 Files selected for processing (6)
  • apps/server/src/j5/a2a/DeliveryTransport.integration.test.ts
  • apps/server/src/j5/a2a/DeliveryWorker.test.ts
  • apps/server/src/j5/a2a/DeliveryWorker.ts
  • apps/server/src/j5/a2a/SendService.test.ts
  • apps/server/src/j5/a2a/SendService.ts
  • apps/server/src/j5/a2a/SilenceDetector.test.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L 100-499 effective changed lines (test files excluded in mixed PRs). labels Oct 3, 2026
@Jacksondr5
Jacksondr5 merged commit 6653f51 into j5/main Oct 3, 2026
28 checks passed
@Jacksondr5
Jacksondr5 deleted the fix/cross-squadron-reply branch October 3, 2026 03:41

This branch was successfully deployed

1 active deployment
Preview — 6c10e052 Deployed Oct 3, 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.

A reply to an ask from another Squadron is refused

1 participant