docs/architecture/worker-commands.md
Worker commands are server-initiated instructions sent to workers via Nexus. Each worker process has a dedicated control task queue that it polls via Nexus RPC. A single control queue serves one or more workers running within the same process. This enables the server to push actions to workers without relying on heartbeats or long-poll cycles.
To route a command, the server needs to know the target worker's control queue. For commands that target activities, this information is stored directly in the mutable state (ActivityInfo) when the activity was dispatched to the worker.
graph LR
subgraph History
A[Create Task] -->|1| C[Outbound Queue]
C -->|2| D[Dispatch]
end
subgraph Matching
E[Control Queue]
end
D -->|3| E
E -->|7| D
E ~~~ Worker
subgraph Worker
G[Poller] -->|5| F[Execute]
end
G -.->|4| E
F -.->|6| E
WorkerCommand protos and calls GenerateWorkerCommandsTasks, which persists them as an outbound task. Serialization is command-agnostic (task_serializers.go).Execute.dispatcher sends a DispatchNexusTask RPC to matching. This is synchronous — matching holds the request until a worker responds or the request times out.WorkerCommand in message.proto (api repo).GenerateWorkerCommandsTasks (see task_generator.go).