Skip to content

Status and health streams

How the SDK (2.40.0) pushes node state and node health to the engine: the per-node status queue fed by the state machine, the per-node health queue fed by the health monitor, the controller's fan-out to gRPC subscribers, the heartbeat re-send with its [resend] marker, the replay buffers for late subscribers, how streams end on stop and reconfigure, and how the engine and the cloud proxy relay them to the UI. The node-author view is Health reporting; the state transitions that produce status items are on Architecture.

End-to-end flow

sequenceDiagram
    participant Node as NodeBase (state machine, health monitor)
    participant SDK as NodeController
    participant API as NodeServiceApi (gRPC)
    participant NES as Node Engine
    participant Proxy as Node Engine Proxy
    participant UI as Cloud UI

    Note over Node,SDK: InitializeNode
    NES->>API: InitializeNode (wire id)
    SDK->>SDK: fresh status_queue + fan-out + heartbeat, fresh health_queue + fan-out
    SDK->>Node: initialize(status_queue, node_id, health_queue=health_queue)

    Note over Node,SDK: ConfigureNode
    NES->>API: ConfigureNode
    Node->>Node: state IDLE to CONFIGURED: status dict on status_queue
    Node->>Node: _push_current_health(), start health-monitor thread

    Note over UI,NES: Subscribe
    UI->>Proxy: SubscribeGraphNodesStatusStream / SubscribeGraphNodesHealthStream
    Proxy->>NES: command stream relay
    NES->>API: SubscribeNodeStatusStream / SubscribeNodeHealthStream (per node)
    API->>SDK: generator: subscriber queue appended, replay snapshot pushed
    loop live items
        SDK-->>API: status or health dict
        API-->>NES: SubscribeNode*StreamResponse
        NES-->>Proxy: graph stream
        Proxy-->>UI: nodeId, state or isHealthy, resultMessage
    end
    Note over Node,SDK: StopNode or reconfigure: None sentinel ends every subscriber stream
Layer Status RPC Health RPC
Node container (this SDK, node-service.proto) SubscribeNodeStatusStream -> {meta, state, nodeId, resultCode, resultMessage, graphStopRequested, graphStopMode} SubscribeNodeHealthStream -> {meta, nodeId, isHealthy, resultMessage}
Node engine, edge (nodegraph-api.proto) SubscribeGraphNodesStatusStream, multiplexed per graph SubscribeGraphNodesHealthStream, same fields
Node engine proxy, cloud Same RPC, relays the edge stream over the command stream to the UI Same

Unary snapshots stay available: GetHealthCheck on the node service runs get_health_check() once, and the engine's GetNodesHealthStatus returns nodeHealthStatuses (id to bool), totalNodes, healthyNodes and nodeHealthMessages. The streams are the primary path for live badges.

Queues and threads per node

Everything is keyed by the wire id the engine sends ({uuid}:{node_id}, fresh per configure cycle).

Object Owner Created Ended
status_queue (queue.Queue) NodeController.status_queues[node_id] __get_status_queue() on InitializeNode; recreated by configure_node() when missing None sentinel from StateMachine.end_status_stream() (stop transitions and NodeBase.stop()); popped on stop, configure failure and stale-generation release
status fan-out thread (daemon) __get_status_queue() with the queue exits after forwarding the sentinel
status-heartbeat-<node_id> thread (daemon) _start_heartbeat() with the queue when status_stream_heartbeat_interval_s > 0 _stop_heartbeat() sets its event on stop, reconfigure and configure failure
health_queue (queue.Queue) NodeController.health_queues[node_id] __get_health_queue() on InitializeNode; recreated by configure_node() when missing None sentinel from NodeBase._end_health_stream() in stop()
health fan-out thread (daemon) __get_health_queue() with the queue exits after forwarding the sentinel
health-monitor-<node_id> thread (daemon) NodeBase._start_health_monitor() in configure() after every successful configure(), when health_stream_check_interval_s > 0 and a health queue exists _stop_health_monitor() from _end_health_stream() or the next configure()
unhealthy-escalation-<node_id> thread (daemon) NodeBase._handle_health_sample() on an unhealthy probe when escalate_unhealthy_to_error is on one-shot after the first unhealthy sample of a fault, while RUNNING _stop_unhealthy_escalation() on healthy, stop, reconfigure; the worker clears itself after it fires or is cancelled
subscriber queue.Queue, one per open gRPC stream subscribe_node_*_stream() generators on subscribe removed in the generator's finally
_last_status_by_node_id, _last_health_by_node_id controller replay buffers updated by the fan-out for every non-sentinel item popped on stop, configure failure and stale-generation release

