Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(agentos): load southbound SSH keys from /home/{user_id}/.ssh

yechenzhen73c9abc20a47
diff --git a/jiuwenswarm/extensions/agentos/agentos_router/config.py b/jiuwenswarm/extensions/agentos/agentos_router/config.py
index 01414681dc..7a782fdc3e 100644
--- a/jiuwenswarm/extensions/agentos/agentos_router/config.py
+++ b/jiuwenswarm/extensions/agentos/agentos_router/config.py
@@ -15,6 +15,8 @@ from jiuwenswarm.extensions.agentos.agentos_router.ssh_relay import (
load_yuanrong_ssh_settings,
)
+DEFAULT_AGENT_WORKSPACE_ROOT = "/home/agentos/users"
+
@dataclass(frozen=True)
class SshChannelEndpoint:
@@ -35,6 +37,7 @@ class RouterConfig:
agent_timeout_s: float = 300.0
creating_timeout_seconds: float = 60.0
agent_key_fields: tuple[str, ...] = DEFAULT_AGENT_KEY_FIELDS
+ workspace_root: str = DEFAULT_AGENT_WORKSPACE_ROOT
ssh: YuanrongSshSettings = YuanrongSshSettings()
ssh_channel: SshChannelEndpoint | None = None
@@ -117,6 +120,10 @@ def load_router_config(config: dict[str, Any]) -> RouterConfig:
agent_key_fields=normalize_agent_key_fields(
agentos.get("agent_key_fields")
),
+ workspace_root=str(
+ agentos.get("workspace_root") or DEFAULT_AGENT_WORKSPACE_ROOT
+ ).strip()
+ or DEFAULT_AGENT_WORKSPACE_ROOT,
ssh=load_yuanrong_ssh_settings(agentos.get("ssh")),
ssh_channel=load_ssh_channel_endpoint(config),
)
diff --git a/jiuwenswarm/extensions/agentos/agentos_router/extension.py b/jiuwenswarm/extensions/agentos/agentos_router/extension.py
index c5ab8f6f53..c3a27a065e 100644
--- a/jiuwenswarm/extensions/agentos/agentos_router/extension.py
+++ b/jiuwenswarm/extensions/agentos/agentos_router/extension.py
@@ -52,6 +52,7 @@ class AgentOSRouter(AgentServerClientExtension, ThirdAgentExtension):
self._agent_manager,
ssh_relay=self._ssh_relay,
ssh_channel_endpoint=config.ssh_channel,
+ workspace_root=config.workspace_root,
)
self._third_agent = AgentOSThirdAgent(self._router_client)
self._closed = False
diff --git a/jiuwenswarm/extensions/agentos/agentos_router/router_client.py b/jiuwenswarm/extensions/agentos/agentos_router/router_client.py
index 0c8f7407e5..03d98809ce 100644
--- a/jiuwenswarm/extensions/agentos/agentos_router/router_client.py
+++ b/jiuwenswarm/extensions/agentos/agentos_router/router_client.py
@@ -20,7 +20,10 @@ from jiuwenswarm.extensions.agentos.agentos_router.agent_manager import (
AgentRuntime,
THIRD_PARTY_AGENT_TYPES,
)
-from jiuwenswarm.extensions.agentos.agentos_router.config import SshChannelEndpoint
+from jiuwenswarm.extensions.agentos.agentos_router.config import (
+ DEFAULT_AGENT_WORKSPACE_ROOT,
+ SshChannelEndpoint,
+)
from jiuwenswarm.extensions.agentos.agentos_router.models import (
AgentInfo,
AgentStatus,
@@ -58,19 +61,16 @@ def build_inline_runtime_spec(image_info: ImageInfo) -> AgentRuntimeSpec:
def resolve_agent_workspace(user_id: str, *, workspace_root: str | None = None) -> str:
"""Resolve host workspace bind path for one agent user.
- Default: ``/home/<user_id>``. Optional ``workspace_root`` overrides the
- parent directory (``{workspace_root}/<user_id>``).
+ Default: ``/home/agentos/users/<user_id>``. Optional ``workspace_root``
+ overrides the parent directory (``{workspace_root}/<user_id>``).
Best-effort ``mkdir``: permission errors are ignored so callers (and unit
tests) can still pass the path to YuanRong create; the host/deploy side
remains responsible for a writable mount source.
"""
safe_user = _WORKSPACE_NAME_RE.sub("_", str(user_id or "").strip()) or "default"
- if workspace_root:
- root = Path(workspace_root).expanduser()
- workspace = (root / safe_user).resolve()
- else:
- workspace = Path("/home") / safe_user
+ root = Path(workspace_root or DEFAULT_AGENT_WORKSPACE_ROOT).expanduser()
+ workspace = (root / safe_user).resolve()
try:
workspace.mkdir(parents=True, exist_ok=True)
except OSError as exc:
@@ -92,12 +92,16 @@ class AgentOSRouterClient(AgentServerClient):
agent_manager: AgentManager,
ssh_relay: YuanrongSshRelay | None = None,
ssh_channel_endpoint: SshChannelEndpoint | None = None,
+ workspace_root: str = DEFAULT_AGENT_WORKSPACE_ROOT,
) -> None:
self._yuanrong = yuanrong
self._registry = registry
self._agent_manager = agent_manager
self._ssh_relay = ssh_relay
self._ssh_channel_endpoint = ssh_channel_endpoint
+ self._workspace_root = (
+ str(workspace_root or "").strip() or DEFAULT_AGENT_WORKSPACE_ROOT
+ )
self._server_ready = False
self._background_tasks: set[asyncio.Task[Any]] = set()
self._closed = False
@@ -414,7 +418,11 @@ class AgentOSRouterClient(AgentServerClient):
runtime.info.user_id,
instance_id,
)
- await ssh_relay.run(relay_session, instance_id)
+ await ssh_relay.run(
+ relay_session,
+ instance_id,
+ user_id=runtime.info.user_id,
+ )
def _apply_current_agent_type_for_ssh(self, envelope: E2AEnvelope) -> None:
"""SSH 接入跟随用户当前 agent_type(由 3rdagent.switch 记录)。"""
@@ -458,7 +466,10 @@ class AgentOSRouterClient(AgentServerClient):
image_info = await self._registry.get_image_info(agent_info.agent_type)
runtime_spec = build_inline_runtime_spec(image_info)
- workspace = resolve_agent_workspace(agent_info.user_id)
+ workspace = resolve_agent_workspace(
+ agent_info.user_id,
+ workspace_root=self._workspace_root,
+ )
env_raw = image_info.metadata.get("env_vars")
env_vars = (
{str(k): str(v) for k, v in dict(env_raw).items()}
diff --git a/jiuwenswarm/extensions/agentos/agentos_router/ssh_relay.py b/jiuwenswarm/extensions/agentos/agentos_router/ssh_relay.py
index e71c98f5a8..37732f49a4 100644
--- a/jiuwenswarm/extensions/agentos/agentos_router/ssh_relay.py
+++ b/jiuwenswarm/extensions/agentos/agentos_router/ssh_relay.py
@@ -8,6 +8,9 @@ endpoint::
ssh -p 2222 'yr:instance:<instance_id>'@<frontend-host>
+Client private keys are loaded from ``client_keys_dir`` (default
+``/root/.ssh``).
+
``<instance_id>`` is the instance id returned by the YuanRong agent
create API (``POST /api/agent``), resolved by the AgentOS Router.
"""
@@ -16,15 +19,29 @@ from __future__ import annotations
import asyncio
import logging
+import re
import urllib.parse
from dataclasses import dataclass
+from pathlib import Path
from typing import Any
logger = logging.getLogger(__name__)
DEFAULT_SSH_PORT = 2222
DEFAULT_SSH_USER_TEMPLATE = "yr:instance:{instance}"
+DEFAULT_CLIENT_KEYS_DIR = "/root/.ssh"
_RELAY_BUFFER_SIZE = 32768
+_USER_ID_SAFE_RE = re.compile(r"[^A-Za-z0-9._-]+")
+# OpenSSH default IdentityFile basenames (skip *.pub / config / known_hosts).
+_DEFAULT_CLIENT_KEY_NAMES = (
+ "id_ed25519",
+ "id_ed25519_sk",
+ "id_ecdsa",
+ "id_ecdsa_sk",
+ "id_rsa",
+ "id_dsa",
+ "id_ed448",
+)
def _raise_missing_asyncssh(exc: ImportError) -> None:
@@ -43,6 +60,31 @@ def _import_asyncssh() -> Any:
return asyncssh
+def resolve_client_keys_dir(template: str, user_id: str = "") -> Path:
+ """Resolve ``client_keys_dir``; substitute ``{user_id}`` when present."""
+ safe_user = _USER_ID_SAFE_RE.sub("_", str(user_id or "").strip()) or "default"
+ raw = str(template or DEFAULT_CLIENT_KEYS_DIR).strip() or DEFAULT_CLIENT_KEYS_DIR
+ try:
+ rendered = raw.format(user_id=safe_user)
+ except (KeyError, ValueError) as exc:
+ raise ValueError(
+ f"invalid client_keys_dir template {raw!r}: {exc}"
+ ) from exc
+ return Path(rendered).expanduser()
+
+
+def list_client_key_paths(keys_dir: Path) -> list[str]:
+ """Return existing private-key paths under *keys_dir* (OpenSSH defaults)."""
+ if not keys_dir.is_dir():
+ return []
+ paths: list[str] = []
+ for name in _DEFAULT_CLIENT_KEY_NAMES:
+ path = keys_dir / name
+ if path.is_file():
+ paths.append(str(path))
+ return paths
+
+
@dataclass(frozen=True)
class YuanrongSshSettings:
"""Southbound SSH access settings for the YuanRong frontend."""
@@ -50,6 +92,7 @@ class YuanrongSshSettings:
port: int = DEFAULT_SSH_PORT
user_template: str = DEFAULT_SSH_USER_TEMPLATE
connect_timeout_s: float = 30.0
+ client_keys_dir: str = DEFAULT_CLIENT_KEYS_DIR
def load_yuanrong_ssh_settings(raw: Any) -> YuanrongSshSettings:
@@ -62,6 +105,10 @@ def load_yuanrong_ssh_settings(raw: Any) -> YuanrongSshSettings:
raw.get("user_template") or DEFAULT_SSH_USER_TEMPLATE
).strip(),
connect_timeout_s=float(raw.get("connect_timeout_s") or 30.0),
+ client_keys_dir=str(
+ raw.get("client_keys_dir") or DEFAULT_CLIENT_KEYS_DIR
+ ).strip()
+ or DEFAULT_CLIENT_KEYS_DIR,
)
@@ -92,7 +139,13 @@ class YuanrongSshRelay:
raise ValueError("instance_id is required for YuanRong SSH relay")
return self._settings.user_template.format(instance=instance)
- async def run(self, session: Any, instance_id: str) -> int:
+ async def run(
+ self,
+ session: Any,
+ instance_id: str,
+ *,
+ user_id: str = "",
+ ) -> int:
"""Relay *session* to the YuanRong instance; returns the exit code.
Always resolves ``session.done`` and ``session.exit_code`` so the
@@ -100,7 +153,7 @@ class YuanrongSshRelay:
"""
exit_code = 1
try:
- exit_code = await self._relay(session, instance_id)
+ exit_code = await self._relay(session, instance_id, user_id=user_id)
except Exception as exc: # noqa: BLE001 - report any relay failure to the client
logger.exception(
"[YuanrongSshRelay] relay failed: session=%s instance=%s",
@@ -126,7 +179,25 @@ class YuanrongSshRelay:
except Exception: # noqa: BLE001 - client may already be gone
logger.debug("[YuanrongSshRelay] client write failed", exc_info=True)
- async def _relay(self, session: Any, instance_id: str) -> int:
+ def _resolve_client_keys(self, user_id: str) -> list[str]:
+ keys_dir = resolve_client_keys_dir(
+ self._settings.client_keys_dir, user_id
+ )
+ key_paths = list_client_key_paths(keys_dir)
+ if not key_paths:
+ raise ValueError(
+ f"no SSH private keys found in {keys_dir} "
+ f"(expected one of: {', '.join(_DEFAULT_CLIENT_KEY_NAMES)})"
+ )
+ return key_paths
+
+ async def _relay(
+ self,
+ session: Any,
+ instance_id: str,
+ *,
+ user_id: str = "",
+ ) -> int:
asyncssh = _import_asyncssh()
host = self.backend_host
@@ -136,19 +207,24 @@ class YuanrongSshRelay:
"(set gateway.agent_client.frontend_endpoint with a hostname)"
)
username = self.backend_username(instance_id)
+ client_keys = self._resolve_client_keys(user_id)
logger.info(
- "[YuanrongSshRelay] connecting: %s@%s:%s session=%s",
+ "[YuanrongSshRelay] connecting: %s@%s:%s session=%s keys_dir=%s keys=%s",
username,
host,
self._settings.port,
session.session_id,
+ resolve_client_keys_dir(self._settings.client_keys_dir, user_id),
+ len(client_keys),
)
conn = await asyncio.wait_for(
asyncssh.connect(
host,
port=self._settings.port,
username=username,
+ client_keys=client_keys,
+ agent_path=None,
known_hosts=None,
),
timeout=self._settings.connect_timeout_s,
diff --git a/jiuwenswarm/resources/config.yaml b/jiuwenswarm/resources/config.yaml
index 6630dd62b2..47d97f43c7 100644
--- a/jiuwenswarm/resources/config.yaml
+++ b/jiuwenswarm/resources/config.yaml
@@ -580,6 +580,8 @@ gateway:
# AgentOS Router Extension 配置;agent_client.type=agentos_router 时生效。
agentos:
creating_timeout_seconds: 60
+ # Agent create 时宿主机 workspace 父目录;实际路径为 {workspace_root}/{user_id}
+ workspace_root: "/home/agentos/users"
# Agent 复用 key 字段,默认 user_id + agent_type。
# 可选字段:user_id、agent_type、session_id(必须包含前两项)。
# 示例:加入 session_id 后同一用户每个会话独立 Agent。
@@ -595,10 +597,12 @@ gateway:
# SSH 南向接入 YuanRong 实例(配合 channels.ssh 北向使用):
# ssh -p <port> 'yr:instance:<instance_id>'@<frontend-host>
# 主机取自 agent_client.frontend_endpoint;<instance_id> 为 create agent 返回的实例 id。
+ # 客户端私钥目录(默认 /root/.ssh;若模板含 {user_id} 则按用户替换)。
ssh:
port: 2222
user_template: "yr:instance:{instance}"
connect_timeout_s: 30
+ client_keys_dir: "/root/.ssh"
heartbeat:
# 心跳间隔(秒),默认 3600
diff --git a/tests/unit_tests/extensions/test_agentos_router.py b/tests/unit_tests/extensions/test_agentos_router.py
index 3ec0d47cf2..e3cf6406a0 100644
--- a/tests/unit_tests/extensions/test_agentos_router.py
+++ b/tests/unit_tests/extensions/test_agentos_router.py
@@ -9,6 +9,7 @@ from jiuwenswarm.common.e2a.models import E2AEnvelope
from jiuwenswarm.common.schema.agent import AgentResponse, AgentResponseChunk
from jiuwenswarm.extensions.agentos.agentos_router.agent_manager import AgentManager
from jiuwenswarm.extensions.agentos.agentos_router.config import (
+ DEFAULT_AGENT_WORKSPACE_ROOT,
SshChannelEndpoint,
agentos_router_selected,
load_router_config,
@@ -19,7 +20,10 @@ from jiuwenswarm.extensions.agentos.agentos_router.models import (
AgentStatus,
ImageInfo,
)
-from jiuwenswarm.extensions.agentos.agentos_router.router_client import AgentOSRouterClient
+from jiuwenswarm.extensions.agentos.agentos_router.router_client import (
+ AgentOSRouterClient,
+ resolve_agent_workspace,
+)
from jiuwenswarm.extensions.yuanrong_frontend_client import SandboxInfo
@@ -211,6 +215,14 @@ async def test_swarm_request_repeated_stays_direct() -> None:
assert yuanrong.send_calls == 2
+def test_resolve_agent_workspace_defaults_under_agentos_users() -> None:
+ assert resolve_agent_workspace("alice") == f"{DEFAULT_AGENT_WORKSPACE_ROOT}/alice"
+ assert resolve_agent_workspace("alice/../bob") == (
+ f"{DEFAULT_AGENT_WORKSPACE_ROOT}/alice_.._bob"
+ )
+ assert resolve_agent_workspace("u1", workspace_root="/data/ws") == "/data/ws/u1"
+
+
@pytest.mark.asyncio
async def test_third_party_type_creates_via_yuanrong() -> None:
yuanrong = FakeYuanRongClient()
@@ -221,11 +233,13 @@ async def test_third_party_type_creates_via_yuanrong() -> None:
assert response.ok
assert yuanrong.create_calls == 1
+ assert yuanrong.create_payloads[0]["workspace"] == f"{DEFAULT_AGENT_WORKSPACE_ROOT}/u1"
assert yuanrong.send_calls == 1
agents = await agent_manager.list_user_agents("u1")
assert agents[0].info.agent_type == "opencode"
assert agents[0].info.status is AgentStatus.READY
assert agents[0].info.sandbox_id == "sbx-1"
+ assert agents[0].info.metadata["workspace"] == f"{DEFAULT_AGENT_WORKSPACE_ROOT}/u1"
@pytest.mark.asyncio
@@ -477,6 +491,8 @@ def test_load_router_config_agent_key_fields() -> None:
},
"agentos": {
"agent_key_fields": ["user_id", "agent_type", "session_id"],
+ "workspace_root": "/data/agentos/users",
+ "ssh": {"client_keys_dir": "/data/agentos/.ssh"},
"registry": {
"endpoint": "http://127.0.0.1:8000",
"node": "192.168.0.12",
@@ -486,6 +502,8 @@ def test_load_router_config_agent_key_fields() -> None:
}
loaded = load_router_config(config)
assert loaded.agent_key_fields == ("user_id", "agent_type", "session_id")
+ assert loaded.workspace_root == "/data/agentos/users"
+ assert loaded.ssh.client_keys_dir == "/data/agentos/.ssh"
assert loaded.registry.endpoint == "http://127.0.0.1:8000"
assert loaded.registry.node == "192.168.0.12"
@@ -500,6 +518,30 @@ def test_load_router_config_agent_key_fields() -> None:
}
)
assert default_loaded.agent_key_fields == ("user_id", "agent_type")
+ assert default_loaded.workspace_root == DEFAULT_AGENT_WORKSPACE_ROOT
+ assert default_loaded.ssh.client_keys_dir == "/root/.ssh"
+
+
+async def test_create_uses_configured_workspace_root() -> None:
+ yuanrong = FakeYuanRongClient()
+ client = AgentOSRouterClient(
+ yuanrong,
+ FakeRegistryClient(),
+ AgentManager(),
+ ssh_channel_endpoint=_ssh_channel(),
+ workspace_root="/mnt/workspaces",
+ )
+ try:
+ response = await client.thirdagent_switch(
+ user_id="u1",
+ agent_type="claude",
+ session_id="sess-1",
+ )
+ assert response["ok"] is True
+ assert yuanrong.create_payloads[0]["workspace"] == "/mnt/workspaces/u1"
+ finally:
+ await client.shutdown()
@pytest.mark.asyncio
diff --git a/tests/unit_tests/extensions/test_agentos_ssh_relay.py b/tests/unit_tests/extensions/test_agentos_ssh_relay.py
index 73f4b14856..0fc8ffd1f3 100644
--- a/tests/unit_tests/extensions/test_agentos_ssh_relay.py
+++ b/tests/unit_tests/extensions/test_agentos_ssh_relay.py
@@ -5,6 +5,7 @@
from __future__ import annotations
import asyncio
+from pathlib import Path
from typing import Any
import pytest
@@ -18,10 +19,13 @@ from jiuwenswarm.extensions.agentos.agentos_router.config import (
)
from jiuwenswarm.extensions.agentos.agentos_router.router_client import AgentOSRouterClient
from jiuwenswarm.extensions.agentos.agentos_router.ssh_relay import (
+ DEFAULT_CLIENT_KEYS_DIR,
DEFAULT_SSH_USER_TEMPLATE,
YuanrongSshRelay,
YuanrongSshSettings,
+ list_client_key_paths,
load_yuanrong_ssh_settings,
+ resolve_client_keys_dir,
)
from jiuwenswarm.gateway.channel_manager.protocol.ssh.ssh_connect import SshRelaySession
@@ -68,7 +72,7 @@ class StubSshRelay:
backend_host: str = "frontend.yuanrong.test",
backend_port: int = 2222,
) -> None:
- self.ran: list[tuple[str, str]] = []
+ self.ran: list[tuple[str, str, str]] = []
self.failed: list[tuple[str, str]] = []
self.backend_host = backend_host
self.backend_port = backend_port
@@ -76,8 +80,14 @@ class StubSshRelay:
def backend_username(self, instance_id: str) -> str:
return DEFAULT_SSH_USER_TEMPLATE.format(instance=instance_id)
- async def run(self, session: Any, instance_id: str) -> int:
- self.ran.append((session.session_id, instance_id))
+ async def run(
+ self,
+ session: Any,
+ instance_id: str,
+ *,
+ user_id: str = "",
+ ) -> int:
+ self.ran.append((session.session_id, instance_id, user_id))
session.exit_code = 0
session.done.set()
return 0
@@ -124,12 +134,52 @@ def test_load_yuanrong_ssh_settings_defaults() -> None:
assert settings.port == 2222
assert settings.user_template == DEFAULT_SSH_USER_TEMPLATE
assert settings.connect_timeout_s == 30.0
+ assert settings.client_keys_dir == DEFAULT_CLIENT_KEYS_DIR
custom = load_yuanrong_ssh_settings(
- {"port": 2223, "user_template": "yr:{instance}"}
+ {
+ "port": 2223,
+ "user_template": "yr:{instance}",
+ "client_keys_dir": "/data/{user_id}/keys",
+ }
)
assert custom.port == 2223
assert custom.user_template == "yr:{instance}"
+ assert custom.client_keys_dir == "/data/{user_id}/keys"
+
+
+def test_resolve_client_keys_dir_defaults_to_root_ssh() -> None:
+ assert resolve_client_keys_dir(DEFAULT_CLIENT_KEYS_DIR, "alice") == Path(
+ "/root/.ssh"
+ )
+ assert resolve_client_keys_dir(
+ "/home/{user_id}/.ssh", "alice/../bob"
+ ) == Path("/home/alice_.._bob/.ssh")
+
+
+def test_list_client_key_paths_reads_default_names(tmp_path: Path) -> None:
+ (tmp_path / "id_ed25519").write_text("key-ed", encoding="utf-8")
+ (tmp_path / "id_rsa").write_text("key-rsa", encoding="utf-8")
+ (tmp_path / "id_rsa.pub").write_text("pub", encoding="utf-8")
+ (tmp_path / "known_hosts").write_text("h", encoding="utf-8")
+ assert list_client_key_paths(tmp_path) == [
+ str(tmp_path / "id_ed25519"),
+ str(tmp_path / "id_rsa"),
+ ]
+ assert list_client_key_paths(tmp_path / "missing") == []
+
+
+def test_resolve_client_keys_requires_private_key(tmp_path: Path) -> None:
+ relay = YuanrongSshRelay(
+ YuanrongSshSettings(client_keys_dir=str(tmp_path / "{user_id}")),
+ )
+ with pytest.raises(ValueError, match="no SSH private keys found"):
+ relay._resolve_client_keys("alice")
+
+ key_dir = tmp_path / "alice"
+ key_dir.mkdir()
+ (key_dir / "id_ed25519").write_text("k", encoding="utf-8")
+ assert relay._resolve_client_keys("alice") == [str(key_dir / "id_ed25519")]
def test_import_asyncssh_raises_actionable_hint(monkeypatch: pytest.MonkeyPatch) -> None:
@@ -172,6 +222,8 @@ def test_load_router_config_parses_ssh_block() -> None:
assert loaded.ssh.port == 2222
assert loaded.ssh.user_template == DEFAULT_SSH_USER_TEMPLATE
assert loaded.ssh_channel == SshChannelEndpoint(ip="192.168.1.10", port=2222)
+ assert loaded.ssh.client_keys_dir == DEFAULT_CLIENT_KEYS_DIR
+ assert loaded.workspace_root == "/home/agentos/users"
def test_load_router_config_ssh_channel_requires_enabled() -> None:
@@ -217,7 +269,7 @@ async def test_ssh_relay_creates_instance_and_starts_relay() -> None:
assert response.payload["status"] == "relay_started"
await asyncio.wait_for(session.done.wait(), timeout=5)
- assert stub_relay.ran == [("ssh_alice_1234", "sbx-1")]
+ assert stub_relay.ran == [("ssh_alice_1234", "sbx-1", "alice")]
assert stub_relay.failed == []
assert session.exit_code == 0
@@ -281,7 +333,7 @@ async def test_ssh_relay_follows_user_current_agent_type() -> None:
await asyncio.wait_for(session.done.wait(), timeout=5)
assert yuanrong.create_calls == 1 # switch 已创建,SSH 复用
- assert stub_relay.ran == [("ssh_alice_switch", "sbx-1")]
+ assert stub_relay.ran == [("ssh_alice_switch", "sbx-1", "alice")]
agents = await agent_manager.list_user_agents("alice")
assert [a.info.agent_type for a in agents] == ["opencode"]
finally: