binary-husky/gpt_academic · error · RuntimeError

{moonshot_bro_result} 程序终止。

Error message

{moonshot_bro_result} 程序终止。

What it means

Watchdog abort in the Moonshot (Kimi) streaming bridge: while iterating stream_response, if time.time() - observe_window[1] exceeds watch_dog_patience the code sets observe_window[2] = '请求超时,程序终止。' and raises RuntimeError(f'{moonshot_bro_result} 程序终止。') with the partial buffer so far. It indicates the Moonshot API stream went silent past the patience window.

Source

Thrown at request_llms/bridge_moonshot.py:189

def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=None,
                                  console_silence=False):
    gpt_bro_init = MoonShotInit()
    watch_dog_patience = 60  # 看门狗的耐心, 设置10秒即可
    stream_response = gpt_bro_init.generate_messages(inputs, llm_kwargs, history, sys_prompt, True)
    moonshot_bro_result = ''
    for content, moonshot_bro_result, error_bro_meg in stream_response:
        moonshot_bro_result = moonshot_bro_result
        if error_bro_meg:
            if len(observe_window) >= 3:
                observe_window[2] = error_bro_meg
            return f'{moonshot_bro_result} 对话错误'
            # 观测窗
        if len(observe_window) >= 1:
            observe_window[0] = moonshot_bro_result
        if len(observe_window) >= 2:
            if (time.time() - observe_window[1]) > watch_dog_patience:
                observe_window[2] = "请求超时,程序终止。"
                raise RuntimeError(f"{moonshot_bro_result} 程序终止。")
    return moonshot_bro_result

if __name__ == '__main__':
    moon_ai = MoonShotInit()
    for g in moon_ai.generate_messages('hello', {'llm_model': 'moonshot-v1-8k'},
                                       [], '', True):
        print(g)

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Check connectivity/proxy to api.moonshot.cn and the Moonshot service status; retry once.
  2. Increase watch_dog_patience or update observe_window[1] on each received chunk in the caller.
  3. Verify MOONSHOT_API_KEY and quota — auth failures can also produce silent streams before the error path fires.
  4. Check observe_window[2] after the failure; it is set to '请求超时' and confirms the watchdog (not the API error branch) fired.

Example fix

// before
if (time.time() - observe_window[1]) > watch_dog_patience:
    observe_window[2] = "请求超时,程序终止。"
    raise RuntimeError(f"{moonshot_bro_result} 程序终止。")

# after
watch_dog_patience = 60  # Kimi long generations can be silent >5s
if (time.time() - observe_window[1]) > watch_dog_patience:
    observe_window[2] = "请求超时,程序终止。"
    raise RuntimeError(f"{moonshot_bro_result} 请求超时(>{watch_dog_patience}s),程序终止。")
Defensive patterns

Strategy: retry

Validate before calling

import time
window = ['', time.time(), None]
# after the call, window[2] == '请求超时...' distinguishes watchdog stall from API error

Try / catch

try:
    out = predict_no_ui_long_connection(..., observe_window=window)
except RuntimeError as e:
    if window[2] and '请求超时' in window[2]:
        window[1] = time.time()
        out = predict_no_ui_long_connection(..., observe_window=window)  # single retry
    else:
        raise

Prevention

When it happens

Trigger: Calling predict_no_ui_long_connection against api.moonshot.cn where no chunk (or no non-error chunk) arrives within the patience window — slow network, proxy stall, server-side hang, or long silence between SSE events.

Common situations: Long generations with sparse SSE keepalives, unstable proxy to moonshot.cn, rate limiting/throttling that pauses the stream, watch_dog_patience left at default 5s.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/62005b2605806fbe. Report an issue: GitHub.