A remote start names its dispatch
What changes
- Producers (agent-server, the CF Durable Object): the answer to a
/startthat carries abindingnames itsdispatchId: onRemoteStartResponse(started, attached), and on theALREADY_RUNNING/ALREADY_COMPLETEDenvelope. A/startwhosebindingis not the session's own delegation is 409state_child_session_taken, whatever the session is doing (agent-server answeredALREADY_RUNNINGwith its stream id, orALREADY_COMPLETED; the Durable ObjectALREADY_RUNNINGwhile it was busy). - Parents (every runtime): a remote call sends its keyed, bound
/startfirst, and accepts the answer only when it names its own dispatch. Another dispatch fails the call withstate_child_session_taken; none withtransport_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. RemoteAgentTransporthas a requiredforDispatch(dispatchId). A transport that cannot name the dispatch is refused (framework_not_supported, non-retryable, nothing sent), never used without it.RemoteAgentAlreadyRunningErrorhasdispatchId;RemoteAgentAlreadyCompletedErrorandRemoteDispatchUnnamedErrorare new; so is the error codetransport_remote_dispatch_unnamed.
What to do
Upgrade producers first, then the parents that call them:
Parent Producer A remote call older new Works. A start the new producer refuses ( state_child_session_taken) fails the call typed.new older Fails with transport_remote_dispatch_unnamed. The call to a producer not yet upgraded starts there and is not used; its run ends by itself.A custom producer: name the
dispatchIdof the start'sbindingin the answers above, only when the session's stored binding is that delegation's.A custom transport: keep
dispatchIdwhen it parses a start's answer, map a non-2xx answer with coreremoteEntryProtocolError, and addforDispatch: a copy whose requests carryDISPATCH_HEADER.A subclass of
HttpRemoteAgentTransportorDOStubTransportoverrides 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:typescriptclass 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 whatforDispatchreturns 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.A
Record<ErrorCode, …>in app code needs the new code.Test doubles of
RemoteAgentTransport: returndispatchId: request.binding?.dispatchIdfromstart, and the double itself fromforDispatch. A started child's status is not read before its stream; answerstatus: 'attached'for a child that is already there.