fix(planning): handle empty LLM response in macro plan parsing (#162)#171
fix(planning): handle empty LLM response in macro plan parsing (#162)#171liaoyl830 wants to merge 1 commit into
Conversation
…inglinyi#162) When using glm-4.5-air or other models that occasionally return empty responses, _parse_llm_response would throw a cryptic JSONDecodeError instead of a clear error message. Add a check for empty cleaned content before attempting json.loads(), raising a descriptive ValueError that autopilot_daemon can handle gracefully via its existing error handling.
📝 WalkthroughWalkthroughThis PR adds defensive error handling and improves EPUB export robustness. LLM response parsing now validates and fails early with a user-friendly error when content is empty. EPUB export adds diagnostic logging for missing chapter content and explicitly generates proper EPUB 3 navigation documents. ChangesError Handling and Export Improvements
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
application/core/services/export_service.py (1)
200-203: ⚡ Quick winInclude nav in spine for EPUB 3 reader compatibility.
At Line 203,
EpubNav()is added, but the spine still excludes"nav". Some readers rely on nav being in reading order; adding it to spine improves compatibility.Proposed change
- book.spine = spine_items + book.spine = ["nav", *spine_items]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@application/core/services/export_service.py` around lines 200 - 203, The EPUB spine currently assigns book.spine = spine_items after adding book.add_item(epub.EpubNav()), but it never includes the "nav" item id in the spine; modify the spine construction so the nav id is included in the reading order (e.g., insert or append "nav" into the spine_items list before assigning book.spine) so the epub.EpubNav() item added by book.add_item(epub.EpubNav()) is present in the spine for EPUB 3 compatibility.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@application/core/services/export_service.py`:
- Around line 200-203: The EPUB spine currently assigns book.spine = spine_items
after adding book.add_item(epub.EpubNav()), but it never includes the "nav" item
id in the spine; modify the spine construction so the nav id is included in the
reading order (e.g., insert or append "nav" into the spine_items list before
assigning book.spine) so the epub.EpubNav() item added by
book.add_item(epub.EpubNav()) is present in the spine for EPUB 3 compatibility.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: f5b19975-a32b-4796-90ec-19ad7b0969cd
📒 Files selected for processing (2)
application/blueprint/services/continuous_planning_service.pyapplication/core/services/export_service.py
变更类型
fixBug 修复变更说明
修复使用 glm-4.5-air 等模型时,LLM 偶尔返回空响应导致的
JSONDecodeError: Expecting value: line 1 column 1 (char 0)错误。根因
_parse_llm_response()方法在清理 LLM 返回内容后,直接调用json.loads()。当模型返回空字符串时(可能由于 API 限流、网络问题或模型自身问题),json.loads("")会抛出难以理解的 JSONDecodeError。修复
在
json.loads()之前增加空内容检查,返回描述性ValueError,便于autopilot_daemon的现有错误处理逻辑识别并优雅降级。架构影响
applicationSummary by CodeRabbit