Skip to main content

Module send

Module send 

Source
Expand description

Synchronous event delivery — collapses the legacy wire send → outbox → daemon push → relay 3-step into a single direct relay POST.

§Why this exists

Paul (2026-06-01): “Why are we dealing with this whole outbox queued delivered thing it’s a headache and always breaks can we streamline and collapse steps.”

Pre-fix, every wire send (CLI and MCP) wrote to <outbox_dir>/<peer>.jsonl and returned status: "queued". The daemon’s 5s push loop later POSTed the event to the relay. Three distinct silent-drop classes hide in those steps:

  1. outbox write succeeds, daemon never pushes — daemon dead, daemon on wrong WIRE_HOME, TLS broken (the #176 → #183 saga), operator never ran wire push. queued looked like success but no byte ever left the box.
  2. daemon pushed, peer’s relay slot stale — earlier half-paired state, peer rotated slot, slot_token expired (the brisk-iris case). Push got 4xx, marked as skipped in the daemon log, operator never sees it from the wire send side.
  3. content-hash dedup blocks retriesevent_id is sha256(canonical(body)). Sending the same body twice produces the same event_id; relay drops the second as duplicate. Retry feels like success but never reaches the peer.

§The new contract

  • Default (wire send, tool_send): synchronous POST to the peer’s pinned relay slot. Returns Delivered / Duplicate / Failed inline. No outbox write on the happy path. Operator sees the actual verdict, not a fake queued.

  • --queue opt-in (CLI flag; MCP queue: true arg): preserves the legacy outbox-write path for explicit batching / offline-buffer / pre-pair queue use cases. The daemon’s run_sync_push loop continues to drain the outbox so anything written via this path still delivers.

  • Peer not pinned: the relay coords are unknown — sync POST is impossible. We error explicitly with a hint to run wire dial <peer> (or pass --queue if the operator wants pre-pair queueing). Pre-fix this case silently wrote to outbox and the daemon would never push it; now it’s loud.

  • Stale slot (4xx from relay): return Failed with the slot error string. The existing cli::error_smells_like_slot_4xx classifier already detects this shape; the caller surfaces the re-resolve hint. We do NOT auto-re-pair without the operator’s consent (that’s wire dial’s job).

Enums§

SyncDelivery
Result of attempting a synchronous delivery to a peer.

Functions§

attempt_deliver
Attempt synchronous delivery of signed_event to peer_handle.
delivery_json
Render a SyncDelivery as the JSON value wire send --json / tool_send return. Fields are flat (no nested struct) so JSON consumers can read .status + .event_id directly without pattern-matching the variant tag.