Skip to content

✨ feat(ci): add sticky_summary mode to code review - #49

Open
lishuceo wants to merge 1 commit into
mainfrom
feat/sticky-summary-review
Open

lishuceo wants to merge 1 commit into
mainfrom
feat/sticky-summary-review

Conversation

@lishuceo

Copy link
Copy Markdown
Contributor

Problem

Every review run posts a new summary via gh pr comment, so a PR pushed N times collects N top-level claude[bot] comments. Two independent causes: the prompt tells the model to gh pr comment, and without track_progress + use_sticky_comment the action never provides a reusable comment to update.

The current thread reconcile also has gaps observed on real PRs:

  • Prior comments are read with one unpaginated REST call (pulls/N/comments, 30 items, filtered after fetching), so on long PRs older threads are invisible and issues get re-reported.
  • Only claude[bot] comments are kept, so the model never sees human replies and adds "✅ Fixed" after the author already confirmed.
  • "Still unresolved" is re-posted on every push, even when the push did not touch the related code.
  • A run reviewing an older head can still post right after a newer push.
  • Inline comments without confirmed: true are buffered for the post-session classifier, which can drop real findings.

Change

New opt-in input sticky_summary (default false). The existing step is byte-identical, only guarded by if: ${{ !inputs.sticky_summary }}, so current callers are unaffected. When enabled, a second step runs:

  • track_progress + use_sticky_comment: the action (not the model) creates one tracking comment and reuses it on later runs; the model rewrites its body via update_claude_comment to describe the current head.
  • Top-level comment creation denied at the permission layer: no gh pr comment / gh pr review; gh api narrowed to GraphQL + the review-comment replies endpoint; creation mutations / review and issue-comment endpoints denied by glob.
  • Tag mode (forced by track_progress) adds edit / git commit / push tools by itself; these are denied so the review stays read-only.
  • Thread query via GraphQL with human replies; resolved threads truncated to a 300-char gist in --jq to bound context.
  • Human-confirmed fix → resolve without reply; "still unresolved" only when related code changed (git log --since) or a human replied since the last comment.
  • Stale-head guard before each write phase (gh pr view --json headRefOid).
  • Regression matching against resolved threads by meaning; report defect classes (all sibling sites) as one finding.
  • confirmed: true + classify_inline_comments: false.

Verified against the pinned action SHA: tag mode registers the inline-comment MCP server from --allowedTools; agent mode already runs checkHumanActor, so no allowed_bots change is needed; confirmed exists on create_inline_comment. The new thread query + jq was run against a real PR (6 threads → 3.2 KB).

Behavior differences vs. the legacy path

  • Each run first resets the sticky comment to the action's progress placeholder; if the run times out or fails, the previous summary is gone until the next successful run. The 15-minute timeout is the first thing to watch.
  • Editing a comment sends no notification, so authors no longer get a new summary ping per push (inline thread replies still notify).
  • Sticky lookup (upstream create-initial.ts) matches the first claude[bot] top-level comment and is not paginated (~30); documented in README.

Not included

  • No proxy budget preflight (gateway-specific) and no "verify completed" step: the pinned action SHA has no conclusion output, and bumping the pin would affect every caller.
  • Timeout / budget / effort unchanged.

Testing

  • YAML parsed; both steps' if guards checked. actionlint not run locally.
  • Not tested end-to-end. The first real run happens after this merges and a caller sets sticky_summary: true.
  • README was run through prettier (it was not prettier-clean before), so the diff includes unrelated table alignment.

🤖 Generated with Claude Code

Every run of the review posts a fresh summary via `gh pr comment`, so a PR
pushed N times accumulates N top-level claude[bot] comments. Two independent
causes, both need fixing: the prompt tells the model to `gh pr comment`, and
without `track_progress` + `use_sticky_comment` the action never provides a
reusable comment to update.

Add an opt-in `sticky_summary` input (default false; the existing step is
untouched behind `if: !inputs.sticky_summary`). When enabled:

