Skip to content

fix(prompt-auto-optimization): skip non-dict edit list entries - #383

Open
santhreal wants to merge 2 commits into
bojieli:mainfrom
santhreal:upstream/prompt-auto-opt-non-dict-edit
Open

fix(prompt-auto-optimization): skip non-dict edit list entries#383
santhreal wants to merge 2 commits into
bojieli:mainfrom
santhreal:upstream/prompt-auto-opt-non-dict-edit

Conversation

@santhreal

@santhreal santhreal commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

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 修复

    • 改善编辑输入的容错能力,避免非法格式导致运行时错误。
    • 自动跳过非对象类型的编辑项并记录错误,同时继续处理其他有效编辑。
    • 当编辑列表为空或缺失时,统一按空列表处理。
  • 测试

    • 新增对字符串、空值及空编辑列表等异常输入场景的覆盖。

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.
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@santhreal, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 09e5a70f-0bd7-46c2-a376-560ec9898d1b

📥 Commits

Reviewing files that changed from the base of the PR and between 1f0a4fb and 1b2484d.

📒 Files selected for processing (1)
  • chapter8/prompt-auto-optimization/coding_agent.py
📝 Walkthrough

Walkthrough

更新 _apply_edits_from_args,使缺失或为 None 的编辑列表归一化为空列表,并跳过非字典编辑项、记录错误。新增测试覆盖字符串、None 编辑项及空编辑列表。

Changes

编辑输入容错处理

Layer / File(s) Summary
编辑校验与测试
chapter8/prompt-auto-optimization/coding_agent.py, chapter8/prompt-auto-optimization/test_non_dict_edit.py
编辑应用函数校验每个条目的字典类型,跳过非法条目并记录错误;测试验证非法条目不会中断处理,空编辑输入返回空列表。

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次变更:跳过 edits 列表中的非字典条目。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7fb5692 and 1f0a4fb.

📒 Files selected for processing (2)
  • chapter8/prompt-auto-optimization/coding_agent.py
  • chapter8/prompt-auto-optimization/test_non_dict_edit.py

Comment on lines +70 to +72
if not isinstance(e, dict):
errors.append(f"edit 必须是对象,收到 {type(e).__name__}")
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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 bojieli left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants