fix-dedupe — 写修复前的查重守卫
语言规则
检测用户使用的语言,全程使用同一语言输出。
中文版
核心用途
排障→定位根因→动手写修复,是 Agent 修构建失败/线上问题的标准路径。这条路径有个真实踩过的坑:等你写完修复、甚至推完分支,才发现别人已经用另一种方式修好了——两种修法并存会留下指向已删文件的豁免登记、互相矛盾的补丁;查重晚了还会污染任务列表(重试链里多出一串白跑的任务)。本 skill 把「查重」固化成动手前的强制动作。
适用场景与触发条件
- 准备为一个故障/失败写任何代码修复之前(必做);
- 收到「某某构建又失败了」,准备提任务/重试之前(先查失败是否已被后续提交修掉);
- 接手别人排查到一半的问题,准备继续写补丁之前。
不触发:纯问答、纯诊断(不改代码)的场景。
执行步骤
- 任务/工单层:这个问题最早一次失败之后,有没有新的同分支任务成功?(有 → 问题可能已被修,看它的 sourceCommit 与失败任务的差)
- 全引用提交扫描:
python3 scripts/fix_dedupe.py commits --repo <路径> --since-days 14 --keywords "fix,hotfix,patch,<领域词>"退出码 1 = 列出了候选修复提交(hash/作者/分支/标题)。 - 在途分支扫描:
python3 scripts/fix_dedupe.py inflight --repo <路径> --base origin/<基线分支>列出「超前于基线、还没合」的候选修复——最常见的漏网处:修复只落在出事的分支或某个 feature 分支上,main/基线上没有。 - MR/PR 搜索(补 git 扫不到的元数据):
gh pr list --search "<关键词>"/glab api "merge_requests?state=opened&search=<关键词>"。 - 决策:
- 已有人用仓库标准机制修复且构建/测试通过 → 不引入第二种修法。缺口只剩「目标分支本身还没带上修复」时,cherry-pick 原提交(保留原作者)开 MR,不要重写。
- 有人的修复在途未合 → 等合入再提交受影响任务,或如实说明「修复在途」。
- 确认没人修 → 正常写修复,并在描述里注明查重结论。
输出
commits:候选提交列表(含所在引用装饰),退出码 1/0。inflight:按分支分组的超前候选 + 决策提示,退出码 1/0。
异常处理
- 关键词要带领域词(如
notary、gate、marketplace),只查 "fix" 会漏掉不带前缀的修复提交。 --cherry-pick --right-only已忽略等价补丁;若修复是重做版(内容不同),仍会列出。- 脚本只读(git log / branch),不会 fetch——先
git fetch --all再跑inflight,否则远端分支视图是旧的。
验收标准
- 对一个「修复只落在 feature 分支」的仓库,
inflight必须把该分支列为候选(退出码 1)。 - 对最近无修复提交的仓库,两个子命令都退出 0。
English
Purpose
The standard incident path is diagnose → root-cause → write a fix. A real trap: you finish your fix — sometimes even push the branch — before discovering someone already fixed it a different way. Two competing mechanisms leave inconsistent artifacts (exclusions pointing at deleted files, contradictory patches), and late dedupe pollutes job/retry chains. This skill makes dedupe a mandatory pre-fix step.
Steps
- Task layer: any newer successful run on the same branch after the failure? Its diff vs the failing sourceCommit may already contain the fix.
commits— keyword scan across ALL refs (exit 1 = candidates listed).inflight— per-remote-branch commits ahead of the base matching keywords (the usual blind spot: the fix landed on the incident branch or a feature branch, not main).- MR/PR search for metadata git can't see.
- Decide: standard fix already merged → do not add a second approach; cherry-pick the original commit (keep the author) only to fill the gap of an unreached branch. In-flight → wait, or report honestly. Nothing found → proceed, and note the dedupe result in your description.
Read-only (git log / branch); run git fetch --all first so remote views are fresh.
