Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
231 changes: 231 additions & 0 deletions .github/workflows/pr-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
# Nitpick AI PR review for queso/FlowSpec.
#
# INLINED COPY — do not convert this back into a `uses:` caller. FlowSpec is public and
# queso/nitpick-flow is private, and a public caller cannot resolve a private reusable
# workflow: the run dies at resolution time with no jobs scheduled (seen on PR #9). Inlining
# is the same workaround theaiteam-dev/conduit-harness uses for the cross-org case.
#
# PROVENANCE: inlined from nitpick-flow .github/workflows/nitpick.yml @ 6bbcb0b, which is the
# source of truth. Comments here are deliberately brief — the full rationale for each step
# (sizing limits, retry semantics, container ownership rules, and the measurements behind
# them) lives upstream in that file. Re-inline from upstream rather than hand-patching here.
#
# Prerequisites (one-time, outside this file):
# 1. Image published: ghcr.io/queso/nitpick-flow:main.
# 2. This repo granted Read on that package (package -> Manage Actions access). The image
# is private; same-owner, so a package grant suffices and no PAT is needed.
# 3. Repo secret FIREWORKS_AI_API_KEY — the model gateway key.
#
# Longer term this should be a GitHub App, which removes both the workflow-access and the
# image-access problem.

name: Nitpick PR Review

on:
pull_request:
types: [opened, reopened, ready_for_review, synchronize]

# These are the reusable workflow's `inputs`, pinned as env for the inlined form. Keep the image
# tag and model strings in sync with nitpick.yml upstream.
env:
FLOW_IMAGE: ghcr.io/queso/nitpick-flow:main
REVIEWER_MODEL: accounts/fireworks/models/gpt-oss-120b
COORDINATOR_MODEL: accounts/fireworks/models/qwen3p7-plus
CONDUIT_BASE_URL: https://api.fireworks.ai/inference/v1

jobs:
review:
# FORK GUARD. FlowSpec is public, and GitHub withholds secrets from fork PRs, so without
# this an outside contributor's PR fails on a missing CONDUIT_API_KEY — a red check they
# cannot fix. Branches pushed to this repo review normally. Deliberately NOT
# pull_request_target, which would put secrets in scope against untrusted PR code.
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
packages: read
steps:
- uses: actions/checkout@v4

