From 3828cd4415ef7edafd4d299ed2814fb31818d7ff Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Tue, 29 Sep 2026 13:14:05 +0200 Subject: [PATCH] fix: browsing folders in the terminal file browser breaks the prompt cache With an Open Terminal connected, opening another folder in the terminal's file browser changed the tools sent to the model on the next message, because the current folder was written into the run_command tool's description. The provider's prompt cache then missed from the first byte and the whole chat was processed again. The tools now stay the same for the whole chat, and the current folder is reported in the result of each command instead. Fixes #31589 --- backend/open_webui/utils/tools.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/open_webui/utils/tools.py b/backend/open_webui/utils/tools.py index 7bd6a8dd69..262d964b4a 100644 --- a/backend/open_webui/utils/tools.py +++ b/backend/open_webui/utils/tools.py @@ -1436,17 +1436,12 @@ async def get_terminal_tools( function_name = spec['name'] tool_spec = clean_openai_tool_schema(add_terminal_display_file_inline_param(spec)) - if function_name == 'run_command' and terminal_cwd: - tool_spec['description'] = ( - tool_spec.get('description', '') + f'\n\nThe current working directory is: {terminal_cwd}' - ) - async def make_tool_function(fn_name, srv_data, hdrs, cks): async def tool_function(**kwargs): params = dict(kwargs) if fn_name == 'display_file': params.pop('page', None) - return await execute_tool_server( + data, response_headers = await execute_tool_server( url=srv_data['url'], headers=hdrs, cookies=cks, @@ -1454,6 +1449,11 @@ async def get_terminal_tools( params=params, server_data=srv_data, ) + # Reported with the result so the tool description, and the cached prompt prefix, stay the same + is_command_result = fn_name == 'run_command' and response_headers is not None and isinstance(data, dict) + if is_command_result and terminal_cwd and not params.get('cwd'): + data['cwd'] = terminal_cwd + return data, response_headers return tool_function