From 1fe94898f68a71c1befd645ea8cece61b9673d79 Mon Sep 17 00:00:00 2001 From: Re-bin Date: Fri, 27 Feb 2026 16:13:26 +0000 Subject: [PATCH 1/7] fix: generate short alphanumeric tool_call_id for Mistral compatibility --- nanobot/providers/litellm_provider.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nanobot/providers/litellm_provider.py b/nanobot/providers/litellm_provider.py index 0918954..5427d97 100644 --- a/nanobot/providers/litellm_provider.py +++ b/nanobot/providers/litellm_provider.py @@ -3,6 +3,8 @@ import json import json_repair import os +import secrets +import string from typing import Any import litellm @@ -15,6 +17,11 @@ from nanobot.providers.registry import find_by_model, find_gateway # Standard OpenAI chat-completion message keys plus reasoning_content for # thinking-enabled models (Kimi k2.5, DeepSeek-R1, etc.). _ALLOWED_MSG_KEYS = frozenset({"role", "content", "tool_calls", "tool_call_id", "name", "reasoning_content"}) +_ALNUM = string.ascii_letters + string.digits + +def _short_tool_id() -> str: + """Generate a 9-char alphanumeric ID compatible with all providers (incl. Mistral).""" + return "".join(secrets.choice(_ALNUM) for _ in range(9)) class LiteLLMProvider(LLMProvider): @@ -245,7 +252,7 @@ class LiteLLMProvider(LLMProvider): args = json_repair.loads(args) tool_calls.append(ToolCallRequest( - id=tc.id, + id=_short_tool_id(), name=tc.function.name, arguments=args, )) From 8842fb2b4d734e06caded189a129a432bfa31731 Mon Sep 17 00:00:00 2001 From: GabrielWithTina Date: Sat, 28 Feb 2026 09:44:28 +0800 Subject: [PATCH 2/7] fix: pass msg_id in QQ C2C reply to avoid proactive message permission error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QQ's bot API requires a msg_id (original inbound message ID) to send a passive reply. Without it the request is treated as a proactive message and fails with error 40034102 (无权限). The message_id was already stored in InboundMessage.metadata and forwarded to OutboundMessage, but was never read in send(). Co-Authored-By: Claude Sonnet 4.6 --- nanobot/channels/qq.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nanobot/channels/qq.py b/nanobot/channels/qq.py index 5352a30..50dbbde 100644 --- a/nanobot/channels/qq.py +++ b/nanobot/channels/qq.py @@ -100,10 +100,12 @@ class QQChannel(BaseChannel): logger.warning("QQ client not initialized") return try: + msg_id = msg.metadata.get("message_id") await self._client.api.post_c2c_message( openid=msg.chat_id, msg_type=0, content=msg.content, + msg_id=msg_id, ) except Exception as e: logger.error("Error sending QQ message: {}", e) From 66063abb8cc6d79371bbfd3ae28c9c7a13784c6e Mon Sep 17 00:00:00 2001 From: Nikolas de Hor Date: Sat, 28 Feb 2026 00:57:08 -0300 Subject: [PATCH 3/7] fix: prevent session poisoning from null/error LLM responses When an LLM returns content: null on a plain assistant message (no tool_calls), the null gets saved to session history and causes permanent 400 errors on every subsequent request. - Sanitize None content on plain assistant messages to "(empty)" in _sanitize_empty_content(), matching the existing empty-string handling - Skip persisting error responses (finish_reason="error") to the message history in _run_agent_loop(), preventing poison loops Closes #1303 --- nanobot/agent/loop.py | 6 ++++++ nanobot/providers/base.py | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.py index 6fe37e9..6cd8e56 100644 --- a/nanobot/agent/loop.py +++ b/nanobot/agent/loop.py @@ -224,6 +224,12 @@ class AgentLoop: ) else: clean = self._strip_think(response.content) + # Don't persist error responses to session history — they can + # poison the context and cause permanent 400 loops (#1303). + if response.finish_reason == "error": + logger.error("LLM returned error: {}", (clean or "")[:200]) + final_content = clean or "Sorry, I encountered an error calling the AI model." + break messages = self.context.add_assistant_message( messages, clean, reasoning_content=response.reasoning_content, ) diff --git a/nanobot/providers/base.py b/nanobot/providers/base.py index eb1599a..f52a951 100644 --- a/nanobot/providers/base.py +++ b/nanobot/providers/base.py @@ -51,6 +51,14 @@ class LLMProvider(ABC): for msg in messages: content = msg.get("content") + # None content on a plain assistant message (no tool_calls) crashes + # providers with "invalid message content type: ". + if content is None and msg.get("role") == "assistant" and not msg.get("tool_calls"): + clean = dict(msg) + clean["content"] = "(empty)" + result.append(clean) + continue + if isinstance(content, str) and not content: clean = dict(msg) clean["content"] = None if (msg.get("role") == "assistant" and msg.get("tool_calls")) else "(empty)" From cc8864dc1f049d617b13bbbe973901304b210115 Mon Sep 17 00:00:00 2001 From: Nikolas de Hor Date: Sat, 28 Feb 2026 01:01:20 -0300 Subject: [PATCH 4/7] fix: remove overly broad "codex" keyword from openai_codex provider The bare keyword "codex" causes false positive matches when any model name happens to contain "codex" (e.g. "gpt-5.3-codex" on a custom provider). This incorrectly routes the request through the OAuth-based OpenAI Codex provider, producing "OAuth credentials not found" errors even when a valid custom api_key and api_base are configured. Keep only the explicit "openai-codex" keyword so that auto-detection requires the canonical prefix. Users can still set provider: "custom" to force the custom endpoint, but auto-detection should not collide. Closes #1311 --- nanobot/providers/registry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nanobot/providers/registry.py b/nanobot/providers/registry.py index 2766929..df915b7 100644 --- a/nanobot/providers/registry.py +++ b/nanobot/providers/registry.py @@ -201,7 +201,7 @@ PROVIDERS: tuple[ProviderSpec, ...] = ( # OpenAI Codex: uses OAuth, not API key. ProviderSpec( name="openai_codex", - keywords=("openai-codex", "codex"), + keywords=("openai-codex",), env_key="", # OAuth-based, no API key display_name="OpenAI Codex", litellm_prefix="", # Not routed through LiteLLM From 936e094a7f8446fdb1835bf28e7a1df8480fdd0d Mon Sep 17 00:00:00 2001 From: Yan-ke Guo Date: Sat, 28 Feb 2026 14:03:36 +0800 Subject: [PATCH 5/7] Modify Feishu bot permissions in README Updated permissions for Feishu bot setup instructions. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 251181b..d788e5e 100644 --- a/README.md +++ b/README.md @@ -420,7 +420,7 @@ Uses **WebSocket** long connection — no public IP required. **1. Create a Feishu bot** - Visit [Feishu Open Platform](https://open.feishu.cn/app) - Create a new app → Enable **Bot** capability -- **Permissions**: Add `im:message` (send messages) +- **Permissions**: Add `im:message` (send messages) and `im:message.p2p_msg:readonly` (receive messages) - **Events**: Add `im.message.receive_v1` (receive messages) - Select **Long Connection** mode (requires running nanobot first to establish connection) - Get **App ID** and **App Secret** from "Credentials & Basic Info" From e440aa72c59cc0c8d39374a28d05a6003d9adda3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=AD=A3?= <30361780+azhengzz@users.noreply.github.com> Date: Sat, 28 Feb 2026 15:10:35 +0800 Subject: [PATCH 6/7] fix the interactive message text cannot be extracted --- nanobot/channels/feishu.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nanobot/channels/feishu.py b/nanobot/channels/feishu.py index 4a6312e..6703f21 100644 --- a/nanobot/channels/feishu.py +++ b/nanobot/channels/feishu.py @@ -89,8 +89,9 @@ def _extract_interactive_content(content: dict) -> list[str]: elif isinstance(title, str): parts.append(f"title: {title}") - for element in content.get("elements", []) if isinstance(content.get("elements"), list) else []: - parts.extend(_extract_element_content(element)) + for elements in content.get("elements", []) if isinstance(content.get("elements"), list) else []: + for element in elements: + parts.extend(_extract_element_content(element)) card = content.get("card", {}) if card: From 0036116e0ba94b2b7a1889a570d0a345ddc538a3 Mon Sep 17 00:00:00 2001 From: Re-bin Date: Sat, 28 Feb 2026 07:35:07 +0000 Subject: [PATCH 7/7] fix: filter empty assistant messages in _save_turn instead of patching at send time --- nanobot/agent/loop.py | 2 ++ nanobot/providers/base.py | 8 -------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.py index 6cd8e56..9bca0a2 100644 --- a/nanobot/agent/loop.py +++ b/nanobot/agent/loop.py @@ -451,6 +451,8 @@ class AgentLoop: for m in messages[skip:]: entry = {k: v for k, v in m.items() if k != "reasoning_content"} role, content = entry.get("role"), entry.get("content") + if role == "assistant" and not content and not entry.get("tool_calls"): + continue # skip empty assistant messages — they poison session context if role == "tool" and isinstance(content, str) and len(content) > self._TOOL_RESULT_MAX_CHARS: entry["content"] = content[:self._TOOL_RESULT_MAX_CHARS] + "\n... (truncated)" elif role == "user": diff --git a/nanobot/providers/base.py b/nanobot/providers/base.py index f52a951..eb1599a 100644 --- a/nanobot/providers/base.py +++ b/nanobot/providers/base.py @@ -51,14 +51,6 @@ class LLMProvider(ABC): for msg in messages: content = msg.get("content") - # None content on a plain assistant message (no tool_calls) crashes - # providers with "invalid message content type: ". - if content is None and msg.get("role") == "assistant" and not msg.get("tool_calls"): - clean = dict(msg) - clean["content"] = "(empty)" - result.append(clean) - continue - if isinstance(content, str) and not content: clean = dict(msg) clean["content"] = None if (msg.get("role") == "assistant" and msg.get("tool_calls")) else "(empty)"