@@ -34,6 +34,21 @@ name: main broken watcher |
34 | 34 | # fleet monitor enqueues the priority packet; no queue write |
35 | 35 | # happens from this workflow's release job. |
36 | 36 | # |
| 37 | +# Scout leg (#2176, failure-triage design): between filing and any |
| 38 | +# remediation spend, a scout step reads the failing jobs' log tails |
| 39 | +# (scripts/classify_failure.py) and classifies the breakage -- |
| 40 | +# quota-or-secret / infra-runner / infra-network / flake-suspect / |
| 41 | +# real-regression / unknown -- posting an agent-note:v1 with 3-5 |
| 42 | +# evidence lines on the breakage issue BEFORE the jules label or a |
| 43 | +# fresh fix task is applied. Routing: quota/secret escalates (zero |
| 44 | +# fix attempts); infra and flake get one automatic re-run of the |
| 45 | +# failed jobs (a repeat escalates as infrastructure; a third flake |
| 46 | +# strike files a flake-fix issue); real-regression and unknown take |
| 47 | +# the existing Jules/queue routing with the diagnosis attached. |
| 48 | +# Authority limits preserved: the scout may re-run once, comment, |
| 49 | +# label, and file within the chain's labels; it never edits code, |
| 50 | +# merges, touches secrets, or disables workflows. |
| 51 | +# |
37 | 52 | # Dry-run: workflow_dispatch with dry_run=true and a run_id prints |
38 | 53 | # what WOULD be filed and files nothing. |
39 | 54 |
|
|
84 | 99 | permissions: |
85 | 100 | contents: read |
86 | 101 | issues: write |
87 | | - actions: read |
| 102 | + actions: write |
88 | 103 | pull-requests: read |
89 | 104 | id-token: write |
90 | 105 | env: |
@@ -149,7 +164,7 @@ jobs: |
149 | 164 | if [ -n "$existing" ]; then |
150 | 165 | echo "DRY-RUN: would append a comment with run $run_url to issue #$existing and queue a fresh fix task on it via the pm-dispatch queuer." |
151 | 166 | else |
152 | | - echo "DRY-RUN: would queue '$title' via the pm-dispatch queuer (which creates the issue) with Breakage-ID: $bid, then apply labels kind/ci, priority/critical, main-broken, queue/queued, status/needs-triage; agent-note holder: chain (filing); then jules label if <3 open main-broken issues carry it." |
| 167 | + echo "DRY-RUN: would run the scout classifier first; on a fix route it would queue '$title' via the pm-dispatch queuer (which creates the issue) with Breakage-ID: $bid, on a rerun/escalate route it would file the issue directly with NO fix task queued; then apply labels kind/ci, priority/critical, main-broken, status/needs-triage (queue/queued only when a fix task was queued); agent-note holder: chain (filing); then jules label if <3 open main-broken issues carry it and the scout route is fix." |
153 | 168 | fi |
154 | 169 | echo "action=dry" >> "$GITHUB_OUTPUT" |
155 | 170 | exit 0 |
@@ -186,6 +201,41 @@ jobs: |
186 | 201 | } >> "$GITHUB_OUTPUT" |
187 | 202 | echo "Identified breakage: action=${action} existing=${existing:-none} Breakage-ID=${bid}" |
188 | 203 |
|
| 204 | + # Scout leg (#2176): classify from the failing jobs' log tails |
| 205 | + # BEFORE any remediation spend. This step runs ahead of the |
| 206 | + # create-path dispatch on purpose (Codex finding, PR #7806): |
| 207 | + # pm-dispatch always enqueues a fix task, so the create dispatch, |
| 208 | + # the jules label step, and the append dispatch all gate on the |
| 209 | + # scout route; non-fix routes file the issue without a fix task |
| 210 | + # (see the file-issue-only step below). Fail-open by design: if |
| 211 | + # the classifier errors, route stays empty and the chain behaves |
| 212 | + # as before. |
| 213 | + - name: Scout - classify the failure from job log tails (#2176) |
| 214 | + id: scout |
| 215 | + if: steps.identify.outputs.action == 'create' || steps.identify.outputs.action == 'append' || steps.identify.outputs.action == 'dry' |
| 216 | + continue-on-error: true |
| 217 | + run: | |
| 218 | + set -euo pipefail |
| 219 | + mkdir -p scout-logs |
| 220 | + gh api "repos/$GH_REPO/actions/runs/$RUN_ID/jobs?per_page=100" \ |
| 221 | + --jq '.jobs[] | select(.conclusion == "failure") | [.id, .name] | @tsv' \ |
| 222 | + > scout-logs/jobs.tsv || true |
| 223 | + while IFS=$'\t' read -r jid jname; do |
| 224 | + [ -n "$jid" ] || continue |
| 225 | + gh api "repos/$GH_REPO/actions/jobs/$jid/logs" > "scout-logs/$jid.log" 2>/dev/null \ |
| 226 | + || echo "log download failed for job $jid ($jname)" > "scout-logs/$jid.log" |
| 227 | + done < scout-logs/jobs.tsv |
| 228 | + python3 scripts/classify_failure.py --logs-dir scout-logs \ |
| 229 | + --jobs-manifest scout-logs/jobs.tsv > scout.json \ |
| 230 | + || echo '{"classification":"unknown","route":"fix","detail":"classifier error","evidence":[],"jobs":[]}' > scout.json |
| 231 | + cat scout.json |
| 232 | + { |
| 233 | + echo "classification=$(jq -r .classification scout.json)" |
| 234 | + echo "route=$(jq -r .route scout.json)" |
| 235 | + echo "detail=$(jq -r '.detail // ""' scout.json)" |
| 236 | + } >> "$GITHUB_OUTPUT" |
| 237 | + jq -r '.evidence[]?' scout.json > scout-evidence.txt || true |
| 238 | +
|
189 | 239 | # Coin labels if missing (main-broken + jules included: the |
190 | 240 | # plain `jules` label did not exist before this workflow). Only |
191 | 241 | # needed on the create path, before the label-apply step. |
@@ -199,7 +249,8 @@ jobs: |
199 | 249 | "main-broken|B60205|main branch full-suite (main tier) is red; remediation chain owns this" \ |
200 | 250 | "queue/queued|7057ff|Has a queued task in the fleet agent queue" \ |
201 | 251 | "status/needs-triage|fbca04|Not yet triaged; needs a first look" \ |
202 | | - "jules|57ab5a|Hand this issue to remediation (issue-labeled job in jules.yml, via pm-dispatch)"; do |
| 252 | + "jules|57ab5a|Hand this issue to remediation (issue-labeled job in jules.yml, via pm-dispatch)" \ |
| 253 | + "flake-fix|f9d0c4|Third-strike flake: diagnose and deflake (filed by the main-broken scout leg)"; do |
203 | 254 | IFS='|' read -r lname lcolor ldesc <<<"$spec" |
204 | 255 | gh label create "$lname" --repo "$GH_REPO" --color "$lcolor" --description "$ldesc" 2>/dev/null || true |
205 | 256 | done |
@@ -208,46 +259,161 @@ jobs: |
208 | 259 | # queue/queued + source/dispatch labels pm-dispatch applies). |
209 | 260 | - name: Queue the breakage via pm-dispatch (creates the issue) |
210 | 261 | id: dispatch-create |
211 | | - if: steps.identify.outputs.action == 'create' |
| 262 | + if: steps.identify.outputs.action == 'create' && (steps.scout.outputs.route == '' || steps.scout.outputs.route == 'fix') |
212 | 263 | uses: ./.github/actions/pm-dispatch-queue |
213 | 264 | with: |
214 | 265 | title: ${{ steps.identify.outputs.title }} |
215 | 266 | prompt: ${{ steps.identify.outputs.prompt }} |
216 | 267 | issue: "true" |
217 | 268 |
|
| 269 | + # Create path, non-fix scout routes: file the breakage issue |
| 270 | + # directly WITHOUT queueing a fix task. pm-dispatch has no |
| 271 | + # issue-only mode -- its POST always enqueues a fix attempt -- |
| 272 | + # so a quota/secret or infra/flake breakage must not go through |
| 273 | + # it before classification (Codex finding, PR #7806). The scout |
| 274 | + # note/routing step below attaches the classification, the |
| 275 | + # escalation, or the one automatic re-run to this issue. |
| 276 | + - name: File the breakage issue only (scout-gated, no fix dispatch) |
| 277 | + id: file-issue-only |
| 278 | + if: steps.identify.outputs.action == 'create' && steps.scout.outputs.route != '' && steps.scout.outputs.route != 'fix' |
| 279 | + env: |
| 280 | + TITLE: ${{ steps.identify.outputs.title }} |
| 281 | + BODY: ${{ steps.identify.outputs.body }} |
| 282 | + run: | |
| 283 | + set -euo pipefail |
| 284 | + url=$(gh issue create --repo "$GH_REPO" --title "$TITLE" --body "$BODY") |
| 285 | + inum=${url##*/} |
| 286 | + { |
| 287 | + echo "issue_number=$inum" |
| 288 | + echo "issue_url=$url" |
| 289 | + } >> "$GITHUB_OUTPUT" |
| 290 | + echo "Filed issue #$inum with no fix task queued (scout route: ${{ steps.scout.outputs.route }})" |
| 291 | +
|
218 | 292 | # The queuer only applies queue/queued + source/dispatch, so this |
219 | 293 | # workflow's own label set is applied here from its output. |
220 | 294 | - name: Apply the chain label set to the created issue |
221 | 295 | if: steps.identify.outputs.action == 'create' |
222 | 296 | env: |
223 | | - INUM: ${{ steps.dispatch-create.outputs.issue_number }} |
| 297 | + INUM: ${{ steps.dispatch-create.outputs.issue_number || steps.file-issue-only.outputs.issue_number }} |
| 298 | + ROUTE: ${{ steps.scout.outputs.route }} |
224 | 299 | run: | |
225 | 300 | set -euo pipefail |
226 | 301 | if [ -z "${INUM}" ]; then |
227 | 302 | echo "::error::pm-dispatch queuer returned no issue_number"; exit 1 |
228 | 303 | fi |
229 | 304 | gh issue edit "$INUM" --repo "$GH_REPO" \ |
230 | 305 | --add-label "kind/ci" --add-label "priority/critical" \ |
231 | | - --add-label "main-broken" --add-label "queue/queued" \ |
| 306 | + --add-label "main-broken" \ |
232 | 307 | --add-label "status/needs-triage" |
| 308 | + # queue/queued asserts a fix task exists; only the dispatch |
| 309 | + # path queued one (fix route or fail-open). |
| 310 | + if [ -z "$ROUTE" ] || [ "$ROUTE" = "fix" ]; then |
| 311 | + gh issue edit "$INUM" --repo "$GH_REPO" --add-label "queue/queued" |
| 312 | + fi |
233 | 313 | echo "Filed issue #$INUM via pm-dispatch: ${{ steps.dispatch-create.outputs.issue_url }}" |
234 | 314 |
|
235 | 315 | - name: Record the filing holder note |
236 | 316 | if: steps.identify.outputs.action == 'create' |
237 | 317 | env: |
238 | | - INUM: ${{ steps.dispatch-create.outputs.issue_number }} |
| 318 | + INUM: ${{ steps.dispatch-create.outputs.issue_number || steps.file-issue-only.outputs.issue_number }} |
239 | 319 | TS: ${{ steps.identify.outputs.ts }} |
240 | 320 | BID: ${{ steps.identify.outputs.bid }} |
241 | 321 | run: | |
242 | 322 | set -euo pipefail |
243 | 323 | gh issue comment "$INUM" --repo "$GH_REPO" \ |
244 | 324 | --body "agent-note:v1 — holder: chain (filing), at $TS. Breakage-ID: $BID" |
245 | 325 |
|
| 326 | +
|
| 327 | + - name: Scout - post the classification note and route (#2176) |
| 328 | + if: (steps.identify.outputs.action == 'create' || steps.identify.outputs.action == 'append') && steps.scout.outputs.classification != '' |
| 329 | + continue-on-error: true |
| 330 | + env: |
| 331 | + INUM: ${{ steps.dispatch-create.outputs.issue_number || steps.file-issue-only.outputs.issue_number || steps.identify.outputs.existing_number }} |
| 332 | + CLASS: ${{ steps.scout.outputs.classification }} |
| 333 | + ROUTE: ${{ steps.scout.outputs.route }} |
| 334 | + DETAIL: ${{ steps.scout.outputs.detail }} |
| 335 | + BID: ${{ steps.identify.outputs.bid }} |
| 336 | + RUN_URL_OUT: ${{ steps.identify.outputs.run_url }} |
| 337 | + WF: ${{ steps.identify.outputs.wf }} |
| 338 | + run: | |
| 339 | + set -euo pipefail |
| 340 | + ts=$(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 341 | + ev=$(sed 's/^/ /' scout-evidence.txt 2>/dev/null || true) |
| 342 | + [ -n "$ev" ] || ev=" (no evidence lines extracted)" |
| 343 | + action_line="route: existing Jules/queue fix routing, diagnosis attached." |
| 344 | + do_rerun=false |
| 345 | + if [ "$ROUTE" = "escalate" ]; then |
| 346 | + action_line="escalating: quota/secret - zero fix attempts. Drew: $DETAIL" |
| 347 | + elif [ "$ROUTE" = "rerun" ]; then |
| 348 | + attempt=$(gh api "repos/$GH_REPO/actions/runs/$RUN_ID" --jq '.run_attempt // 1') |
| 349 | + if [ "${attempt:-1}" -lt 2 ]; then |
| 350 | + do_rerun=true |
| 351 | + action_line="route: one automatic re-run of the failed jobs (this was attempt $attempt)." |
| 352 | + else |
| 353 | + action_line="escalating: already re-run once (attempt $attempt) and still failing - treat as infrastructure, not a code fix." |
| 354 | + fi |
| 355 | + if [ "$CLASS" = "flake-suspect" ]; then |
| 356 | + # --paginate + count matching comment ids: counting only |
| 357 | + # the first page of comments misses strikes on long-lived |
| 358 | + # breakage issues (CodeRabbit finding, PR #7806). |
| 359 | + strikes=$(gh api --paginate "repos/$GH_REPO/issues/$INUM/comments?per_page=100" \ |
| 360 | + --jq '.[] | select(.body | test("scout: classification flake-suspect")) | .id' | wc -l | tr -d ' ') |
| 361 | + if [ "${strikes:-0}" -ge 2 ]; then |
| 362 | + action_line="$action_line Third flake strike for Breakage-ID $BID - filing a flake-fix issue." |
| 363 | + fi |
| 364 | + fi |
| 365 | + fi |
| 366 | + gh issue comment "$INUM" --repo "$GH_REPO" \ |
| 367 | + --body "agent-note:v1 - scout: classification $CLASS, at $ts. Breakage-ID: $BID. Run: $RUN_URL_OUT |
| 368 | + Evidence (failing job log tails): |
| 369 | + $ev |
| 370 | + $action_line" |
| 371 | + if [ "$ROUTE" = "escalate" ]; then |
| 372 | + gh issue edit "$INUM" --repo "$GH_REPO" --add-label "status/needs-triage" || true |
| 373 | + fi |
| 374 | + if [ "$do_rerun" = "true" ]; then |
| 375 | + # A failed rerun request must not read as a rerun on the |
| 376 | + # issue: report it so the breakage gets manual triage |
| 377 | + # (CodeRabbit finding, PR #7806). |
| 378 | + if ! gh run rerun "$RUN_ID" --repo "$GH_REPO" --failed; then |
| 379 | + gh issue comment "$INUM" --repo "$GH_REPO" \ |
| 380 | + --body "agent-note:v1 - scout: automatic re-run request FAILED for run $RUN_URL_OUT (Breakage-ID: $BID); no rerun happened and no fix task is queued - triage manually." || true |
| 381 | + fi |
| 382 | + fi |
| 383 | + if [ "$CLASS" = "flake-suspect" ] && [ "${strikes:-0}" -ge 2 ]; then |
| 384 | + # in:title + exclude this breakage issue itself: the scout |
| 385 | + # note just posted carries both "flake-fix" and the |
| 386 | + # Breakage-ID in a COMMENT, and issue search covers |
| 387 | + # comments -- unfiltered, the breakage issue matches its |
| 388 | + # own dedupe lookup and suppresses the flake-fix filing |
| 389 | + # (Codex finding, PR #7806). |
| 390 | + existing_fix=$(gh issue list --repo "$GH_REPO" --state open \ |
| 391 | + --search "flake-fix in:title Breakage-ID: $BID" --json number \ |
| 392 | + --jq '.[].number' | grep -vx "${INUM:-0}" | head -n1 || true) |
| 393 | + if [ -z "$existing_fix" ]; then |
| 394 | + # Distinct flake-fix label, NOT main-broken: the auxiliary |
| 395 | + # issue body carries the Breakage-ID, so with the main-broken |
| 396 | + # label it would match Identify's canonical-breakage lookup |
| 397 | + # (label + ID search) and steal the breakage from the |
| 398 | + # original issue (Codex finding, PR #7806). |
| 399 | + # gh issue create does not coin missing labels, and the |
| 400 | + # coin-labels step only runs on the create path while a |
| 401 | + # third strike happens on a recurrence -- ensure the |
| 402 | + # flake-fix label exists here too, or the filing fails |
| 403 | + # silently under || true (Codex finding, PR #7806). |
| 404 | + gh label create "flake-fix" --repo "$GH_REPO" --color "f9d0c4" --description "Third-strike flake: diagnose and deflake (filed by the main-broken scout leg)" 2>/dev/null || true |
| 405 | + gh issue create --repo "$GH_REPO" \ |
| 406 | + --title "flake-fix: $WF - Breakage-ID: $BID" \ |
| 407 | + --label "kind/ci" --label "flake-fix" \ |
| 408 | + --body "Third flake-suspect strike for Breakage-ID $BID (breakage issue #$INUM). The scout leg of the main-broken chain files this per the #2176 failure-triage design: diagnose and deflake the failing job(s) named in the scout notes on #$INUM." || true |
| 409 | + fi |
| 410 | + fi |
| 411 | +
|
246 | 412 | # Remediation budget: <3 concurrent remediations in flight. The |
247 | 413 | # `jules` label application logic is unchanged; the label now |
248 | 414 | # triggers an OpenCode session via the migrated jules.yml. |
249 | 415 | - name: Apply the jules label within the remediation budget |
250 | | - if: steps.identify.outputs.action == 'create' |
| 416 | + if: steps.identify.outputs.action == 'create' && (steps.scout.outputs.route == '' || steps.scout.outputs.route == 'fix') |
251 | 417 | env: |
252 | 418 | INUM: ${{ steps.dispatch-create.outputs.issue_number }} |
253 | 419 | BID: ${{ steps.identify.outputs.bid }} |
@@ -270,15 +436,15 @@ jobs: |
270 | 436 | # existing Breakage-ID issue -- no second issue is created. |
271 | 437 | - name: Queue a fresh fix task via pm-dispatch (existing issue) |
272 | 438 | id: dispatch-append |
273 | | - if: steps.identify.outputs.action == 'append' |
| 439 | + if: steps.identify.outputs.action == 'append' && (steps.scout.outputs.route == '' || steps.scout.outputs.route == 'fix') |
274 | 440 | uses: ./.github/actions/pm-dispatch-queue |
275 | 441 | with: |
276 | 442 | title: ${{ steps.identify.outputs.title }} |
277 | 443 | prompt: ${{ steps.identify.outputs.prompt }} |
278 | 444 | issue_number: ${{ steps.identify.outputs.existing_number }} |
279 | 445 |
|
280 | 446 | - name: Append a recurrence comment to the existing issue |
281 | | - if: steps.identify.outputs.action == 'append' |
| 447 | + if: steps.identify.outputs.action == 'append' && (steps.scout.outputs.route == '' || steps.scout.outputs.route == 'fix') |
282 | 448 | env: |
283 | 449 | EXISTING: ${{ steps.identify.outputs.existing_number }} |
284 | 450 | RUN_URL_OUT: ${{ steps.identify.outputs.run_url }} |
|