Awesome Reviewers

Network code should behave deterministically across retries/reconnects by (a) confirming exactly when data is accepted/“dispatched”, (b) preventing duplicate sends, and (c) bounding/aborting all network work.

Apply this as a checklist: 1) Use an explicit dispatch/acceptance boundary

2) Make retries safe with in-flight tracking

3) Bound and abort every network path

4) Preserve intended routing for local services under proxies

Minimal pattern (dispatch boundary + resend gating):

type SendFailure =
  | { kind: "preDispatch"; unsentPrompt: string }
  | { kind: "postDispatch"; warning?: string };

async function sendWithSafeReplay(hub: HubClient, payload: string): Promise<void> {
  const result = await hub.send({ payload });
  // result must include whether transport accepted the dispatch boundary
  // e.g. { dispatched: true } or a typed failure with pre/postDispatch.

  if (result.ok) return;

  if (result.failure.kind === "preDispatch") {
    // eligible: UI can offer the unsent draft for retry
    throw new Error(`Pre-dispatch failed; can retry draft: ${result.failure.unsentPrompt}`);
  }

  // not eligible: the transport may have already sent; do not offer replay
  throw new Error("Post-dispatch failure; do not resend to avoid duplicates");
}

Concrete outcomes you should see after adopting this: