Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions .github/workflows/qwen-code-pr-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ jobs:
startsWith(github.event.review.body, '@qwen-code /review ') ||
startsWith(github.event.review.body, format('@qwen-code /review{0}', '\n'))) &&
needs.authorize.outputs.should_review == 'true'))
timeout-minutes: 120
timeout-minutes: 200
runs-on: ['self-hosted', 'linux', 'x64', 'ecs-qwen']
permissions:
contents: 'read'
Expand Down Expand Up @@ -370,11 +370,14 @@ jobs:
TRIGGER_BODY: "${{ github.event.comment.body || github.event.review.body || '' }}"
run: |-
set -euo pipefail
DEFAULT_TIMEOUT_MINUTES=120
TIMEOUT_MINUTES="$DEFAULT_TIMEOUT_MINUTES"
TRIGGER_COMMAND="${TRIGGER_BODY%%$'\n'*}"

if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
PR_NUMBER="${{ github.event.inputs.pr_number }}"
REVIEW_MODE="${{ github.event.inputs.review_mode }}"
TIMEOUT_MINUTES="${{ github.event.inputs.timeout_minutes || '120' }}"
elif [ "${{ github.event_name }}" = "issue_comment" ]; then
if ! printf '%s\n' "$TRIGGER_COMMAND" | grep -Eq '^@qwen-code[[:space:]]+/review([[:space:]]|$)'; then
echo "should_run=false" >> "$GITHUB_OUTPUT"
Expand All @@ -397,7 +400,20 @@ jobs:
exit 1
fi

TIMEOUT_MINUTES="${{ github.event.inputs.timeout_minutes || '120' }}"
if [ -n "$TRIGGER_COMMAND" ]; then
set -f
for token in $TRIGGER_COMMAND; do
case "$token" in
--timeout=*)
TIMEOUT_MINUTES="${token#--timeout=}"
;;
timeout=*)
TIMEOUT_MINUTES="${token#timeout=}"
;;
esac
done
set +f
fi

