babysit-pr
GitHub自动监控GitHub Actions PR的CI状态,诊断失败原因(如测试、Lint、构建等),并尝试修复重试,最多3次。适用于PR监控、CI故障排查及自动化修复场景。
Trigger Scenarios
Install
npx skills add mermaid-js/zenuml-core --skill babysit-pr -g -y
SKILL.md
Frontmatter
{
"name": "babysit-pr",
"description": "Monitor and fix failing GitHub Actions CI checks on PRs for mermaid-js\/zenuml-core. Use when the user says \"babysit PR\", \"check PR status\", \"fix CI\", \"PR is failing\", \"watch this PR\", \"why is CI red\", or when used with \/loop to continuously monitor a PR. Also use when Playwright snapshot failures occur in CI, lint\/format issues block merging, or unit tests fail on a PR. Triggers on any PR monitoring, CI failure diagnosis, or automated fix-and-retry workflow."
}
Babysit PR
Monitor a GitHub Actions PR, diagnose failures, attempt fixes, and retry — up to 3 times total.
Scope
This skill targets mermaid-js/zenuml-core only. All commands run from the zenuml-core directory.
Step 1: Find the PR
Resolve which PR to babysit, in this priority order:
- Explicit PR number — if the user provided one (e.g.,
#341), use it - Current branch PR — run
gh pr view --json number,title,headRefName,state,statusCheckRollupfrom the zenuml-core directory - Recently failed PR — if no PR on current branch, find the most recent failed PR in the last 10 minutes:
Filter to runs created within the last 10 minutes. If multiple, pick the most recent.gh run list --repo mermaid-js/zenuml-core --status failure --limit 5 --json databaseId,headBranch,event,createdAt,conclusion,name
If no PR is found, tell the user and stop.
Step 2: Check CI Status
gh pr checks <PR_NUMBER> --repo mermaid-js/zenuml-core
Before claiming the PR is green or merge-ready, inspect its target branch and mergeability:
gh pr view <PR_NUMBER> --repo mermaid-js/zenuml-core --json mergeable,baseRefName,headRefName
If all checks pass: Verify merge readiness before reporting success, including whether the published PR branch can merge cleanly into the target branch. If a merge conflict exists, proceed to the Merge Conflict flow in Step 4 even though CI is green. Report success only after the branch is conflict-free and the required checks have completed.
If checks are still running: Report status and wait. Use gh run watch <RUN_ID> --repo mermaid-js/zenuml-core to wait for completion (with a 10-minute timeout). Then re-evaluate.
If checks are absent or inconclusive: Inspect the PR merge state and target/head relationship. If a merge conflict exists, proceed to the Merge Conflict flow in Step 4; otherwise report that no completed CI result is available and do not claim the PR is green.
If checks failed: Proceed to Step 3.
Step 3: Diagnose Failures
For each failed check, pull the logs:
gh run view <RUN_ID> --repo mermaid-js/zenuml-core --log-failed
Categorize the failure:
| Category | Indicators |
|---|---|
| Playwright snapshot mismatch | Error: A]snapshot.*doesn't match, Screenshot comparison failed, pixel diff errors, -linux.png referenced |
| Playwright test logic failure | Assertion errors, timeouts, element not found — but NOT snapshot diffs |
| Unit test failure | Failures in bun run test, vitest output |
| Lint/format failure | ESLint errors, Prettier diffs |
| Build failure | Vite build errors, TypeScript compilation errors |
| Merge conflict | CONFLICT, merge conflict, cannot rebase cleanly |
| Infra/flaky | Network timeouts, runner issues, cache failures |
Step 4: Attempt Fix
Important: Before fixing, make sure the local branch is up to date with the PR branch:
git fetch origin && git checkout <PR_BRANCH> && git pull origin <PR_BRANCH>
Before any local bun pw run in this workflow, verify that port 14000 is either free or already owned by a dev server started from this repo. playwright.config.ts reuses existing servers outside CI, so a Vite server from another repo will produce invalid local results.
PORT="${PORT:-14000}"
THIS_REPO="$(pwd -P)"
LISTENER_PID="$(lsof -tiTCP:${PORT} -sTCP:LISTEN 2>/dev/null | head -n1 || true)"
if [ -n "$LISTENER_PID" ]; then
LISTENER_CMD="$(ps -p "$LISTENER_PID" -o command=)"
if [[ "$LISTENER_CMD" != *"$THIS_REPO"* ]]; then
echo "Port ${PORT} is owned by another repo; killing PID ${LISTENER_PID}"
kill "$LISTENER_PID"
fi
fi
If you killed a different repo's server, do not start Vite manually. Let bun pw launch the correct dev server from this folder.
Fix by Category
Playwright Snapshot Mismatch (Linux)
This is the most common CI-only failure because snapshots are platform-specific.
- Verify it's a snapshot diff (not a logic error) by reading the failure log
- Check if the change is intentional — look at recent commits on the branch. If they modified rendering code, SVG output, or CSS, snapshot updates are expected. Run the
snapshot-visual-checkskill (.claude/skills/snapshot-visual-check/) on the failing screenshots first; trigger the update only when every diff cluster isintended. Aregressionor unexplained cluster means fix the code instead - Trigger the Linux snapshot update workflow:
gh workflow run update-snapshots.yml --repo mermaid-js/zenuml-core --ref <PR_BRANCH> - Wait for the workflow to complete:
# Find the run ID (most recent on that branch) gh run list --repo mermaid-js/zenuml-core --workflow update-snapshots.yml --branch <PR_BRANCH> --limit 1 --json databaseId,status # Watch it gh run watch <RUN_ID> --repo mermaid-js/zenuml-core - Pull the auto-committed snapshots locally:
git pull origin <PR_BRANCH> - Inspect the auto-committed Linux PNGs with the
snapshot-visual-checkskill (step 6, Linux baselines) before treating them as final. Clusters must match the ones approved in step 2. - The update-snapshots workflow commits and verifies automatically. If it passes, CI should go green on next run.
Playwright Test Logic Failure
- Reproduce locally first:
# Run the 14000 ownership preflight above first. bun pw --grep "<test name pattern>" - Read the failing test to understand what it expects
- Fix the code (not the test, unless the test expectation is wrong)
- Verify locally:
bun pw --grep "<test name pattern>" - Commit and push
Unit Test Failure
- Reproduce locally:
bun run test --run - Fix the code or test
- Verify:
bun run test --run - Commit and push
Lint/Format Failure
- Auto-fix:
bun eslint bun prettier - Verify no remaining issues:
bun eslint 2>&1 | tail -5 - Commit and push the formatting fixes
Build Failure
- Reproduce locally:
bun build - Read the error — usually TypeScript errors or missing imports
- Fix, verify locally, commit and push
Merge Conflict
- Wait for any previous CI run to finish before pushing. A green or absent check result does not remove this requirement.
- Preserve unrelated local work: inspect the working tree and keep changes outside the authorized PR/shipping scope intact. Do not reset, discard, or overwrite unrelated edits.
- Fetch and merge the target branch into the published PR branch:
git fetch origin <TARGET_BRANCH> git merge --no-edit origin/<TARGET_BRANCH> - Inspect base, ours, and theirs for every conflict and reconcile the intended source and test behavior from both branches. Preserve all intended requirements and assertions; do not weaken or delete assertions to make the merge pass, and do not resolve conflicts by blanket-choosing one side.
- Inspect both versions of every snapshot conflict. Use the
snapshot-visual-checkskill for every PNG conflict. Preserve intended expectations in text snapshots. Regenerate and review intentional Darwin visual baselines locally with the repository's snapshot-update commands. For Linux binary conflicts, choose a provisional baseline only to complete the local merge, record the affected paths as provisional, and do not treat it as final. - Verify and integrate in order: resolve every conflict and marker, run the full unit, browser, and lint validation (
bun run test --run,bun pw, andbun eslint), then complete the merge and push the published PR branch with regular ancestry (git push origin <PR_BRANCH>); never force-push. - Verify the remote result: wait for the new CI runs to finish. If Linux baselines need updating, run the existing Linux snapshot update workflow against the merged remote PR head, wait for generation and verification, then pull and inspect its results. Claim CI green only after the required checks pass. Ask the user only when a genuine behavioral ambiguity or required human decision remains, and report the concrete issue.
Infra/Flaky
- Re-run the failed job:
gh run rerun <RUN_ID> --repo mermaid-js/zenuml-core --failed - If it fails again with the same infra error, report to user.
Step 5: Push and Monitor
After applying a fix:
- Run the full local test suite before pushing (when the failure category allows local reproduction):
bun run test --run # unit tests # Run the 14000 ownership preflight above first. bun pw # playwright (local, macOS — won't catch Linux snapshot diffs) bun eslint # lint - Commit with a clear message:
git add <specific files> git commit -m "fix: <what was fixed> to pass CI" - Push:
git push origin <PR_BRANCH> - Wait for CI — use
gh run watchon the new run - Evaluate result — go back to Step 2
Step 6: Retry Budget
Track attempts. Each "attempt" is one push-and-wait cycle (or one workflow trigger-and-wait for snapshot updates).
- Maximum 3 attempts total
- After each failed attempt, re-diagnose from scratch (Step 3) — the failure mode may have changed
- If a test passes on retry without code changes, flag it as potentially flaky:
"Test
<name>passed on retry without changes — likely flaky. Consider investigating stability." - After 3 failed attempts, stop and report:
- What was tried
- What the current failure is
- Your best theory for root cause
- Suggested next steps for the user
Step 7: Summary Report
After babysitting completes (success or exhausted retries), produce a brief report:
## PR #<number> Babysit Report
- **Status**: [PASSED | FAILED after N attempts]
- **Failures found**: <list of categories>
- **Fixes applied**: <list of commits pushed>
- **Flaky tests**: <any tests that passed on retry without changes>
- **Manual attention needed**: <anything unresolved>
Safety Rules
- Never force-push — always regular
git push - Resolve merge conflicts autonomously within the authorized PR/shipping scope; ask only when a genuine behavioral ambiguity or required human decision remains, and report the concrete issue
- Never push while CI is still running from a previous attempt — wait for it to finish first
- Never modify the snapshot update workflow itself — only trigger it
- Always verify fixes locally before pushing (except Linux snapshot updates which can only be verified in CI)
- Check for in-progress CI before pushing — avoid wasting CI minutes on runs that will be superseded
Version History
-
fb11b8e
Current 2026-10-20 02:14
新增对合并冲突的检测与处理流程;在确认CI通过前增加对分支合并就绪状态的验证,若存在冲突则进入冲突修复流程。
- 377f600 2026-08-20 15:11


