From bb928b0dfed6c093f3980b3079f7a528ab7d06a6 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 27 Jul 2026 09:07:47 +0200 Subject: [PATCH] fix: fetch the terminal system prompt per request (#27242) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: fetch terminal system prompt per request with TTL cache The system prompt was only fetched once in set_terminal_servers (startup or connection save) with a 3s timeout, using a synthetic 'system' user. That snapshot silently stays empty when the fetch races a cold-started orchestrator instance, and goes stale when instances are reprovisioned with a changed OPEN_TERMINAL_SYSTEM_PROMPT — recovering only after a restart or a manual connection re-save. - Fetch /system during get_terminal_tools with the user's own credentials via a central TTL-cached method (5 min per server+user; failures cached 60s so a dead instance doesn't stall every request), falling back to the cached snapshot. - Raise the fetch timeout from 3s to 30s so cold-provisioned instances can answer. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01KjnQJNKozp47vTB13pRyYs * refac: fetch the terminal system prompt per request without a cache Drop the module-level TTL cache and fetch the system prompt directly in get_terminal_tools, gathered with the existing uncached per-request cwd fetch that already follows this pattern. The fetch uses the user's own credentials and falls back to the set_terminal_servers snapshot, so a cold or unreachable instance degrades to the previous behaviour instead of needing an error cache. Also restore the 3s timeout: on the request path a 30s wait would stall chat completions, and a cold instance is covered by the snapshot fallback until it warms up. --------- Co-authored-by: Claude --- backend/open_webui/utils/tools.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/utils/tools.py b/backend/open_webui/utils/tools.py index 624f3d3c77..e02570c2f4 100644 --- a/backend/open_webui/utils/tools.py +++ b/backend/open_webui/utils/tools.py @@ -1357,15 +1357,19 @@ async def get_terminal_tools( headers.update(bearer_auth_header(oauth_token.get('access_token', ''))) # auth_type == "none": no Authorization header - system_prompt = server_data.get('system_prompt') - # Use chat_id as the per-session key for cwd tracking metadata = extra_params.get('__metadata__', {}) session_id = metadata.get('chat_id') if session_id: headers['X-Session-Id'] = session_id - terminal_cwd = await get_terminal_cwd(server_data['url'], headers, cookies) + # Fetch live with the user's credentials so prompt changes apply without a restart + terminal_cwd, system_prompt = await asyncio.gather( + get_terminal_cwd(server_data['url'], headers, cookies), + get_terminal_system_prompt(server_data['url'], headers, cookies), + ) + if not system_prompt: + system_prompt = server_data.get('system_prompt') tools_dict = {} for spec in specs: