fix(terminal): collapse CWD-only overrides to shared container

When register_task_env_overrides is called with only a 'cwd' key
(ACP adapter workspace tracking), the task_id should collapse to
'default' so all interactive surfaces (TUI, gateway, dashboard)
share one long-lived container.

Previously, any override registration — even CWD-only — caused
_resolve_container_task_id to return the session key unchanged,
spinning up a separate container per session. This made it
impossible to authenticate into external services once and have
that auth available across all surfaces.

Now only overrides containing isolation keys (docker_image,
modal_image, singularity_image, daytona_image, env_type) trigger
per-task container isolation.

Fixes #37361
This commit is contained in:
liuhao1024 2026-06-02 19:54:37 +08:00 committed by Teknium
parent 1a626470ca
commit 6459b3d991
2 changed files with 58 additions and 1 deletions

View file

@ -1006,9 +1006,20 @@ def _resolve_container_task_id(task_id: Optional[str]) -> str:
task_id, we honour it by returning the task_id unchanged -- those
rollouts need their own isolated sandbox, which is the whole point of
the override.
CWD-only overrides (registered by the ACP adapter for workspace
tracking) are *not* isolation signals they should not cause each
session to spin up its own container. Only overrides containing
backend-specific image keys or ``env_type`` trigger isolation.
"""
_ISOLATION_KEYS = frozenset({
"docker_image", "modal_image", "singularity_image",
"daytona_image", "env_type",
})
if task_id and task_id in _task_env_overrides:
return task_id
overrides = _task_env_overrides[task_id]
if set(overrides.keys()) & _ISOLATION_KEYS:
return task_id
return "default"