{"record":{"id":"62005b2605806fbe","repo":"binary-husky/gpt_academic","slug":"moonshot-bro-result","errorCode":null,"errorMessage":"{moonshot_bro_result} 程序终止。","messagePattern":"\\{moonshot_bro_result\\} 程序终止。","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"request_llms/bridge_moonshot.py","lineNumber":189,"sourceCode":"def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt=\"\", observe_window=None,\n                                  console_silence=False):\n    gpt_bro_init = MoonShotInit()\n    watch_dog_patience = 60  # 看门狗的耐心, 设置10秒即可\n    stream_response = gpt_bro_init.generate_messages(inputs, llm_kwargs, history, sys_prompt, True)\n    moonshot_bro_result = ''\n    for content, moonshot_bro_result, error_bro_meg in stream_response:\n        moonshot_bro_result = moonshot_bro_result\n        if error_bro_meg:\n            if len(observe_window) >= 3:\n                observe_window[2] = error_bro_meg\n            return f'{moonshot_bro_result} 对话错误'\n            # 观测窗\n        if len(observe_window) >= 1:\n            observe_window[0] = moonshot_bro_result\n        if len(observe_window) >= 2:\n            if (time.time() - observe_window[1]) > watch_dog_patience:\n                observe_window[2] = \"请求超时，程序终止。\"\n                raise RuntimeError(f\"{moonshot_bro_result} 程序终止。\")\n    return moonshot_bro_result\n\nif __name__ == '__main__':\n    moon_ai = MoonShotInit()\n    for g in moon_ai.generate_messages('hello', {'llm_model': 'moonshot-v1-8k'},\n                                       [], '', True):\n        print(g)\n","sourceCodeStart":171,"sourceCodeEnd":197,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/bridge_moonshot.py#L171-L197","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check connectivity/proxy to api.moonshot.cn and the Moonshot service status; retry once.","Increase watch_dog_patience or update observe_window[1] on each received chunk in the caller.","Verify MOONSHOT_API_KEY and quota — auth failures can also produce silent streams before the error path fires.","Check observe_window[2] after the failure; it is set to '请求超时' and confirms the watchdog (not the API error branch) fired."],"exampleFix":"// before\nif (time.time() - observe_window[1]) > watch_dog_patience:\n    observe_window[2] = \"请求超时，程序终止。\"\n    raise RuntimeError(f\"{moonshot_bro_result} 程序终止。\")\n\n# after\nwatch_dog_patience = 60  # Kimi long generations can be silent >5s\nif (time.time() - observe_window[1]) > watch_dog_patience:\n    observe_window[2] = \"请求超时，程序终止。\"\n    raise RuntimeError(f\"{moonshot_bro_result} 请求超时(>{watch_dog_patience}s)，程序终止。\")","handlingStrategy":"retry","validationCode":"import time\nwindow = ['', time.time(), None]\n# after the call, window[2] == '请求超时...' distinguishes watchdog stall from API error\n","typeGuard":null,"tryCatchPattern":"try:\n    out = predict_no_ui_long_connection(..., observe_window=window)\nexcept RuntimeError as e:\n    if window[2] and '请求超时' in window[2]:\n        window[1] = time.time()\n        out = predict_no_ui_long_connection(..., observe_window=window)  # single retry\n    else:\n        raise","preventionTips":["Use a 3-element observe_window so window[2] tells you timeout vs error","watch_dog_patience >= 30s for long Kimi generations","Verify MOONSHOT_API_KEY/quota before batch jobs"],"tags":["moonshot","kimi","watchdog","timeout","streaming","network"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}