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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(society): a drill file that reproduces a slow start in a running app (#573)
Ruben Lütke47a0a57c450d
diff --git a/docs/agent-society/team-leads.md b/docs/agent-society/team-leads.mdindex b9ed23bd07..6f539ddb4e 100644--- a/docs/agent-society/team-leads.md+++ b/docs/agent-society/team-leads.md@@ -113,3 +113,23 @@ stuck work and starts standing duties the mission names. A check-in is anordinary agent routine tagged `team-checkin:<team id>`, so it appears with thelead's other routines and follows the same rules for which seat may runbackground work.++## Drills++One failure cannot be produced on demand through the app: a start that takes+longer than the board waits for it. A drill file makes it reproducible in a+running app, with a real model and without changing any code.++Create `society_drill.json` in the app's data directory:++```json+{"slow_start_s": 8}+```++While the file exists, every start of a member's turn is held for that many+seconds (at most 30) after the turn has begun. The board gives up on the start+after five seconds, so the task stays `assigned` although the member is+working. A few minutes later the sweep reads the member's finished turn from+its chat, the task becomes `done`, and the lead is woken with the result. The+file is read on every start: delete it and the next start is normal again, no+restart needed. Each held start is logged as `society drill: holding the start`.diff --git a/jarvis/society/runtime.py b/jarvis/society/runtime.pyindex fb2f939f25..2405f63932 100644--- a/jarvis/society/runtime.py+++ b/jarvis/society/runtime.py@@ -81,6 +81,9 @@ _LEAD_INCOMING_TYPES: Final[frozenset[MsgType]] = frozenset({MsgType.SAY, MsgType.QUERY, MsgType.ANSWER, MsgType.PROPOSE})_WATCH_EVENT_POLL_SECONDS: Final[float] = 2.0+#: The drill switch: a file in the data dir that injects a named fault.+_DRILL_FILE: Final[str] = "society_drill.json"+_DRILL_MAX_S: Final[float] = 30.0_current: SocietyRuntime | None = None@@ -826,6 +829,25 @@ class SocietyRuntime:return await self.team_leads.accept_assignment(target, env)return await self._dispatch_chat(target, env)+ def _drill_seconds(self, key: str) -> float:+ """A fault the person switched on for a drill, in seconds; ``0`` = off.++ Read from ``<data dir>/society_drill.json`` on every use, so a drill+ starts and ends without a restart and is off whenever the file is+ absent. Capped: a drill delays one start, it never hangs the society.+ """+ path = self._data_dir / _DRILL_FILE+ if not path.is_file():+ return 0.0+ try:+ import json++ value = float(json.loads(path.read_text(encoding="utf-8")).get(key) or 0)+ except (OSError, ValueError, TypeError, AttributeError):+ log.warning("society drill: %s is unreadable; no fault is injected", path)+ return 0.0+ return max(0.0, min(value, _DRILL_MAX_S))+async def _dispatch_chat(self, target: AgentRecord, env: SocietyEnvelope) -> str:svc = self._get_chat()if svc is None:@@ -866,6 +888,17 @@ class SocietyRuntime:raisefinally:incoming_context.reset(token)+ hold = self._drill_seconds("slow_start_s")+ if hold:+ # A drill the person switched on (docs/agent-society/team-leads.md):+ # the turn is running, and this start now takes long enough for the+ # board to give up on it, exactly as a slow start does.+ log.warning("society drill: holding the start of %s for %.0f s", target.name, hold)+ try:+ await asyncio.sleep(hold)+ except asyncio.CancelledError:+ svc.unsubscribe(session.session_id, queue)+ raiserun_id = f"turn:{turn_id}"watcher = asyncio.create_task(self._watch_turn(svc, session.session_id, queue, turn_id, run_id, target, env)diff --git a/tests/fakes/team_chat.py b/tests/fakes/team_chat.pyindex 5b284e1e4c..d12cb55ab5 100644--- a/tests/fakes/team_chat.py+++ b/tests/fakes/team_chat.py@@ -72,6 +72,8 @@ class TeamChatFake:turn_id = f"turn-{len(self.sent)}"self.sent.append((session_id, text, kwargs, turn_id))self.busy.add(session_id)+ # As the real service does: the prompt of a turn is part of the chat.+ self._emit(session_id, "user_message", {"text": text})self._turns[session_id] = asyncio.create_task(self._run(session_id, turn_id, text, kwargs))diff --git a/tests/unit/society/test_team_lead.py b/tests/unit/society/test_team_lead.pyindex bb5ccf0d35..e70b331f19 100644--- a/tests/unit/society/test_team_lead.py+++ b/tests/unit/society/test_team_lead.py@@ -546,6 +546,12 @@ async def test_the_sweep_reports_a_run_that_died_silently(team):rt.scheduler.note_run_ended(task.run_id)await rt.store.update_team_task(task.task_id, {"updated_ms": 1})await leads.sweep()+ # The member's chat still runs that turn: it is not dead, so nobody is told so.+ assert (await leads.tasks(goal.goal_id))[0].state is TeamTaskState.RUNNING+ assert len(seen) == 1+ # Now the turn is gone without an ending in the chat: that is a silent death.+ svc.busy.discard(SCOUT)+ await leads.sweep()await until(_state_is(rt, goal.goal_id, TeamGoalState.FAILED))assert "The run ended without a result." in seen[1]@@ -659,6 +665,54 @@ async def test_a_lost_assignment_is_read_back_from_the_members_chat(team):assert len(await leads.tasks(goal_id)) == 1 and svc.prompts(SCOUT) == []+async def test_the_slow_start_drill_loses_the_start_and_the_sweep_recovers_it(+ team, tmp_path: Path, monkeypatch: pytest.MonkeyPatch+):+ """The drill file makes a real start outlast the board's patience."""+ from jarvis.society import bus++ rt, svc = team+ leads = rt.team_leads+ monkeypatch.setattr(bus, "_HANDLER_TIMEOUT_S", 0.05)+ (tmp_path / "society_drill.json").write_text('{"slow_start_s": 0.4}', encoding="utf-8")+ svc.replies[SCOUT] = "Found: three sources."+ seen: list[str] = []++ async def boss(text: str, kwargs: dict[str, Any]) -> str:+ seen.append(text)+ if len(seen) == 1:+ receipt = await leads.assign("boss", member="scout", title="Research", brief="Go.")+ assert receipt["state"] == "assigned" # the start was never confirmed+ return "Assigned."+ await leads.report("boss", status="done", summary="Scout found it.")+ return "Closed."++ svc.scripts[LEAD] = boss+ goal = await leads.start_goal("team", "Research it")+ await until(lambda: len(svc.prompts(SCOUT)) == 1 and svc.idle())+ task = (await leads.tasks(goal.goal_id))[0]+ # The member worked, yet the board holds no claim and no result for it.+ assert task.state is TeamTaskState.ASSIGNED and task.run_id == ""+ kinds = [e.msg_type for e in await rt.store.events_for_trace(task.trace_id)]+ assert kinds == [MsgType.ASSIGN]+ assert not rt.scheduler.running and len(seen) == 1++ await rt.store.update_team_task(task.task_id, {"updated_ms": 1})+ await leads.sweep()+ await until(_state_is(rt, goal.goal_id, TeamGoalState.DONE))+ done = (await leads.tasks(goal.goal_id))[0]+ assert done.state is TeamTaskState.DONE and done.result == "Found: three sources."+ assert len(await leads.tasks(goal.goal_id)) == 1 and len(svc.prompts(SCOUT)) == 1++ # Without the file the same start is claimed as usual.+ (tmp_path / "society_drill.json").unlink()+ assert rt._drill_seconds("slow_start_s") == 0.0 # noqa: SLF001+ (tmp_path / "society_drill.json").write_text("not json", encoding="utf-8")+ assert rt._drill_seconds("slow_start_s") == 0.0 # noqa: SLF001+ (tmp_path / "society_drill.json").write_text('{"slow_start_s": 900}', encoding="utf-8")+ assert rt._drill_seconds("slow_start_s") == 30.0 # noqa: SLF001++async def test_a_lost_assignment_that_failed_or_never_arrived_is_reported_blocked(team):rt, svc = teamleads, goal_id, task, say = await _lost_assignment(rt, svc)