oh-ci
Fix CI failures on a pull request. Work in an isolated worktree, diagnose failures from check run logs, apply fixes, verify, and push.
Invocation
/oh-ci <pr-number>
<pr-number> - the pull request number with failing CI
Prerequisites
- Repo context: Run from the repo root where the PR exists
- GitHub issue PR: The PR should be from an oh-task session (branch
issue/<number>)
Flow
Read dive context (if available) for project background:
cat .wm/dive_context.md 2>/dev/null || echo "No dive context"
Get PR branch info and create worktree:
# Save original directory for cleanup
ORIGINAL_DIR=$(pwd)
# Get the PR branch name
BRANCH=$(gh pr view <pr-number> --json headRefName -q .headRefName)
# Fetch and create worktree tracking the remote branch
git fetch origin
git worktree add .worktrees/ci-<pr-number> -B $BRANCH origin/$BRANCH
cd .worktrees/ci-<pr-number>
sg init
Fetch CI check run details and logs:
# Get the head SHA
HEAD_SHA=$(gh pr view <pr-number> --json headRefName,commits -q '.commits[-1].oid')
# List all check runs for this commit
gh api repos/{owner}/{repo}/commits/${HEAD_SHA}/check-runs --jq '.check_runs[] | select(.conclusion == "failure") | {name: .name, id: .id, conclusion: .conclusion}'
# For each failed check run, get the log
gh api repos/{owner}/{repo}/check-runs/{check_run_id}/annotations
If check run logs are insufficient, also try:
# Get workflow run logs (GitHub Actions)
gh run view --log-failed
Diagnose failures:
- Parse the CI logs to identify the root cause
- Common categories: type errors, test failures, lint violations, build errors
- If multiple failures, identify if they share a root cause
- Read the relevant source files to understand context
Fix the code:
- Apply targeted fixes for each failure
- Stage changes (
git add)
- Run
sg review on staged changes
- Handle review findings:
- P1-P3 trivial: fix inline, re-stage
- P1-P3 non-trivial: create GitHub issue as descendant
- P4: discard
Verify the fix locally:
# Run the same checks that failed, if possible
# For TypeScript projects:
pnpm typecheck 2>&1 || true
pnpm test 2>&1 || true
pnpm lint 2>&1 || true
# For Rust projects:
cargo check 2>&1 || true
cargo test 2>&1 || true
cargo clippy 2>&1 || true
Adapt commands to the project's build system (check package.json scripts, Makefile, etc.).
Commit fixes:
git commit -m "fix: resolve CI failures on PR #<pr-number>
- <summary of each fix>
Fixes #<descendant-issue> (if any)"
Push:
git push
Cleanup worktree:
cd $ORIGINAL_DIR
git worktree remove .worktrees/ci-<pr-number>
Exit and report:
- List what CI checks were failing and what was fixed
- Note any remaining issues that need human attention
- Provide PR URL
Descendant Issues
If sg review finds non-trivial issues during the fix, create GitHub issues:
PARENT_ISSUE=${BRANCH#issue/}
NEW_ISSUE=$(gh issue create \
--title "Fix: <brief description>" \
--body "Spawned from #${PARENT_ISSUE} during CI fix on PR #<pr-number>.
## Context
<what was found>
## Acceptance
- [ ] Fix applied
- [ ] CI passes" \
--assignee @me | grep -oE '[0-9]+$')
Complete ALL descendant issues before the final push.
Failure Modes
- Flaky tests: If a test failure appears non-deterministic, note it and push anyway. Report as "potentially flaky" in completion.
- Infrastructure failures: If CI failed due to infra (runner OOM, timeout, service outage), report as blocked — no code fix possible.
- Dependency issues: If a transitive dependency broke, attempt version pin or update. If not feasible, report as blocked.
Exit Conditions
- Success: All CI failures diagnosed and fixed, changes pushed
- Blocked: Failure requires human decision or is infrastructure-related
- Error: Cannot diagnose the failure or fix creates worse problems
Completion Signaling (MANDATORY)
CRITICAL: You MUST signal completion when done. Call the signal_completion tool as your FINAL action.
Signal based on outcome:
| Outcome |
Call |
| CI fixed, changes pushed |
signal_completion(status: "success", pr: "<pr-url>") |
| Needs human decision |
signal_completion(status: "blocked", blocker: "<reason>") |
| Unrecoverable failure |
signal_completion(status: "error", error: "<reason>") |
| If you do not signal, the orchestrator will not know you are done and the session becomes orphaned. |
|
Fallback: If the signal_completion tool is not available, output your completion status as your final message in the format: COMPLETION: status=<status> pr=<url> or COMPLETION: status=<status> error=<reason>.
1---2name: oh-ci-23description: Diagnose and fix CI failures on a PR, push fixes4---56# oh-ci78Fix CI failures on a pull request. Work in an isolated worktree, diagnose failures from check run logs, apply fixes, verify, and push.910## Invocation1112`/oh-ci <pr-number>`1314- `<pr-number>` - the pull request number with failing CI1516## Prerequisites1718- **Repo context**: Run from the repo root where the PR exists19- **GitHub issue PR**: The PR should be from an oh-task session (branch `issue/<number>`)2021## Flow22231. Read dive context (if available) for project background:24 ```bash25 cat .wm/dive_context.md 2>/dev/null || echo "No dive context"26 ```27282. Get PR branch info and create worktree:29 ```bash30 # Save original directory for cleanup31 ORIGINAL_DIR=$(pwd)3233 # Get the PR branch name34 BRANCH=$(gh pr view <pr-number> --json headRefName -q .headRefName)3536 # Fetch and create worktree tracking the remote branch37 git fetch origin38 git worktree add .worktrees/ci-<pr-number> -B $BRANCH origin/$BRANCH39 cd .worktrees/ci-<pr-number>40 sg init41 ```42433. Fetch CI check run details and logs:44 ```bash45 # Get the head SHA46 HEAD_SHA=$(gh pr view <pr-number> --json headRefName,commits -q '.commits[-1].oid')4748 # List all check runs for this commit49 gh api repos/{owner}/{repo}/commits/${HEAD_SHA}/check-runs --jq '.check_runs[] | select(.conclusion == "failure") | {name: .name, id: .id, conclusion: .conclusion}'5051 # For each failed check run, get the log52 gh api repos/{owner}/{repo}/check-runs/{check_run_id}/annotations53 ```5455 If check run logs are insufficient, also try:56 ```bash57 # Get workflow run logs (GitHub Actions)58 gh run view --log-failed59 ```60614. Diagnose failures:62 - Parse the CI logs to identify the root cause63 - Common categories: type errors, test failures, lint violations, build errors64 - If multiple failures, identify if they share a root cause65 - Read the relevant source files to understand context66675. Fix the code:68 - Apply targeted fixes for each failure69 - Stage changes (`git add`)70 - Run `sg review` on staged changes71 - Handle review findings:72 - P1-P3 trivial: fix inline, re-stage73 - P1-P3 non-trivial: create GitHub issue as descendant74 - P4: discard75766. Verify the fix locally:77 ```bash78 # Run the same checks that failed, if possible79 # For TypeScript projects:80 pnpm typecheck 2>&1 || true81 pnpm test 2>&1 || true82 pnpm lint 2>&1 || true8384 # For Rust projects:85 cargo check 2>&1 || true86 cargo test 2>&1 || true87 cargo clippy 2>&1 || true88 ```89 Adapt commands to the project's build system (check package.json scripts, Makefile, etc.).90917. Commit fixes:92 ```bash93 git commit -m "fix: resolve CI failures on PR #<pr-number>9495 - <summary of each fix>9697 Fixes #<descendant-issue> (if any)"98 ```991008. Push:101 ```bash102 git push103 ```1041059. Cleanup worktree:106 ```bash107 cd $ORIGINAL_DIR108 git worktree remove .worktrees/ci-<pr-number>109 ```11011110. Exit and report:112 - List what CI checks were failing and what was fixed113 - Note any remaining issues that need human attention114 - Provide PR URL115116## Descendant Issues117118If `sg review` finds non-trivial issues during the fix, create GitHub issues:119```bash120PARENT_ISSUE=${BRANCH#issue/}121NEW_ISSUE=$(gh issue create \122 --title "Fix: <brief description>" \123 --body "Spawned from #${PARENT_ISSUE} during CI fix on PR #<pr-number>.124125## Context126<what was found>127128## Acceptance129- [ ] Fix applied130- [ ] CI passes" \131 --assignee @me | grep -oE '[0-9]+$')132```133134Complete ALL descendant issues before the final push.135136## Failure Modes137138- **Flaky tests**: If a test failure appears non-deterministic, note it and push anyway. Report as "potentially flaky" in completion.139- **Infrastructure failures**: If CI failed due to infra (runner OOM, timeout, service outage), report as blocked — no code fix possible.140- **Dependency issues**: If a transitive dependency broke, attempt version pin or update. If not feasible, report as blocked.141142## Exit Conditions143144- **Success**: All CI failures diagnosed and fixed, changes pushed145- **Blocked**: Failure requires human decision or is infrastructure-related146- **Error**: Cannot diagnose the failure or fix creates worse problems147148## Completion Signaling (MANDATORY)149**CRITICAL: You MUST signal completion when done.** Call the `signal_completion` tool as your FINAL action.150**Signal based on outcome:**151| Outcome | Call |152|---------|------|153| CI fixed, changes pushed | `signal_completion(status: "success", pr: "<pr-url>")` |154| Needs human decision | `signal_completion(status: "blocked", blocker: "<reason>")` |155| Unrecoverable failure | `signal_completion(status: "error", error: "<reason>")` |156**If you do not signal, the orchestrator will not know you are done and the session becomes orphaned.**157158**Fallback:** If the `signal_completion` tool is not available, output your completion status as your final message in the format: `COMPLETION: status=<status> pr=<url>` or `COMPLETION: status=<status> error=<reason>`.