Repository navigation
fix(pr-review): ignore empty COMMENTED thread-reply wrappers - #9509
loopx-agent wants to merge 1 commit into
Conversation
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google · self_reported
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
Verdict: APPROVE (author-owned exact-head review at 9509@e87e70360142895f536c9a598efc5cdc2d1724d5).
No blocking findings remain on exact head e87e70360142895f536c9a598efc5cdc2d1724d5 (merge_base=6915df67db6a8836df344a661f295006873a3ba8, OPEN, MERGEABLE, 0/0 review threads, 1/1 DCO-signed commit, 0 merge-tree conflicts). On origin/main@6915df67db, posting an inline review-thread reply via GitHub GraphQL (addPullRequestReviewThreadReply) created an empty-body COMMENTED review object from the repository collaborator account, which tricked pr_review_approval_closeout.ts::independentReviewEvidence into marking the PR as current_head_concluded (review_action_kind=null) and even overwriting earlier formal opinions—blocking review while --check-merge-readiness failed with current_head_review_missing_or_invalid. Exact head e87e703601 resolves this cleanly across TypeScript and Python while preserving genuine inline-only root reviews and failing closed when comment pagination is incomplete (wait_for_ci=false). Because this PR is author-owned (loopx-agent), GitHub blocks formal self-approval; this COMMENT review records the exact-head approval conclusion while leaving the PR OPEN.
动机 / Motivation
当社区贡献者或作者针对其他开发者提交的 PR 回复某条具体代码行审校讨论线程(例如在旧意见下解释已修复)时,GitHub GraphQL 接口会附带生成一条正文为空字符串、状态为 COMMENTED 且绑定当前精确提交的 review 包装记录。在此前的主干 6915df67db 上,loopx pr-review 的待审队列与独立审校判断逻辑无法区分“真正的只含行内根评论的 COMMENTED 评审”与“仅用于回复现有线程的空包装记录”,导致评审调度者与合并前门禁遇到严重阻塞:哪怕真正的 CHANGES_REQUESTED 尚未被复核解决、且 --check-merge-readiness 仍报告缺少当前精确提交的有效审校,队列也会将该 PR 错误归入 current_head_concluded(review_action_kind=null)并隐藏可执行入口,甚至用一条回复覆盖掉同一评审账号此前提交的正式 CHANGES_REQUESTED 意见。
本 PR(精确提交 e87e70360142895f536c9a598efc5cdc2d1724d5)在完全不增加普通 PR 或模拟测试额外 GitHub API 调用的前提下,仅当完整审校历史出现当前提交的非作者空正文 COMMENTED 记录时,二次分页拉取行内评论并在 pulls/{n}/comments 上验证是否所有关联评论都带有合法 in_reply_to_id:若确定属于纯粹的线程回复包装(thread_reply_only=true)且非有效格式化结论,TypeScript 核心所有者 independentReviewEvidence 会在写入最新意见与提交集合前将其剔除;同时真正不含回复包装的普通行内只评审(in_reply_to_id=null)与已格式化有效结论均完整保留,任何拉取异常或空响应均 fail-closed 不做标记。在真实 PR 现场对比中,该修复把原先被误判跳过的 PR #9038(14b8f48355)准确恢复为可动作的 rereview_pull_request_exact_head 队列项;本轮不包含重构历史已合并 PR 数据,也不引入人为的审校账号白名单。
改动思路 / Approach
整体严格遵循“Python 提供方只采集可验证的原始事实 + TypeScript 控制面唯一持有历史判定所有权”的架构分工:
- 按需增量事实采集(
github_source.py):_attach_review_provenance在拿到完整分页reviews后,仅针对存在“当前精确 head、非 PR 作者、空白body、COMMENTED状态”候选记录的 PR,通过fetch_complete_pr_review_comments分页拉取repos/{repo}/pulls/{number}/comments?per_page=100(正常 PR 或非空正文COMMENTED评审零额外请求)。_thread_reply_only_review_ids仅在分页结果非空列表且合法字典齐全、至少匹配 1 条对应pull_request_review_id评论、且所有匹配评论的in_reply_to_id均为正整数时标记thread_reply_only=true;只要拉取报错、返回为空/畸形、0 条匹配或存在任意一条in_reply_to_id缺失/为None的根评论,一律 fail-closed 不标记。 - 所有权前置拦截与状态投影(
pr_review.py→pr_review_approval_closeout.ts):loopx/pr_review.py仅作为无决策透传把thread_reply_only带入select_review_history;核心仲裁留在independentReviewEvidence(pr_review_approval_closeout.ts:56):在submitted?.push和latest.set(row.login, candidate)之前直接跳过row.state === "COMMENTED" && source.thread_reply_only === true && row.conclusion.valid !== true。这样既避免它触发误判independent_review,也防止它覆盖或退休同一评审者早先在同一提交上发表的正式CHANGES_REQUESTED/APPROVED或根行内评审。 - 架构放置与当前 PR 边界:
retain——thread_reply_only严格作为基于 GitHub RESTin_reply_to_id的只读派生投影(derived_projection),由github_source.py负责 fail-closed 溯源采集、由唯一 TS 所有者pr_review_approval_closeout.ts执行归属判定;未新增独立配置项、持久化状态或绕过机制,也不改动effectiveOpinions与既有review_body_valid门禁边界。
GitHub reviews (complete)
├─ No empty-body non-author COMMENTED on current head ──> 0 extra API calls
└─ Candidate exists ──> fetch_complete_pr_review_comments (fail-closed -> null => not marked)
├─ All >=1 matched comments have positive int in_reply_to_id ──> thread_reply_only=true
│ └─ pr_review_approval_closeout.ts#L56 (when !conclusion.valid) skips before latest.set / submitted.push
└─ Any root comment (in_reply_to_id null/missing) or 0 matched ──> keeps ordinary inline-only COMMENTED eligibility
(上述流程按精确提交 e87e703601 源码整理,用作结构说明。)
具体改动 / Changes
精确变更范围为 6915df67db6a8836df344a661f295006873a3ba8..e87e70360142895f536c9a598efc5cdc2d1724d5,共涉及 6 个文件(+324 / -2),全部紧凑聚焦于溯源识别与双端测试:
- 生产代码 (
production,3 个文件,+82 / -2):loopx/capabilities/pr_review_queue/github_source.py(+77/-1)、loopx/control_plane/capabilities/pr_review_approval_closeout.ts(+4/-1)、loopx/pr_review.py(+1/-0)。 - 构建配置 (
build_or_config,1 个文件,+1 / -0):tsconfig.control-plane.json(将新 TS 单测纳入 typecheck)。 - 测试验证 (
tests_or_fixtures,2 个文件,+241 / -0):tests/capabilities/test_pr_review_independent_review.py(+112/-0)、tests/control_plane_ts/pr_review_approval_closeout.test.ts(+129/-0)。
对照既有合同文档 loopx/capabilities/pr_review_queue/README.md(不可变基线 6915df67db6a8836df344a661f295006873a3ba8)核验条目:
IND-Formal-Only(implemented):independent_review仅可由正式审校事件建立,线程回复包装不得视作独立审校或抹去同评审者先前的正式意见,由github_source.py::_thread_reply_only_review_ids与pr_review_approval_closeout.ts::independentReviewEvidence及真实 PR #9038 基线/候选对比实验验证。IND-Inline-Root-Preserved(implemented):真正的只含行内根评论的COMMENTED评审(无论有无正文、或混合根评论+回复)必须继续建立independent_review并保持既有行为,由test_inline_root_empty_commented_review_still_establishes_independent_review与 TS 测试覆盖。IND-Fail-Closed-Incomplete(implemented):行内评论分页拉取报错、空列表或格式畸形时不得推断thread_reply_only,保留既有 fail-closed 处理,由test_incomplete_or_empty_comment_fetch_fails_closed_for_thread_reply_detection覆盖。
关键代码讲解
fetch_complete_pr_review_comments与_thread_reply_only_review_ids:先经_empty_commented_non_author_review_ids精确锁定当前 head 上非作者且空正文的COMMENTED审校 ID(reviews无此类记录时直接返回空集,不发起任何comments请求)。拉取pulls/{number}/comments?per_page=100时采用--paginate --slurp并检查每一页结构与每条评论对象;随后仅当某候选review_id至少有 1 条归属评论且没有任何缺失正整数in_reply_to_id的根评论时,才返回该 ID。_attach_review_provenance:在校验完完整reviews之后、复核headRefOid/baseRefOid一致性之前计算reply_only_ids并为命中条目标记item["thread_reply_only"] = True,随后继续以二次pr view保证整个历史快照未被并发推送替换。_review_conclusion:保持最小改动(+1 行),在不额外改变include_model_coverage或reviewer_model_family=None行为的情况下,仅当review.get("thread_reply_only") is True时向 TSselect_review_history透传"thread_reply_only": True。independentReviewEvidence:在for (const row of reviews)循环中严格于submitted?.push和latest.set(row.login, candidate)之前拦截row.state === "COMMENTED" && source.thread_reply_only === true && row.conclusion.valid !== true。因此既不把空回复包装当成覆盖证据,也不让迟到的回复包装覆盖同一评审者在当前提交上原有的CHANGES_REQUESTED或普通根评论意见,且保留合法格式化结论不被误杀。
对主干的风险 / Risks
本次改动定位精准、影响面完全受控于 pr_review 独立审校覆盖判定与 GitHub provider 元数据附着流程:
- 对正常路径与原有契约的隔离:
DEFAULT与include_model_coverage=False路径保留原有的普通文本/空白正文行内根评论资格(既有的 171+ 项pr_review单元测试全部无需放宽断言直接通过);正常无空正文COMMENTED审校的 PR 完全不触发pulls/{n}/comments请求。 - 边界与反例表现:
- 真实现场修复对照 (
LIVE_9038_BASE_TO_HEAD_FIX_VERIFIED):针对实时 PR #9038(14b8f48355,含6080550180空COMMENTED线程回复包装),基线6915df67db返回scheduling_lane="current_head_concluded"、review_action_kind=None、independent_review.review_id=6080550180、review_sequence=[];切换至精确候选头e87e703601后立即变为scheduling_lane="community_feedback"、review_action_kind="rereview_pull_request_exact_head"、has_independent_review=False、review_sequence=[9038]。 - 覆盖域与失败闭环:若回复评论 API 失败、
[]/[[]]、数据非对象、或同一审校包含in_reply_to_id=None/<=0根评论,均 fail-closed 保留原行为而不误删审校覆盖;若之前同一审校人已有当前提交正式CHANGES_REQUESTED,后附回复包装按时间正/反序输入均保留原有CHANGES_REQUESTED。 - 打包与公私边界:
tests/test_core_distribution.py -k test_core_staging通过(2 passed, 57 deselected),确认pr_review_queue与control_plane文件均正常入列独立 Core 分发边界,且loopx check公私扫描6文件零报错零警告。
- 真实现场修复对照 (
- 非阻塞残余风险与缺失覆盖:若某 PR 在 GraphQL 与 REST 之间遭遇极端瞬时并发,或者作者回复的
thread_reply_only记录恰巧没有关联任何/comments评论(0 matched),系统按安全策略 fail-closed 保留其原COMMENTED状态而非猜测忽略;test_core_pr_review_distribution.py的2项安装后独立 wheel 用例在本轮因未构造独立LOOPX_CORE_TEST_PYTHON环境而跳过(由test_core_staging校验打包清单等价)。 - 验证汇总(精确头
e87e703601,wait_for_ci=false):npm run typecheck:control-plane:PASS(0errors)node --no-warnings --experimental-sqlite --experimental-strip-types --test tests/control_plane_ts/pr_review_approval_closeout.test.ts tests/control_plane_ts/effect_runtime_handlers.test.ts:PASS(40 passed, 0 failed, 0 skipped)python -m pytest -q tests/capabilities/test_pr_review_independent_review.py tests/capabilities/test_pr_review_approval_closeout.py tests/capabilities/test_pr_review_queue.py tests/test_pr_review*.py tests/test_core_pr_review_distribution.py:PASS(271 passed, 2 skipped in 4.88s;2 skips 为test_core_pr_review_distribution.py需外部LOOPX_CORE_TEST_PYTHON轮子环境)python -m pytest -q tests/test_core_distribution.py -k test_core_staging:PASS(2 passed, 57 deselected in 3.00s)python -m pytest -q -n 4 tests/architecture/ tests/canary/test_maintainability_ratchet.py tests/capabilities/test_pr_review*.py:PASS(2529 passed, 45 skipped in 81.98s,0 failed;45 skips 为test_pr_review_behavior.py:488explicit no-tools live qualification only)ruff check(touched 3 Python files):PASS(0issues);mypy --strict --follow-imports=silent github_source.py:PASS(0/1);mypy --follow-imports=silent pr_review.py:PASS(0/1);kernelmypy --follow-imports=silent:PASS(0/17);check_rfc_bilingual.py:PASS;loopx check --scan-path ...:PASS(6files,0errors/0warnings);Goalcanary premerge --tier standard --from-git-diff --git-diff-base origin/main:PASS(ok=true、gate.status="passed"、merge_gate_passed=true、4/4direct +1/1py_compile +6/6catalog +8/8risk-profile,0failures/0manual holds)。- 真实对照实验 (
9038@14b8f48355base vs headloopx pr-review):PASS(LIVE_9038_BASE_TO_HEAD_FIX_VERIFIED)。
我的整体评价 / Verdict
APPROVE。 PR #9509 以最小、精确且 fail-closed 的方案根治了 GitHub addPullRequestReviewThreadReply 空 COMMENTED 包装导致的队列假完成与阻塞覆盖漏洞,同时完整保留了普通行内根评论与现有全部契约测试,并由真实线上 PR #9038 对照实测证实修复生效。
- 长程效果 (
long_horizon:improved):打通pr-review自动化队列对他人 PR 修复线程后的精确重新入队,防止本应重审阻塞的 PR 被虚假标记为current_head_concluded而静默停滞。 - 用户体验 (
user_experience:preserved):保持现有全部 CLI/参数与正常 PR 零额外接口调用,纯后端逻辑不涉及前端界面(visual_review:not_applicable)。 - 代码体量与兼容边界:6 文件共
+324/-2行属于最小必要修复(code_volume:necessary、compatibility_assessment:not_applicable),设计比例恰当(change_proportionality:proportionate、架构判断retain),保持默认与异常路径安全隔离(default_off_isolation:isolated、authority_semantics:aligned),仅复用现有pr_review_approval_closeout所有权并补充只读thread_reply_only事实字段(semantic_alignment:aligned)。所有本地检查及真实 PR #9038 对比验证均已通过(wait_for_ci=false),可保持OPEN批准。
English verdict: APPROVE at e87e703. Option-1 thread-reply provenance detection (github_source.py fail-closed pulls/{n}/comments check -> pr_review.py -> pr_review_approval_closeout.ts#independentReviewEvidence pre-filter) eliminates the empty COMMENTED wrapper false positive without breaking inline-root reviews or adding overhead to normal PRs, verified across TS (40/40), Py (271 passed, 2 skipped + architecture + test_core_staging), canary premerge (0 failures), and live 9038@14b8f48355 base-vs-head comparison (wait_for_ci=false).
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Request changes conclusion (author-owned PR; GitHub blocks formal self-review)
[P2] 评论来源未知时仍把回复包装算作已审。同一个 reply-only 快照仅让 inline comments 请求失败,候选改报 current_head_concluded、source_complete=true 并清空复评动作。第二页出现无法归属的条目时,候选也仍把该读取标作完整。 将已验证仅回复、已验证含 root、评论证据未知作为三类来源状态。未知时保留复审候选,且不得以 source_complete=true 声称已获独立评审。 源码
动机 / Motivation
让原生 PR 队列依照完整的 GitHub 来源事实,区分正式独评、inline-root 评审与回复包装。 GitHub 的回复包装会生成空 COMMENTED 记录,过去在当前头可被当作正式独评,遮住待复评提交。 PR 队列、独评覆盖和同 head 复评的使用者。
一次评论读取失败便可静默跳过一个仍需独评的当前提交。 同一开放 #9038 提交 14b8f48 上,基线把空包装 6080550180 当作独立评审,候选正确恢复复评动作。两页中确有 root 时仍保留独立评审。 候选 Python 182 项、Node 40 项通过,并通过控制面 typecheck。实际 GitHub 对照确认包装的 inline 条目有父评论。四组独立 provider 对照覆盖完整回复、读取失败、第二页 root 与缺归属的第二页。 本次实测为只读 GitHub #9038 和隔离 transport 对照。无 GitHub 写入参与验证,未查询托管 CI。 验收契约
改动思路 / Approach
该改动沿用 loopx pr-review → 完整 GitHub reviews 及必要 inline comments → 版本再核对 → TypeScript review selector → queue。沿用完整 review 收集和 typed reducer,仅为必要候选读取分页评论,并复用精确 base/head 读回。 根评论证据和完整性是候选能确立独立活动的事实。空列表式传播把读取失败和无回复分类折叠为同一状态。 在已有来源资格判定中保留已知、未知两层语义,让未查证的包装不产生新的授权或抑制。
具体改动 / Changes
精确提交 e87e703,本次对照目标 6915df6。6 文件新增 324 行,删除 2 行。增加 GitHub 评论读取和候选过滤、单个 TS 承接分支和反例。
关键代码讲解
-
fetch_complete_pr_review_comments。按需读取 inline 评论页。 源码 -
_thread_reply_only_review_ids。根据完整可归属评论判定空包装。 源码 -
_attach_review_provenance。将 GitHub 来源标记接入当前提交复核。 源码 -
independentReviewEvidence。消费完整版本化事实并决定独评或复评动作。 源码 -
independent-review-provenance(not_met)。只有完整可验证的独立评审才可抑制精确提交复评。
对主干的风险 / Risks
同一个 reply-only 快照仅让 inline comments 请求失败,候选改报 current_head_concluded、source_complete=true 并清空复评动作。第二页出现无法归属的条目时,候选也仍把该读取标作完整。 健康读路径有效。当前故障路径会静默留回原误报,恰好遮蔽该修复试图恢复的工作。 显式处理评论证据未知,保留强正例,禁止把未知假设包装为已确证活动。
语义与 CI 对齐
同一个 reply-only 快照仅让 inline comments 请求失败,候选改报 current_head_concluded、source_complete=true 并清空复评动作。第二页出现无法归属的条目时,候选也仍把该读取标作完整。 显式处理评论证据未知,保留强正例,禁止把未知假设包装为已确证活动。
我的整体评价 / Verdict
REQUEST_CHANGES。 健康 GitHub 路径已纠正实际误报,请补齐缺证据时的状态和复评资格。 长程队列的可接续性依赖于失去读证据时保留当前复评资格。
English verdict: REQUEST_CHANGES at e87e703. The live paired read fixes the complete-data case. A failed inline-comment read still certifies the same reply wrapper as complete independent review and suppresses exact-head review.
| comments = fetch_complete_pr_review_comments( | ||
| repository=repository, number=number, cwd=cwd, run_gh_json=run_gh_json, | ||
| ) | ||
| if comments is None: |
There was a problem hiding this comment.
[P2] 评论来源未知时仍把回复包装算作已审
同一个 reply-only 快照仅让 inline comments 请求失败,候选改报 current_head_concluded、source_complete=true 并清空复评动作。第二页出现无法归属的条目时,候选也仍把该读取标作完整。 将已验证仅回复、已验证含 root、评论证据未知作为三类来源状态。未知时保留复审候选,且不得以 source_complete=true 声称已获独立评审。
Summary
Prevents GitHub GraphQL inline thread-reply
COMMENTEDwrapper reviews (for example,addPullRequestReviewThreadReplycreating aCOMMENTEDreview with an empty top-level body whose inline comments all carryin_reply_to_id != null) from falsely establishingindependent_reviewor overwriting an earlier formal/inline-root opinion by the same account inloopx pr-review, while preserving genuine human inline-only code reviews (in_reply_to_id == null).loopx/capabilities/pr_review_queue/github_source.py:fetch_complete_pr_review_commentsand_thread_reply_only_review_idsinside_attach_review_provenance.repos/{repository}/pulls/{number}/comments?per_page=100only when complete reviews contain at least one current-head, non-author, empty/whitespace-bodyCOMMENTEDreview (0extra API calls for ordinary PRs and non-empty reviews).thread_reply_only=Trueonly when pagination completes, the review body is empty/whitespace,>= 1inline comment matchespull_request_review_id, and every matched comment has a positive integerin_reply_to_id(leavingthread_reply_onlyunset when fetches fail, return malformed/incomplete data, return0comments, or include any root comment).loopx/pr_review.py&loopx/control_plane/capabilities/pr_review_approval_closeout.ts:thread_reply_onlyintoselect_review_history(independentReviewEvidence) without creating a parallel policy owner or alteringreview_body_validrules for ordinaryCOMMENTEDreviews.row.state === "COMMENTED" && source.thread_reply_only === true && row.conclusion.valid !== trueinindependentReviewEvidencebeforesubmitted?.pushandlatest.set(row.login, candidate), so thread-reply wrappers neither concludescheduling_lane="current_head_concluded"(review_action_kind=None) nor overwrite/retire an earlier current-head formal/inline-root opinion by the same reviewer.tests/control_plane_ts/pr_review_approval_closeout.test.ts,tsconfig.control-plane.json, &tests/capabilities/test_pr_review_independent_review.py:COMMENTEDreviews (in_reply_to_idabsent orNone, plus mixed root+reply), preservation of earlier current-head formal opinions across later thread replies in any order, fail-closed incomplete/empty comment pagination, and cross-model coverage exclusion.Author declaration
model_agentorigin/main@6915df67db6a8836df344a661f295006873a3ba8(e87e70360142895f536c9a598efc5cdc2d1724d5carries DCO sign-off viagit commit -s).Verification (on exact
HEADe87e70360142895f536c9a598efc5cdc2d1724d5)npm run typecheck:control-plane:0errors.node --no-warnings --experimental-sqlite --experimental-strip-types --test tests/control_plane_ts/pr_review_approval_closeout.test.ts tests/control_plane_ts/effect_runtime_handlers.test.ts:40/40passed (0failed,0skipped).uv run --extra test python -m pytest -q tests/capabilities/test_pr_review_independent_review.py tests/capabilities/test_pr_review_approval_closeout.py tests/capabilities/test_pr_review_queue.py:182 passed in 2.68s(0failed,0skipped).uv run --extra test python -m pytest -n 4 -q tests/capabilities/test_pr_review*.py tests/test_core_pr_review_distribution.py tests/architecture/ tests/canary/test_maintainability_ratchet.py:2,530 passed, 47 skipped in 84.72s(LOOPX_CORE_TEST_PYTHON/LOOPX_REVIEW_TEST_ENABLEDexternal-wheel/optional env skips).ruff check(loopx/pr_review.py,loopx/capabilities/pr_review_queue/github_source.py,tests/capabilities/test_pr_review_independent_review.pyclean);mypy --strict --follow-imports=silent loopx/capabilities/pr_review_queue/github_source.py(1/1clean);mypy --follow-imports=silent(17/17configured files clean).scripts/check_rfc_bilingual.py --base origin/main --head HEAD,examples/semantic-vocabulary-drift-smoke.py(34/34),examples/control_plane/control-plane-maintainability-ratchet-smoke.py(unreviewed=0,stale_exceptions=0,magnitude_regressions=0),git merge-tree --write-tree origin/main HEAD(bd4f2eecbf,0conflicts), andloopx check(6files,ok=true,errors=0,warnings=0): all passed.loopx-project/loopx#9038 @ 14b8f48355(authorcocolord, previously masked by empty-body thread-reply wrapper6080550180fromloopx-agent): confirmsscheduling_lane="community_feedback",review_action_kind="rereview_pull_request_exact_head",has_independent_review=False,review_sequence=[9038].cqr_603bffb2eb09cfd1eeda, scope fingerprint603bffb2eb09cfd1eedabf8ea51e0a87fe47cc5f93d4c5ae79006442a70d923f):decision="pass",receipt_valid=true,blocking=false.loopx canary premerge --from-git-diff --git-diff-base origin/main --tier standard:ok=true,gate.status="passed",merge_gate_passed=true,6/6direct checks,14/14smokes (6/6catalog +8/8risk-profile,0failures,0warnings,0manual holds).Boundary checklist
scripts/check_rfc_bilingual.py --base origin/main --head HEAD).Signed-off-bytrailer (git commit -s).