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(agents): send a Claude CLI contract too long for argv on stdin

rubenluetke10-beep9eca0eceae94
diff --git a/jarvis/plugins/brain/claude_cli.py b/jarvis/plugins/brain/claude_cli.py
index 78de62b6d1..7aab0c1163 100644
--- a/jarvis/plugins/brain/claude_cli.py
+++ b/jarvis/plugins/brain/claude_cli.py
@@ -124,6 +124,11 @@ _FAST_STRUCTURED_ARGS: tuple[tuple[str, tuple[str, ...]], ...] = (
# wait this mapping exists to stop.
_EFFORT_LEVELS: frozenset[str] = frozenset({"low", "medium", "high"})
+#: The most characters the argv of one turn may take. Windows refuses a
+#: command line over 32,767 characters; elsewhere a single argument is capped
+#: at 128 KiB (Linux MAX_ARG_STRLEN). Room is left for the binary path.
+_ARGV_BUDGET: int = 30_000 if sys.platform == "win32" else 120_000
+
# The probed set of long options this install's CLI understands, filled once
# per process from ``claude --help``. ``None`` means "not probed yet"; an empty
# set means the probe failed and every gated flag stays off — slower, but every
@@ -304,6 +309,12 @@ class ClaudeCliBrain:
if "--effort" in known and effort in _EFFORT_LEVELS:
argv += ["--effort", effort]
system = str(getattr(req, "system", "") or "").strip()
+ if system and len(system) + sum(len(arg) + 1 for arg in argv) > _ARGV_BUDGET:
+ # Too long for one command line (Windows caps the whole line at
+ # 32,767 chars; live: every browser turn of a society agent died
+ # with WinError 206). stdin has no such limit, and the
+ # structured rendering already carries the contract verbatim.
+ return argv, render_structured_prompt(req)
if system:
argv += ["--system-prompt", system]
# The contract already rides in argv; sending it on stdin too
diff --git a/tests/unit/plugins/brain/test_claude_cli_brain.py b/tests/unit/plugins/brain/test_claude_cli_brain.py
index 53083957a5..3464b61d0c 100644
--- a/tests/unit/plugins/brain/test_claude_cli_brain.py
+++ b/tests/unit/plugins/brain/test_claude_cli_brain.py
@@ -5,6 +5,7 @@ The invocation builder is pure on purpose: what this brain gets wrong is not
is decided entirely by argv plus the stdin payload. Testing that pair directly
catches the failure that matters without spawning a CLI.
"""
+
from __future__ import annotations
import pytest
@@ -38,9 +39,7 @@ def test_structured_mode_forwards_the_system_contract_verbatim() -> None:
def test_conversational_mode_does_not_leak_the_router_prompt() -> None:
"""A voice turn stays short and never carries the heavy tool prompt."""
brain = ClaudeCliBrain(structured_prompts=False)
- _argv, prompt = brain.build_invocation(
- _req(system="ROUTER PROMPT WITH TOOLS", user="hello")
- )
+ _argv, prompt = brain.build_invocation(_req(system="ROUTER PROMPT WITH TOOLS", user="hello"))
assert "ROUTER PROMPT WITH TOOLS" not in prompt
assert "hello" in prompt
@@ -85,9 +84,7 @@ def test_subscription_probe_never_raises(monkeypatch: pytest.MonkeyPatch) -> Non
def _explode() -> object:
raise OSError("no keychain on this host")
- monkeypatch.setattr(
- "jarvis.claude_auth.ClaudeAuthService", lambda *a, **k: _explode()
- )
+ monkeypatch.setattr("jarvis.claude_auth.ClaudeAuthService", lambda *a, **k: _explode())
assert ClaudeCliBrain.subscription_connected() is False
@@ -98,9 +95,7 @@ def test_api_key_login_does_not_masquerade_as_a_subscription(
monkeypatch.setattr(
"jarvis.claude_auth.ClaudeAuthService",
- lambda: SimpleNamespace(
- status=lambda: SimpleNamespace(connected=True, mode="api_key")
- ),
+ lambda: SimpleNamespace(status=lambda: SimpleNamespace(connected=True, mode="api_key")),
)
assert ClaudeCliBrain.subscription_connected() is False
@@ -109,9 +104,7 @@ async def test_complete_raises_a_clear_error_when_the_cli_is_absent(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""A headless host with no CLI gets an actionable message, never a hang."""
- monkeypatch.setattr(
- "jarvis.plugins.brain.claude_cli._resolve_claude_binary", lambda: None
- )
+ monkeypatch.setattr("jarvis.plugins.brain.claude_cli._resolve_claude_binary", lambda: None)
brain = ClaudeCliBrain(structured_prompts=True)
with pytest.raises(RuntimeError, match="Claude CLI"):
async for _delta in brain.complete(_req()):
@@ -137,8 +130,7 @@ def test_structured_turns_shed_startup_weight_the_cli_supports() -> None:
argv, _prompt = brain.build_invocation(_req(), cli_flags=_FAST_FLAGS)
assert "--tools" in argv
assert argv[argv.index("--tools") + 1] == ""
- for flag in ("--strict-mcp-config", "--disable-slash-commands",
- "--no-session-persistence"):
+ for flag in ("--strict-mcp-config", "--disable-slash-commands", "--no-session-persistence"):
assert flag in argv
@@ -236,3 +228,20 @@ def test_a_failed_probe_degrades_to_the_minimal_invocation(
assert claude_cli._probe_supported_flags() == frozenset() # noqa: SLF001
finally:
claude_cli.reset_flag_probe_cache()
+
+
+def test_a_contract_too_long_for_one_command_line_travels_on_stdin() -> None:
+ """Windows refuses a command line over 32,767 characters (WinError 206):
+ every browser turn of a society agent died at spawn. The contract then
+ rides on stdin, verbatim, and argv stays short."""
+ brain = ClaudeCliBrain(structured_prompts=True)
+ contract = "RULE " * 20_000
+ argv, prompt = brain.build_invocation(
+ _req(system=contract, user="do X"), cli_flags=frozenset({"--system-prompt"})
+ )
+ assert "--system-prompt" not in argv
+ assert sum(len(arg) for arg in argv) < 30_000
+ assert contract.strip() in prompt and "do X" in prompt
+ # A short contract keeps its dedicated flag.
+ argv, _ = brain.build_invocation(_req(), cli_flags=frozenset({"--system-prompt"}))
+ assert "--system-prompt" in argv