Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(routines): honor live form schemas and workflow owner state

rubenluetke10-beep99a6e5504409
diff --git a/jarvis/society/routine_runner.py b/jarvis/society/routine_runner.py
index 2e0720af38..3307be6d64 100644
--- a/jarvis/society/routine_runner.py
+++ b/jarvis/society/routine_runner.py
@@ -9,9 +9,8 @@ from .chat_binding import ensure_session
from .routines import agent_id_from_tags
-async def run_owned_routine(
- runtime: Any, task_id: str, tags: tuple[str, ...], prompt: str, cancel_token: Any = None
-) -> str | None:
+async def guard_owned_routine(runtime: Any, tags: tuple[str, ...]) -> Any:
+ """Check live owner availability for both chat and native workflow actions."""
agent_id = agent_id_from_tags(tags)
if agent_id is None:
return None
@@ -20,6 +19,15 @@ async def run_owned_routine(
agent = await runtime.roster.get(agent_id)
if agent is None or str(agent.state) != "active":
raise RuntimeError("The routine owner is unavailable or paused")
+ return agent
+
+
+async def run_owned_routine(
+ runtime: Any, task_id: str, tags: tuple[str, ...], prompt: str, cancel_token: Any = None
+) -> str | None:
+ agent = await guard_owned_routine(runtime, tags)
+ if agent is None:
+ return None
service = runtime.chat_service()
if service is None:
raise RuntimeError("The canonical chat service is unavailable")
diff --git a/jarvis/tasks/runner.py b/jarvis/tasks/runner.py
index 8cb97a6d4b..6fb92ff099 100644
--- a/jarvis/tasks/runner.py
+++ b/jarvis/tasks/runner.py
@@ -133,6 +133,7 @@ class TaskRunner:
owned_agent_runner: Callable[[str, tuple[str, ...], str, Any], Awaitable[str | None]]
| None = None,
workflow_services: Any = None,
+ owned_action_guard: Callable[[tuple[str, ...]], Awaitable[None]] | None = None,
) -> None:
self._store = store
self._bus = bus
@@ -148,6 +149,7 @@ class TaskRunner:
self._result_sink = result_sink
self._owned_agent_runner = owned_agent_runner
self._workflow_services = workflow_services
+ self._owned_action_guard = owned_action_guard
# ------------------------------------------------------------------
@@ -294,6 +296,11 @@ class TaskRunner:
elif action.kind == "workflow":
import json
+ tags = tuple(str(tag) for tag in spec.tags)
+ if any(tag.startswith("agent:") for tag in tags):
+ if self._owned_action_guard is None:
+ raise RuntimeError("The routine owner's action guard is unavailable")
+ await self._owned_action_guard(tags)
services = self._workflow_services() if self._workflow_services else (None, None)
row = await services[0].get_workflow(str(action.workflow_id)) if services[0] else None
if row is None or not row.get("enabled") or services[1] is None:
diff --git a/jarvis/ui/web/frontend/src/components/society/card/SourceControls.test.tsx b/jarvis/ui/web/frontend/src/components/society/card/SourceControls.test.tsx
new file mode 100644
index 0000000000..e0a69a2327
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/card/SourceControls.test.tsx
@@ -0,0 +1,24 @@
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { afterEach, expect, test, vi } from "vitest";
+import { SourceControls } from "./SourceControls";
+
+afterEach(() => { cleanup(); vi.unstubAllGlobals(); });
+
+test("a form updated through chat discards input from its previous schema", async () => {
+ const requests: Record<string, unknown>[] = [];
+ vi.stubGlobal("fetch", vi.fn(async (_url: string, init?: RequestInit) => {
+ if (init?.method === "POST") requests.push(JSON.parse(String(init.body)));
+ return { ok: true, json: async () => ({ status: "queued" }) } as Response;
+ }));
+ const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
+ const view = (name: string) => <QueryClientProvider client={client}><SourceControls taskId="form-1" source={{ kind: "form", form_fields: { [name]: { label: name, kind: "text", required: true, choices: [] } } }} /></QueryClientProvider>;
+ const mounted = render(view("old_field"));
+ fireEvent.click(await screen.findByRole("button", { name: "Trigger input" }));
+ fireEvent.change(screen.getByLabelText("old_field"), { target: { value: "stale" } });
+ mounted.rerender(view("new_field"));
+ fireEvent.click(await screen.findByRole("button", { name: "Trigger input" }));
+ fireEvent.change(screen.getByLabelText("new_field"), { target: { value: "current" } });
+ fireEvent.submit(screen.getByLabelText("new_field").closest("form")!);
+ await waitFor(() => expect(requests).toEqual([{ payload: { "new_field": "current" } }]));
+});
diff --git a/jarvis/ui/web/frontend/src/components/society/card/SourceControls.tsx b/jarvis/ui/web/frontend/src/components/society/card/SourceControls.tsx
index daf56badc4..8200075bef 100644
--- a/jarvis/ui/web/frontend/src/components/society/card/SourceControls.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/card/SourceControls.tsx
@@ -5,6 +5,10 @@ import { useLocaleChunk, useT } from "@/i18n";
type Source = { kind: string; form_fields?: Record<string, { label: string; kind: string; required: boolean; choices: string[] }> };
export function SourceControls({ taskId, source }: { taskId: string; source: Source }) {
+ return <SourceInputs key={`${taskId}:${JSON.stringify(source)}`} taskId={taskId} source={source} />;
+}
+
+function SourceInputs({ taskId, source }: { taskId: string; source: Source }) {
const t = useT();
useLocaleChunk("society");
const cache = useQueryClient();
diff --git a/jarvis/ui/web/server.py b/jarvis/ui/web/server.py
index 41af99c44f..3dc49c8cbd 100644
--- a/jarvis/ui/web/server.py
+++ b/jarvis/ui/web/server.py
@@ -3372,6 +3372,7 @@ class WebServer:
auto_approver=auto_approver,
result_sink=self._society_routine_result,
owned_agent_runner=self._run_society_routine,
+ owned_action_guard=self._guard_society_routine_action,
workflow_services=workflow_services,
)
scheduler = TaskScheduler(
@@ -3583,6 +3584,17 @@ class WebServer:
except Exception: # noqa: BLE001 — the task already recorded its result; delivery is best effort
logger.warning("society: routine result not delivered to {}", agent_id, exc_info=True)
+ async def _guard_society_routine_action(self, tags: tuple[str, ...]) -> None:
+ from jarvis.society.routine_runner import guard_owned_routine
+ from jarvis.society.runtime import current_runtime
+
+ runtime = current_runtime()
+ if runtime is None:
+ runtime = self._build_society_runtime()
+ self.app.state.society = runtime
+ await runtime.ensure_started()
+ await guard_owned_routine(runtime, tags)
+
async def _run_society_routine(
self, task_id: str, tags: tuple[str, ...], prompt: str, cancel: Any
) -> str | None:
diff --git a/tests/contract/test_trigger_sources.py b/tests/contract/test_trigger_sources.py
index 93af5adc07..2e8f29521a 100644
--- a/tests/contract/test_trigger_sources.py
+++ b/tests/contract/test_trigger_sources.py
@@ -70,9 +70,7 @@ async def finish(scheduler):
def test_form_large_integer_does_not_overflow_float_validation():
from jarvis.tasks.source_schema import validate_form
- form = SourceSettings(
- kind="form", form_fields={"count": {"label": "Count", "kind": "number"}}
- )
+ form = SourceSettings(kind="form", form_fields={"count": {"label": "Count", "kind": "number"}})
validate_form(form, {"count": 10**400})
with pytest.raises(ValueError):
validate_form(form, {"count": float("inf")})
@@ -418,3 +416,68 @@ async def test_native_workflow_dispatch_receives_trusted_ancestry(stack):
assert calls[0][1]["input_data"] == {"value": 7}
assert calls[0][2] == ("task:" + tid,)
assert current_trigger_path.get() == ()
+
+
+ "owner_state,halted,with_guard,allowed",
+ [
+ ("active", False, True, True),
+ ("paused", False, True, False),
+ ("active", True, True, False),
+ ("active", False, False, False),
+ ],
+)
+async def test_owned_workflow_dispatch_honors_live_owner_state(
+ stack, owner_state, halted, with_guard, allowed
+):
+ from types import SimpleNamespace
+ from uuid import uuid4
+
+ from jarvis.society.routine_runner import guard_owned_routine
+
+ store, scheduler, _ = stack
+ calls = []
+
+ class Workflows:
+ async def get_workflow(self, workflow_id):
+ return {"id": workflow_id, "enabled": True}
+
+ async def trigger(self, workflow_id, **kwargs):
+ calls.append(workflow_id)
+ return "child-run"
+
+ class Roster:
+ async def get(self, agent_id):
+ return SimpleNamespace(state=owner_state)
+
+ class State:
+ async def kill_switch(self):
+ return halted
+
+ runtime = SimpleNamespace(roster=Roster(), store=State())
+
+ async def guard(tags):
+ await guard_owned_routine(runtime, tags)
+
+ workflows = Workflows()
+ scheduler._workflow_services = lambda: (workflows, workflows)
+ scheduler.attach_runner(
+ TaskRunner(
+ store,
+ EventBus(),
+ workflow_services=lambda: (workflows, workflows),
+ owned_action_guard=guard if with_guard else None,
+ )
+ )
+ tid = await scheduler.schedule(
+ TaskSpec(
+ title="Owned workflow",
+ trigger=source("manual"),
+ action=WorkflowAction(workflow_id=uuid4()),
+ tags=("society", "agent:owner"),
+ )
+ )
+ await scheduler.invoke_source(tid, {}, "owner-check", mode="manual")
+ await finish(scheduler)
+ assert bool(calls) is allowed
+ assert bool((await store.get(tid))["last_error"]) is not allowed