Skip to content

fix(j5): a delivery alarm tells its sender - #658

Merged
Jacksondr5 merged 2 commits into
j5/mainfrom
j5/alarm-notice-to-sender
Oct 19, 2026
Merged

Jacksondr5 merged 2 commits into
j5/mainfrom
j5/alarm-notice-to-sender

Conversation

@Jacksondr5

@Jacksondr5 Jacksondr5 commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

Problem

When an A2A delivery alarmed because its receiver couldn't be reached, nobody was told. Only a peer server's refusal sent the sender a not-delivered notice. So a peer server that was sent to directly and never answered, and a local delivery that used up its attempts, both alarmed silently. The a2a definition calls an alarm "a visible fact attributed to the sender, never a silent loss".

Closes #260

What changed

  • Every alarm sends the sender one not-delivered notice. It is the same notice a refusal sends, with the same message id. recordFailure adds it in the same transaction that records the alarm: alarmNotices in DeliveryWorker.ts. The reason names the receiver and quotes what the last attempt failed with, on one line and bounded, as peer text already is. For example:
    • Peer server: Your message to agent:…support on Home may not have been delivered: this server could not reach Home in 3 attempts, and it will not be tried again. The last attempt failed with: "Transport: connect ECONNREFUSED (POST https://home.example:3773/…)"
    • Local: Your message to agent:… may not have been delivered: delivery failed 3 times, and it will not be tried again. The last attempt failed with: "…"
  • Every alarm says "may not have been delivered". A direct attempt to a peer server whose answer was lost may still have landed, and a local steer can be acknowledged after its wait timed out. Peer removal already uses this wording (mayHaveArrived) for rows attempted directly.
  • A refusal still sends exactly one notice. A refusal takes the refusal branch and never reaches the alarm branch. Peer removal skips any message whose notice id is already recorded, so an alarm followed by removing the peer still sends one notice.
  • Who is not told:
    • A sender on a peer server, when this server's own delivery of its message alarms after the receipt was returned. This matches the removed-queued-message notice, because a peer server accepts a platform notice only for an Exchange. The a2a definition, AC12 and cross-device now state this exception, and a test pins it.
    • Platform and machine senders. Like a refusal, this uses canBeNotified.
    • Anyone, for a platform notice's own alarm. So a notice that can't be delivered never sends a notice about itself.
  • Unchanged: polling peers (link_mode = 'store') never alarm, and retry timing, re-driving and sweeps are untouched.

An alarmed ask keeps its Exchange open

A refused ask is dropped, but an alarmed ask stays open. Its notice says so and gives the way out: Exchange … is still open; if the ask did arrive, its reply still comes on it. To stop waiting, withdraw it with j5_clear_own_ask, then tell your person or send a new ask. The reasons:

  1. The ask may have arrived. A peer server can accept it and lose its answer. A local steer can be acknowledged after the 30-second timeout, which docs/user/j5-peer-messages.md already says can happen. If we dropped the Exchange, a real reply would arrive on a closed Exchange.
  2. a2a AC12, Fleet page AC24 and a2a's "A failed delivery" scenario. Together they treat the alarm as the sender's problem until the sender withdraws the ask. AC24 counts an alarm only while its Exchange is open. Dropping it automatically would clear that problem without anyone acting on it.
  3. The silence detector stays consistent, and nobody hears twice. Its alarmed branch (dependencyNotice) only fires for an open ask to a human, and it tells a different party: the subject's own asker hears "awaiting the human (human-doesnt-know)". That stays true while the Exchange is open. Dropping it would turn that notice into the less accurate "turn ended without replying". The asker whose ask alarmed gets only the not-delivered notice. For an ask to an agent on a peer server, the subject's asker still hears "blocked on peer", which is still true.

Docs: a2a's delivery paragraph, AC12 and the failed-delivery scenario are rewritten, and so is the delivery paragraph in cross-device. Each gets a History line.

Live testing

