Skip to content

fix(factory): re-run red CI a no-op watch pass left instead of asking Claude again - #936

Merged
JakubAnderwald merged 6 commits into
mainfrom
fix/factory-watch-red-check-rerun
Nov 25, 2026
Merged

JakubAnderwald merged 6 commits into
mainfrom
fix/factory-watch-red-check-rerun

Conversation

@JakubAnderwald

@JakubAnderwald JakubAnderwald commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Why

The factory session audit (watch-waste item 5a) found that a --watch fix pass ending noop on red CI is asked again on every tick. Card #899 (PR #915) spent ten Claude passes on one head and one red. None of them could change the outcome, and the red only needed a gh run rerun --failed. ADR-0041's attempts bound stopped the loop only after the whole FACTORY_MAX_ATTEMPTS budget was spent.

What changed

  • Noop arm (scripts/factory-agent.sh): a noop pass on red CI still spends one attempt. It now also records ciNoop = "<head sha>:<failing required check names, sorted, newline-joined (a matrix job name can contain a comma)>".
  • Next tick: after classify_failing_required, a red on the recorded head SHA goes to recover_noop_red_ci when its failing required checks are the recorded ones or some of them. That path has no Claude run and no fix attempt.
    • A subset counts because the jobs of one re-run finish minutes apart. A tick in the middle of a re-run often sees the faster job red again while the slower one is still running. A re-run that turns some checks green leaves only red the agent already judged.
    • A red check the noop pass didn't see is new, so it goes to the fix loop.
    • It re-runs the checks with rerun_infra_failures, sharing the per-head ciRerun budget (FACTORY_CI_RERUN_MAX, default 2) and waiting while the run is in progress.
    • Once the budget is spent, comment_ci_noop_hold posts one comment per head (<!-- drafto-factory-ci-noop-hold:<sha12> -->) with the gh run rerun commands and the re-arm command. It sets lastError, moves the card to Blocked and releases its slot.
    • If the comments can't be read or the post fails, the card waits in In Review for the next tick rather than being parked without the notice. That path returns success, and the call site has || true. The --watch loop runs under set -euo pipefail, so a non-zero status there would end the whole tick and file a factory-failure issue.
  • Re-arming: nothing picks cards out of Blocked. After a push, drag the card back to In Review; the new SHA re-arms it. To re-arm on the same commit: node scripts/lib/state-cli.mjs factory:set-issue-field <n> ciNoop "" --state-file logs/factory-state.json. Clear ciRerun too to get fresh re-runs.
  • pr_infra_rerun_ids skips checks that have no Actions run URL.
  • State: new per-issue field ciNoop (factory-state.mjs: emptyIssue and MUTABLE_ISSUE_FIELDS; state-cli.mjs: doc comment).
  • Prompt (factory-watch-prompt.md): it now says what a noop on red CI leads to: an attempt spent, a bash re-run, then Blocked. This replaces the stale "rather than burning the retry budget". The pinned "It is context, not a budget" sentence is unchanged.
  • --release's red-CI hand-back and the Testing stage's ci-red hand-back clear ciNoop (clear_ci_noop), so a card they send back gets its fix pass instead of going straight to Blocked. The migration renumber gate (ADR-0077) runs before the bash re-run, as it does before a fix pass.

Docs

  • New ADR-0102, with a row in the ADR index (docs/adr/README.md).
  • ADR-0041 gets an "Amended by ADR-0102" blockquote.
  • The runbook's "Red or cancelled CI on a factory PR" section now covers this, with the re-arm recipe. One paragraph was added to docs/features/dark-factory.md.

Knobs and defaults

No new knob. It reuses FACTORY_CI_RERUN_MAX (default 2), so a noop on red now costs one Claude pass and at most 2 bash re-runs before the card goes to Blocked. With FACTORY_CI_RERUN_MAX=0, the card goes straight to Blocked on the next tick.

Tests

scripts/__tests__/factory-agent-required-checks.test.mjs:

  • Static pins: the new helpers exist; the noop arm records ciNoop; the repeat check comes after classification (asserted present) and before the fix loop, and is called with || true and followed by continue.
  • pr_ci_noop_key and record_ci_noop (including dry run).
  • ci_noop_repeat should match on:
    • the same head;
    • a mid-re-run rollup (one recorded check red, the other in progress);
    • a re-run that leaves some recorded checks red.
  • ci_noop_repeat should not match on:
    • a new SHA (it re-arms the card), including a subset on a new SHA;
    • a red check outside the record;
    • a missing or unreadable record.
  • An end-to-end sequence against a stateful stub: recorded → re-run 1 → re-run 2 (no Claude) → Blocked with one comment → back to Blocked without a second comment → a new SHA re-arms.
  • Under set -euo pipefail with a two-card loop shaped like the watch block, the hold's transient paths (refused comment, unreadable comments) leave the card in place and the loop moves on to the next card. A mid-re-run tick waits for the run with no re-run and no Claude.
  • comment_ci_noop_hold edge cases, including the "push and drag back" wording; a non-Actions URL in pr_infra_rerun_ids; the noop log wording.

scripts/__tests__/factory-state.test.mjs: ciNoop set and clear.