_fan_out_worker (controllers/node_controller.py) is shared by both streams: it iterates main_queue.get until None, calls on_status_item (the snapshot recorder) for each dict, snapshots the subscriber list under the per-node lock, and put_nowaits the item on every subscriber queue. A full subscriber queue drops the item with an ERROR log naming the node and state, because a silently starved consumer is otherwise invisible. On the sentinel it forwards None to every subscriber and exits. _initialize_node_locked() always creates fresh queues and threads: a fan-out that has seen the sentinel is never reused.

Status stream

Producers

  1. Real transitions. StateMachine.transition_to() calls send_status_message(), which builds {"nodeId", "state", "resultCode" (0, or 1 for ERROR), "resultMessage": "State of node with ID ... changed from X to Y | Message: ..."} and put_nowaits it. ConfiguredState, RunningState, PausedState and ErrorState end the stream on stop(); IdleState.stop() does not. NodeBase.stop() also calls end_status_stream() as a teardown step, which is a no-op when the state machine already did it.
  2. Graph stop requests. NodeBase.request_graph_stop(reason, mode="hard") puts one item carrying "graphStopRequested": True and the requested "graphStopMode" on the same queue. See Graph stop requests.
  3. Heartbeat re-emits. _heartbeat_worker enforces a maximum quiet period rather than a fixed rate: whenever nothing has flowed through the main queue for status_stream_heartbeat_interval_s (default 1.0 s in NodeServiceConfig; some gateway service configs set 10 s; 0 or negative disables it), it re-puts the last recorded snapshot with [resend] prepended to resultMessage. The prefix is idempotent (a second heartbeat over the same snapshot does not double it), real transitions never carry it because send_status_message() builds the message fresh, and the UI uses it to suppress repeated ERROR popups. The worker tracks its own last emit time as well as the fan-out's recorded timestamp so it cannot tight-loop while the fan-out catches up. The brief is specifications/prompts/170-status-resend.md; the planned follow-up is a proto field is_resend that would replace the marker.

Subscriber lifecycle

