Skip to content

Self-improving AI Employees for everyone

feat(temporal): route per-type activities to declared queues when pool on (Wave 16.3)

trohitgd4b55c475451
diff --git a/server/services/temporal/workflow.py b/server/services/temporal/workflow.py
index 0c6af6a4..57f131e5 100644
--- a/server/services/temporal/workflow.py
+++ b/server/services/temporal/workflow.py
@@ -451,14 +451,17 @@ class MachinaWorkflow:
"""Resolve (activity_name, task_queue) for a node type.
F4.A: when ``settings.temporal_per_type_dispatch`` is on AND the
- plugin class is registered, returns
- ``("node.{type}.v{version}", None)`` so the activity is scheduled
- by per-type name but stays on the workflow's default task queue.
- The default queue is what ``TemporalWorkerManager`` polls today;
- per-queue routing (``cls.task_queue``) becomes meaningful only
- once ``TemporalWorkerPool`` is wired with one worker per queue
- — until then, returning ``cls.task_queue`` would schedule the
- activity to a queue no worker polls and the workflow would hang.
+ plugin class is registered, returns the per-type activity name
+ ``node.{type}.v{version}``.
+
+ Wave 16.3: the returned queue is ``cls.task_queue`` when
+ ``settings.temporal_worker_pool_enabled`` is on (each declared
+ queue then has a dedicated ``TemporalWorkerPool`` worker polling
+ it — wired in main.py right after the manager starts), or
+ ``None`` otherwise so the activity stays on the workflow's
+ default queue, which the single ``TemporalWorkerManager`` polls.
+ The flag is the rollback channel: flipping it off routes every
+ activity back to the manager worker without code changes.
Falls back to ``("execute_node_activity", None)`` when:
- the flag is off (preserves pre-F4.A behavior exactly), OR
@@ -474,14 +477,16 @@ class MachinaWorkflow:
from core.config import Settings
from services.node_registry import get_node_class
- if not Settings().temporal_per_type_dispatch:
+ settings = Settings()
+ if not settings.temporal_per_type_dispatch:
return "execute_node_activity", None
cls = get_node_class(node_type)
if cls is None:
return "execute_node_activity", None
- return f"node.{cls.type}.v{cls.version}", None
+ queue = cls.task_queue if settings.temporal_worker_pool_enabled else None
+ return f"node.{cls.type}.v{cls.version}", queue
async def _wait_any_complete(self, running: Dict[str, Any]) -> tuple:
"""Wait for any activity to complete, return (node_id, result).
diff --git a/server/tests/temporal/test_dispatch.py b/server/tests/temporal/test_dispatch.py
index df37b14c..adccaa27 100644
--- a/server/tests/temporal/test_dispatch.py
+++ b/server/tests/temporal/test_dispatch.py
@@ -4,7 +4,9 @@ Locks the orchestrator's `_resolve_activity` contract:
- flag OFF (default): every node routes to legacy `execute_node_activity`
- flag ON + registered plugin: routes to `node.{type}.v{version}`
- flag ON + unknown type: falls back to legacy
- - task_queue is always None (per-queue routing waits for TemporalWorkerPool)
+ - task_queue is None while `temporal_worker_pool_enabled` is off;
+ `cls.task_queue` once the pool flag is on (Wave 16.3 — one
+ TemporalWorkerPool worker per declared queue polls it)
If these invariants drift the Temporal worker will either silently lose
per-type activity wiring (regression to single-dispatcher) or schedule
@@ -29,18 +31,21 @@ def workflow_instance() -> MachinaWorkflow:
return MachinaWorkflow()
-def _set_flag(value: bool):
+def _set_flag(value: bool, *, pool: bool = False):
"""Patch the ``Settings`` import used by ``_resolve_activity``.
``tests/conftest.py`` stubs ``core.config.Settings`` as a MagicMock,
so we can't go through the real env var. Instead, swap the lazy
import inside the resolver for a SimpleNamespace returning the
- desired flag value. Same effective contract — the resolver only
- reads ``Settings().temporal_per_type_dispatch``.
+ desired flag values. Same effective contract — the resolver reads
+ ``temporal_per_type_dispatch`` + ``temporal_worker_pool_enabled``.
"""
def fake_settings_factory():
- return SimpleNamespace(temporal_per_type_dispatch=value)
+ return SimpleNamespace(
+ temporal_per_type_dispatch=value,
+ temporal_worker_pool_enabled=pool,
+ )
return patch("core.config.Settings", side_effect=lambda: fake_settings_factory())
@@ -74,8 +79,8 @@ class TestResolveActivityFlagOn:
with _set_flag(True):
name, queue = workflow_instance._resolve_activity("pythonExecutor")
assert name == "node.pythonExecutor.v1"
- # F4.A intentionally returns None for queue — per-queue routing
- # depends on TemporalWorkerPool which isn't wired yet.
+ # queue stays None while temporal_worker_pool_enabled is off —
+ # the single manager worker polls only the default queue.
assert queue is None
def test_agent_routes_per_type(self, workflow_instance):
@@ -104,6 +109,38 @@ class TestResolveActivityFlagOn:
assert name == f"node.coding_agent.v{cls.version}"
+class TestResolveActivityPoolRouting:
+ """Wave 16.3: with BOTH flags on, the resolver returns the plugin's
+ declared ``cls.task_queue`` so per-type activities land on their
+ specialised TemporalWorkerPool worker. Pool flag off = None (the
+ rollback channel)."""
+
+ def test_pool_on_routes_to_declared_queue(self, workflow_instance):
+ from services.node_registry import get_node_class
+
+ with _set_flag(True, pool=True):
+ name, queue = workflow_instance._resolve_activity("pythonExecutor")
+ assert name == "node.pythonExecutor.v1"
+ assert queue == get_node_class("pythonExecutor").task_queue
+ assert queue == "code-exec"
+
+ def test_pool_on_ai_agent_routes_to_ai_heavy(self, workflow_instance):
+ with _set_flag(True, pool=True):
+ _, queue = workflow_instance._resolve_activity("aiAgent")
+ assert queue == "ai-heavy"
+
+ def test_pool_off_is_the_rollback_channel(self, workflow_instance):
+ with _set_flag(True, pool=False):
+ _, queue = workflow_instance._resolve_activity("pythonExecutor")
+ assert queue is None
+
+ def test_pool_on_unknown_type_still_falls_back_to_legacy(self, workflow_instance):
+ with _set_flag(True, pool=True):
+ name, queue = workflow_instance._resolve_activity("nonExistentType")
+ assert name == "execute_node_activity"
+ assert queue is None
+
+
class TestAgentWorkflowDispatch:
"""F4.B: when the agent-workflow flag is on AND the node type is in
AGENT_WORKFLOW_TYPES, dispatch must route through the child workflow
@@ -118,6 +155,7 @@ class TestAgentWorkflowDispatch:
return SimpleNamespace(
temporal_per_type_dispatch=per_type,
temporal_agent_workflow_enabled=agent_wf,
+ temporal_worker_pool_enabled=False,
)
return _patch("core.config.Settings", side_effect=lambda: fake_settings())