The review panel ran a live test on two peered servers, with Claude Haiku 5.5 and GPT-6-Luna, at f5d96e3. Verdict: pass. Full report and screenshots are in the panel's review.

  • Remote stopped: a plain message and an ask each alarmed after 3 attempts and each gave exactly one notice. The ask's Exchange stayed open and its notice named j5_clear_own_ask. After a restart nothing was re-driven.
  • Refusals: one notice each, and a refused ask's Exchange closed.
  • Peer removed after the alarms: no second not-delivered notice. The open ask got one exchange-dropped notice, which closed it.
  • Not exercised live: a local delivery failure, an alarm on a message from a peer server, polling, and the platform-sender exclusions. Unit tests cover the first, second and fourth. The follow-up commit only changes wording and docs, so it wasn't re-tested live.

Checklist

  • One concern: the description has no "also"
  • Tests cover the changed behavior (backend changes ship with focused tests)
    • Peer server unreachable, plain message and ask: one notice; the ask's Exchange stays open with nothing dropped.
    • Local alarm, plain message and ask: one notice; the notice's own alarm tells nobody.
    • A message from a peer server that alarms on its local delivery: no notice.
    • Refusal: the existing refused-ask and refused-plain tests still pass and assert exactly one notice.
  • UI changes: before/after screenshots above, and a video for motion or interaction (no UI change)
  • Live testing: the section above says what ran live and what did not
  • Upstream-owned files: each one is recorded in FORK.md (case text and file-table row) in this PR (none: J5-owned paths only)
  • 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, with no contract change.
    • The way out is j5_clear_own_ask, which already exists.
    • Local, direct-peer and polling-peer modes are each decided above.
  • Docs: definitions under docs/j5/product/ and user docs rewritten where this changes them

Built by Claude Opus 5.5 in Claude Code (J5 Code).

🤖 Generated with Claude Code

When a delivery alarmed because its receiver couldn't be reached, nobody was
told: only a peer server's refusal sent the sender a not-delivered notice.
Every alarm now sends the sender that same notice, once, naming the receiver
and what the last attempt failed with. An alarmed ask's Exchange stays open
for the sender to withdraw, since the ask may still have arrived.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vercel

vercel Bot commented Oct 19, 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 19, 2026 2:23am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 9d4785a6-ae37-4e30-876f-2a82d2ba2222
📥 Commits

Reviewing files that changed from the base of the PR and between 3a55dfe and 1914773.

📒 Files selected for processing: 6
  • apps/server/src/j5/a2a/DeliveryWorker.test.ts
  • apps/server/src/j5/a2a/DeliveryWorker.ts
  • apps/server/src/j5/a2a/PeerOutbound.test.ts
  • apps/server/src/j5/a2a/deliveryNotices.ts
  • docs/j5/product/a2a/index.md
  • docs/j5/product/cross-device.md

Included review availability: This review used your included allowance. 2 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour.

📝 Walkthrough

Delivery alarms now create not-delivered notices for eligible senders. Notices report the receiver, attempt count, and last failure. An alarmed ask remains open and its notice includes instructions for withdrawal. Peer-origin alarms do not create a local sender notice.

Changes: Delivery alarm notices

Layer / File(s) Summary
Notice content and event contract
apps/server/src/j5/a2a/deliveryNotices.ts
Notice formatting supports alarm reasons, optional peer names, and open Exchange IDs. Peer-provided reasons use shared normalization.
Delivery alarm processing
apps/server/src/j5/a2a/DeliveryWorker.ts, apps/server/src/j5/a2a/DeliveryWorker.test.ts
DeliveryWorker extracts the innermost failure and creates notices for eligible local-origin alarms. Tests cover asks, ordinary messages, peer-origin alarms, and notice retry limits.
Peer delivery retries and documented behavior
apps/server/src/j5/a2a/PeerOutbound.test.ts, docs/j5/product/a2a/index.md, docs/j5/product/cross-device.md
Peer delivery tests simulate refused connections and verify notices after three attempts. Product documentation describes alarm notices and the distinction between local and peer-server alarms.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant DeliveryWorker
  participant deliveryAlarmReason
  participant notDeliveredNoticeEvent
  DeliveryWorker->>deliveryAlarmReason: Build reason from attempt count and last failure
  DeliveryWorker->>notDeliveredNoticeEvent: Create notice event with sender and optional open Exchange ID
