fix(knowledge-graph): 消除 KG Build LLM 调用重试死循环 — 全局统一超时与重试管控 - #518
Merged
Conversation
根因:OpenAI SDK 内部隐形重试(默认 max_retries=2)与应用层重试(max_retries=2) 叠加,导致单 chunk 提取超时预算从设计的 61s 膨胀至 187s,每个 chunk 白等 90s。 修复策略: - 新增全局可配置常量 KG_LLM_TIMEOUT_SECONDS=300s(5min)、KG_LLM_MAX_RETRIES=3, 支持环境变量覆盖 - 所有 litellm.acompletion() 调用统一传入 num_retries=0, max_retries=0,彻底禁用 SDK 隐形重试,全链路由应用层统一管控 - 新增 call_llm_with_retry() 公共工具函数,供 community_summarizer / global_search 复用,获得与提取器一致的 3 次重试保障 - service.py 外层 chunk_extract_timeout 改为自动推导,确保预算覆盖内层重试 - 断路器新增 llm_cancel 协同取消信号,OPEN 时通知同批并发 chunk 立即跳过 LLM 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
…rror; 当 CooccurrenceRelationExtractor.extract() 抛出异常时,relations 变量在 try 块内 赋值被跳过,但 return 语句在 try/except 外仍执行。在 except 块内初始化 relations = [] 确保 fallback 失败时安全返回空关系列表。 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
核心变更
litellm.acompletion()调用统一传入num_retries=0, max_retries=0,消除 OpenAI SDK 内部不可控的重试层KG_LLM_TIMEOUT_SECONDS=300s(5min 单次超时)和KG_LLM_MAX_RETRIES=3(每个独立 LLM 请求最多 3 次重试),支持环境变量覆盖call_llm_with_retry()供 community_summarizer / global_search 复用,获得与提取器一致的调用保障chunk_extract_timeout由max_retries × timeout + backoff自动计算,确保预算覆盖llm_cancel事件信号,断路器 OPEN 时通知同批并发 chunk 立即跳过 LLM 走 fallback风险与回滚
git revert即可恢复原始行为验证证据
test_extraction_llm_plan)影响范围
extractors.py、service.py、community_summarizer.py、global_search.pyNext Best Action
Retrying request to /chat/completions死循环🤖 Generated with Claude Code