chore: improve AI PR-review (model selection, cost reporting, instructions)#9063
Conversation
Fold the design-level review of #9059 into .github/prompts/review-instructions.md so the automated reviewer catches architectural defects, not just line-level bugs: - Add a DESIGN & INTEGRATION CHECK, run first, with a mandatory owner search (name the *Load*/*Unload*/facade/disposal owners that already own the lifecycle), anti-rationalization guards (author framing, "it's hard", and assembly boundaries are not justifications), and a teardown/consumption trace for every subscription/buffer. - Require judging whether a new long-lived unit should exist at all vs. integrating into the existing lifecycle owner. - Add blocking categories: subscription/resource leaks, allocated-but-unconsumed infrastructure, detached async for essential work, nullability-contract violations, dead/false-intent conditions. Verified clean-room against #9059: reproduces the human review's architectural findings reliably on Opus and the resource/lifecycle findings on Sonnet. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…structions Consolidates a manual PR review of the media-stream camera-off placeholder work into .github/prompts/review-instructions.md, complementing the existing DESIGN & INTEGRATION CHECK. - Add a CONSTRUCTION, ENCAPSULATION & RESOURCE CHECKLIST: DI vs self-new, invariant-at-construction, naming-vs-responsibility, AI-comment smell, encapsulation/responsibility leaks, side-effect-free funcs, magic values + MordorConstants reuse, thread-safety docs, and resource lifecycle (use-after-destroy ownership, cache cost/benefit, all-or-nothing eviction, per-frame GPU expense). - Reframe the reporting guardrail so project-standard violations are blocking, not "nice-to-have" nitpicks (this was suppressing exactly these findings). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
On-demand `@claude review` now accepts a model, defaulting to Sonnet: - "@claude review opus" runs claude-opus-4-6; otherwise claude-sonnet-4-6. - Model-aware --max-turns ceiling (Sonnet 50, Opus 30) to bound spend. A capped run fails as error_max_turns, so caps are sized to let a normal review finish rather than pay-and-truncate. - The selected model is shown in the pending status. Both the on-demand and auto-review jobs append the run's USD cost to the end of the review comment (after the QA_REQUIRED block), e.g. "Review cost: $0.42 - claude-opus-4-6 - 28 turns". Runs on always() so failed/aborted reviews still report cost (annotated "did not finish"), is idempotent across re-runs, falls back to a standalone comment if the bot comment can't be edited, and is continue-on-error so it never fails the job. The push-triggered auto-review job stays on claude-sonnet-4-6. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
💰 Review cost: unknown · |
This comment has been minimized.
This comment has been minimized.
|
@claude review opus |
|
Claude finished @mikhail-dcl's task in 3m 4s —— View job Review —
|
…ember audit Consolidates NickKhalow's second review round on the media-stream PR (#9043) into the AI review instructions and sharpens the weakest checks. - Naming: flag names that hide a precondition the member depends on (e.g. IsCurrentVideoMuted -> IsCurrentCameraVideoMuted). - Comments: extend the smell list to over-explanation that restates a well-named member and assumptions about code outside the scope. - Add a Predicates, accessors & single-use members section, framed as a MANDATORY MEMBER AUDIT (enumerate each touched member's consumers, then test it against single-use-merge, absent-not-false/null, and don't-re-derive), mirroring the existing OWNER SEARCH pattern to force systematic coverage instead of opportunistic line-by-line flagging. - Carve thin forwarding accessors (e.g. fromIdentity => key.identity) out of the single-use rule so it does not recommend deleting intentional encapsulation — a false positive caught during local validation. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The cost-reporting github-script block was duplicated verbatim in the auto-review and on-demand-review jobs. Move it into .github/scripts/report-review-cost.js, called from both via require(), so there is a single copy and it can be run locally with a stubbed github/context. Addresses NickKhalow review feedback on #9063. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Keep the single-agent flow and one parsed verdict, but split the work into an explicit STEP 1..9 protocol (load context, root-cause, design/owner search, member audit, line-level review, complexity, QA, warnings, verdict). Ordering is now structural with a required written output per step, rather than the soft "do this before any line-level review" wording the reviewer distrusted. The verdict trailer is unchanged, so the auto-approve/QA automation is unaffected. Also folds in the rest of NickKhalow's review feedback on #9063: - enumerate concrete leak openers and their mirrors in the leak check - add RAII-for-native-resources to the resource-lifecycle checks - split the dead/false-intent check: keep the semantic "misleading intent" part, leave unreachable / always-true-false to ReSharper Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
🔒 Claude reviewed this PR — sensitive paths modified ( |
This comment has been minimized.
This comment has been minimized.
Add Read, Glob, and Grep to --allowedTools in both the auto-review and on-demand review jobs so the reviewer can run ripgrep-style searches. This is additive to the action's default read-only file access; Bash stays limited to the gh allowlist and the auto-approve path is unchanged (the new tools are read-only, and approval is a separate parsed step). Wire the instructions to use it: Step 1 states the working tree is checked out with Read/Glob/Grep available; Step 5's leak check (#7) now greps each changed *.cs for the openers and their mirrors. Addresses NickKhalow's grep-driven-leak-detection feedback on #9063. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Claude finished @mikhail-dcl's task in 1m 22s —— View job Security Review —
|
| Control | Status | Evidence |
|---|---|---|
| W.1 Prompt from base, not PR head | ✅ secure | both jobs fetch via gh api .../contents/...?ref=$BASE_SHA (base.sha / steps.pr.outputs.base_sha, lines 88, 421). A PR editing the prompt cannot self-modify its own reviewer. |
| W.2 Random heredoc delimiter | ✅ secure | DELIM="PROMPT_EOF_$(uuidgen)" (lines 85, 418). |
| W.3 TOCTOU / post-comment push | ✅ secure | review job rejects when pr.head.repo.pushed_at > comment.created_at (lines 351–364), using pushed_at — not the forgeable committer date. |
| W.4 Untrusted event text in prompt | ✅ secure | comment.body is never interpolated into the LLM prompt — only a boolean contains(...) selecting between two fixed strings (line 437), and read via the COMMENT_BODY env var for the model grep (grep -qiE '\bopus\b' <<< "$COMMENT_BODY"). No injection channel. |
| W.6 Actor gate | ✅ secure | review job needs: check-member, which calls GET /orgs/decentraland/members/$USER with ORG_ACCESS_TOKEN (lines 313–324). |
W.8 pull_request_target |
✅ n/a | auto-review uses pull_request; on-demand uses issue_comment behind the member gate. No pull_request_target. |
| W.9 Artifact retention | ✅ secure | retention-days: 7 (lines 120, 454). |
| W.10 Permissions | ✅ secure | explicit minimal per-job permissions: blocks. |
New this diff — Read,Glob,Grep added to --allowedTools (lines 110, 444). These are read-only tools scoped to the checked-out PR-head working tree. Risk assessment:
- They broaden the LLM's read surface (repo files), but introduce no new exfil primitive — the allowlist still has no
Bash(cat:*),curl, orWebFetch(W.5b). The only outbound channels remaingh pr comment/ inline comments, whose contents are the review output and are public regardless. - The reviewer already consumed PR-head diff content, so reading neighbouring source files is the same trust tier (PR-head code is data, the base-sourced prompt is the instruction set — W.1 keeps that boundary).
- Repo files contain no secrets (workflow secrets live in the Actions env, not the tree), so a
Readcan't surfaceANTHROPIC_API_KEY/GITHUB_TOKEN. - Gated behind the org-member trigger (on-demand) and a base-sourced prompt.
→ Acceptable, low risk. The addition is proportionate to the prompt's new STEP 1/3/5 requirement that the reviewer search the repo (lifecycle-owner search, leak-mirror grep) rather than work from the diff alone.
report-review-cost.js — low risk. Reads the action's own $RUNNER_TEMP/claude-execution-output.json and appends a cost block to the latest claude[bot] comment. The only non-numeric value interpolated into the comment is subtype (line 31 → did not finish (${subtype})), which comes from the action's own result event, not PR-controlled input. Idempotent (`` marker), continue-on-error, no new tool/permission surface. Falls back to `createComment` if the edit fails. Good extraction of the prior ~33-line duplication.
MEDIUM — pre-existing, not introduced by this PR
These live in the file under review but are unchanged by this diff. Flagged per protocol; they should not block this PR.
Bash(gh pr review:*)wildcard inallowedTools(lines 110, 444). A wildcardgh pr reviewgrants the LLM approve/request-changes on an arbitrary PR number (W.5a). Mitigated by the org-member gate and the separate enforce-approvals workflow, but worth scoping to the triggering PR next time this file is touched.Bash(gh pr comment:*)is similar, lower impact.- Secret-holding action on a mutable tag (W.7a).
anthropics/claude-code-action@v1(lines 97, 429) consumessecrets.ANTHROPIC_API_KEY;actions/github-script@v8,actions/checkout@v6,actions/upload-artifact@v6are tag-pinned. Consider SHA-pinning in a follow-up.
Neither is a regression from this PR. The prompt changes introduce no tool-allowlist escalation that reaches the network or grants write beyond the existing gh pr comment/create_inline_comment — the new sections only steer analysis depth and the read-only Read/Glob/Grep discussed above.
Verdict
The changes this PR introduces are secure: the prompt is sourced from base, no untrusted text reaches the LLM prompt, the model-selection grep is env-quoted, the cost script adds no privileged surface, and the new Read/Glob/Grep tools are read-only with no exfil channel. The two MEDIUM items are pre-existing config worth a human glance but are not blockers.
DEPENDENCY_REVIEW: NEEDS_ATTENTION
Pull Request Description
What does this PR change?
Improves the automated
Claude ReviewCI so it catches design/architecture defects (not just line bugs) and is cheaper to operate..github/only — no runtime/player code..github/prompts/review-instructions.md): a Design & Integration check (mandatory lifecycle-owner search + anti-rationalization guards), a teardown/consumption trace, and new blocking categories (resource leaks, dead infrastructure, detached async, nullability, dead conditions). Distilled from a human review whose architectural findings the prior prompt missed. Based on feat: prioritize share-screen source and fix camera-off frozen frame #9043 & feat: poc enable comms for PEXs interacting with the authoritative-server #9059@claude review opusrunsclaude-opus-4-6; default staysclaude-sonnet-4-6. The chosen model is shown in the pending status.--max-turns(Sonnet 50 / Opus 30) to bound spend without truncating a normal review.QA_REQUIRED), e.g.Review cost: $0.42 - claude-opus-4-6 - 28 turns. Posts even when a run fails/maxes out (annotated), idempotent across re-runs, andcontinue-on-errorso it never fails the job.Test Instructions
Prerequisites
dev(required for the comment-triggered path)ANTHROPIC_API_KEYhas access toclaude-opus-4-6Test Steps
@claude review→ runs on Sonnet; pending status shows(sonnet); the posted review comment ends with aReview cost:block.@claude review opus→ runs onclaude-opus-4-6; status shows(opus); cost block reflects the opus model.fix:/chore:PR (auto-review path) → its auto-review comment also ends with a cost block.did not finish (error_max_turns).Additional Testing Notes
auto-reviewjob stays onclaude-sonnet-4-6.Quality Checklist
--max-turns; the cost step is read-only andcontinue-on-errorCode Review Reference
Please review our Branch & PR Standards before submitting.