fix: clearer terminal backend requirement errors

Salvaged from PR #979 onto current main.

Preserve the current terminal backend checks while surfacing actionable
preflight errors for unknown TERMINAL_ENV values, missing SSH host/user
configuration, and missing Modal credentials/config. Tighten the modal
regression test so it deterministically exercises the config-missing
path.
This commit is contained in:
Oktay Aydin 2026-03-14 06:04:39 -07:00 committed by teknium1
parent b646440ca0
commit 00a0f18544
2 changed files with 87 additions and 5 deletions

View file

@ -1171,7 +1171,13 @@ def check_terminal_requirements() -> bool:
elif env_type == "ssh":
# Check that host and user are configured
return bool(config.get("ssh_host")) and bool(config.get("ssh_user"))
if not config.get("ssh_host") or not config.get("ssh_user"):
logger.error(
"SSH backend selected but TERMINAL_SSH_HOST and TERMINAL_SSH_USER "
"are not both set. Configure both or switch TERMINAL_ENV to 'local'."
)
return False
return True
elif env_type == "modal":
ensure_minisweagent_on_path(Path(__file__).resolve().parent.parent)
@ -1179,16 +1185,30 @@ def check_terminal_requirements() -> bool:
logger.error("mini-swe-agent is required for modal terminal backend but is not importable")
return False
# Check for modal token
return os.getenv("MODAL_TOKEN_ID") is not None or Path.home().joinpath(".modal.toml").exists()
has_token = os.getenv("MODAL_TOKEN_ID") is not None
has_config = Path.home().joinpath(".modal.toml").exists()
if not (has_token or has_config):
logger.error(
"Modal backend selected but no MODAL_TOKEN_ID environment variable "
"or ~/.modal.toml config file was found. Configure Modal or choose "
"a different TERMINAL_ENV."
)
return False
return True
elif env_type == "daytona":
from daytona import Daytona
return os.getenv("DAYTONA_API_KEY") is not None
else:
logger.error(
"Unknown TERMINAL_ENV '%s'. Use one of: local, docker, singularity, "
"modal, daytona, ssh.",
env_type,
)
return False
except Exception as e:
logger.error("Terminal requirements check failed: %s", e)
logger.error("Terminal requirements check failed: %s", e, exc_info=True)
return False