From b6317157f32b551fe68ebc55e549a6d2d28ec006 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Thu, 3 Dec 2026 00:21:03 +0100 Subject: [PATCH] fix: a folder's instruction file is left out when it and the home AGENTS.md fit 32 KiB together (#35564) The 32 KiB limit for AGENTS.md files counted the heading added in front of the one in the machine's home folder as if it were file content. A home file and a folder's AGENTS.md or CLAUDE.md that together are exactly 32 KiB therefore lost the folder's instructions, while a single 32 KiB home file was accepted. The limit now counts only the files themselves, the same way for one file and for two. Fixes #35559 --- backend/open_webui/utils/machines/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/utils/machines/__init__.py b/backend/open_webui/utils/machines/__init__.py index 9000f51097..994ff4dae9 100644 --- a/backend/open_webui/utils/machines/__init__.py +++ b/backend/open_webui/utils/machines/__init__.py @@ -907,6 +907,7 @@ async def get_machine_agents_md(request, user, metadata: dict, extra_params: dic if not isinstance(home, str) or not (posixpath.isabs(home) or ntpath.isabs(home)): return None contents = [] + total_bytes = 0 candidates = [[home, ('AGENTS.md',)]] directory = await get_chat_folder_directory(metadata) if directory and directory != home: @@ -918,10 +919,11 @@ async def get_machine_agents_md(request, user, metadata: dict, extra_params: dic content = data.get('content') if isinstance(data, dict) else None if not isinstance(content, str) or not content.strip(): continue - size = sum(len(text.encode('utf-8')) for text in [*contents, content]) - if size > MAX_AGENTS_MD_BYTES: + size = len(content.encode('utf-8')) + if total_bytes + size > MAX_AGENTS_MD_BYTES: log.warning('Skipping machine %s: exceeds %s bytes', name, MAX_AGENTS_MD_BYTES) else: + total_bytes += size contents.append(f'# {name}\n\n{content}') break return '\n\n'.join(contents) or None