From 06e3e8f0f6a240abf700207b731cb5bfdcbe7093 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Thu, 20 Aug 2026 22:06:30 +0200 Subject: [PATCH] refactor: remove the deprecated automation worker alias and unused terminal helper The automation module wraps the scheduler loop under its old name, with a comment saying it is kept so stale imports still work. Startup imports the real name directly and nothing anywhere in the tree reaches the alias, so it only provides a second name for the same loop. A helper that pushes a working directory to a terminal server sits beside it with no caller either. That helper was the only reader of the terminal block in the automation payload. The block still validates and persists, so this change leaves it in place, but nothing consumes it any more. This removes around 55 lines and leaves one entry point for the scheduler. --- backend/open_webui/utils/automations.py | 55 ------------------------- 1 file changed, 55 deletions(-) diff --git a/backend/open_webui/utils/automations.py b/backend/open_webui/utils/automations.py index 1d4be9b20b..d5f18a9807 100644 --- a/backend/open_webui/utils/automations.py +++ b/backend/open_webui/utils/automations.py @@ -41,7 +41,6 @@ from open_webui.models.users import Users from open_webui.utils.auth import create_token from open_webui.utils.misc import parse_duration from open_webui.utils.task import prompt_template -from open_webui.utils.terminals import get_terminal_server_url from starlette.datastructures import Headers log = logging.getLogger(__name__) @@ -198,12 +197,6 @@ def rrule_interval_seconds(s: str) -> Optional[int]: ############################ -# Keep the old name as an alias so any stale imports still work. -async def automation_worker_loop(app) -> None: - """Deprecated alias — use scheduler_worker_loop.""" - await scheduler_worker_loop(app) - - async def scheduler_worker_loop(app) -> None: """Unified background scheduler for all time-based work. @@ -332,54 +325,6 @@ async def _resolve_model_defaults(app, model_id: str) -> tuple[list[str], dict, return tool_ids, features, filter_ids, terminal_id -async def _set_terminal_cwd(app, server_id: str, user, cwd: str, chat_id: str) -> None: - """Set the working directory on a terminal server via the proxy. - - Routes through the open-webui terminal proxy endpoint so that - auth headers, orchestrator policy routing, and X-User-Id are - handled correctly — same path the frontend uses. - """ - import aiohttp - from open_webui.env import AIOHTTP_CLIENT_SESSION_SSL - - connections = getattr(getattr(app, 'state', None), 'config', None) - if connections is None: - return - connections = getattr(connections, 'TERMINAL_SERVER_CONNECTIONS', None) or [] - connection = next((c for c in connections if c.get('id') == server_id), None) - if connection is None: - log.warning(f'Terminal server {server_id} not found for CWD set') - return - - base_url = get_terminal_server_url(connection) - if not base_url: - return - - target_url = f'{base_url}/files/cwd' - - headers = {'Content-Type': 'application/json', 'X-User-Id': user.id} - if chat_id: - headers['X-Session-Id'] = chat_id - - auth_type = connection.get('auth_type', 'bearer') - if auth_type == 'bearer': - headers['Authorization'] = f'Bearer {connection.get("key", "")}' - - try: - async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=10)) as session: - async with session.post( - target_url, - json={'path': cwd}, - headers=headers, - ssl=AIOHTTP_CLIENT_SESSION_SSL, - ) as resp: - if resp.status != 200: - body = await resp.text() - log.warning(f'Failed to set terminal CWD to {cwd}: HTTP {resp.status} — {body[:200]}') - except Exception as e: - log.warning(f'Failed to set terminal CWD: {e}') - - async def _execute_channel_automation( app, automation: AutomationModel,