Skip to content

Commit 8da71e4

Browse files
Allow automation to add notes to repeated workflow failures (#20599)
Repeated workflow failures currently add only the run URL to an existing issue, which loses useful context when an occurrence affects a different job or platform or has a different contributing factor. Add `comment_note` to the workflow-failure diagnosis and append it when recording another sample, while preserving the concise comment for identical repeats and rejecting generated notes that contain `@mentions`.
1 parent 1e1d01f commit 8da71e4

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

‎.github/workflows/diagnose-workflow-failure.yml‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ jobs:
148148
exit 1
149149
fi
150150
151+
if ! jq --exit-status '
152+
(.comment_note | type == "string")
153+
and (.comment_note | test("@[A-Za-z0-9][A-Za-z0-9-]*") | not)
154+
' "$RUNNER_TEMP/diagnosis.json" > /dev/null; then
155+
echo "The workflow failure comment note is invalid or contains a user mention; refusing to comment." >&2
156+
exit 1
157+
fi
158+
159+
run_url="https://github.com/$ISSUE_REPOSITORY/actions/runs/$RUN_ID"
160+
jq --raw-output --arg run_url "$run_url" '
161+
"Another workflow run encountered this failure: " + $run_url
162+
+ (if (.comment_note | length) > 0 then "\n\n" + .comment_note else "" end)
163+
' "$RUNNER_TEMP/diagnosis.json" > "$RUNNER_TEMP/comment.md"
164+
151165
if [ "$(jq -r '.decision' "$RUNNER_TEMP/diagnosis.json")" = "duplicate" ]; then
152166
duplicate_issue="$(jq -r --arg repository "$ISSUE_REPOSITORY" '
153167
[
@@ -165,10 +179,9 @@ jobs:
165179
exit 0
166180
fi
167181
168-
run_url="https://github.com/$ISSUE_REPOSITORY/actions/runs/$RUN_ID"
169182
gh issue comment "$duplicate_issue" \
170183
--repo "$ISSUE_REPOSITORY" \
171-
--body "Another workflow run encountered this failure: $run_url"
184+
--body-file "$RUNNER_TEMP/comment.md"
172185
exit 0
173186
fi
174187
@@ -198,10 +211,9 @@ jobs:
198211
'[.[] | select(.title == $title)][0].number // empty' \
199212
"$RUNNER_TEMP/existing-issues.json")"
200213
if [ -n "$existing_issue" ]; then
201-
run_url="https://github.com/$ISSUE_REPOSITORY/actions/runs/$RUN_ID"
202214
gh issue comment "$existing_issue" \
203215
--repo "$ISSUE_REPOSITORY" \
204-
--body "Another workflow run encountered this failure: $run_url"
216+
--body-file "$RUNNER_TEMP/comment.md"
205217
exit 0
206218
fi
207219

‎agents/prompts/diagnose-workflow-failure.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ Explain the decision in `decision_reason`. Do not create an issue merely because
3636
red. If a run contains multiple independent actionable failures, describe the most important
3737
untracked failure and mention the others in the body or related results.
3838

39+
For `duplicate`, populate `comment_note` with a concise note only when this occurrence differs in a
40+
useful way from the tracked failure, such as an affected job, platform, error, or contributing
41+
factor. Leave `comment_note` empty when there is no useful difference and for `create` or `ignore`.
42+
Do not include `@mentions` or sensitive values.
43+
3944
For `create`, populate `issue` with a concise, test- or symptom-specific title, a clear body, and
4045
exactly one label: use `ci-flake` for flaky tests or CI infrastructure, and `bug` for a
4146
deterministic repository or workflow defect. The body must include the failed run or job URL, the

‎agents/schemas/workflow-failure.json‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"enum": ["create", "duplicate", "ignore"]
3838
},
3939
"decision_reason": { "type": "string" },
40+
"comment_note": { "type": "string" },
4041
"issue": {
4142
"type": "object",
4243
"additionalProperties": false,
@@ -51,5 +52,11 @@
5152
"required": ["title", "body", "label"]
5253
}
5354
},
54-
"required": ["related", "decision", "decision_reason", "issue"]
55+
"required": [
56+
"related",
57+
"decision",
58+
"decision_reason",
59+
"comment_note",
60+
"issue"
61+
]
5562
}

0 commit comments

Comments
 (0)