- The action creates/reuses one tracking comment; the model rewrites its body
  via `update_claude_comment` to reflect the current head commit.
- Top-level comment creation is denied at the permission layer (no
  `gh pr comment`/`gh pr review`, `gh api` narrowed to GraphQL + the
  review-comment replies endpoint, creation mutations denied by glob).
- Tag mode (forced by `track_progress`) adds edit/commit/push tools by
  itself; those are denied so the review stays read-only.
- Thread reconcile reads threads via GraphQL instead of one unpaginated REST
  page (30 items, silently truncated on long PRs), includes human replies,
  and truncates resolved threads to a 300-char gist to bound context.
- A thread a human already confirmed is resolved without an extra reply;
  "still unresolved" is only re-posted when the related code changed or a
  human replied since the last comment.
- Stale-head guard: stop writing if the PR head moved past the reviewed
  commit.
- Regression check against resolved threads by meaning, and report defect
  classes (all sibling sites) as one finding.
- Inline comments are posted with `confirmed: true` and the post-session
  classifier is disabled, so real findings are not dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lishuceo
lishuceo marked this pull request as ready for review November 20, 2026 06:17
@github-actions
github-actions Bot requested a balanced review from Copilot November 20, 2026 06:18
@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The new review behavior affects PR comments only for callers that enable sticky mode.

建议先修正过期检查再合并;默认未启用新模式的调用方不受该问题影响。

Fix All in CodexFindings

  1. P1 正常运行也会被判过期 ▶
  2. P2 历史讨论仍会被截断 ▶

Summary

新增可选的 sticky_summary 模式,复用一条摘要评论,并调整历史讨论检查和工具权限。

  • Review runs update one summary comment when sticky mode is on.
  • Review threads use human replies and avoid repeat updates.

lishuceo 已说明并接受:运行失败可能留下进度占位内容;编辑摘要不会通知作者;上游摘要查找只检查前约 30 条评论,且可能覆盖其他工作流的首条 Claude 评论。预算预检和完成验证暂不纳入本次改动。

Reviews (1) · Last reviewed commit: "✨ feat(ci): add sticky_summary mode to c..." · Reviewed by Greptile

Comment on lines +258 to +262
The commit you review is `git log -1 --format=%H` in the checkout.
Before Step 1 actions, before posting inline comments in Step 4, and before Step 5, run
`gh pr view ${{ github.event.pull_request.number || inputs.pr_number }} --json headRefOid,state,isDraft`.
If `headRefOid` differs from the reviewed commit, or the PR is no longer open / is a draft, **stop writing anything**
and end with a final message that this run is obsolete. A newer run owns the PR; replies based on an old commit are wrong.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 正常运行也会被判过期:actions/checkout 没有指定 ref,在支持的 pull_request 事件下默认检出 PR 的合并提交。这里却把本地 HEAD 与分支末端的 headRefOid 比较,两者通常不同,即使没有新推送也会要求停止写入。启用 sticky_summary 后,审查因此无法发布行内问题或最终摘要。请比较同一种提交:使用事件记录的 PR head SHA 做过期检查,或明确检出该 SHA。

Fix in Codex Fix in Claude Code

Comment on lines +270 to +271
gh api graphql -f query='{ repository(owner:"${{ github.repository_owner }}", name:"${{ github.event.repository.name }}") { pullRequest(number:${{ github.event.pull_request.number || inputs.pr_number }}) { reviewThreads(first:100) { nodes { id isResolved isOutdated comments(first:20) { nodes { databaseId author { login } path line originalLine createdAt body } } } } } } }' \
--jq '[.data.repository.pullRequest.reviewThreads.nodes[] | select(.comments.nodes[0].author.login == "claude") | {id, isResolved, isOutdated, dbid: .comments.nodes[0].databaseId, path: .comments.nodes[0].path, line: (.comments.nodes[0].line // .comments.nodes[0].originalLine), lastActivity: .comments.nodes[-1].createdAt, lastAuthor: .comments.nodes[-1].author.login} + (if .isResolved then {gist: (.comments.nodes[0].body | gsub("<[^>]*>";"") | gsub("\\[[^]]*\\]\\([^)]*\\)";"") | .[0:300])} else {body: .comments.nodes[0].body, replies: [.comments.nodes[1:][] | {a: .author.login, at: .createdAt, body}]} end)]'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 历史讨论仍会被截断:查询只取前 100 个讨论,每个讨论只取前 20 条评论,没有读取后续页。长 PR 超过任一上限后,已有问题或最新人工回复就会消失;lastActivity 也可能停在第 20 条评论,导致每次推送都重复回复。后续步骤却把这些结果当作完整历史来去重、计算未解决问题。请为两层列表加入游标分页,再做过滤和摘要;单独读取讨论的查询也需要同样处理。

