Repository navigation
fix(api): 允许 insert_after 使用唯一的多行文本块锚点 (#599) - #607
Merged
Shadow-Azure merged 8 commits intoNov 25, 2026
Merged
Conversation
根因:validator 对 insert_after 强制单行,prompt/派生 schema 与 07 5.5.4 只要求锚存在且唯一,模型提交的 4 行块锚点在 patch 阶段被拒、整轮失败。移除单行拒绝,应用器改为整段唯一匹配并插入到块末行之后;单行输出逐字节不变;同步 prompt 与设计文档,补多行/CRLF/缺失/多义与生产形状 replay 回归。
检视发现:_insert_after_text 在文件末行无结尾换行且 target 不到 EOF 时,
用 text[:match_end] 作 prefix 会静默丢弃 match 之后到 EOF 的文本。
改为整段保留(prefix = f"{text}{ending}",suffix 为空)。
补 4 格单行字节回归(末行行中 target、CRLF 半终止、bare-\r target)、
prompt 契约断言与 replace 多行锚行为断言;Note 明确唯一性按不重叠计数、
EOF 插入点与逐字节承诺边界;07 §5.5.4 把「多义回喂」纠正为 ambiguous 拒绝。
) #588(744f4f57)给 make_probe_report.py 增加了必需的 --conclusion 与 --root-cause,并更新 SKILL.md 要求显式结论;但平台 MCP 工具的 ReportFields 没有这两个字段(extra=forbid),也不会转发,导致 case-tools 模式的 attribution 报告全部被脚本拒绝、unit-tests-api 红、 main 自身 CI 为 failure。 本提交在 attribution_case_tools.py 的 ReportFields 增加必需 conclusion 枚举与非空 root_cause(validator 拒绝空白),由既有转发 循环生成 --conclusion/--root-cause;test_case_tools.py 补 selected_target fixture,并断言结论/根因透传、非法结论/空根因/缺字段 被拒绝。新增 Agent Note 记录取舍;flow issue 补 scope 与附带修复说明。 否则 main 上的 unit-tests-api 红会阻塞所有 PR,包括本 PR。
Shadow-Azure
deleted the
agent/develop-issue-599-edit-insert-anchor-multiline
branch
November 25, 2026 08:56
Shadow-Azure
added a commit
that referenced
this pull request
Nov 25, 2026
Shadow-Azure
pushed a commit
that referenced
this pull request
Nov 25, 2026
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.
背景
生产 full run
01M885592456VVK5B68DSMRKTE第 6/7 步第 3/10 轮在 patch 阶段失败(claude-code edit submission failed validation)。提交文件已正常解析(submissionParsedBy=json5),但EditPlan.model_validate()以edits.6: target must be a single-line substring拒绝了第 7 条insert_after——它的 target 是### 验收与回归模板的 4 行唯一文本块。prompt、派生 schema 与 07 §5.5.4 都只说「锚文本存在且唯一」,单行规则只活在 validator;edit 单次调用不重试,合法计划因此把整轮打死。改动(最终 diff:14 文件,+1090/−53)
主修复
apps/api/app/third_party_api/ai_agent/edits.py:删除EditOp._validate_op_fields()的 insert_after 单行拒绝;_insert_after_text()改为整段唯一匹配 + 块末行之后插入(target 自带结尾换行 → 换行后插入;否则匹配末字符所在行的下一个行终止符之后;无终止符的末行即文件末尾,插入点在 EOF;插入行沿用锚行\r\n/\n风格)。apps/api/app/service/evolution/patch_source.py:_edit_prompt()写明「锚文本是文件内唯一出现的文本片段,可跨行;insert_after 插到该片段末行之后」。plans/fullstack-design/07-backend-implementation.md:§5.5.4 执行流与 json5 示例注释同步同一契约。测试
apps/api/tests/test_edit_plan_applier.py:删除单行拒绝用例;新增 4 行块锚点校验+应用、9 格单行字节矩阵(行中/行尾/EOF 无终止符/末行行中 target/CRLF 半终止/bare\rtarget)、块锚缺失与多义、CRLF 块插入、生产形状 8 条编辑合成 replay(不含生产原文)、_edit_prompt契约断言;replace多行锚改为实际应用断言。apps/api/tests/test_ai_agent_claude_code.py:2 个 POSIX 专用进程组用例加os.name != "posix"跳过(Windows 本机无os.getpgid/SIGKILL)。检视修复(
01d3bd8c)pr-review检视(文档:plans/2026-11-25-pr607-review.md)发现并修复:_insert_after_text在文件末行无结尾换行且 target 不到 EOF 时,用text[:match_end]作 prefix 会静默丢弃 match 之后到 EOF 的文本(如{\n "version": "1.0"}+ target"version"丢"1.0"},report 仍是applied)。改为整段保留(prefix = f"{text}{ending}"),并补 4 格单行字节回归。text.count不重叠计数,Note 与 07 显式标注「不重叠唯一」;「逐字节一致」限定为\n/\r\n/ 纯 bare\r文件(混合换行与splitlines的 Unicode 分隔符记为已知边界,无实害)。_edit_prompt()契约断言;replace多行锚弱用例改为实际应用断言;07 §5.5.4「多义回喂」纠正为ambiguous拒绝(edit 无重试)。文档与流程
2026-11-25-edit-insert-anchor-multiline);flow issuestatus: ready → in-progress、adr回填。plans/2026-11-25-pr607-review.md(§6 结论、§7 分流、§10 处置与独立验证);实现计划plans/superpowers/plans/2026-11-25-issue-599-edit-insert-anchor-multiline.md。与 main 的关系
合并
origin/main(#610/#613)后,#604的修复已包含本 PR 早前顺带处理的 flow 状态(bugfix-58/done)与 attribution writer 的conclusion/root_cause契约,因此在合并树中取 main 版本,这两处附带修复不再产生净差异(提交023662e4/dede73b3/e4008dec仅保留为历史)。与设计对照
text.count不重叠计数),可以是单行或多行文本块;insert_after 块末行之后」,edits.py行为、prompt 与测试三方一致。claude_code.py/submission.py/ 工具面 / 预算 / 超时 / 前端;不增加 edit 反馈重试(issue 非目标)。验证(本地 Windows)
pnpm test:api -- tests/test_edit_plan_applier.py tests/test_ai_agent_claude_code.py:141 passed, 10 skipped(symlink 4 例 + POSIX 2 例 + 真实 CLI opt-in 4 例跳过)pnpm lint:api:All checks passedpnpm verify:flow:okpnpm lint:docs:doc-quick 全绿(11 叶)pnpm typecheck:api:本地 Windows 有 13 个平台属性误报(signal.SIGKILL/os.O_NOFOLLOW/os.killpg等,均与本次改动文件无关;Linux CI 上这些属性存在),probe_query.py的 redundant-cast 为既有报错。edits.py跑新用例得 2 failed(target must be a single-line substring),恢复实现后全绿。集成冒烟与截图(证据不入库)
范围说明:本 PR 为纯后端校验/应用器修复,无 UI 变更,
plans/ui-prototype-v2/harness-evolution.html的原型对照不适用(没有可对齐的页面状态);冒烟改为「真实提交通道 + 真实应用器」的端到端集成,证据为报告与前后文本 diff(见下图与 release)。冒烟方式:真实
ClaudeCodeProvider.edit_workspace()(仅用 fake CLI 进程替换外部claude二进制,prepare/collect/ JSON5 解析 / Pydantic 校验均为生产代码)+ 真实apply_edit_plan,工作区为合成skills/demo/SKILL.md(不含生产原文/凭据)。结果:4 场景 / 8 断言全部通过,0 未解决缺陷
parsed_by=json5、validation_failures=0、parse_failures=0、edits=8 / block_lines=4applied,只改SKILL.mdstatuses=[applied]×8、files=('skills/demo/SKILL.md',)、content 紧接块末行insert_after逐字节不变one\ntwo\n+two→one\ntwo\nthree\nskipped_anchor_missing;2 次 →error(anchor is ambiguous)report-data.json、assertions.json、submission-edits.json5、前后SKILL.md与截图)部署后验收
issue 验收第 5 条「一次真实 full run 完成此前失败的第 3 轮」需要生产环境(真实
claudeCLI + MiniMax 凭据),本 PR 无法在本地替代;部署后需新建 full run 并确认第 6 步第 3 轮agent.edit为outcome=ok、submissionValidationFailures=0且进入 candidate/push/eval。在此之前 issue 保持in-progress。