Loading
Merge Risk: ⚪ Minimal · up to 19147

Delivery alarms now tell the sender once, with wording that the message may not have been delivered. Alarmed asks stay open and the notice explains how to withdraw them. No merge-blocking risk was identified in the supplied changes.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Linked Issues check Warning The implementation meets the main #260 requirements for local-origin deliveries and directly contacted peers. It records one alarm notice in the failure transaction, preserves refusal notices, include… Handle alarmed local deliveries whose message originated on a peer server, so the sender also receives the required single not-delivered notice, or revise #260's coding requirement before merging this exception.
Passed Passed checks: 3 passed
Check name Status Explanation
Out of Scope Changes check Passed The changes stay within #260. The worker changes implement alarm notices and failure text. The notice formatter changes support receiver naming, bounded reasons, possible delivery, and open ask Exchan…
Title check Passed The title is concise, specific, and accurately identifies the main change: delivery alarms now notify the sender.
Description check Passed The description covers the problem, implementation, behavior changes, exclusions, testing, documentation, checklist, and authoring details. The omitted UI and upstream-impact sections are appropriatel…
Full details: Out of Scope Changes check

Explanation

The changes stay within #260. The worker changes implement alarm notices and failure text. The notice formatter changes support receiver naming, bounded reasons, possible delivery, and open ask Exchanges. The tests cover the required alarm, refusal, local, peer, and notice-alarm behavior. The transport stub and the a2a and cross-device documentation support the same delivery-alarm behavior. No unrelated product or UI change is present.

Full details: Description check

Explanation

The description covers the problem, implementation, behavior changes, exclusions, testing, documentation, checklist, and authoring details. The omitted UI and upstream-impact sections are appropriately treated as not applicable.

Full details: Linked Issues check

Explanation

The implementation meets the main #260 requirements for local-origin deliveries and directly contacted peers. It records one alarm notice in the failure transaction, preserves refusal notices, includes the receiver and bounded last-error text, keeps alarmed asks open, and adds focused plain-message and ask tests. However, #260 states that every alarmed local delivery produces one notice in the sender's thread. alarmNotices skips rows with a non-null origin_environment_id. The added test confirms that a peer-server sender receives no notice when this server's local delivery alarms. The linked issue does not define this exclusion.

Resolution

Handle alarmed local deliveries whose message originated on a peer server, so the sender also receives the required single not-delivered notice, or revise #260's coding requirement before merging this exception.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · 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 the vouch:trusted Author is trusted by repo permissions or the VOUCHED list. label Oct 19, 2026
@github-actions github-actions Bot added the size:L 100-499 effective changed lines (test files excluded in mixed PRs). label Oct 19, 2026
Jacksondr5 added a commit that referenced this pull request Oct 19, 2026

@Jacksondr5 Jacksondr5 left a comment

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.

Review panel: Claude Opus 5.5 + GPT-6-Astra

Both reviewers checked these findings independently against the source at f5d96e3.

What holds: the notice is committed in the same transaction as the alarm (DeliveryWorker.ts recordFailure). Refusal and alarm are separate branches, the command id is stable per attempt, and alarmed rows are never re-driven. Peer removal skips a message whose notice id is already recorded. Keeping an alarmed ask's Exchange open is right: an alarm is uncertainty, not a decision by the receiver. It matches AC12, Fleet AC24 and the failed-delivery scenario, and SilenceDetector.dependencyNotice still reports accurately. The focused tests drive the real worker and ledger, and they pass.

1. A local alarm promises the message wasn't delivered, though it may have been

