Skip to content

feat: Bot Diff方案探索 - 技术博客与实验记录 #1521(01)#1524

Open
gh-pr-review[bot] wants to merge 16 commits intomasterfrom
feat/gh_pr_review_bot/diff-experiment-1521
Open

feat: Bot Diff方案探索 - 技术博客与实验记录 #1521(01)#1524
gh-pr-review[bot] wants to merge 16 commits intomasterfrom
feat/gh_pr_review_bot/diff-experiment-1521

Conversation

@gh-pr-review
Copy link
Copy Markdown
Contributor

@gh-pr-review gh-pr-review bot commented Apr 19, 2026

关联 Issue

Closes #1521

概述

本 PR 包含一篇技术博客文章 Solutions/Other - Bot Diff方案探索.md,系统性地探索了 LLM Bot 使用 diff 模式进行文件修改的可靠方法。

背景

LLM Bot 在创建文件时表现良好,但在后续修改(b→c)时容易"乱改"。本次探索通过反复实验,找到了一套稳定可靠的 diff 使用规则。

实验记录

实验 目标 结果 关键发现
实验1 博客文件内 diff 修改 ❌ 失败 上下文行不唯一导致匹配错位;文件内含 diff 代码块干扰解析
实验2A 干净测试文件单处修改 ⚠️ 部分成功 行号不精确导致插入位置偏移
实验2B 精确行号单处修改 ✅ 成功 验证了精确行号 + 唯一上下文的有效性
实验2C 双 hunk 同时修改 ✅ 成功 2个 hunk 同时应用无误
实验2D 三 hunk 复杂修改 ⚠️ 部分成功 前2个 hunk 成功,第3个 hunk 因累积偏移失败
最终验证 向博客文件插入新章节 ✅ 成功 在7547字节的文件中精确插入8行内容

核心结论

✅ Diff 五大规则

  1. 行号必须精确 — 通过实际获取文件内容并计数确认
  2. 上下文行必须唯一 — 用章节标题等独特内容作为锚点
  3. 避免含 diff 代码块的文件 — 会干扰 patch 解析器
  4. 每次修改后必须验证 — 不能信任 API 返回的成功状态
  5. ≥3 hunk 时拆分提交 — 避免累积偏移导致的错误

✅ 模式选择指南

场景 推荐模式
小文件(<100行)全量修改 files 模式
大文件单处精确修改 diff 模式
大文件多处修改(≤2处) diff 模式(多 hunk)
大文件多处修改(≥3处) 拆分为多次 diff 提交
文件含 diff 代码块 files 模式

文件变更

  • 新增 Solutions/Other - Bot Diff方案探索.md — 主博客文章(完整实验记录与结论)
  • 新增 Solutions/test-diff-experiment.md — diff 实验用的测试文件(临时文件,可后续清理)

备注

test-diff-experiment.md 是实验过程中使用的临时测试文件,如 Issue 中所述,可由仓库维护者后续清理。

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Comment thread Solutions/test-diff-experiment.md Outdated
alpha_timeout = 60
alpha_retry_count = 3
alpha_cache_size = 1024
alpha_log_level = INFO
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.

把alpha_log_level这一行移动到alpha_timeout行下面

3. 格式转换
4. 输出结果

### Beta的配置参数
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.

把这一章节一动到 章节 Beta的处理流程 的前面

Comment thread Solutions/test-diff-experiment.md Outdated
gamma_redis_ttl = 3600
gamma_s3_bucket = production-data

## 第四章:Delta模块
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.

把这一章节的内容叫做 Gamma并移动到前面,把原有Gamma章节内容叫做Delta并移动到这里

delta_memory_threshold = 90
delta_latency_threshold = 500
delta_error_rate_threshold = 5

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.

添加一个数字.字符串章节

@LetMeFly666 LetMeFly666 changed the title feat: Bot Diff方案探索 - 技术博客与实验记录 #1521 feat: Bot Diff方案探索 - 技术博客与实验记录 #1521(01) Apr 19, 2026
gh-pr-review bot added 3 commits April 19, 2026 10:28
Review comment 1: 把alpha_log_level移动到alpha_timeout行下面
Review comment 2: 把Beta的配置参数章节移到Beta的处理流程前面

使用files模式(<100行文件全量修改,符合博文总结的最佳实践)
Review comment 3: 把第四章Delta的内容叫做Gamma移到第三章,原第三章Gamma的内容叫做Delta移到第四章

使用diff模式(章节内容互换,精确的单hunk替换)
上一个diff提交在交换Gamma/Delta时丢失了Gamma配置参数子章节,
验证了博文结论:复杂的多区域替换应使用files模式。

Review comment 3: 第三章↔第四章内容交换(Delta↔Gamma)
Review comment 4: 新增第五章:数字.字符串
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.

[feature]bot diff方案探索

1 participant