From a8343103f1b28e1f67eac302dc7f21961a526466 Mon Sep 17 00:00:00 2001 From: zhaochangle Date: Sat, 14 Mar 2026 23:53:18 +0800 Subject: [PATCH] - Add error capture and reporting for OpenCode review failures - Capture both exit status and error messages (Error:/SSE timeout) from OpenCode output - Post failure comment to PR with error details and workflow run link when review fails - Use continue-on-error with explicit failure handling to ensure workflow reports failures correctly - Update code review skill to emphasize holistic analysis of upstream/downstream call --- .claude/skills/code-review/SKILL.md | 3 +- .github/workflows/opencode-review.yml | 51 ++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/.claude/skills/code-review/SKILL.md b/.claude/skills/code-review/SKILL.md index 2a3fd54e71617f..fcff7368bfc66c 100644 --- a/.claude/skills/code-review/SKILL.md +++ b/.claude/skills/code-review/SKILL.md @@ -34,10 +34,11 @@ Always focus on the following core invariants during review: ### 1.2 Review Principles - **Follow Context**: Match adjacent code's error handling, interface usage, and lock patterns unless a clearly better approach exists -- **Reuse First**: Search for existing implementations before adding new ones; ensure good abstraction afterward +- **Reuse First**: Search for existing implementations before adding new ones; ensure good abstraction afterward. For example, in the implementation of SQL functions in BE, we prefer to use an existing base template rather than implementing everything from scratch. The same principle applies to the implementation of other features. Common parts should be abstracted as much as possible. - **Code Over Docs**: When this skill conflicts with actual code, defer to code and note the mismatch - **Performance First**: All obviously redundant operations should be optimized away, all obvious performance optimizations must be applied, and obvious anti-patterns must be eliminated. - **Evidence Speaks**: All issues with code itself (not memory or environment) must be clearly identified as either having problems or not. For any erroneous situation, if it cannot be confirmed locally, you must provide the specific path or logic where the error occurs. That is, if you believe that if A then B, you must specify a clear scenario where A occurs. +- **Review Holistically**: For any new feature or modification, you must analyze its upstream and downstream code to understand the real invocation chain. Identify all implicit assumptions and constraints throughout the flow, then verify carefully that the current change works correctly within the entire end-to-end process. Also determine whether a seemingly problematic local pattern is actually safe due to strong guarantees from upstream or downstream, or whether a conventional local implementation fails to achieve optimal performance because it does not leverage additional information available from the surrounding context. ### 1.3 Critical Checkpoints (Self-Review and Review Priority) diff --git a/.github/workflows/opencode-review.yml b/.github/workflows/opencode-review.yml index 303228df82f37d..12db3ee067f4e8 100644 --- a/.github/workflows/opencode-review.yml +++ b/.github/workflows/opencode-review.yml @@ -108,8 +108,57 @@ jobs: BASE_SHA: ${{ steps.pr.outputs.base_sha }} - name: Run automated code review + id: review + continue-on-error: true env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | PROMPT=$(cat /tmp/review_prompt.txt) - opencode run "$PROMPT" -m "github-copilot/claude-opus-4.6" + + set +e + opencode run "$PROMPT" -m "github-copilot/claude-opus-4.6" 2>&1 | tee /tmp/opencode-review.log + status=${PIPESTATUS[0]} + set -e + + last_log_line=$(awk 'NF { line = $0 } END { print line }' /tmp/opencode-review.log) + + failure_reason="" + if printf '%s\n' "$last_log_line" | rg -q -i '^Error:|SSE read timed out'; then + failure_reason="$last_log_line" + elif [ "$status" -ne 0 ]; then + failure_reason="OpenCode exited with status $status" + fi + + if [ -n "$failure_reason" ]; then + { + echo "failure_reason<> "$GITHUB_OUTPUT" + exit 1 + fi + + - name: Comment PR on review failure + if: ${{ steps.review.outcome == 'failure' }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + FAILURE_REASON: ${{ steps.review.outputs.failure_reason }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + gh pr comment "${{ github.event.issue.number }}" --body "$(cat <