DeliveryWorker.ts:591 sets mayHaveArrived only when the receiver is on a peer server. So a local alarm's notice says "was not delivered" (deliveryNotices.ts:100). But a local steer can still land after the alarm: DeliveryTransport.ts:382 times out only the wait, and docs/user/j5-peer-messages.md already says a delayed acknowledgment may still arrive. A sender told "was not delivered" may repeat work that already landed. For a local ask, the same notice also says "if the ask did arrive, its reply still comes on it", which contradicts its first line. Suggest using the "may not have been delivered" wording for every alarm, which also removes a branch.

2. The docs promise that every alarm tells its sender, but a sender on a peer server is never told

docs/j5/product/a2a/index.md:74, AC12 (:129) and docs/j5/product/cross-device.md:46 say an alarmed message is reported to its sender. In cross-device, that sentence comes right after the one about the peer server's own delivery alarming there. But alarmNotices returns nothing when origin_environment_id is set (DeliveryWorker.ts:570-574). Concretely: A sends to B, gets B's receipt, and then B's local delivery alarms. Nobody is told on either server. The PR body discloses this, but the product definition and AC12 don't. We're not asking for machinery to cover it (a peer server only accepts Exchange-shaped platform notices, PeerInboundService.ts:266-283). Suggest stating the exception in both docs and AC12, for example "a sender on a peer server is not told". A small test pinning the exclusion would keep it deliberate.

Live test (two peered servers, Claude Haiku 5.5 and GPT-6-Luna)

  • Remote stopped: a plain message and an ask from Local each alarmed after 3 attempts, and each gave exactly one notice. The ask's Exchange stayed open, and its notice named j5_clear_own_ask. After a restart, the same two notices remained, and nothing was re-driven when Remote came back.
  • Refusals (recipient archived on a running Remote): one notice each. A fresh refused ask got one notice, and its Exchange closed.
  • Peer removed after the alarms: no second not-delivered notice. The open alarmed ask got one separate exchange-dropped notice that closed it, which is correct new information.
  • Not exercised live: a local delivery failure, an alarm on a message from a peer server, polling, and the platform-sender exclusions. Unit tests cover the local failure and a notice's own alarm.

Evidence:

A local steer can land after its wait times out, so a local alarm no longer
claims the message was not delivered. The a2a and cross-device definitions
now state that a sender on a peer server is not told of an alarm on the
receiving server after its receipt; a test pins that exclusion.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Jacksondr5

Copy link
Copy Markdown
Owner Author

Re: panel review. Both findings are fixed in 1914773.

  1. Every alarm now says "may not have been delivered", local alarms included. alarmNotices sets mayHaveArrived for every alarm, so the branch is gone. A local ask's notice no longer contradicts itself, and the local test asserts the new wording.
  2. The exception is now in the docs. The a2a delivery paragraph and AC12 now say a sender on a peer server is not told when the receiving server's own delivery alarms after its receipt. AC12's notice wording now matches. The cross-device paragraph says an alarm on the peer server after its receipt is not reported back. Each has its History line. Nothing new was built for it. A new test in DeliveryWorker.test.ts, "tells nobody when a message from a peer server alarms on its local delivery", pins the exclusion.

The PR description's live-testing section now carries the panel's results.

— Claude Opus 5.5 (Claude Code)

@Jacksondr5

Copy link
Copy Markdown
Owner Author

Re: CodeRabbit's Linked Issues warning, about a message from a peer server that alarms on its local delivery. This exception is deliberate, so I'm leaving the code as it is. The review panel asked for it in its review.

A peer server accepts a platform notice only for an Exchange (PeerInboundService.ts). The removed-queued-message notice already skips senders on a peer server for the same reason. Covering this case would mean building a new cross-server notice, which #260 scopes out.

Instead, the a2a definition, AC12 and cross-device now state the exception, and a test checks that it sends no notice.

— Claude Opus 5.5 (Claude Code)

@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.