{
echo "should_run=true"
Expand Down Expand Up @@ -426,8 +442,12 @@ jobs:
fail() {
local message="$1"
local code="${2:-1}"
local kind="${3:-}"
echo "$message" >&2
echo "failure_reason=$message" >> "$GITHUB_OUTPUT"
if [ -n "$kind" ]; then
echo "failure_kind=$kind" >> "$GITHUB_OUTPUT"
fi
echo "$message" >> "$GITHUB_STEP_SUMMARY"
exit "$code"
}
Expand Down Expand Up @@ -524,11 +544,14 @@ jobs:
fail "Invalid timeout_minutes: ${TIMEOUT_MINUTES}"
;;
esac
if [ "${#TIMEOUT_MINUTES}" -gt 3 ]; then
fail "Invalid timeout_minutes: ${TIMEOUT_MINUTES}"
fi
if [ "$TIMEOUT_MINUTES" -le 5 ]; then
fail "timeout_minutes must be greater than 5"
fi
if [ "$TIMEOUT_MINUTES" -gt 120 ]; then
fail "timeout_minutes must not exceed the 120 minute job timeout"
if [ "$TIMEOUT_MINUTES" -gt 180 ]; then
fail "timeout_minutes must not exceed 180 minutes"
fi

if ! PR_STATE="$(gh pr view "$PR_NUMBER" --repo "$REPO" --json state --jq '.state')"; then
Expand All @@ -549,7 +572,7 @@ jobs:
MODEL_ARGS=(--model "$OPENAI_MODEL")
fi

QWEN_TIMEOUT=$((TIMEOUT_MINUTES - 5))
QWEN_TIMEOUT="$TIMEOUT_MINUTES"
set +e
# GNU timeout times out command children unless --foreground is used.
timeout --kill-after=10s "${QWEN_TIMEOUT}m" qwen \
Expand All @@ -567,8 +590,9 @@ jobs:
if [ "$tee_status" -ne 0 ]; then
fail "Failed to write qwen review log."
fi
if [ "$qwen_status" -eq 124 ]; then
fail "Qwen review timed out after ${QWEN_TIMEOUT} minutes."
# GNU timeout may report 137 if --kill-after escalates to SIGKILL.
if [ "$qwen_status" -eq 124 ] || [ "$qwen_status" -eq 137 ]; then
fail "Qwen review timed out after ${QWEN_TIMEOUT} minutes." 1 "timeout"
fi
if [ "$qwen_status" -ne 0 ]; then
fail "Qwen review exited with status ${qwen_status}."
Expand Down Expand Up @@ -609,13 +633,24 @@ jobs:
steps.context.outputs.pr_number != ''
env:
GH_TOKEN: '${{ secrets.CI_BOT_PAT }}'
FAILURE_KIND: "${{ steps.review.outputs.failure_kind || '' }}"
FAILURE_REASON: "${{ steps.review.outputs.failure_reason || 'Run review failed. See workflow logs for details.' }}"
PR_NUMBER: '${{ steps.context.outputs.pr_number }}'
RUN_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
TIMEOUT_MINUTES: '${{ steps.context.outputs.timeout_minutes }}'
run: |-
if [ "$FAILURE_KIND" = "timeout" ]; then
if [ "$TIMEOUT_MINUTES" -lt 180 ]; then
body="**Qwen Code review timed out.** ${FAILURE_REASON} For large PRs, retry with a longer timeout by commenting: \`@qwen-code /review --timeout=180\`. See [workflow logs](${RUN_URL})."
else
body="**Qwen Code review timed out.** ${FAILURE_REASON} This run already used the maximum 180 minute timeout. See [workflow logs](${RUN_URL})."
fi
else
body="**Qwen Code review did not complete successfully.** ${FAILURE_REASON} See [workflow logs](${RUN_URL})."
fi
gh pr comment "$PR_NUMBER" \
--repo "$GITHUB_REPOSITORY" \
--body "_Qwen Code review did not complete successfully: ${FAILURE_REASON} See [workflow logs](${RUN_URL})._"
--body "$body"

resolve-pr:
needs: ['authorize']
Expand Down
38 changes: 38 additions & 0 deletions scripts/tests/qwen-resolve-workflow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,44 @@ describe('qwen resolve workflow', () => {
expect(agentStep).toContain("QWEN_HOME: '${{ runner.temp }}/qwen-home'");
});

it('allows maintainers to extend review timeout from /review comments', () => {
const contextStep = step(reviewJob, 'Resolve PR context');
const runStep = step(reviewJob, 'Run review');

expect(reviewJob).toContain('timeout-minutes: 200');
expect(contextStep).toContain('DEFAULT_TIMEOUT_MINUTES=120');
expect(contextStep).toContain('case "$token" in');
expect(contextStep).toContain('--timeout=*)');
expect(contextStep).toContain('TIMEOUT_MINUTES="${token#--timeout=}"');
expect(contextStep).toContain('timeout=*)');
expect(contextStep).toContain('TIMEOUT_MINUTES="${token#timeout=}"');
expect(runStep).toContain('if [ "${#TIMEOUT_MINUTES}" -gt 3 ]; then');
expect(runStep).toContain('timeout_minutes must not exceed 180 minutes');
expect(runStep).toContain('QWEN_TIMEOUT="$TIMEOUT_MINUTES"');
expect(runStep).not.toContain('QWEN_TIMEOUT=$((TIMEOUT_MINUTES - 5))');
});

it('tells maintainers how to retry timed-out reviews with more time', () => {
const runStep = step(reviewJob, 'Run review');
const fallbackStep = step(reviewJob, 'Post fallback comment on failure');

expect(runStep).toContain('failure_kind=$kind');
expect(runStep).toContain(
'fail "Qwen review timed out after ${QWEN_TIMEOUT} minutes." 1 "timeout"',
);
expect(runStep).toContain('[ "$qwen_status" -eq 137 ]');
expect(fallbackStep).toContain('FAILURE_KIND:');
expect(fallbackStep).toContain('TIMEOUT_MINUTES:');
expect(fallbackStep).toContain('@qwen-code /review --timeout=180');
expect(fallbackStep).toContain(
'This run already used the maximum 180 minute timeout.',
);
expect(fallbackStep).toContain('**Qwen Code review timed out.**');
expect(fallbackStep).not.toContain(
'_Qwen Code review did not complete successfully:',
);
});

// Whole-file `toContain` cannot tell which job a guard lives on. Slice the
// resolve-pr job so these assertions fail if a future edit drops a guard
// specifically from the credentialed conflict-resolution path. Bound the slice
Expand Down
Loading