From f877299d311520ddbf47a7faad02eeecc3cc689d Mon Sep 17 00:00:00 2001 From: Harsh Mahajan <115500013+007harshmahajan@users.noreply.github.com> Date: Tue, 19 May 2026 17:34:00 +0530 Subject: [PATCH] fix: deepseek write error: Broken pipe and Argument list too long (#11940) --- .github/workflows/deepseek-pr-review.yml | 71 +++++++++++++----------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/.github/workflows/deepseek-pr-review.yml b/.github/workflows/deepseek-pr-review.yml index 11517e1a8a..3fdb4efa93 100644 --- a/.github/workflows/deepseek-pr-review.yml +++ b/.github/workflows/deepseek-pr-review.yml @@ -79,18 +79,16 @@ jobs: PR_NUMBER="${{ steps.pr.outputs.pr_number }}" EXISTING_COMMENT_ID="${{ steps.find_comment.outputs.comment_id }}" - EXISTING_BODY="" if [ -n "$EXISTING_COMMENT_ID" ]; then - EXISTING_BODY=$(gh api "repos/${{ github.repository }}/issues/comments/$EXISTING_COMMENT_ID" --jq '.body') + gh api "repos/${{ github.repository }}/issues/comments/$EXISTING_COMMENT_ID" \ + --jq '.body' > /tmp/existing_body.txt + else + printf '' > /tmp/existing_body.txt fi - PR_DIFF=$(cat /tmp/pr_diff.txt) - PR_COMMITS=$(cat /tmp/pr_commits.json) - DIFF_TRUNCATED=$(echo "$PR_DIFF" | head -n 6000) + head -n 6000 /tmp/pr_diff.txt > /tmp/pr_diff_truncated.txt - SYSTEM_PROMPT="You are a senior code reviewer. Review the following PR diff for bugs, security issues, and performance problems. Skip style suggestions, documentation, and trivial improvements. Be concise — 2 sentences max per issue. Max 10 issues. Prioritize by severity." - - INSTRUCTIONS=$(cat <<'ENDINSTRUCTIONS' + cat > /tmp/instructions.txt <<'ENDINSTRUCTIONS' ## Code Review Request **Repository:** ${{ github.repository }} @@ -111,17 +109,29 @@ jobs: ### OUTPUT FORMAT — FAILURE TO FOLLOW MEANS YOU FAILED - You MUST output ONLY the comment exactly as shown. NO preamble, NO "Here is the review", NO markdown outside the table. + You MUST output ONLY the comment exactly as shown. NO preamble, NO "Here is the review". + Issues found: ``` ## Code Review - | # | File | Severity | Issue | - |---|------|----------|-------| - | 1 | `path/file:line` | 🔴 High | Description. **Fix:** suggestion | +
+ 🔴 High: `path/file:line` + + Description of the issue. **Fix:** suggestion. + +
+ +
+ 🟡 Medium: `path/file:line` + + Description of the issue. **Fix:** suggestion. + +
``` + Each issue MUST be wrapped in `
` like above. If NO issues found: ``` @@ -131,24 +141,25 @@ jobs: ``` STRICT RULES: - - Output the markdown table ONLY — no extra text, no summaries, no praise - - Each issue: file path with line, severity (🔴 High / 🟡 Medium / 🟢 Low), one-line description with fix suggestion - - 2 sentences max per issue + - Output ONLY the `` marker followed by the review content — no extra text, no summaries, no praise + - Each finding MUST be a `
` block with severity emoji in the ``: `🔴 High`, `🟡 Medium`, `🟢 Low` + - The summary line format: `🔴 High: \`path/file:line\`` (severity + file path with line) + - Inside each `
` block: one or two sentences describing the issue and fix - Max 10 issues, sorted by severity (high first) - If existing review body shows resolved issues, append a "### Resolved" section with ~~strikethrough~~ - - DO NOT number items outside the table column - - DO NOT use "1.", "2." at the start of each issue — use the table's `#` column instead + - Maintain a blank line between `
` and the next `
` ENDINSTRUCTIONS - ) - JSON_BODY=$(jq -n \ + SYSTEM_PROMPT="You are a senior code reviewer. Review the following PR diff for bugs, security issues, and performance problems. Skip style suggestions, documentation, and trivial improvements. Be concise — 2 sentences max per issue. Max 10 issues. Prioritize by severity." + + RESPONSE=$(jq -n \ --arg model "deepseek-chat" \ --arg sys "$SYSTEM_PROMPT" \ - --arg instructions "$INSTRUCTIONS" \ --arg pr_number "$PR_NUMBER" \ - --arg pr_commits "$PR_COMMITS" \ - --arg diff_truncated "$DIFF_TRUNCATED" \ - --arg existing_body "$EXISTING_BODY" \ + --rawfile instructions /tmp/instructions.txt \ + --rawfile pr_commits /tmp/pr_commits.json \ + --rawfile diff_truncated /tmp/pr_diff_truncated.txt \ + --rawfile existing_body /tmp/existing_body.txt \ '{ model: $model, messages: [ @@ -162,18 +173,16 @@ jobs: ], temperature: 0.0, max_tokens: 8192 - }') + }' | curl -s https://api.deepseek.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $DEEPSEEK_API_KEY" \ + -d @-) - RESPONSE=$(curl -s https://api.deepseek.com/v1/chat/completions \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $DEEPSEEK_API_KEY" \ - -d "$JSON_BODY") - - REVIEW_BODY=$(echo "$RESPONSE" | jq -r '.choices[0].message.content // empty') + REVIEW_BODY=$(printf '%s' "$RESPONSE" | jq -r '.choices[0].message.content // empty') if [ -z "$REVIEW_BODY" ]; then echo "DeepSeek API returned empty response" - echo "Error: $(echo "$RESPONSE" | jq -r '.error.message // "unknown error"')" + echo "Error: $(printf '%s' "$RESPONSE" | jq -r '.error.message // "unknown error"')" exit 1 fi