[fix](ci) Add error handling and PR notification for OpenCode review failures (#61334)

before it may silently fail. now try it best to return the status if
failed.
This commit is contained in:
zclllyybb authored and GitHub committed 2026-03-16 10:07:29 +08:00
1 parent 3e0dd362b8
commit 0ceacf6c2e
2 files changed
+52 -2

No files matched your search

+2 -1
View File
@@ -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)
+50 -1
View File
@@ -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<<EOF"
printf '%s\n' "$failure_reason"
echo "EOF"
} >> "$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 <<EOF
OpenCode automated review failed and did not complete.
Error: ${FAILURE_REASON}
Workflow run: ${RUN_URL}
Please inspect the workflow logs and rerun the review after the underlying issue is resolved.
EOF
)"
- name: Fail workflow if review failed
if: ${{ steps.review.outcome == 'failure' }}
env:
FAILURE_REASON: ${{ steps.review.outputs.failure_reason }}
run: |
echo "OpenCode automated review failed: ${FAILURE_REASON}"
exit 1