From 9a8748796dfbca1bbc8d1ae16041d87d9722f996 Mon Sep 17 00:00:00 2001 From: David Metcalfe <80915+DavidMetcalfe@users.noreply.github.com> Date: Fri, 24 Jul 2026 16:29:44 -0700 Subject: [PATCH] fix(kimi): exclude brotli from Accept-Encoding to work around httpx/brotlicffi streaming decode bug (#59556) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit httpx's brotlicffi backend (pinned for Discord attachment decoding) fails on Kimi API's content-encoding: br SSE streaming responses with: brotli: decoder process called with data when can_accept_more_data() is False This surfaces as 'API call failed after 3 retries: Connection error' on Windows Desktop where the Electron-packaged Python venv includes brotlicffi (#59556). DeepSeek and Xiaomi are unaffected — only moonshot endpoints (api.moonshot.ai, api.moonshot.cn) trigger the bug. The fix forces Accept-Encoding: gzip so the Kimi API falls back to gzip compression, which httpx handles reliably on all platforms. This is the same workaround already applied in tools/skills_hub.py for sitemap fetches and the Hermes index download. Closes associated issues: #28043, #48428 (cherry picked from commit 9c130133b0676138858b73847d1d7c7549339484) --- plugins/model-providers/kimi-coding/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/model-providers/kimi-coding/__init__.py b/plugins/model-providers/kimi-coding/__init__.py index 85d93de286..3bf88f080c 100644 --- a/plugins/model-providers/kimi-coding/__init__.py +++ b/plugins/model-providers/kimi-coding/__init__.py @@ -13,6 +13,10 @@ _HEADERS = { "HTTP-Referer": "https://hermes-agent.nousresearch.com", "X-Title": "Hermes Agent", "User-Agent": f"HermesAgent/{_HERMES_VERSION}", + # Exclude brotli: httpx's brotlicffi backend has a streaming decode bug on + # Moonshot's content-encoding: br SSE responses (#28043, #48428, #59556). + # gzip sidesteps it while still compressing the transfer. + "Accept-Encoding": "gzip", }