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
@ fix(agentic-ide): let a pane be its CLI own session, not the launcher child
Ruben Lütkebfd1353276e5
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.pyindex 815cbdb945..75a4f5ee34 100644--- a/jarvis/agentic_ide/session.py+++ b/jarvis/agentic_ide/session.py@@ -493,6 +493,78 @@ def _redirected_home(term: Terminal) -> Path | None:return agent_accounts.config_dir_for(term.agent, term.account) # type: ignore[arg-type]+#: Environment markers left behind by the coding-agent session that STARTED this+#: app, which a pane must never inherit.+#:+#: The app is regularly launched from inside a coding CLI — a contributor running+#: ``run.bat`` from an agent's terminal, the in-app restart (which hands the new+#: process its predecessor's environment, so one such launch survives every+#: restart afterwards). A CLI that finds these variables believes it is a NESTED+#: run of itself, and Claude Code answers that by switching its transcript off:+#: "Transcript saving is off — inherited CLAUDE_CODE_CHILD_SESSION". A pane whose+#: conversation is never written to disk cannot be continued afterwards, so every+#: pane came back with an empty history while the restore point looked healthy —+#: it held a session id for a conversation that was never recorded (found+#: 2026-07-28: not one transcript on disk for a whole morning's work).+#:+#: Deliberately an explicit list rather than a ``CLAUDE_*`` prefix sweep: the same+#: namespace carries credentials (``CLAUDE_CODE_OAUTH_TOKEN``), the account+#: redirection this module sets itself (``CLAUDE_CONFIG_DIR``) and settings a user+#: legitimately exports for every terminal they open. Only markers that identify+#: a RUNNING session belong here — add new ones as CLIs introduce them.+PARENT_AGENT_SESSION_VARS: frozenset[str] = frozenset(+ {+ # Claude Code (and every launch profile that borrows its binary).+ "CLAUDECODE",+ "CLAUDE_CODE_CHILD_SESSION",+ "CLAUDE_CODE_SESSION_ID",+ "CLAUDE_CODE_ENTRYPOINT",+ "CLAUDE_CODE_EXECPATH",+ "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS",+ "CLAUDE_CODE_NO_FLICKER",+ "CLAUDE_CODE_USE_POWERSHELL_TOOL",+ "CLAUDE_EFFORT",+ "CLAUDE_PID",+ "CLAUDE_PLUGIN_DATA",+ # Codex: a pane inside a parent's sandbox refuses work it may do.+ "CODEX_SANDBOX",+ "CODEX_SANDBOX_NETWORK_DISABLED",+ }+)++#: Said once per process, not once per pane: a full grid would otherwise repeat+#: the same line a dozen times for one cause.+_parent_session_reported = False+++def _without_parent_agent_session(env: dict[str, str] | None) -> dict[str, str] | None:+ """``env`` with the parent session's markers removed.++ ``None`` in and nothing to strip means ``None`` out — plain inheritance, the+ spawn this app produced before any of this existed. Stripping is what makes a+ pane a TOP-LEVEL session of its CLI, which is the only kind that records a+ conversation and can therefore be resumed.+ """+ global _parent_session_reported++ source = os.environ if env is None else env+ present = sorted(name for name in PARENT_AGENT_SESSION_VARS if name in source)+ if not present:+ return env+ cleaned = dict(source)+ for name in present:+ cleaned.pop(name, None)+ if not _parent_session_reported:+ _parent_session_reported = True+ logger.info(+ "Agentic IDE: this app was started from a coding-agent session; "+ "dropping {} from every pane so its CLI runs as its own session "+ "and can be resumed later",+ ", ".join(present),+ )+ return cleaned++def _spawn_env(term: Terminal) -> dict[str, str] | None:"""The child environment that puts this pane on its own subscription.@@ -542,7 +614,7 @@ def _spawn_env(term: Terminal) -> dict[str, str] | None:overlay = agent_spawn_overlay(term.agent)if not overlay:- return env+ return _without_parent_agent_session(env)env = dict(os.environ if env is None else env)for key, value in overlay.items():# An empty value means "remove this variable from the child". A GLM pane@@ -553,7 +625,7 @@ def _spawn_env(term: Terminal) -> dict[str, str] | None:env[key] = valueelse:env.pop(key, None)- return env+ return _without_parent_agent_session(env)def agent_spawn_overlay(agent: str) -> dict[str, str]:diff --git a/tests/unit/agentic_ide/test_account_spawn.py b/tests/unit/agentic_ide/test_account_spawn.pyindex 4735c0bf56..f89d56460f 100644--- a/tests/unit/agentic_ide/test_account_spawn.py+++ b/tests/unit/agentic_ide/test_account_spawn.py@@ -23,6 +23,22 @@ from jarvis.agentic_ide.session import Registry, SessionErrorfrom tests.fakes.fake_pty_manager import FakePtyManager[email protected](autouse=True)+def _launched_from_a_plain_shell(monkeypatch: pytest.MonkeyPatch) -> None:+ """Assert the ACCOUNT, on a spawn nothing else is interfering with.++ Several assertions here read "no environment was passed at all", which is the+ promise to every user who never opens the account switcher. That promise holds+ for an app started from a plain terminal; an app started from a coding-agent+ session hands its panes an environment on purpose, with that session's markers+ removed (``test_parent_session_env``). Without this fixture the same suite+ would pass or fail depending on which terminal it was launched from — and CI+ runs it from one of each.+ """+ for marker in session_mod.PARENT_AGENT_SESSION_VARS:+ monkeypatch.delenv(marker, raising=False)++@pytest.fixturedef fake_pty() -> FakePtyManager:return FakePtyManager()@@ -263,7 +279,9 @@ async def test_a_pane_on_the_builtin_account_spawns_exactly_as_it_always_did("""No environment is passed at all — plain inheritance, byte for byte.This is the promise to everyone who never opens the switcher: adding the- feature changed nothing about how their panes start.+ feature changed nothing about how their panes start. Read together with+ ``_launched_from_a_plain_shell`` above, which is what makes "at all" a+ statement about this code rather than about the terminal running the suite."""await registry.start(str(tmp_path), [{"agent": "claude"}])await _attach(registry, registry.session.terminals[0].name)diff --git a/tests/unit/agentic_ide/test_new_cli_providers.py b/tests/unit/agentic_ide/test_new_cli_providers.pyindex fb6d2e86e2..6427290b72 100644--- a/tests/unit/agentic_ide/test_new_cli_providers.py+++ b/tests/unit/agentic_ide/test_new_cli_providers.py@@ -394,7 +394,13 @@ def test_the_environment_reaches_a_pane_through_the_real_spawn_path(assert kimi_env["KIMI_CODE_NO_AUTO_UPDATE"] == "1"# A CLI that declares nothing still inherits the machine's environment- # untouched — the behaviour every pane had before any of this existed.+ # untouched — the behaviour every pane had before any of this existed. True of+ # an app started from a plain terminal; one started from a coding-agent+ # session strips that session's markers instead (test_parent_session_env), so+ # they are cleared here rather than letting the launching terminal decide+ # whether this passes.+ for marker in ide_session.PARENT_AGENT_SESSION_VARS:+ monkeypatch.delenv(marker, raising=False)assert registry._prepare_spawn(_stub_pane("claude"), str(tmp_path)) is Nonediff --git a/tests/unit/agentic_ide/test_parent_session_env.py b/tests/unit/agentic_ide/test_parent_session_env.pynew file mode 100644index 0000000000..d8bb847d1c--- /dev/null+++ b/tests/unit/agentic_ide/test_parent_session_env.py@@ -0,0 +1,147 @@+"""A pane runs as its CLI's OWN session, never as a child of the app's launcher.++The failure these pin down is silent and total, and it only shows up a restart+later. The app is regularly started from inside a coding CLI — a contributor+running it from an agent's terminal, and the in-app restart, which hands the new+process its predecessor's environment and therefore carries one such launch+forward forever. Claude Code finds ``CLAUDE_CODE_CHILD_SESSION`` in a pane's+environment, concludes it is a nested run of itself, and switches its transcript+off: "Transcript saving is off — inherited CLAUDE_CODE_CHILD_SESSION".++Nothing looks wrong at that point. The pane works, the restore point is written,+and every pane in it holds a session id. The bill arrives on the next restart:+there is no conversation on disk behind any of those ids, so every pane comes+back with a blank history (found 2026-07-28 — a whole morning's work in five+panes, not one transcript written).++So the environment is asserted at the spawn: what a pane must NOT carry, and —+just as important — what it must still get, because a sweep of the whole+``CLAUDE_*`` namespace would take the login with it.+"""++from __future__ import annotations++from pathlib import Path++import pytest++from jarvis import agent_accounts+from jarvis.agentic_ide import session as session_mod+from jarvis.agentic_ide.session import Registry+from tests.fakes.fake_pty_manager import FakePtyManager+++def fake_pty() -> FakePtyManager:+ return FakePtyManager()+++def registry(fake_pty: FakePtyManager, monkeypatch: pytest.MonkeyPatch) -> Registry:+ monkeypatch.setattr(session_mod, "agent_argv", lambda name: (f"/usr/bin/{name}",))+ return Registry(pty_manager=fake_pty)+++async def _noop(_text: str) -> None:+ return None+++async def _noop_exit(_code: int) -> None:+ return None+++async def _spawn_one(registry: Registry, folder: Path, **pane: object) -> dict[str, str] | None:+ await registry.start(str(folder), [{"agent": "claude", **pane}])+ term = registry.session.terminals[0]+ await registry.attach(term.name, 80, 24, _noop, _noop_exit)+ manager = registry._manager() # noqa: SLF001 - the spawn record is the assertion+ assert isinstance(manager, FakePtyManager)+ return manager.spawns[0]["env"]+++async def test_a_pane_does_not_inherit_the_launching_agents_session(+ registry: Registry, tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ """The one that costs the conversation: no transcript, so nothing to resume."""+ monkeypatch.setenv("CLAUDE_CODE_CHILD_SESSION", "1")+ monkeypatch.setenv("CLAUDE_CODE_SESSION_ID", "a3f1-parent")+ monkeypatch.setenv("CLAUDECODE", "1")++ env = await _spawn_one(registry, tmp_path)++ assert env is not None, "a parent session must force an explicit environment"+ assert "CLAUDE_CODE_CHILD_SESSION" not in env+ assert "CLAUDE_CODE_SESSION_ID" not in env+ assert "CLAUDECODE" not in env+++async def test_stripping_keeps_the_login_and_the_path(+ registry: Registry, tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ """A ``CLAUDE_*`` prefix sweep would open a pane with no credential at all."""+ monkeypatch.setenv("CLAUDE_CODE_CHILD_SESSION", "1")+ monkeypatch.setenv("CLAUDE_CODE_OAUTH_TOKEN", "sk-ant-oat-not-a-real-token")+ monkeypatch.setenv("CLAUDE_CODE_MAX_OUTPUT_TOKENS", "8192")++ env = await _spawn_one(registry, tmp_path)++ assert env is not None+ assert env["CLAUDE_CODE_OAUTH_TOKEN"] == "sk-ant-oat-not-a-real-token" # noqa: S105+ # A setting the user exports for every terminal they open is theirs, not a+ # session marker.+ assert env["CLAUDE_CODE_MAX_OUTPUT_TOKENS"] == "8192"+ assert env.get("PATH")+++async def test_an_added_account_keeps_its_redirection_while_being_stripped(+ registry: Registry, tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ """Both halves land: the account this module points the CLI at, and the strip.++ The two are written by different code paths and the strip runs last, so this+ is where a fix for one could quietly undo the other.+ """+ monkeypatch.setenv("CLAUDE_CODE_CHILD_SESSION", "1")+ second = agent_accounts.create_account("claude", "Second seat")++ env = await _spawn_one(registry, tmp_path, account=second.id)++ assert env is not None+ assert env["CLAUDE_CONFIG_DIR"] == str(second.config_dir)+ assert "CLAUDE_CODE_CHILD_SESSION" not in env+++async def test_a_codex_pane_is_not_confined_to_the_parents_sandbox(+ registry: Registry, tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ """Same class, other CLI: a pane inside a parent's sandbox refuses real work."""+ monkeypatch.setenv("CODEX_SANDBOX", "seatbelt")+ monkeypatch.setenv("CODEX_SANDBOX_NETWORK_DISABLED", "1")++ await registry.start(str(tmp_path), [{"agent": "codex"}])+ term = registry.session.terminals[0]+ await registry.attach(term.name, 80, 24, _noop, _noop_exit)+ manager = registry._manager() # noqa: SLF001+ assert isinstance(manager, FakePtyManager)+ env = manager.spawns[0]["env"]++ assert env is not None+ assert "CODEX_SANDBOX" not in env+ assert "CODEX_SANDBOX_NETWORK_DISABLED" not in env+++def test_no_credential_or_config_pointer_is_on_the_strip_list() -> None:+ """The list may only ever hold markers of a RUNNING session.++ Spelled out as a test because the tempting "just sweep ``CLAUDE_*``" edit+ passes every other assertion in this file while opening every pane logged+ out, or pointing it back at the machine's default account.+ """+ forbidden = {+ "ANTHROPIC_API_KEY",+ "CLAUDE_CODE_OAUTH_TOKEN",+ "CLAUDE_CONFIG_DIR",+ "CODEX_HOME",+ "PATH",+ }+ assert not (session_mod.PARENT_AGENT_SESSION_VARS & forbidden)