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
"""New coding requests cannot borrow, correct, or replay another pane's work."""
from __future__ import annotations
import asyncio
from types import SimpleNamespace
from uuid import uuid4
import pytest
from dodaios.agentic_ide.dispatch_intent import dispatch_context
from dodaios.agentic_ide.orchestration import WorkspaceOrchestrator
from dodaios.agentic_ide.session import SessionError
from dodaios.brain.tool_gateway import BrainSupervisorToolGateway
from dodaios.brain.workspace_tool import WorkspaceOrchestrationTool
from dodaios.core.protocols import ExecutionContext
from dodaios.live.state import LiveLedger
from dodaios.live.tools import LiveTools
from tests.contract import test_workspace_orchestration as support
rig = support.rig
runnable = support.runnable
def context(text="Start a new Codex session here to fix audio mute.", revision=1):
return ExecutionContext(
uuid4(),
text,
{
"live_session_id": "voice-test",
"task_revision": revision,
"workspace_user_utterance": text,
},
None,
)
def create_args(**extra):
return {
"action": "create",
"workspace": "Personal Jarvis",
"cli": "codex",
"prompt": "Fix output mute",
**extra,
}
@pytest.mark.parametrize(
"text",
[
"Start a new Codex session here to fix audio mute.",
"Fix audio mute in a new Codex agent.",
"Open two new Claude Code agents.",
"Starte einen neuen Codex Agenten hier und repariere Audio.", # i18n-allow
"Open a new terminal",
"Create a new OpenCode session",
],
)
def test_new_intent_comes_from_user_words(text):
assert dispatch_context(text, {}, "turn")["_requires_new"]
@pytest.mark.parametrize(
"text",
[
"Create a new button in the Codex session.",
"Send this to the existing agent.",
"Do not create a new Codex session; use the existing pane.",
],
)
def test_task_content_and_negation_do_not_request_new_panes(text):
assert not dispatch_context(text, {}, "turn")["_requires_new"]
def test_latest_voice_segment_overrides_old_new_request_and_scope_ignores_asr_edits():
cfg = {
"live_session_id": "voice",
"task_revision": 3,
"workspace_user_utterance": "Send this to the existing agent.",
}
first = dispatch_context("Start a new Codex session", cfg, "call-a")
assert not first["_requires_new"]
assert (
first["_dispatch_scope"]
== dispatch_context(
"older context",
{**cfg, "workspace_user_utterance": "Corrected caption"},
"call-b",
)["_dispatch_scope"]
)
assert (
first["_dispatch_scope"]
!= dispatch_context(
"older context",
{**cfg, "task_revision": 4},
"call-b",
)["_dispatch_scope"]
)
@pytest.mark.parametrize("activity", ["working", "idle", "starting"])
async def test_new_request_never_resolves_an_existing_pane(rig, activity):
orchestrator, registry, sessions = rig
for owner in registry.sessions:
owner.terminals[0].activity = activity
result = await WorkspaceOrchestrationTool(orchestrator).execute(
{"action": "resolve", "workspace": "Personal Jarvis"},
context(),
)
assert not result.success
assert result.output["status"] == "new_agent_required"
assert not sessions.calls
async def test_new_panes_ignore_stale_focused_target_and_retries_are_durable(rig, runnable):
orchestrator, registry, sessions = rig
old = await orchestrator.run({"action": "resolve"})
existing = {t.history_id for w in registry.sessions for t in w.terminals}
tool = WorkspaceOrchestrationTool(orchestrator)
args = create_args(terminal_id=old["target"]["terminal_id"], request_id=old["request_id"])
first = await tool.execute(args, context())
assert first.success, first
new_id = first.output["agents"][0]["terminal_id"]
assert new_id.removeprefix("pane:") not in existing
assert [c["terminal_id"] for c in sessions.calls] == [new_id]
reopened = WorkspaceOrchestrationTool(
WorkspaceOrchestrator(registry, sessions, orchestrator.ledger)
)
repeated = await reopened.execute(args, context())
assert repeated.output == first.output
assert len(sessions.calls) == 1
async def test_slow_start_retries_and_cancellation_keep_only_allocated_ids(rig, runnable):
orchestrator, registry, sessions = rig
entered, release = asyncio.Event(), asyncio.Event()
calls = []
async def slow(args):
calls.append(args)
entered.set()
await release.wait()
return {"delivery": "accepted", "submitted": True}
sessions.run = slow
tool = WorkspaceOrchestrationTool(orchestrator)
task = asyncio.create_task(tool.execute(create_args(count=2), context()))
await asyncio.wait_for(entered.wait(), 5)
registry._active = registry.sessions[-1].id
pending = await tool.execute(create_args(count=2), context())
assert pending.output["status"] == "uncertain"
created = {a["terminal_id"] for a in pending.output["agents"]}
assert {c["terminal_id"] for c in calls} <= created
task.cancel()
with pytest.raises(asyncio.CancelledError):
await task
after = await tool.execute(create_args(count=2), context())
assert after.output == pending.output
assert len(calls) == 2
assert sum(len(w.terminals) for w in registry.sessions) == 4
async def test_partial_multi_target_uncertainty_cannot_fan_out_recovery(rig, runnable):
orchestrator, registry, sessions = rig
calls = []
async def mixed(args):
calls.append(args)
if len(calls) == 1:
raise RuntimeError("lost receipt after write")
return {"delivery": "accepted", "submitted": True}
sessions.run = mixed
tool = WorkspaceOrchestrationTool(orchestrator)
first = await tool.execute(create_args(count=2), context())
assert {d["status"] for d in first.output["deliveries"]} == {"accepted", "uncertain"}
assert not first.success
for owner in registry.sessions:
for term in owner.terminals:
result = await tool.execute(
{
"action": "send",
"project_id": owner.project_id,
"workspace_id": owner.id,
"terminal_id": "pane:" + term.history_id,
"prompt": "Correction: do the task",
},
context(),
)
assert not result.success
assert len(calls) == 2
retry = await tool.execute(create_args(count=2), context())
assert retry.output == first.output
assert len(calls) == 2
async def test_new_empty_pane_can_receive_one_assignment_only(rig, runnable):
tool = WorkspaceOrchestrationTool(rig[0])
created = await tool.execute(create_args(prompt=""), context())
pane = created.output["agents"][0]
args = {
"action": "send",
"project_id": created.output["project_id"],
"workspace_id": created.output["workspace_id"],
"terminal_id": pane["terminal_id"],
"request_id": pane["request_id"],
"prompt": "Task",
}
first = await tool.execute(args, context())
assert first.success
assert (await tool.execute(args, context())).output == first.output
assert not (
await tool.execute({**args, "prompt": "Correction: another task"}, context())
).success
assert len(rig[2].calls) == 1
async def test_separate_requests_with_same_brief_have_disjoint_new_targets(rig, runnable):
tool = WorkspaceOrchestrationTool(rig[0])
a, b = await asyncio.gather(
tool.execute(create_args(), context(revision=1)),
tool.execute(create_args(), context(revision=2)),
)
assert a.output["agents"][0]["terminal_id"] != b.output["agents"][0]["terminal_id"]
assert len({c["terminal_id"] for c in rig[2].calls}) == 2
async def test_request_id_from_another_pane_is_rejected_even_when_both_exist(rig):
a, b = [await rig[0].run({"action": "resolve", "workspace": w.id}) for w in rig[1].sessions]
with pytest.raises(ValueError, match="conflict"):
await rig[0].run(
{"action": "send", **b["target"], "request_id": a["request_id"], "prompt": "Task"}
)
assert not rig[2].calls
async def test_fresh_request_id_cannot_replay_uncertain_write_after_restart(rig):
selected = await rig[0].run({"action": "resolve"})
args = {
"action": "send",
**selected["target"],
"request_id": selected["request_id"],
"prompt": "Task",
}
rig[2].fail = True
assert (await rig[0].run(args))["status"] == "uncertain"
reopened = WorkspaceOrchestrator(rig[1], rig[2], rig[0].ledger)
assert (await reopened.run({**args, "request_id": uuid4().hex}))["status"] == "uncertain"
assert len(rig[2].calls) == 1
async def test_used_request_id_cannot_silently_become_a_correction(rig):
selected = await rig[0].run({"action": "resolve"})
args = {
"action": "send",
**selected["target"],
"request_id": selected["request_id"],
"prompt": "Task",
}
assert (await rig[0].run(args))["status"] == "accepted"
result = await rig[0].run({**args, "prompt": "Correction: abandon your assignment"})
assert result["success"] is False
assert len(rig[2].calls) == 1
async def test_creation_payload_change_and_earlier_idle_resolve_cannot_reassign(rig, runnable):
old = await rig[0].run({"action": "resolve"})
tool = WorkspaceOrchestrationTool(rig[0])
first = await tool.execute(create_args(), context())
changed = await tool.execute(create_args(prompt="Correction: new task"), context())
assert not changed.success
bad = await tool.execute(
{
"action": "send",
**old["target"],
"request_id": old["request_id"],
"prompt": "Fix output mute",
},
context(),
)
assert not bad.success
assert rig[2].calls[0]["terminal_id"] == first.output["agents"][0]["terminal_id"]
assert len(rig[2].calls) == 1
async def test_partial_allocation_keeps_created_ids_without_repeating_first_group(
rig,
runnable,
monkeypatch,
):
original = rig[1].add_terminals
async def add(count, *, agent, workspace_id):
if agent == "claude":
raise SessionError("Later group could not start")
return await original(count, agent=agent, workspace_id=workspace_id)
monkeypatch.setattr(rig[1], "add_terminals", add)
tool = WorkspaceOrchestrationTool(rig[0])
args = create_args(agents=[{"cli": "codex", "count": 1}, {"cli": "claude", "count": 1}])
result = await tool.execute(args, context())
assert not result.success
assert result.output["creation_error"] == "Later group could not start"
assert len(result.output["agents"]) == 1
assert rig[2].calls[0]["terminal_id"] == result.output["agents"][0]["terminal_id"]
assert (await tool.execute(args, context())).output == result.output
assert len(rig[2].calls) == 1
async def test_explicit_invalid_project_id_cannot_fall_back_to_named_workspace(rig, runnable):
result = await rig[0].run(create_args(project_id="missing-project"))
assert result["status"] == "stale_target"
assert sum(len(w.terminals) for w in rig[1].sessions) == 2
assert not rig[2].calls
async def test_live_retries_use_host_request_scope_and_old_revision_cannot_act(
rig,
runnable,
tmp_path,
):
class Executor:
async def execute(self, tool, args, **kwargs):
return await tool.execute(
args,
ExecutionContext(
kwargs["trace_id"],
kwargs["user_utterance"],
kwargs["config_snapshot"],
None,
),
)
tool = WorkspaceOrchestrationTool(rig[0])
gateway = BrainSupervisorToolGateway(
SimpleNamespace(_tools={}, _tool_executor=Executor()),
workspace_tool=tool,
)
ledger = LiveLedger(tmp_path / "live-dispatch.db")
try:
live = LiveTools(gateway, ledger, "voice", language="en", backend_model="")
live.user_text = "Start a new Codex session here to fix audio mute."
live.revision = 1
refusal = await live.execute("resolve", tool.name, {"action": "resolve"}, 1)
assert refusal["output"]["status"] == "new_agent_required"
first = await live.execute("create-a", tool.name, create_args(), 1)
retry = await live.execute("create-b", tool.name, create_args(), 1)
assert first["success"] and retry["output"] == first["output"]
assert len(rig[2].calls) == 1
live.user_text = "Only inspect the current work."
live.revision = 2
late = await live.execute("late-correction", tool.name, create_args(), 1)
assert late["status"] == "superseded" and late["executed"] is False
assert len(rig[2].calls) == 1
finally:
ledger.close()
def project_of(rig, name="Personal Jarvis"):
return next(p for p in rig[0].graph()["projects"] if p["name"] == name)
OPEN_TEXT = "Open a new workspace with a new Claude Code agent to audit the startup instructions."
@pytest.mark.parametrize("briefed", [True, False], ids=["agents-and-prompt", "bare"])
async def test_new_request_opens_one_new_workspace_and_never_touches_old_panes(
rig, runnable, briefed
):
# Live 2026-10-07: open_workspace for a NEW agent was refused as pane reuse
# ("new_agent_required"), with and without agents/prompt; nothing opened.
orchestrator, registry, sessions = rig
project = project_of(rig)
before = {w.id for w in registry.sessions}
existing = {t.history_id for w in registry.sessions for t in w.terminals}
args = {"action": "open_workspace", "project_id": project["id"], "name": "Agents.md"}
if briefed:
args |= {"agents": [{"cli": "Claude Code", "count": 1}], "prompt": "Audit the stack"}
else:
args |= {"folder": project["path"]}
tool = WorkspaceOrchestrationTool(orchestrator)
first = await tool.execute(args, context(OPEN_TEXT))
assert first.success, first
assert first.output["status"] == "opened"
assert first.output["workspace"] == "Agents.md"
assert first.output["workspace_id"] not in before
new_ids = [a["terminal_id"] for a in first.output["agents"]]
assert len(new_ids) == 1
assert not {i.removeprefix("pane:") for i in new_ids} & existing
assert [c["terminal_id"] for c in sessions.calls] == (new_ids if briefed else [])
# A retry in the same request scope reads the receipt; no second workspace.
reopened = WorkspaceOrchestrationTool(
WorkspaceOrchestrator(registry, sessions, orchestrator.ledger)
)
repeated = await reopened.execute(args, context(OPEN_TEXT))
assert repeated.output == first.output
assert len(registry.sessions) == len(before) + 1
assert len(sessions.calls) == (1 if briefed else 0)
# The new-agent guard still keeps old panes out of this request.
refused = await tool.execute({"action": "resolve"}, context(OPEN_TEXT))
assert refused.output["status"] == "new_agent_required"
old = next(t for w in registry.sessions if w.id in before for t in w.terminals)
owner = next(w for w in registry.sessions if w.id in before)
stolen = await tool.execute(
{
"action": "send",
"project_id": owner.project_id,
"workspace_id": owner.id,
"terminal_id": "pane:" + old.history_id,
"prompt": "Correction",
},
context(OPEN_TEXT),
)
assert stolen.output["status"] == "new_agent_required"
assert len(sessions.calls) == (1 if briefed else 0)
async def test_bare_new_workspace_pane_takes_one_assignment_only(rig, runnable):
tool = WorkspaceOrchestrationTool(rig[0])
project = project_of(rig)
opened = await tool.execute(
{"action": "open_workspace", "folder": project["path"], "name": "Agents.md"},
context(OPEN_TEXT),
)
pane = opened.output["agents"][0]
args = {
"action": "send",
"project_id": opened.output["project_id"],
"workspace_id": opened.output["workspace_id"],
"terminal_id": pane["terminal_id"],
"request_id": pane["request_id"],
"prompt": "Task",
}
first = await tool.execute(args, context(OPEN_TEXT))
assert first.success, first
assert not (
await tool.execute({**args, "prompt": "Correction: another task"}, context(OPEN_TEXT))
).success
assert len(rig[2].calls) == 1
async def test_second_open_in_the_same_request_cannot_open_another_workspace(rig, runnable):
tool = WorkspaceOrchestrationTool(rig[0])
project = project_of(rig)
count = len(rig[1].sessions)
base = {"action": "open_workspace", "folder": project["path"]}
assert (await tool.execute({**base, "name": "Agents.md"}, context(OPEN_TEXT))).success
other = await tool.execute({**base, "name": "Another"}, context(OPEN_TEXT))
assert not other.success
assert len(rig[1].sessions) == count + 1
async def test_open_workspace_by_project_id_alone_opens_that_project(rig, runnable):
project = project_of(rig, "Other project")
result = await rig[0].run({"action": "open_workspace", "project_id": project["id"]})
assert result["status"] == "opened", result
assert result["project_id"] == project["id"]
@pytest.mark.parametrize("action", ["restore", "show"])
async def test_new_request_still_cannot_reopen_or_show_existing_workspaces(rig, action):
result = await WorkspaceOrchestrationTool(rig[0]).execute(
{"action": action, "workspace": "Personal Jarvis"}, context(OPEN_TEXT)
)
assert result.output["status"] == "new_agent_required"
MIXED_TEXT = (
"First send the approved brief to Alex in Personal Jarvis, then start a new Codex "
"session to fix audio mute."
)
def named_pane(rig, workspace="Personal Jarvis"):
owner = next(w for w in rig[1].sessions if w.name == workspace)
return owner, owner.terminals[0]
@pytest.mark.parametrize(
"create_first", [False, True], ids=["update-then-create", "create-then-update"]
)
async def test_mixed_request_updates_the_named_pane_and_creates_a_new_one(
rig, runnable, create_first
):
# Live 2026-10-07: "first update the PR #430 session, then create a new
# bug-fix session" refused the update (and a retry) as pane reuse.
orchestrator, registry, sessions = rig
tool = WorkspaceOrchestrationTool(orchestrator)
assert dispatch_context(MIXED_TEXT, {}, "turn")["_requires_new"]
owner, old = named_pane(rig)
old_id = "pane:" + old.history_id
async def update():
resolved = await tool.execute(
{"action": "resolve", "workspace": "Personal Jarvis", "agent": "Alex"},
context(MIXED_TEXT),
)
assert resolved.output["status"] == "resolved", resolved.output
assert resolved.output["target"]["terminal_id"] == old_id
sent = await tool.execute(
{"action": "send", **{k: resolved.output["target"][k] for k in (
"project_id", "workspace_id", "terminal_id")},
"request_id": resolved.output["request_id"], "prompt": "Apply the approved plan"},
context(MIXED_TEXT),
)
assert sent.success, sent.output
return sent
async def create():
made = await tool.execute(create_args(), context(MIXED_TEXT))
assert made.success, made.output
return made.output["agents"][0]["terminal_id"]
if create_first:
new_id = await create()
await update()
else:
await update()
new_id = await create()
assert new_id != old_id
assert sorted(c["terminal_id"] for c in sessions.calls) == sorted([old_id, new_id])
briefs = {c["terminal_id"]: c["prompt"] for c in sessions.calls}
assert briefs == {old_id: "Apply the approved plan", new_id: "Fix output mute"}
@pytest.mark.parametrize("agent", ["", "Codex", "codex"])
async def test_new_request_never_picks_an_idle_or_cli_kind_pane(rig, agent):
tool = WorkspaceOrchestrationTool(rig[0])
args = {"action": "resolve", "workspace": "Personal Jarvis"}
if agent:
args["agent"] = agent
result = await tool.execute(args, context(MIXED_TEXT))
assert result.output["status"] == "new_agent_required"
# The refusal still hands over the IDs a following create needs.
owner, _ = named_pane(rig)
assert result.output["workspace_id"] == owner.id
assert result.output["project_id"] == owner.project_id
assert not rig[2].calls
async def test_new_panes_brief_cannot_also_go_to_a_named_old_pane(rig, runnable):
tool = WorkspaceOrchestrationTool(rig[0])
made = await tool.execute(create_args(), context(MIXED_TEXT))
assert made.success
resolved = await tool.execute(
{"action": "resolve", "workspace": "Personal Jarvis", "agent": "Alex"},
context(MIXED_TEXT),
)
duplicate = await tool.execute(
{"action": "send", **{k: resolved.output["target"][k] for k in (
"project_id", "workspace_id", "terminal_id")},
"request_id": resolved.output["request_id"], "prompt": "Fix output mute"},
context(MIXED_TEXT),
)
assert duplicate.output["status"] == "delivery_already_owned"
assert [c["terminal_id"] for c in rig[2].calls] == [made.output["agents"][0]["terminal_id"]]
async def test_named_update_refused_as_busy_retries_with_the_same_request_id(rig, runnable):
tool = WorkspaceOrchestrationTool(rig[0])
resolved = await tool.execute(
{"action": "resolve", "workspace": "Personal Jarvis", "agent": "Alex"},
context(MIXED_TEXT),
)
args = {"action": "send", **{k: resolved.output["target"][k] for k in (
"project_id", "workspace_id", "terminal_id")},
"request_id": resolved.output["request_id"], "prompt": "Apply the approved plan"}
rig[2].refused = True
busy = await tool.execute(args, context(MIXED_TEXT))
assert busy.output["status"] == "not_accepted"
rig[2].refused = False
# Proven non-delivery: the same request may go once the pane is idle.
retry = await tool.execute(args, context(MIXED_TEXT))
assert retry.success and retry.output["status"] == "accepted"
assert (await tool.execute(args, context(MIXED_TEXT))).output["status"] == "accepted"
assert len(rig[2].calls) == 2
async def test_named_pane_actions_stay_available_in_a_new_request(rig):
tool = WorkspaceOrchestrationTool(rig[0])
owner, old = named_pane(rig)
blind = await tool.execute(
{"action": "interrupt", "workspace_id": owner.id,
"terminal_id": "pane:" + old.history_id},
context(MIXED_TEXT),
)
assert blind.output["status"] == "new_agent_required"
pressed = await tool.execute(
{"action": "interrupt", "workspace": "Personal Jarvis", "agent": "Alex"},
context(MIXED_TEXT),
)
assert pressed.output["status"] != "new_agent_required"
assert pressed.output["target"]["terminal_id"] == "pane:" + old.history_id