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(missions): observed tool refusals reach the critic instead of failing the mission
Ruben Lütkef36023732702
diff --git a/jarvis/missions/kontrollierer/orchestrator.py b/jarvis/missions/kontrollierer/orchestrator.pyindex 54876a6206..2bea6598f2 100644--- a/jarvis/missions/kontrollierer/orchestrator.py+++ b/jarvis/missions/kontrollierer/orchestrator.py@@ -1438,8 +1438,9 @@ class Kontrollierer:),}logger.error(- "Task %s iter %d: refusing critic review after an unclean "- "supervisor tool grant: %s",+ "Task %s iter %d: refusing critic review after an "+ "integrity-compromised supervisor tool grant (a call was "+ "still running or its outcome is unknown): %s",step.task_id,iteration,error_detail,@@ -1656,13 +1657,28 @@ class Kontrollierer:if safety_kill_reason is not None:return TaskOutcome.ERROR- # Critic-Call+ # Critic-Call. Honest supervisor-tool refusals (denied/timed-out/+ # errored calls the worker OBSERVED in-stream) did not abort the+ # iteration — only integrity failures do — but the critic must+ # judge the deliverable WITH the refusal list: "the task depended+ # on the denied call" is a reject, "the worker adapted" is not+ # (BUG-096: execution, artifact, approval, and outcome are four+ # separate facts). Appended to the critic's log view only, never+ # to the diff, and after the safety scan so the scanner never+ # reads our own note.+ critic_log = log_text+ if spawn_result.supervisor_tool_refusals:+ critic_log = (+ f"{log_text}\n\n"+ "# supervisor-tool refusals (observed by the worker)\n"+ f"{spawn_result.supervisor_tool_refusals}\n"+ )env = self._env_builder(mission_dir)try:verdict = await self._runner.run(mission_prompt=mission_prompt,worker_diff=diff_text,- worker_log=log_text,+ worker_log=critic_log,prior_reflections=prior_block,iteration=iteration,worktree=worktree,@@ -1810,6 +1826,7 @@ class Kontrollierer:worker_timed_out: bool = False,supervisor_tool_failed: bool = False,supervisor_tool_error: str | None = None,+ supervisor_tool_refusals: str | None = None,) -> None:self.worker_id = worker_idself.cost_usd = cost_usd@@ -1830,6 +1847,10 @@ class Kontrollierer:self.worker_error = worker_errorself.supervisor_tool_failed = supervisor_tool_failedself.supervisor_tool_error = supervisor_tool_error+ # Observed refusals (denied/timed_out/error/cancelled) — the+ # worker saw these in-stream and could adapt; they do NOT fail+ # the iteration, they inform the critic (BUG-096 four facts).+ self.supervisor_tool_refusals = supervisor_tool_refusalsasync def _spawn_worker_collect(self,@@ -2037,8 +2058,12 @@ class Kontrollierer:session_id=session_id,worker_error=worker_error,worker_timed_out=worker_timed_out,- supervisor_tool_failed=not broker_summary.clean,+ # Only INTEGRITY failures (outcome_unknown / still-active calls)+ # abort the iteration — an observed refusal keeps the work+ # reviewable and reaches the critic as context instead.+ supervisor_tool_failed=broker_summary.integrity_compromised,supervisor_tool_error=broker_summary.failure_summary,+ supervisor_tool_refusals=broker_summary.refusal_summary,)# --- Phase-5 Safety -----------------------------------------------------diff --git a/jarvis/missions/kontrollierer/worker_prompt.py b/jarvis/missions/kontrollierer/worker_prompt.pyindex b971889adf..aa272406ca 100644--- a/jarvis/missions/kontrollierer/worker_prompt.py+++ b/jarvis/missions/kontrollierer/worker_prompt.py@@ -80,7 +80,9 @@ SUPERVISOR_BOUNDARY_DIRECTIVE: Final[str] = ("app; never operate the live desktop or Computer Use; never read control ""credentials; and never change live configuration. For Wiki work, use only ""the supervisor-granted wiki-list, wiki-recall, wiki-page-read, and "- "wiki-ingest tools."+ "wiki-ingest tools. A denied or failed supervisor tool call is a normal, "+ "recoverable event: adapt your approach, use an alternative, or deliver "+ "the remainder of the task and state the limitation in your summary.")diff --git a/jarvis/missions/workers/api_agent_worker.py b/jarvis/missions/workers/api_agent_worker.pyindex ffaa8410c6..b22cea94fb 100644--- a/jarvis/missions/workers/api_agent_worker.py+++ b/jarvis/missions/workers/api_agent_worker.py@@ -171,7 +171,10 @@ _SYSTEM_PROMPT = ("workspace. Your ONLY way to deliver work is to call the provided tools — ""Write, Edit, Read, RunCommand, Ls, plus any mission-scoped connected tools — ""with file paths relative to the workspace root. Connected tools are "- "executed by the supervisor and may honestly require human approval. "+ "executed by the supervisor and may honestly require human approval; a "+ "denied or failed connected-tool call is a normal, recoverable event - "+ "adapt, use an alternative, or deliver the remainder and state the "+ "limitation in your summary. ""Actually CREATE and EDIT the files the task needs; never just describe what ""you would do (a text description is not a deliverable and will be rejected). ""Work autonomously without asking questions: if a detail is unspecified, pick "diff --git a/jarvis/missions/workers/worker_tool_broker.py b/jarvis/missions/workers/worker_tool_broker.pyindex c08a34c205..1d72f55a65 100644--- a/jarvis/missions/workers/worker_tool_broker.py+++ b/jarvis/missions/workers/worker_tool_broker.py@@ -117,6 +117,28 @@ class WorkerToolCallOutcome:error: str = ""+# Statuses the worker OBSERVED as an in-stream error response (broker_stdio+# returns isError=True; API workers get the error dict directly) — the worker+# had the chance to adapt, so these are honest refusals, not integrity holes.+_OBSERVED_REFUSAL_STATUSES: tuple[str, ...] = ("denied", "cancelled", "timed_out", "error")+# Statuses where the supervisor cannot certify what actually happened: the+# call was still running when the grant closed, or its outcome was rewritten+# to unknown at revocation.+_INTEGRITY_STATUSES: tuple[str, ...] = ("outcome_unknown", "active")+++def _outcome_preview(calls: list["WorkerToolCallOutcome"]) -> str | None:+ if not calls:+ return None+ preview = "; ".join(+ f"{call.tool_name}: {call.status}" + (f" ({call.error})" if call.error else "")+ for call in calls[:3]+ )+ if len(calls) > 3:+ preview += f"; +{len(calls) - 3} more"+ return safe_preview(preview, max_chars=300)++@dataclass(frozen=True, slots=True)class WorkerToolExecutionSummary:"""Completion certificate consumed by the mission controller."""@@ -127,23 +149,34 @@ class WorkerToolExecutionSummary:def clean(self) -> bool:return all(call.status == "success" for call in self.calls)+ @property+ def integrity_compromised(self) -> bool:+ """True when the supervisor cannot certify what actually happened.++ Only these outcomes abort an iteration before critic review. Honest+ refusals (:data:`_OBSERVED_REFUSAL_STATUSES`) keep the iteration+ reviewable — per the BUG-096 class rule, worker execution and critic+ approval are separate facts, and the critic judges the deliverable+ WITH knowledge of the refusals (see ``refusal_summary``).+ """+ return any(call.status in _INTEGRITY_STATUSES for call in self.calls)+@propertydef active_count(self) -> int:return sum(call.status == "active" for call in self.calls)@propertydef failure_summary(self) -> str | None:- failed = [call for call in self.calls if call.status != "success"]- if not failed:- return None- preview = "; ".join(- f"{call.tool_name}: {call.status}"- + (f" ({call.error})" if call.error else "")- for call in failed[:3]+ return _outcome_preview(+ [call for call in self.calls if call.status != "success"]+ )++ @property+ def refusal_summary(self) -> str | None:+ """Bounded preview of the observed refusals, for the critic's context."""+ return _outcome_preview(+ [call for call in self.calls if call.status in _OBSERVED_REFUSAL_STATUSES])- if len(failed) > 3:- preview += f"; +{len(failed) - 3} more"- return safe_preview(preview, max_chars=300)def worker_tool_name_allowed(name: str) -> bool:diff --git a/tests/missions/kontrollierer/test_supervisor_tool_completion_gate.py b/tests/missions/kontrollierer/test_supervisor_tool_completion_gate.pyindex d1b8b47738..007e410ec6 100644--- a/tests/missions/kontrollierer/test_supervisor_tool_completion_gate.py+++ b/tests/missions/kontrollierer/test_supervisor_tool_completion_gate.py@@ -1,4 +1,14 @@-"""The critic cannot approve past an unclean supervisor-tool grant."""+"""Supervisor-tool completion certificate: integrity gates, refusals inform.++Two failure classes, two different consequences (BUG-096 four-facts rule):++* INTEGRITY failures (a call still running when the grant closed /+ ``outcome_unknown``) — the supervisor cannot certify what happened, so the+ iteration is aborted and the critic never runs.+* OBSERVED refusals (denied / timed-out / errored calls) — the worker saw the+ error in-stream and could adapt, so the iteration stays reviewable and the+ critic receives the refusal list as context.+"""from __future__ import annotations@@ -126,10 +136,12 @@ def _clean_runtime_refs() -> Any:@pytest.mark.asyncio-async def test_worker_cannot_hide_failed_tool_call_from_approving_critic(+async def test_observed_tool_error_reaches_critic_with_refusal_note(manager: MissionManager,tmp_path: Path,) -> None:+ """A tool ERROR the worker observed in-stream no longer kills the+ iteration — the critic reviews the work WITH the refusal as context."""gateway = _Gateway(ToolResult(success=False, output=None, error="connector unavailable"))@@ -146,14 +158,74 @@ async def test_worker_cannot_hide_failed_tool_call_from_approving_critic(state = await kontrollierer.run_mission(mission_id)- assert state == MissionState.FAILED- assert critic.calls == []+ assert state == MissionState.APPROVEDassert gateway.calls == 1+ assert len(critic.calls) == 1+ critic_log = critic.calls[0]["worker_log"]+ assert "supervisor-tool refusals" in critic_log+ assert "external-action" in critic_log+ assert "connector unavailable" in critic_log+++async def test_denied_tool_call_reaches_critic_and_is_named(+ manager: MissionManager,+ tmp_path: Path,+) -> None:+ """An approval denial (e.g. the unattended 60 s timeout) is an observed+ refusal: the mission is graded, not auto-failed as supervisor_tool_failed."""+ gateway = _Gateway(+ ToolResult(success=False, output=None, error="approval-denied (timeout)")+ )+ runtime_refs.set_supervisor_tool_gateway(gateway)+ worker = _BrokerCallingWorker()+ critic = FakeCriticRunner(_make_approve_verdict())+ kontrollierer = _make_kontrollierer(+ manager=manager,+ tmp_path=tmp_path,+ critic=critic,+ worker_factory_fn=lambda _step: worker,+ )+ mission_id = await manager.dispatch(prompt="Perform an external action")++ state = await kontrollierer.run_mission(mission_id)++ assert state == MissionState.APPROVED+ assert len(critic.calls) == 1+ critic_log = critic.calls[0]["worker_log"]+ assert "denied" in critic_logevents = await manager.store.events_for_mission(mission_id)- approved = [e for e in events if e.payload.event_type == "MissionApproved"]failed = [e for e in events if e.payload.event_type == "MissionFailed"]- assert approved == []- assert failed[-1].payload.error_class == "supervisor_tool_failed" # type: ignore[union-attr]+ assert failed == []+++def test_summary_partitions_refusals_from_integrity_failures() -> None:+ """Every non-success status belongs to exactly one bucket: observed+ refusal (keeps the iteration reviewable) or integrity failure (gates)."""+ from jarvis.missions.workers.worker_tool_broker import (+ WorkerToolCallOutcome,+ WorkerToolExecutionSummary,+ )++ def call(status: str) -> WorkerToolCallOutcome:+ return WorkerToolCallOutcome(trace_id="t", tool_name="x", status=status) # type: ignore[arg-type]++ refusals = WorkerToolExecutionSummary(+ calls=(call("denied"), call("error"), call("timed_out"), call("cancelled"))+ )+ assert refusals.clean is False+ assert refusals.integrity_compromised is False+ assert "denied" in (refusals.refusal_summary or "")++ for status in ("outcome_unknown", "active"):+ summary = WorkerToolExecutionSummary(calls=(call(status),))+ assert summary.integrity_compromised is True+ assert summary.refusal_summary is None++ clean = WorkerToolExecutionSummary(calls=(call("success"),))+ assert clean.clean is True+ assert clean.integrity_compromised is False+ assert clean.refusal_summary is None@pytest.mark.asyncio