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(ide): guard queued startup and verify routine supervision

rubenluetke10-beep11850c75ec34
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.py
index 896ed17173..b7e5098d62 100644
--- a/jarvis/agentic_ide/session.py
+++ b/jarvis/agentic_ide/session.py
@@ -3309,6 +3309,9 @@ class Registry:
# slot stays taken until this pane's input line appears.
async with self._cold_start_slot(ready=lambda: self._prompt_ready(session, term)):
try:
+ identity = "pane:" + term.history_id
+ if term.stopping or self._locate(identity, session.id) != (session, term):
+ raise SessionError("The selected terminal closed before startup.")
pty_session = await manager.spawn(
shell_argv=argv,
shell_id=f"agentic-ide:{term.key}",
@@ -3328,6 +3331,9 @@ class Registry:
# typed. Off the loop it is immediate.
on_probe=term.queries.feed,
)
+ if term.stopping or self._locate(identity, session.id) != (session, term):
+ manager.close(pty_session.terminal_id)
+ raise SessionError("The selected terminal closed during startup.")
except Exception as exc: # noqa: BLE001 - surfaced to the pane
term.status = "error"
term.error = str(exc)
diff --git a/tests/contract/test_society_coding_sessions.py b/tests/contract/test_society_coding_sessions.py
index 89f3b65cbb..9348797713 100644
--- a/tests/contract/test_society_coding_sessions.py
+++ b/tests/contract/test_society_coding_sessions.py
@@ -490,3 +490,41 @@ async def test_jarvis_chat_receives_controller_without_becoming_a_coding_cli(rig
session.permission_mode = "plan"
tools, _ = await kit_payload(session, SimpleNamespace(_config=None))
assert tools is None or "coding-session" not in tools
+
+
+async def test_close_while_startup_is_queued_does_not_spawn(rig, tmp_path, monkeypatch):
+ entered, release = asyncio.Event(), asyncio.Event()
+
+ async def gate(term):
+ entered.set()
+ await release.wait()
+ return None
+
+ monkeypatch.setattr(rig[0], "_acquire_agent_cold_start", gate)
+ pending = asyncio.create_task(open_one(rig, tmp_path))
+ await asyncio.wait_for(entered.wait(), 5)
+ await rig[0].end(rig[0].sessions[0].id)
+ release.set()
+ result = await pending
+ assert result["started"] is False and "closed" in result["error"]
+ assert not rig[1].spawns
+
+
+async def test_close_during_spawn_reaps_only_the_new_orphan(rig, tmp_path, monkeypatch):
+ entered, release = asyncio.Event(), asyncio.Event()
+ original = rig[1].spawn
+
+ async def delayed(self, *args, **kwargs):
+ child = await original(*args, **kwargs)
+ entered.set()
+ await release.wait()
+ return child
+
+ monkeypatch.setattr(type(rig[1]), "spawn", delayed)
+ pending = asyncio.create_task(open_one(rig, tmp_path))
+ await asyncio.wait_for(entered.wait(), 5)
+ await rig[0].end(rig[0].sessions[0].id)
+ release.set()
+ result = await pending
+ assert result["started"] is False and "closed" in result["error"]
+ assert len(rig[1].spawns) == 1 and not rig[1]._live
diff --git a/tests/integration/test_coding_supervision_routine.py b/tests/integration/test_coding_supervision_routine.py
new file mode 100644
index 0000000000..7f2b71c19b
--- /dev/null
+++ b/tests/integration/test_coding_supervision_routine.py
@@ -0,0 +1,130 @@
+"""Real owner chat/routine delivery with a deterministic model and fake PTY."""
+
+from __future__ import annotations
+
+import asyncio
+from types import SimpleNamespace
+
+from jarvis.agent_chat import runner_brain
+from jarvis.agent_chat.service import AgentChatService
+from jarvis.agent_chat.store import AgentChatStore
+from jarvis.agentic_ide import agent_transcript
+from jarvis.agentic_ide.activity import Reading
+from jarvis.agentic_ide.session import Terminal
+from jarvis.core.bus import EventBus
+from jarvis.core.chat_turn import current_chat_turn
+from jarvis.society.routine_runner import run_owned_routine
+from jarvis.society.routines import agent_tag
+from tests.contract.test_society_coding_sessions import open_one
+from tests.contract.test_society_coding_sessions import rig as rig
+from tests.fakes.fake_brain_manager import FakeBrainManager
+
+
+async def test_routine_question_and_result_stay_in_real_owner_chat(rig, tmp_path, monkeypatch):
+ runtime, owner = rig[3], rig[5]
+ owner = await runtime.roster.update(
+ owner.agent_id, {"provider": "openai", "model": "fake-model"}
+ )
+ bus = EventBus()
+ service = AgentChatService(AgentChatStore(str(tmp_path / "chat.db")), bus=lambda: bus)
+ runtime._get_chat = lambda: service
+ runtime._get_cfg = lambda: SimpleNamespace(memory=SimpleNamespace(data_dir=str(tmp_path)))
+ monkeypatch.setattr(runtime.coding_supervision, "_ensure_loop", lambda: None)
+ monkeypatch.setattr(Terminal, "reading", lambda self: Reading("waiting", 1))
+
+ async def confirm(term, payload, manager, multiline):
+ manager.write(term.pty_id, payload)
+ return True
+
+ monkeypatch.setattr(rig[0], "_write_and_confirm", confirm)
+ opened = await open_one(rig, tmp_path)
+ recorded = [{"kind": "assistant_text", "text": "Which branch should I inspect?"}]
+ monkeypatch.setattr(agent_transcript, "can_read", lambda agent: True)
+ monkeypatch.setattr(
+ agent_transcript, "read_timeline", lambda *args, **kwargs: SimpleNamespace(events=recorded)
+ )
+ identities = []
+
+ class WorkflowBrain(FakeBrainManager):
+ async def generate(self, text, **kwargs):
+ turn = current_chat_turn.get()
+ identities.append((turn.session_id, turn.direct_user))
+ override = kwargs["turn_override"]
+ # The deterministic driver replaces model/tool selection only. The
+ # real chat, routine binding, receipts, context and IDE registry run.
+ tool = override.tool_filter(dict(override.tools_extra))["coding-session"]
+ ctx = SimpleNamespace(trace_id=kwargs["trace_id"])
+ if not self.calls:
+ result = await tool.execute(
+ {
+ **opened,
+ "action": "assign",
+ "request_id": "routine-job",
+ "prompt": "Inspect the current branch and report evidence.",
+ },
+ ctx,
+ )
+ self.reply = "Assignment started under supervision."
+ elif len(self.calls) == 1:
+ assert "Which branch" in text
+ status = await tool.execute({**opened, "action": "supervision"}, ctx)
+ input_state = await tool.execute({**opened, "action": "input"}, ctx)
+ result = await tool.execute(
+ {
+ **opened,
+ "action": "respond",
+ "request_id": "routine-answer",
+ "prompt": "Inspect the currently checked-out branch.",
+ "update_id": status.output["update_id"],
+ **input_state.output,
+ },
+ ctx,
+ )
+ self.reply = "Answered the coding agent."
+ else:
+ assert "Inspection complete" in text
+ result = await tool.execute(
+ {
+ **opened,
+ "action": "finish",
+ "request_id": "routine-finish",
+ "summary": "The branch inspection evidence was returned.",
+ },
+ ctx,
+ )
+ self.reply = "Inspection complete with evidence."
+ assert result.success, result.error
+ return await super().generate(text, **kwargs)
+
+ brain = WorkflowBrain(bus=bus)
+ monkeypatch.setattr(runner_brain, "brain_manager", lambda: brain)
+ monkeypatch.setattr(runner_brain, "_agent_secret", lambda *args: "synthetic-test-key")
+
+ async def idle():
+ running = service._running.get(owner.session_id)
+ if running is not None and running.task is not None:
+ await asyncio.wait_for(asyncio.shield(running.task), timeout=5)
+
+ try:
+ answer = await run_owned_routine(
+ runtime, "routine-proof", ("society", agent_tag(owner.agent_id)), "Inspect the branch"
+ )
+ assert answer == "Assignment started under supervision."
+ await idle()
+ key = runtime.coding_supervision.key(opened)
+ await runtime.coding_supervision.tick(key)
+ await idle()
+ recorded[:] = [
+ {"kind": "assistant_text", "text": "Inspection complete; current branch recorded."}
+ ]
+ await runtime.coding_supervision.tick(key)
+ await idle()
+ assert runtime.coding_supervision.rows[key]["state"] == "finished"
+ assert identities == [(owner.session_id, False)] * 3
+ events = service.store.list_events(owner.session_id)
+ assert len([e for e in events if e["kind"] == "agent_message"]) == 2
+ assert len([e for e in events if e["kind"] == "turn_started"]) == 3
+ finally:
+ await service.cancel(owner.session_id)
+ await idle()
+ service.store.close()