fix(prompt-auto-optimization): skip non-dict edit list entries - #383
fix(prompt-auto-optimization): skip non-dict edit list entries#383santhreal wants to merge 2 commits into
Conversation
apply_edits tool args can include a string or null in edits; e.get then AttributeError. Skip those entries with an error and keep applying the rest.
|
Warning Review limit reached
Next review available in: 48 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough更新 Changes编辑输入容错处理
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@chapter8/prompt-auto-optimization/coding_agent.py`:
- Around line 70-72: 调整 optimize_prompt 中对 errors
的处理:非字典编辑项在当前校验分支中记录为可跳过的警告,并继续保留后续及此前成功应用的编辑;仅将 _apply_one 的应用失败纳入触发 working
回滚为 original 的错误集合。更新最终返回状态和反馈,使类型错误仍可见但不会导致全部有效编辑回滚。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 79f45804-8b81-467a-b330-67929862700e
📒 Files selected for processing (2)
chapter8/prompt-auto-optimization/coding_agent.pychapter8/prompt-auto-optimization/test_non_dict_edit.py
| if not isinstance(e, dict): | ||
| errors.append(f"edit 必须是对象,收到 {type(e).__name__}") | ||
| continue |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
避免因可跳过的非字典项回滚全部有效编辑。
这里虽然继续应用了后续合法编辑,但 optimize_prompt 会在 errors 非空时将 working 回滚为 original(Line 153-155)。因此,只要列表中包含一个字符串或 None,有效编辑最终也不会落盘,违背“跳过无效项但继续应用有效项”的目标。
请区分“跳过的类型错误”和 _apply_one 的应用失败:前者应作为警告反馈但保留已应用编辑,后者才触发原子回滚。
🧰 Tools
🪛 Ruff (0.15.21)
[warning] 71-71: String contains ambiguous , (FULLWIDTH COMMA). Did you mean , (COMMA)?
(RUF001)
🤖 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 `@chapter8/prompt-auto-optimization/coding_agent.py` around lines 70 - 72, 调整
optimize_prompt 中对 errors 的处理:非字典编辑项在当前校验分支中记录为可跳过的警告,并继续保留后续及此前成功应用的编辑;仅将
_apply_one 的应用失败纳入触发 working 回滚为 original
的错误集合。更新最终返回状态和反馈,使类型错误仍可见但不会导致全部有效编辑回滚。
bojieli
left a comment
There was a problem hiding this comment.
A mixed list still does not apply its valid edits: the new guard records non-dict entries in errors, and optimize_prompt treats any error as atomic failure and resets working to original. The focused tests exercise only the helper, not the caller rollback. Please separate skipped-entry warnings from real edit failures and add an optimize_prompt-level regression test. This branch also conflicts with main; rebase while preserving the newer structured-feedback handling.
An edits list with a non-dict entry made _apply_edits_from_args crash on .get.
Skip non-dict edit items and apply the rest.
Summary by CodeRabbit
Bug 修复
测试