Watch ci patterns

From ayutaz/piper-plus · View interactive version

Watch ci patterns is an AI agent skill from the GitHub repository ayutaz/piper-plus. CI workflow の最近 run を集計し、 failure を「flake / drift / env / test bug」に自動分類する skill。 既存 `/watch-pr <PR>` の workflow-level 拡張。 引数なしで全 workflow の health check、 `--workflow <name>` で個別 workflow の最近失敗パターンを抽出。 docker-build のような chronic flake (2026-05 の監査時点で failure rate 45%) を可視化する。

How to use this skill

Skill file

CI Failure Pattern Watcher

15 エージェント workflow 監査 (2026-05、 PR #498) の調査結果に基づく skill。 当時の主要 failing workflow と、 CI 統合 (#883〜#906) 後の再測定値:

| Workflow | 2026-05 監査時 | 2026-10-26 再測定 (直近 50 run) | 主要 failure 種別 (監査時) |

|----------|---------------|-------------------------------|-----------------|

| docker-build.yml | 45% | 1/39 (~3%) | flake (arm64 QEMU / disk space / network) |

| docker-test.yml | 16% | 0/37 (0%) | feature-branch test env (disk / arm64) |

| go-ci.yml | 14% | 3/46 (~7%) | dep drift (go.mod resolver) |

| csharp-ci.yml | 13% | 2/45 (~4%) | feature-branch issue-426 (docker mount) |

| multi-runtime-rtf.yml | 5% | 1/31 (~3%) | timing variance / RTF baseline |

再測定値は failure / (success + failure)。 数値は時間とともに変わるため、 判断には本 skill で集計した最新値を使う。

分類カテゴリ

  1. flake: 同じ branch の同じ commit で連続失敗 → 再 run で pass。 timing / network 由来。
  2. drift: lockfile / version pin / contract 不整合。 pre-commit で先回り可能。
  3. env: runner OS specific / QEMU emulation / disk space / Docker daemon。
  4. test bug: 同じ branch で再 run しても再現。 実装変更を要する。

引数

現在の状態

フェーズ 1: workflow 一覧取得

# workflow は 100 本超 (.github/workflows/ に 103 ファイル、 2026-10-26)。 --limit 50 では取りこぼす
gh workflow list --limit 200 --json name,state,id --jq '.[] | select(.state == "active") | .name'

--workflow 指定時はその 1 つだけ、 省略時は全 active workflow を順次処理。

フェーズ 2: 各 workflow の最近 run 集計

gh run list --workflow="$WORKFLOW" --limit "$LIMIT" \
    --json conclusion,name,headBranch,createdAt,displayTitle,databaseId,event

集計:

フェーズ 3: failure run の commit / branch クラスタリング

同じ commit SHA / branch で複数 run があれば flake 疑い。 異なる branch で同じ workflow が同じ step で fail なら drift 疑い:

gh run list --workflow="$WORKFLOW" --status=failure --limit 50 \
    --json headSha,headBranch,databaseId,createdAt \
    --jq 'group_by(.headSha) | map({sha: .[0].headSha, count: length, branches: ([.[].headBranch] | unique)}) | .[]'

count >= 2 && branches.length == 1 = flake or test bug。 count == 1 && branches.length > 1 = drift。

フェーズ 4: 失敗ログのパターン抽出

failure run の上位 3 件を gh run view --log-failed でログ取得、 既知 pattern と grep:

gh run view "$RUN_ID" --log-failed 2>&1 | tail -200 > /tmp/run_$RUN_ID.log

# Pattern matching
grep -E "(disk full|no space left)" /tmp/run_$RUN_ID.log && echo "ENV: disk"
grep -E "(connection refused|timeout|TLS)" /tmp/run_$RUN_ID.log && echo "ENV: network"
grep -E "(go.mod|inconsistent vendoring|missing go.sum)" /tmp/run_$RUN_ID.log && echo "DRIFT: go.mod"
grep -E "(ruff|format.*drift|cargo fmt)" /tmp/run_$RUN_ID.log && echo "DRIFT: format"
grep -E "(qemu|exec format error|illegal instruction)" /tmp/run_$RUN_ID.log && echo "ENV: arm64-emulation"
grep -E "FAILED.*test_" /tmp/run_$RUN_ID.log | head -5  # 実 test failure 名

抽出した signature を分類カテゴリに mapping。

フェーズ 5: report 生成

## CI Pattern Report — $(date +%Y-%m-%d)

### Summary
- workflows scanned: $N
- total runs (last $LIMIT): $TOTAL
- failure rate (overall): $RATE%

### Top failing workflows (値は記入例)
| Workflow | Failure% | Primary category |
|----------|---------|------------------|
| docker-build | 45% | env (arm64 QEMU) |
| go-ci | 14% | drift (go.mod) |
| ... | ... | ... |

### Action items
- [ ] go-ci drift: `go mod tidy` を pre-push に追加検討
- [ ] docker-build flake: arm64 build を concurrency 制限
- [ ] csharp-ci issue-426: 個別 fix (test bug)

フェーズ 6: 既存 skill との連携

flake / env と判定したら何もしない (再 run 任せ)。 drift と判定したら以下を提案:

test bug は個別 fix なので skill では着手しない、 issue 番号で記録。

注意

使用例

# 全 workflow の health check
/watch-ci-patterns

# docker-build に絞って深堀り
/watch-ci-patterns --workflow docker-build.yml --limit 50

# 最近 24h の failure のみ
/watch-ci-patterns --since 24h

# loop で 30 分ごと監視
/loop 30m /watch-ci-patterns --since 24h

期待効果

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.