Looks good to me. I couldn't break the core of it: the alarm and the notice go out in one transaction, the fixed notice ID means peer removal's alreadyTold check skips its own notice so the sender only hears about it once, and nothing can loop back into a notice. Couple of wording things inline that I'd fix before merging, but nothing blocking.

One test gap too. Nothing tests alarm-then-peer-removal end to end. PeerRemovalService.test.ts forces status='alarmed' with SQL, so no alarm notice ever gets written there. The checklist also says the platform-sender exclusions are covered, but on the alarm path only the lifecycle_notice channel case is. I'd either add one test that drives a direct peer to a real alarm, removes the peer, and checks for exactly one not-delivered notice, or soften that checklist line.

Ran DeliveryWorker, PeerOutbound and PeerRemovalService tests locally at 1914773, all 48 pass.

readonly error: string;
}) =>
`${
input.serverName === undefined

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 count can be off. Held-queue rechecks still bump attempts (recordFailure gets row.attempts + 1 either way). So if a receiver's queue is held for an hour, that's about 7–8 rechecks. Resume it, the next real attempt fails once, the alarm fires immediately, and the agent gets told "delivery failed 8 times". The early alarm was already there, but now we're telling an agent a wrong number. Easiest fix is probably just dropping the count ("delivery failed and won't be tried again"). The early alarm after a hold could be its own follow-up.

`${
input.serverName === undefined
? `delivery failed ${input.attempts} times`
: `this server could not reach ${input.serverName} in ${input.attempts} attempts`

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.

"could not reach" isn't always true here. This branch also catches cases where the peer did answer, like a 5xx, a protocol mismatch, or a 401. A 401 is the confusing one: if Home removed us, the sender reads "this server could not reach Home in 3 attempts… answered HTTP 401", when what actually happened is Home ended the peering. Maybe "delivery to Home failed" as neutral wording, and use peerCredentialRejectedReason for the 401?

- **Two questions for the user.** The same agent asks the user "merge now or after the audit?" with urgency _soon_, and separately "may I delete the old branch?". Both appear as inbox items. The agent then learns something relevant to the first question and follows up on it by name; the follow-up appears under that item. The user answers each; each Exchange closes with the exact text delivered to the agent. (AC5, AC7, AC8, AC18)
- **A busy receiver.** An agent in Website Redesign sends a plain message to a peer whose turn is running a long shell command. The message queues; the peer's turn finishes normally; the message starts its next turn. The user, watching the peer, chooses to steer instead — the control says "Steer now" on this provider — and their text is injected into the running turn. (AC13, AC14)
- **A failed delivery.** An agent asks a peer that has been archived. The delivery fails, the alarm is attributed to the asker and shown on its Fleet page row; the asker withdraws its ask; the alarm remains a fact but no longer counts as a problem. (AC9, AC12)
- **A failed delivery.** An agent asks a peer that has been archived. The delivery fails, the alarm is attributed to the asker, told to it in a not-delivered notice, and shown on its Fleet page row; the asker withdraws its ask; the alarm remains a fact but no longer counts as a problem. (AC9, AC12)

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.

Small one. An archived receiver doesn't actually alarm. deliveryUnavailable cancels the row, so no alarm and no notice. That was already wrong before this PR, but since this line now promises a notice, maybe swap the trigger for something that really alarms, like an agent on a peer server that's gone offline?

: flat;
};

/** Why a delivery alarmed, completing "… was not delivered: …". */

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: comment still says "… was not delivered", but every alarm reads "may not have been delivered" now.

@Jacksondr5
Jacksondr5 merged commit 90241e0 into j5/main Oct 19, 2026
35 checks passed
@Jacksondr5
Jacksondr5 deleted the j5/alarm-notice-to-sender branch October 19, 2026 23:58
Jacksondr5 added a commit that referenced this pull request Nov 23, 2026

This branch was successfully deployed

1 active deployment
Preview — 19147732 Deployed Oct 19, 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 delivery alarm tells its sender

2 participants