Run locally under macOS /bin/bash 3.2:

  • factory-agent-required-checks.test.mjs: 78/78 pass.
  • The full scripts suite (cd scripts && node --test __tests__/*.test.mjs): 5763/5763 pass.
  • bash -n, pnpm lint, pnpm typecheck and pnpm format:check pass.

Rollout / live check

The factory self-updates on merge. On the next red card that gets a noop fix pass, the logs on the following ticks should show:

  1. no-op fix pass on N failing required check(s); spending one attempt
  2. re-running them in bash, no Claude run (ADR-0102)
  3. either green CI, or still red after 2 re-run(s); moving to Blocked, followed by the hold comment.

Rollback: revert on main, or node scripts/lib/state-cli.mjs factory:pause.

🤖 Generated with Claude Code

JakubAnderwald and others added 5 commits November 25, 2026 07:44
… Claude again

A --watch fix pass that ends `noop` on red CI now records the head SHA and
the failing required checks (`ciNoop`). The next tick that sees the same red
on the same head re-runs those checks in bash under the shared `ciRerun`
budget (FACTORY_CI_RERUN_MAX), with no Claude run. Once the budget is spent
it comments once (drafto-factory-ci-noop-hold:<sha12>), moves the card to
Blocked and frees its slot. A new push re-arms the card, and so does clearing
`ciNoop` by hand. Card 899 spent ten no-op passes on one head before this.

pr_infra_rerun_ids now skips checks without an Actions run URL. The watch
prompt describes the bash re-run instead of claiming a noop doesn't spend the
budget. ADR-0100, amending ADR-0041.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h a subset of the noop reds

comment_ci_noop_hold returned 1 when it couldn't read the issue's comments
or post the hold notice. The --watch loop is top-level code under
`set -euo pipefail`, so that ended the whole tick (every later card skipped)
and fired the EXIT trap's factory-failure issue on every tick. Both
transient paths now log and return 0, and the call site adds `|| true`.

ci_noop_repeat now matches when the failing required checks on the recorded
head are the recorded ones or some of them. Mid-re-run a tick often sees the
faster job red again and the slower one still running; exact matching sent
that to a Claude fix pass on a head whose CI was still re-running.
rerun_infra_failures already waits on the run's status.

The hold comment, runbook, dark-factory doc and ADR-0100 now say a push must
be followed by dragging the card back to In Review: nothing picks cards out
of Blocked.

Tests: errexit harness running the hold's transient paths in a two-card loop,
mid-re-run and partial-red subset cases, a red check outside the record, and
the classify_failing_required pin asserted present.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…931

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- run the migration renumber gate before re-running a noop-recorded red
- key ciNoop on newline-joined check names, so a comma in a matrix job's
  name can't split it
- keep the slot when the worktree holds commits the PR lacks
- name non-Actions red checks in the hold comment; word the re-run count
  as the head's shared ciRerun budget
- clear ciNoop when --release or the Testing stage hands a red card back
- prompt: noop ends fix passes for the same red checks, not the head

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-red clear

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
drafto Ready Ready Preview Nov 25, 2026 8:23am UTC

@JakubAnderwald

Copy link
Copy Markdown
Owner Author

Changes made after the local /code-review pass (commits 21513f5, 9be2539). Where they differ from the description above:

  • ciNoop joins the check names with a newline, not a comma, because a matrix job's name can contain a comma.
  • On a no-op repeat tick, the migration renumber gate (ADR-0077) now runs before the bash re-run, just as it does before a fix pass.
  • --release's red-CI hand-back and the Testing stage's ci-red hand-back now clear ciNoop (clear_ci_noop). Both comments promise the fix loop, so the card gets that pass instead of going straight to Blocked.
  • The hold keeps the worktree slot when the worktree holds commits the PR lacks (worktree_within_head). It names red checks that aren't Actions jobs, and it describes the re-run count as the head's shared ciRerun budget.
  • The watch prompt now says a noop ends fix passes for the same red checks on that head, not for the whole head.

ADR-0102 and the runbook are updated to match. ADR number 0102 is deliberate: open PRs #929 and #931 reserve 0099 to 0101.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 16 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a8ee249 and 51820d1.

Files selected for processing: 12

  • docs/adr/0041-factory-ci-red-and-cancelled-checks.md
  • docs/adr/0102-factory-reruns-red-ci-after-noop-pass.md
  • docs/adr/README.md
  • docs/features/dark-factory.md
  • docs/operations/factory-runbook.md
  • scripts/__tests__/factory-agent-required-checks.test.mjs
  • scripts/__tests__/factory-agent-verify.test.mjs
  • scripts/__tests__/factory-state.test.mjs
  • scripts/factory-agent.sh
  • scripts/factory-watch-prompt.md
  • scripts/lib/factory-state.mjs
  • scripts/lib/state-cli.mjs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…-check-rerun

# Conflicts:
#	docs/adr/README.md
@JakubAnderwald
JakubAnderwald merged commit 6fb1e61 into main Nov 25, 2026
10 checks passed
@JakubAnderwald
JakubAnderwald deleted the fix/factory-watch-red-check-rerun branch November 25, 2026 20:10

This branch was successfully deployed

1 active deployment
Preview — 51820d16 Deployed Nov 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant