fix: auto-review JSON 解析误判 bug#7
Merged
Merged
Conversation
There was a problem hiding this comment.
Auto Review (Round 1) — Changes Requested
第 1 轮审查:发现 1 个 Critical 问题(O(n²) 性能风险)和 1 个 Warning(异常处理缺失)。核心改进合理(避免贪婪正则被文本中花括号干扰),但嵌套循环在大文本下可能超时,建议优化为单次扫描或限制搜索范围。
- .github/workflows/auto-review.yml L189: [Critical] O(n²) 性能风险:嵌套循环
for i in enumerate(text)+for j in range(len(text), i, -1)在大文本下复杂度为 O(n²)。当text为 2000 字符(text[:2000]fallback)时,最坏情况需要 4M 次迭代。建议优化:(1) 限制搜索范围for i in range(min(len(text), 5000));(2) 或改用单次扫描 + 栈匹配花括号(O(n))。 - .github/workflows/auto-review.yml L194: [Warning] 异常处理范围过宽:
except (json.JSONDecodeError, ValueError)会吞掉所有 JSON 解析错误,包括代码逻辑错误(如text[i:j]越界)。建议只捕获json.JSONDecodeError,其他异常应该暴露出来以便调试。
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.
修复贪婪正则导致 approved:true 被误解析为 False 的问题。改用逐位置尝试解析,找包含 approved key 的 JSON 对象。