Skip to content

A remote start names its dispatch ​

What changes ​

  • Producers (agent-server, the CF Durable Object): the answer to a /start that carries a binding names its dispatchId: on RemoteStartResponse (started, attached), and on the ALREADY_RUNNING / ALREADY_COMPLETED envelope. A /start whose binding is not the session's own delegation is 409 state_child_session_taken, whatever the session is doing (agent-server answered ALREADY_RUNNING with its stream id, or ALREADY_COMPLETED; the Durable Object ALREADY_RUNNING while it was busy).
  • Parents (every runtime): a remote call sends its keyed, bound /start first, and accepts the answer only when it names its own dispatch. Another dispatch fails the call with state_child_session_taken; none with transport_remote_dispatch_unnamed. Both are non-retryable, and nothing of that session is read.
  • A bound call whose child had already finished gets the child's output (ALREADY_COMPLETED), where it failed.
  • Later requests: a parent's requests about its remote child name the dispatch (X-Helix-Dispatch-Id): its reads, and its answers to the child's calls. A producer answers them for that dispatch's session only, any other as none; a request without the header as before.
  • RemoteAgentTransport has a required forDispatch(dispatchId). A transport that cannot name the dispatch is refused (framework_not_supported, non-retryable, nothing sent), never used without it.
  • RemoteAgentAlreadyRunningError has dispatchId; RemoteAgentAlreadyCompletedError and RemoteDispatchUnnamedError are new; so is the error code transport_remote_dispatch_unnamed.

What to do ​

  1. Upgrade producers first, then the parents that call them:

    ParentProducerA remote call
    oldernewWorks. A start the new producer refuses (state_child_session_taken) fails the call typed.
    newolderFails with transport_remote_dispatch_unnamed. The call to a producer not yet upgraded starts there and is not used; its run ends by itself.
  2. A custom producer: name the dispatchId of the start's binding in the answers above, only when the session's stored binding is that delegation's.

  3. A custom transport: keep dispatchId when it parses a start's answer, map a non-2xx answer with core remoteEntryProtocolError, and add forDispatch: a copy whose requests carry DISPATCH_HEADER.

    A subclass of HttpRemoteAgentTransport or DOStubTransport overrides one method, as for trace pinning. It keeps the configuration it was constructed with and builds the copy from it; the copy keeps the trace pin and the dispatch:

    typescript
    class MyTransport extends HttpRemoteAgentTransport {
      constructor(private readonly myConfig: HttpTransportConfig) {
        super(myConfig);
      }
      protected override copyForTraceContext(): this {
        return new MyTransport(this.myConfig) as this; // a copy with the same configuration
      }
    }

    A wrapper around a transport (a Proxy, a decorator) wraps what forDispatch returns too: the runtime sends every request about a child through that copy.

    A proxy or gateway between a parent and its producer forwards X-Helix-Dispatch-Id.

  4. A Record<ErrorCode, …> in app code needs the new code.

  5. Test doubles of RemoteAgentTransport: return dispatchId: request.binding?.dispatchId from start, and the double itself from forDispatch. A started child's status is not read before its stream; answer status: 'attached' for a child that is already there.

Released under the MIT License.