NodeController.subscribe_node_status_stream(node_id, cntx, servicer_context) is the generator behind SubscribeNodeStatusStream; specifications/prompts/190-status-stream-subscriber.md pins it.

  1. Validate. NodeNotFoundError when node_id is not in status_queues (the router maps it to NeuraPublicRuntimeError).
  2. Register. Append a fresh queue.Queue to _status_subscribers[node_id] under the per-node lock. If no lock exists (a queue set without the controller's init path, used by tests) the generator reads the main queue directly.
  3. Arm release. servicer_context.add_callback(lambda: subscriber_queue.put_nowait(None)) injects the sentinel the moment the RPC terminates (client disconnect, cancel, deadline); when add_callback returns False because the RPC already ended, the sentinel is injected at once.
  4. Replay. Push a synthesized current-state item (resultMessage = "Current state: <STATE_NAME>", resultCode 0) read from node_instance.state_machine.get_state(); if that raises (instance torn down, reconfigure race) push _last_status_by_node_id[node_id] instead. This is why a UI that subscribes after ConfigureNode still sees CONFIGURED without waiting for a transition.
  5. Live items. subscriber_queue.get(block=True, timeout=5.0); on queue.Empty the generator checks servicer_context.is_active() and returns when the client is gone (_STREAM_LIVENESS_CHECK_INTERVAL_S = 5.0, the belt-and-braces path next to the termination callback). None ends the stream; every other item is yielded.
  6. Cleanup. The finally removes the subscriber queue from the list.

NodeServiceApi.SubscribeNodeStatusStream (api/grpc/router/node_router.py) skips items without a nodeId, stops when the servicer context is inactive, and maps each dict to SubscribeNodeStatusStreamResponse(nodeId, state, resultCode=str(...), resultMessage, graphStopRequested, graphStopMode), where the mode is translated from the item's "graphStopMode" string by _graph_stop_mode().

Graph stop requests

A node can ask the engine to end the whole graph run. The status stream is the control channel: SubscribeNodeStatusStreamResponse.graphStopRequested (bool, field 6, entities 2.68.0) carries the request, graphStopMode (GraphStopMode, field 7, entities 2.69.0) names the stop it wants, and the existing resultMessage carries the reason. The node never names a graph, because the engine already indexes node status by graph. node-misc's EndRunNode is the first user.

NodeBase.request_graph_stop(reason="", mode="hard") is the producer. It is platform-internal, listed in docs/public-api-exclusions.txt, and absent from the node-author API: an author writes a node that ends the run by using EndRunNode, not by calling this. Lifecycle and states is where the guide describes the behaviour an author sees. It returns False without queueing when the status stream is not open or the run has already ended, and otherwise puts {"nodeId", "state", "resultCode": 0, "resultMessage": "Graph stop requested: <reason>", "graphStopRequested": True, "graphStopMode": "<mode>"} on the status queue and returns True. The engine's answer depends on graphStopMode on the same status item. hard, and a caller that omits the mode, is stop-and-cleanup (stop_and_cleanup_node_graph): every node is stopped and the graph is removed. Only soft soft-stops (stop_execution_node_graph): nodes return to CONFIGURED and the graph stays loaded. Unset on the wire means hard, so a caller that wants the graph to survive has to name the soft stop.

Call it synchronously from on_execute, which is what EndRunNode does. The _run_active guard it checks carries no run identity: it says that some run is live, not which one. On the on_execute thread that is enough, because the run cannot be replaced while the hook is still running. A caller on a background thread has no such guarantee. It can pass the guard after its own run ended and the next one was armed, and so raise a request that belongs to a run which is already over. Nothing on the engine side catches that: the engine ties a request to the run that was current when it read the request off the status queue, so a request raised after the next run was armed is acted on against that new run and ends it. The on_execute rule is what keeps the request tied to the right run. The per-graph status queue is FIFO, so a request raised inside the hook reaches the engine ahead of the node's own CONFIGURED report, and the next run does not start until every node has reported CONFIGURED. Putting run identity on the wire, a run id handed to each node at arming and echoed back with the request, is what would make a background-thread caller safe; it is not in place today.

The request is edge-triggered, and keeping it that way is the whole design:

Concern How it is handled
Heartbeat resend _record_last_status_snapshot() pops graphStopRequested and graphStopMode before writing _last_status_by_node_id. The heartbeat re-emits that snapshot every quiet second, so a flag surviving into it would re-ask the engine to end the run once per second for the life of the node.
Late-subscriber replay Same strip, same reason. An engine reconnecting mid-run reads the replay buffer; it must not be handed a stop request for a run nobody asked to end. Stripping at the single write point of the buffer, rather than inside _heartbeat_worker, is what makes this hold for the replay path and for the /admin/node/status last_status view as well.
Repeat requests None are needed. Delivery is best effort and the engine latches per graph, so a second request during the same stop is a no-op there.

The engine advertises whether it acts on the flag: ArmNodeForRunRequest.supportsGraphStopRequest (bool, field 3). NodeServiceApi.ArmNodeForRun passes it to NodeController.arm_node_for_run(), which passes it to NodeBase.arm_for_run(supports_graph_stop_request=...), where it is stored for the run. configure() also calls arm_for_run(), without the flag, so a run is treated as unsupported until the engine itself arms it. That is the right default for an engine older than the field, which never sends ArmNodeForRun at all. When the capability is false request_graph_stop() logs a warning naming the missing advertisement and sends the request anyway: an old engine drops the unknown field, so the cost is one log line and the node behaves identically on both engine versions.

Health stream

Node side

  • initialize(status_queue, node_id, health_queue=None) stores the health queue and clears _last_health_snapshot.
  • configure() ends with _push_current_health() (forces one snapshot through even if unchanged) and _start_health_monitor(). The monitor thread health-monitor-<node_id> runs _health_monitor_worker: every health_stream_check_interval_s (default 10.0 s; 0 or negative disables the thread) it calls get_health_check() and send_health_update(is_healthy, message); an exception in the check is reported as (False, "Health check failed: ...").
  • get_health_check() clears _health_check_message, calls the author's on_health_check(), and returns (bool, message) with Healthy / Unhealthy as the default message. It never raises. Each sample also arms or cancels the optional unhealthy-escalation waiter (escalate_unhealthy_to_error). _stop_health_monitor() cancels that waiter.
  • When opted in, a running node that stays unhealthy for unhealthy_escalate_after_s (default 7.0 s) moves to ERROR and fires the Error trigger once (err_type=HealthFaultEscalation). See Escalate unhealthy to ERROR.
  • send_health_update(is_healthy, message) returns silently without a queue or node id, deduplicates against _last_health_snapshot, and put_nowaits {"nodeId", "isHealthy", "resultMessage"}; a full queue logs a warning and drops.
  • _end_health_stream(), a step of stop(), stops the monitor, clears the snapshot, puts the None sentinel and drops the queue reference. The next configure() also restarts the monitor, so a reconfigure never leaves two monitors running.

Controller side

__get_health_queue() creates the queue and a fan-out thread whose on_status_item is _record_last_health_snapshot. subscribe_node_health_stream() follows the status generator step for step, with one difference in the replay: it calls node_instance._push_current_health(), which runs a real health check and pushes the result through the main queue (so every current subscriber receives it), falling back to _last_health_by_node_id[node_id] on the subscriber's own queue when the instance is unavailable. The router maps items to SubscribeNodeHealthStreamResponse(nodeId, isHealthy, resultMessage).

Ending streams and releasing workers

Three paths end a subscriber's stream, all through the None sentinel: the node's own stop (end_status_stream() and _end_health_stream()), the RPC termination callback, and _end_streams_for_node() when initialize_node() releases a stale generation of the same logical node. The 5 s liveness check covers a client that vanished without a clean cancel.

Each open stream pins one gRPC worker thread for its whole lifetime, and the engine opens both streams per initialized node, so grpc_server_max_workers (NodeServiceConfig, default 50, passed to grpc.server(ThreadPoolExecutor(max_workers=...)) in node_manager_service.py) bounds how many nodes one node service can serve. Size it at roughly twice the expected node count plus headroom for unary RPCs. Before 2.29.2 the pool was hard-coded to 10 and abandoned streams never released their worker, which is how a long-running node service stopped answering InitializeNode after engine restarts.

Wire formats

Internal queue items already use the proto field names:

# status_queue item (StateMachine.send_status_message, heartbeat copies carry "[resend] " in resultMessage)
{"nodeId": "<wire id>", "state": ExecutionState.EXECUTION_STATE_CONFIGURED, "resultCode": 0, "resultMessage": "State of node with ID ... changed from EXECUTION_STATE_IDLE to EXECUTION_STATE_CONFIGURED"}

# status_queue item (NodeBase.request_graph_stop); the extra key is stripped before the snapshot buffer stores it
{"nodeId": "<wire id>", "state": ExecutionState.EXECUTION_STATE_RUNNING, "resultCode": 0, "resultMessage": "Graph stop requested: task finished", "graphStopRequested": True, "graphStopMode": "hard"}

# health_queue item (NodeBase.send_health_update)
{"nodeId": "<wire id>", "isHealthy": True, "resultMessage": "Healthy"}

The health stream on the node service exists since SDK 2.23.0 and needs neuraverse_entities_apis_messages 2.23.0 or newer for SubscribeNodeHealthStream; the C++ SDK gained it in 2.29.0. Graph-level engine responses use resultMessage for the health text, not message.

Specifications and tests

  • Briefs: specifications/prompts/170-status-resend.md, specifications/prompts/190-status-stream-subscriber.md, specifications/prompts/160-reconfigure-lifecycle.md.
  • In-process specs: specifications/specs/status-resend/ (resend marker, heartbeat worker) and specifications/specs/status-stream-subscriber/ (subscribe and receive, multiple subscribers fan out, disconnect on sentinel, unknown node rejection, replay buffer fallback), run by tests/specs/test_status_resend_specs.py and tests/specs/test_status_stream_subscriber_specs.py.
  • Unit tests: tests/test_stream_release_and_stale_generations.py, tests/test_node_router_full.py.

See also