- name: Fetch PR diff + context
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# The one-shot diff media type hard-fails on large PRs ("diff too_large"); fall back to
# rebuilding a reviewable patch from the paginated per-file entries. Files whose patch
# GitHub also withholds (binaries, generated giants) are listed by name.
PR="repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}"
if ! gh api "$PR" -H "Accept: application/vnd.github.diff" > diff.patch 2>diff.err; then
echo "one-shot diff unavailable ($(cat diff.err | head -c 200)); rebuilding per-file"
gh api --paginate "$PR/files" --jq '.[] |
"diff --git a/\(.filename) b/\(.filename)\n--- a/\(.filename)\n+++ b/\(.filename)\n" +
(.patch // "@@ patch omitted by GitHub (\(.status), +\(.additions)/-\(.deletions)) @@")' \
> diff.patch
fi
rm -f diff.err
# SAFETY VALVE for pathological diffs only (>60k lines). Per-prompt sizing is the shard
# planner's job — each reviewer child sees only its shard's slice — so this is NOT a
# per-prompt cap. Beyond the budget: keep whole files, SOURCE before tests, and close with
# a manifest of what was omitted, so a partial review stays honest about its coverage.
node -e '
const fs = require("fs");
const BUDGET = 60000; // SAFETY VALVE only — sharded fan-out owns sizing (classify shard plan); guards pathological >60k-line diffs
const raw = fs.readFileSync("diff.patch", "utf8").split("\n");
if (raw.length <= BUDGET) process.exit(0);
const files = [];
let cur = null;
for (const line of raw) {
const m = line.match(/^diff --git a\/(.+) b\//);
if (m) { cur = { name: m[1], lines: [] }; files.push(cur); }
if (cur) cur.lines.push(line);
}
const isTest = (n) => /(^|\/)__tests__\//.test(n) || /\.test\.[jt]sx?$/.test(n) || /(^|\/)tests?\//.test(n);
files.sort((a, b) => Number(isTest(a.name)) - Number(isTest(b.name)));
const kept = []; const omitted = [];
let used = 0;
for (const f of files) {
if (used + f.lines.length <= BUDGET) { kept.push(f); used += f.lines.length; }
else omitted.push(f);
}
let out = kept.map((f) => f.lines.join("\n")).join("\n");
if (omitted.length) {
out += "\n\n@@ DIFF TRUNCATED FOR REVIEW: " + omitted.length +
" file(s) omitted to fit the model context (source files were prioritized over tests) @@\n" +
omitted.map((f) => "@@ omitted: " + f.name + " (" + f.lines.length + " diff lines) @@").join("\n") + "\n";
}
fs.writeFileSync("diff.patch", out);
console.log("diff capped: kept " + kept.length + "/" + files.length + " files, " + used + "/" + raw.length + " lines");
'
# Shared context: project conventions the reviewers respect.
{ [ -f CLAUDE.md ] && cat CLAUDE.md; \
find . -maxdepth 3 -name AGENTS.md -exec sh -c 'echo "--- $1 ---"; cat "$1"' _ {} \; ; } \
> context.txt 2>/dev/null || true
node -e 'const fs=require("fs");fs.writeFileSync("context.json",JSON.stringify({context:fs.existsSync("context.txt")?fs.readFileSync("context.txt","utf8"):""}))'

- name: Log in to GHCR
# The image is private, so this must succeed. MUST run before any step that pulls
# FLOW_IMAGE (the spider below) — that step is continue-on-error and would otherwise hide
# an auth failure, silently degrading the coupling graph on every run.
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Spider the checkout (coupling graph + related-code pack)
# Deterministic, fast, zero tokens. Produces graph.json (the coupling graph sharding uses)
# and related.txt (excerpts from UNCHANGED files the diff reaches, for the reviewers'
# RELATED CODE section). MUST run here, not in the flow container: the container gets no
# checkout, only what we docker cp in. Any failure degrades to an empty pack.
run: |
# World-writable scratch dir: the image runs as its non-root `conduit` user, whose uid
# does not match the runner's, so a plain bind-mounted dir is EACCES on first write.
mkdir -p .spider-out && chmod 777 .spider-out
# --entrypoint bun is REQUIRED: the image's ENTRYPOINT is ["bun","src/cli/main.ts"], so a
# bare trailing command APPENDS to it instead of replacing it. Same pattern as the
# report-*/post-review steps below.
docker run --rm -v "$PWD:/repo:ro" -v "$PWD/.spider-out:/out" \
-v "$PWD/diff.patch:/tmp/diff.patch:ro" --entrypoint bun "$FLOW_IMAGE" \
/flow/src/spider.mjs /repo /out/graph.json --diff /tmp/diff.patch --pack /out/related.txt \
&& mv .spider-out/graph.json graph.json \
&& mv .spider-out/related.txt related.txt \
|| echo "spider unavailable — classify falls back to diff-derived edges, reviewers to an empty pack"
continue-on-error: true

- name: Run Nitpick flow
env:
CONDUIT_API_KEY: ${{ secrets.FIREWORKS_AI_API_KEY }}
run: |
set -euo pipefail
# The review stations render related.txt unconditionally, so the file must exist even
# when the spider step above failed (it is continue-on-error). An empty pack is benign:
# the reviewers just get no RELATED CODE section.
[ -f related.txt ] || printf '(no related code identified)\n' > related.txt
# The per-flow image bakes flow.yaml/src/prompts at /flow (CONDUIT_PROJECT_ROOT=/flow).
# We need the PR diff IN and review.json OUT without shadowing that baked /flow, so we
# use the create → cp-in → start → cp-out → rm pattern (no project-root bind-mount).
# Render the model names once. Conduit does NOT interpolate ${...} in flow.yaml —
# we substitute them ourselves. (envsubst is restricted to our two vars so nothing
# else expands.) A throwaway container donates the baked copy.
cid=$(docker create "$FLOW_IMAGE" run /flow/flow.yaml)
docker cp "$cid:/flow/flow.yaml" flow.baked.yaml
docker rm "$cid" >/dev/null
envsubst '$REVIEWER_MODEL $COORDINATOR_MODEL' < flow.baked.yaml > flow.rendered.yaml

# Whole-run retry: a stalled gateway call is currently fatal to a conduit run, and
# re-running the flow is cheap relative to losing it. Fresh state volume per attempt —
# re-entering the same run id on a used volume trips a UNIQUE constraint. Drop this loop
# once the engine retries on stall.
rc=1
for attempt in 1 2 3; do
docker volume rm -f conduit_data >/dev/null 2>&1 || true
docker volume create conduit_data >/dev/null
cid=$(docker create \
-v conduit_data:/data \
-e CONDUIT_API_KEY -e CONDUIT_BASE_URL \
"$FLOW_IMAGE" run /flow/flow.yaml --input /tmp/diff.patch)
docker cp flow.rendered.yaml "$cid:/flow/flow.yaml"
# The diff goes in at /tmp, NOT /flow: `docker cp` creates container files owned
# by root, and `conduit run --input` re-writes the input as the entry artifact
# into the project root — overwriting a root-owned /flow/diff.patch as the
# non-root `conduit` user is an EACCES. Fed from /tmp, the engine creates
# /flow/diff.patch itself with the right ownership. (context.json and the
# rendered flow.yaml are only ever read, so root-owned 644 copies are fine.)
docker cp diff.patch "$cid:/tmp/diff.patch"
docker cp context.json "$cid:/flow/context.json"
docker cp related.txt "$cid:/flow/related.txt"
[ -f graph.json ] && docker cp graph.json "$cid:/flow/graph.json" || true

# Run to a terminal lane. A real failure (scrap/hold, doctor preflight) exits
# non-zero.
rc=0; docker start -a "$cid" || rc=$?
docker cp "$cid:/flow/review.json" review.json 2>/dev/null || true
docker rm "$cid" >/dev/null
[ "$rc" -eq 0 ] && break
echo "conduit run attempt $attempt failed (exit $rc); retrying with a fresh state volume"
done
if [ "$rc" -ne 0 ]; then echo "conduit run failed (exit $rc) after 3 attempts"; exit "$rc"; fi
test -f review.json || { echo "no review.json produced"; exit 1; }

- name: Explain run failure
# `conduit run` is silent between preflight and exit, so a scrap shows only "exit 1".
# report-failure.mjs prints the journal (lane journeys, terminal reasons, gate verdicts,
# model-call spans) as a post-mortem. Never fails the job: the exit code is captured
# explicitly and a reporting failure emits a ::warning:: annotation instead.
if: failure()
run: |
rc=0; out=$(docker run --rm -v conduit_data:/data \
--entrypoint bun "$FLOW_IMAGE" /flow/report-failure.mjs) || rc=$?
if [ "$rc" -eq 0 ]; then printf '%s\n' "$out" | tee -a "$GITHUB_STEP_SUMMARY"
else echo "::warning::Nitpick run post-mortem unavailable (docker exit $rc)"; fi

- name: Report model spend
# Best-effort per-run spend table from the engine's journal, written to the job summary.
# `if: always()` keeps spend visible on failed runs — that's when runaway spend happens.
# Cost is tokens x price table unless the gateway reports real per-call cost. Never fails
# the job; a docker failure surfaces as a ::warning:: annotation.
if: always()
run: |
rc=0; out=$(docker run --rm -v conduit_data:/data \
--entrypoint bun "$FLOW_IMAGE" /flow/report-cost.mjs) || rc=$?
if [ "$rc" -eq 0 ]; then printf '%s\n' "$out" | tee -a "$GITHUB_STEP_SUMMARY"
else echo "::warning::Nitpick spend report unavailable (docker exit $rc)"; fi

- name: Post review
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail
# post-review.mjs is baked into the image (/flow/post-review.mjs); run it via the
# engine's Bun so the workflow needs no checkout of nitpick-flow's own source.
docker run --rm \
-e GITHUB_TOKEN -e GITHUB_REPOSITORY -e PR_NUMBER -e HEAD_SHA \
-e REVIEW_FILE=/review.json \
-v "$PWD/review.json":/review.json:ro \
--entrypoint bun \
"$FLOW_IMAGE" /flow/post-review.mjs
# A blocking verdict exits non-zero here; mark this job a required check to gate merge.
Loading