Repository navigation
Description
Item 1 of 11 in the Crews: organic teamwork milestone. This one goes first: it's the fix for the queue pile-ups.
The problem
When an agent is mid-turn and won't take a message into that turn, every message sent to it waits in its queue and later runs as its own turn. A burst of five updates becomes five turns, and each of those turns tends to send replies that land in someone else's queue. Crew seats end up with 14+ queued items, chew through them one at a time, redo work, and get confused about what's current.
I pulled numbers from my live DB (read-only, crew seats only, queue depth estimated from run timestamps, so treat them as rough):
| Model | Seats | Turns per seat | Deepest queue | Seats that hit 10+ queued |
|---|---|---|---|---|
| claude-opus-5-5 | 78 | ~14 | 77 | 7 |
| claude-fable-5-1 | 48 | ~16 | 58 | 10 |
| gpt-6-sol | 13 | ~12 | 34 | 3 |
| gpt-6.1-sol | 111 | ~6 | 22 | 2 |
| gpt-6-astra | 16 | ~8 | 2 | 0 |
GPT 6 stays shallow because it takes a peer's message into the running turn (divergence D4). Everyone else, Claude especially, turns every queued message into a turn. The two deepest queues had mixed senders (Opus, Sonnet, GPT-6-Sol, GPT-6.1-Sol, Astra), so this isn't one chatty model. It's the "one message = one turn" rule on the receiving end.
Where this sits
Crews only work if seats can talk freely, and right now talking freely is exactly what buries them. The messaging rule (#678) and the crew notepad (#683) cut down how many messages get sent, but they depend on every model behaving. This issue makes the platform behave the same on every provider no matter how chatty the senders are: however many messages land while an agent is busy, it gets one turn to read them all.
This is A2A-wide, not crew-only. It's one delivery rule, and solo Peer Agents get the same benefit.
Definition
The docs PR on j5/crew-teamwork-docs writes the end state into the definitions, so read these first; this issue builds to them. Agent-to-agent communication AC29 and AC41–AC44 (the catch-up turn and its receipts), Agent tool surface AC38 (the deliveryNotice wording), and A2A messages in the thread view AC14 (one card per message).
What we already have
We already do exactly this for one kind of message. CrewSeatFinishNotifier.ts folds a new seat-finished notice into the notice already queued behind the Captain's running turn, using upstream's own queued-run.edit command (apps/server/src/j5/a2a/CrewSeatFinishNotifier.ts:126 finds the queued notice, :307 edits it). queued-run.edit takes the full text and a full replacement attachment list (packages/contracts/src/orchestrationV2.ts:2876), so there's no upstream edit and no new queue.
The places that need to change:
- Delivery,
apps/server/src/j5/a2a/DeliveryTransport.ts. Today a queued delivery isthreads.sendToThread(sendInput)withmessageId = deliveryMessageId(ledgerMessageId). The "did it land" check (landed(), around line 640) looks for a thread message with that exact id, and a folded message won't have one, so the check has to learn about folds. - Backlog advice,
apps/server/src/j5/a2a/receiverBacklog.tsandformatReceiverBacklogNotice. Today it tells the sender each waiting message "will run as its own turn", which becomes untrue. - Not-delivered notices,
apps/server/src/j5/a2a/deliveryNotices.ts. A2A AC30 says a queued message removed before its turn starts is reported to its sender. A folded turn holds several senders' messages. - Product definition,
docs/j5/product/a2a/index.md: already rewritten for the catch-up turn (see Definition above).
Related open work: #136 (agent queue mutations vs A2A accounting; folding is a J5-made queue edit, so it has to keep the ledger truthful the same way), #538 (revisit queue as the default landing), and #285 (envelopes as message-context records; if it lands first, the fold header goes in the record).
Proposal
When an A2A delivery would queue behind a receiver's running turn:
- If the receiver's last queued run is an A2A delivery that hasn't started yet and no person has edited it (its text is still exactly what J5 last wrote), append this message to it with
queued-run.edit. - Otherwise queue it as a new run, like today.
Only folding into the last queued run keeps the order right: if the person queued something in between, the next agent message starts a new run behind it.
The folded turn reads as one header, then each message's envelope intact, oldest first:
3 messages arrived while you were working. Read them all before acting.
[Cross-agent message from …]
…
[Cross-agent message from …]
…
Acceptance criteria
-
A message sent to an agent whose turn is running, and which won't take it into that turn, folds into the receiver's last queued run when that run is an unstarted A2A delivery that no person has edited. Otherwise it becomes a new queued run.
-
A person's queued message is never edited, and an agent message never folds into a run that sits in front of one. A person can still edit or remove a catch-up run like any queued message (shared-conversations AC14). Once a person edits one it's theirs: it takes no more agent messages and runs as they left it. What their edit cut out isn't reported, same as editing a single queued message today, and an ask they cut out still gets its silence notice when the receiver's turn ends without a reply.
-
Each folded message keeps its full envelope, including an ask's reply instruction and exchange id, so replying to any of them works exactly as it does today.
-
Attachments from every folded message ride in the folded run.
-
Steer, restart, and GPT 6 mid-turn delivery are unchanged. A message to an idle agent starts a turn as today.
-
Retrying a delivery never appends the same message twice (the seat notifier's "already included" check is the pattern).
-
Every folded message gets its delivery receipt, and the receipt says which queued run it joined.
-
Removing or cancelling a folded run before it starts sends one not-delivered notice to each sender whose message was in it, naming that message (AC30's behavior, per sender).
-
The sender's backlog notice still counts the waiting messages and the caller's share, and says how many will be read in the same catch-up turn as this one, not that each runs as its own turn. Count only the batch this message joined: a person's message or a platform notice in the queue splits batches, so promising the whole backlog in one turn would be wrong.
-
Platform notices keep their current behavior. Seat-finished notices still fold into their own digest, and nothing in this issue changes them.
-
The shipped
j5_send_messagedescription, its quoted copy inagent-tools.md, and the line inpackages/provider-core/src/j5/orchestrationInstructions.tsthat says a busy receiver handles each message as its own turn are updated together. The quoted tool descriptions inagent-tools.mdstay as shipped until the code changes them, so they change together (EnvelopeFormatter.test.tscompares thej5_send_messageone). -
Focused server tests cover: fold into the last delivery, no fold past a person's message, ask plus reply through a fold, no fold into a run a person edited, the notice's batch count with a person's message in the queue, retry idempotency, removal notifying every sender, and steer/restart untouched. Tests wait on receipts or drain the effect worker, never sleeps.
-
The web renders a catch-up turn as one card per message, oldest first, each exactly as it would render alone. Mobile keeps showing readable text.
Open question for review
Does joining J5's deliveries into one waiting run need its own entry in the register of divergences, or does it sit under D4? It only edits runs J5 created, never a person's, and uses upstream's own queued-run edit, but upstream shows each queued message as its own row. Let's settle that in the docs PR review before building.
Out of scope
- Folding platform notices that aren't seat-finished notices.
- Changing the GPT 6 mid-turn rule (Revisit queue as the default landing for agent messages (due 2027-01-11) #538 owns that).
- Any cap on how many messages fold into one turn. If a folded turn ever gets too big for a provider, it fails visibly and we look at it then.
Dependencies
- None blocking. Ship it alongside Crews: one messaging rule for every model #678.
- Crews: message the whole crew in one call #686 (message the whole crew) is blocked on this.
Activity