Fix in Codex Fix in Claude Code

Copilot AI 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.

🟡 Changes recommended

The GraphQL allowance can bypass mutation deny rules, allowing the write-capable token to create top-level posts that this mode is intended to prohibit.

3 open issues
What changed in this PR

Adds opt-in sticky summaries to the reusable code-review workflow, aiming to reduce repeated top-level bot comments while preserving the legacy behavior by default.

Changes:

  • Introduces sticky_summary, using action-managed tracking comments for in-place summary updates.
  • Adds human-aware thread reconciliation, regression matching, and stale-head checks.
  • Restricts model tools and configures confirmed inline findings to post immediately.
File Description
README.md Documents sticky mode, caller requirements, and upstream limitations; also reformats tables.
.github/​workflows/​code-review.yml Adds the input and separate sticky-review step with updated prompts, tracking settings, and tool restrictions.

Review effort: Balanced

Comment on lines +415 to +416
--allowedTools "Read,Glob,Grep,mcp__github_comment__update_claude_comment,mcp__github_inline_comment__create_inline_comment,Bash(gh api graphql:*),Bash(gh api repos/*/pulls/*/comments/*/replies*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr checks:*),Bash(git log:*),Bash(git blame:*),Bash(git diff:*)"
--disallowedTools "Bash(*addComment*),Bash(*addPullRequestReview*),Bash(*pulls/*/reviews*),Bash(*issues/*/comments*),Bash(gh pr comment:*),Bash(gh pr review:*),Edit,MultiEdit,Write,NotebookEdit,Bash(git add:*),Bash(git commit:*),Bash(git rm:*),Bash(git push:*),Bash(*git-push.sh*),mcp__github_file_ops__commit_files,mcp__github_file_ops__delete_files"
Comment on lines +270 to +271
gh api graphql -f query='{ repository(owner:"${{ github.repository_owner }}", name:"${{ github.event.repository.name }}") { pullRequest(number:${{ github.event.pull_request.number || inputs.pr_number }}) { reviewThreads(first:100) { nodes { id isResolved isOutdated comments(first:20) { nodes { databaseId author { login } path line originalLine createdAt body } } } } } } }' \
--jq '[.data.repository.pullRequest.reviewThreads.nodes[] | select(.comments.nodes[0].author.login == "claude") | {id, isResolved, isOutdated, dbid: .comments.nodes[0].databaseId, path: .comments.nodes[0].path, line: (.comments.nodes[0].line // .comments.nodes[0].originalLine), lastActivity: .comments.nodes[-1].createdAt, lastAuthor: .comments.nodes[-1].author.login} + (if .isResolved then {gist: (.comments.nodes[0].body | gsub("<[^>]*>";"") | gsub("\\[[^]]*\\]\\([^)]*\\)";"") | .[0:300])} else {body: .comments.nodes[0].body, replies: [.comments.nodes[1:][] | {a: .author.login, at: .createdAt, body}]} end)]'
Comment on lines +295 to +297
- **Still present** → reply **only if there is something new**: the relevant code changed since `lastActivity`
(`git log --since="{lastActivity}" --format='%h %s' -- {path}` is non-empty) but did not fix it, or a human
replied after your last comment. Then state precisely what remains. Otherwise **stay silent** — the sticky
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