Skip to content

feat(action): Add incremental PR review - #561

Merged
Jeffreyhung merged 10 commits into
mainfrom
feat/incremental-pr-review
Nov 5, 2026
Merged

Jeffreyhung merged 10 commits into
mainfrom
feat/incremental-pr-review

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Every synchronize currently re-reviews the whole PR diff. On PRs that get many pushes, or that merge/rebase from main, most of that work repeats analysis of hunks that haven't changed. This adds opt-in incremental review: a skill only re-analyzes hunks whose content changed since its last clean run on the PR.

Refs #408

How it works

Baseline storage. No new storage. When a skill check completes with success or neutral and the run reviewed everything (no failed hunks, no files skipped by scan limits or as generated, not cut short by a shared abort), Warden writes an external_id on that check run. It writes it only after the review is posted and every reportable finding reached the PR (posted or matched an existing comment); if posting fails, the head moves first, or findings are over maxFindings, the run is not a baseline:

warden-incremental:v1:<hash(warden version, skill name, prompt hash, trigger settings + policy)>

Any change to the skill, its prompt, Warden's version, the trigger config, or the PR's base branch changes the id, so old baselines stop matching and the next run is a full review.

Finding a baseline. On a new push, createIncrementalBaselineSource walks the newest PR commits (excluding head, capped at 10), lists warden: * check runs for each with filter: latest, and takes the newest commit with a completed, clean check whose external_id matches and whose app.slug equals defaults.incrementalApp. The id is built from predictable fields, so the app check is what stops a look-alike check from another app being accepted as a baseline. It then rebuilds the PR diff as of that commit with a three-dot compare (base...baseline).

Matching hunks. Hunks are fingerprinted on path + hunk body, ignoring line numbers (hunkFingerprint), and matched as a multiset. Hunks whose fingerprint was already present at the baseline are dropped in prepareFiles before split/coalesce. Rebases, merges from main, and edits elsewhere in a file don't invalidate a hunk that didn't change.

Comments on carried hunks. Existing Warden comments that sit on a skipped ("carried") hunk are kept open and are excluded from fix evaluation and stale resolution, the same way re-detected findings are treated. Without this they would be auto-resolved because the current run didn't re-find them. A comment counts as carried if GitHub's current line falls in the carried range, so a hunk shifted by a rebase stays covered. The marker line is only used when GitHub gives no current line. While any carried comment is unresolved, Warden won't dismiss an earlier CHANGES_REQUESTED review.

Fail open. Any error (API failure, missing permission, no matching check, compare failure) logs and falls back to a full review. Incremental mode never makes a run review less than it should because of a lookup problem.

Replay. SkillReport.incremental (externalId, baselineSha, carriedRanges, complete) is carried through the replay report so split analyze/report workflows behave the same as single-job runs. specs/jsonl-schema.json is regenerated.

Enabling it

Configured in warden.toml, not the workflow. incremental follows the same trigger > skill > defaults merge as failCheck, so each skill (built-in or not) picks its own mode:

[defaults]
incremental = true
incrementalApp = "github-actions"  # app that writes Warden checks; your app's slug if you use an app token

[[skills]]
name = "code-review"

[[skills]]
name = "security-review"
incremental = false                # full re-review on every push
  • Defaults to false. The baseline lookup only runs when at least one matched skill has it on.
  • incrementalApp lives in [defaults] only. Without it, an incremental skill warns and does a full review.
  • With a base config (base-config-path), repo-defined skills inherit the base incrementalApp. The repo config can't change the mode of a base skill, since repo duplicates of base skills are already dropped.
  • The workflow still needs checks: read (a GitHub permission, not a Warden setting) and post-checks on, since the check run is where the baseline lives.
  • The CLI ignores incremental.

Docs: github/workflow.mdx ("Incremental Review") and config/output.mdx.

Known limitations

  • A force-push that rewrites all prior commits drops every baseline, so the next run is a full review.
  • Carried findings are not re-validated against changes elsewhere in the PR. A change in file B that makes an old finding in file A wrong (or right) won't be noticed until file A's hunk changes. This trades some recall for cost; the opt-in flag is the escape hatch.
  • The fingerprint covers the skill prompt, not reference files the skill loads. Editing a reference without touching SKILL.md won't invalidate baselines.
  • Baseline lookup only checks the newest 10 commits before head.
  • The app check stops other apps, not the same one. Anyone who can write checks as incrementalApp (for example a same-repo branch whose workflow can mint that app's token) can still forge a baseline. Fork PRs can't. That actor can already change or skip the Warden workflow on their branch, so this adds no new bypass. Likewise, a PR can edit its own warden.toml and name a different app, but it could just as well remove the skill; skills from a base config take incrementalApp from the base config, which the PR can't change.

Relationship to the #408 fork

The fork linked in #408 was read for ideas only; no code was taken from it. It reviews the raw SHA delta between the last reviewed commit and head. That re-reviews everything pulled in by a merge from main, needs fetch-depth: 0, and keys state on line ranges that shift on rebase. This PR matches on hunk content against the PR diff at the baseline instead, which avoids all three.

Questions for reviewers

  • Should reference files be part of the fingerprint? It's more correct, but means reading/hashing them at baseline-id time.
  • Is a 10-commit lookup cap right, or should it scale with PR length?

Testing

  • New action/incremental.test.ts for fingerprinting, planning, baseline id, and baseline lookup (including fail-open paths).
  • New cases in executor.test.ts, github-checks.test.ts, prepare.test.ts, and pr-workflow.test.ts, including a two-run end-to-end analyze-mode test, a report-mode test that carried comments aren't resolved, and regression tests for untrusted-app checks, aborted runs, shifted comments, review dismissal with open carried comments, base retargets, and generated-file skips.
  • loader.test.ts covers the trigger > skill > defaults merge and layered incrementalApp inheritance; executor.test.ts and pr-workflow.test.ts cover skills with it off and a missing incrementalApp.
  • pnpm lint && pnpm build pass. Test suite passes except src/skills/remote.test.ts, which fails the same way on main in my environment (network-dependent).

--

View Session [Sentry]

Skip hunks that were already reviewed by the same skill at a clean
baseline commit. Baselines are recorded in the per-skill check run
external_id and hunks are matched by content fingerprint against the
PR diff at that baseline, so rebases and merges from the base branch
do not trigger re-review of unchanged code.

Opt-in via the `incremental` action input. Requires `checks: read`.
Fails open to a full review whenever a baseline cannot be resolved.

Refs #408

Co-Authored-By: Claude <[email protected]>
@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
warden-prod Skipped Skipped Nov 5, 2026 12:25am UTC

Request Review

Comment thread packages/warden/src/types/index.ts Resolved
Only trust baseline checks written by the GitHub App named in the new
incremental-app input, so look-alike checks from other apps cannot make
Warden skip hunks. Without it, incremental review falls back to a full
review.

Never record an aborted run as a baseline, since queued hunks cancelled by
the shared abort are not counted as failures.

Keep a previous CHANGES_REQUESTED review while a Warden comment on a
carried hunk is still open, and match carried comments by GitHub's current
line as well as the marker line so shifted hunks stay protected.

Co-Authored-By: Claude <[email protected]>
Jeffreyhung added a commit that referenced this pull request Nov 4, 2026
zod < 4.6.6 parses every element of an array/set/map schema and records
an issue per invalid element before any upper size bound runs, so
oversized input can exhaust memory
([GHSA-mrhx-c7xc-m3w5](GHSA-mrhx-c7xc-m3w5)).
Semgrep flagged it on #561.

## Changes

- Direct `zod` dependency `^4.4.3` → `^4.6.7` in `packages/warden`,
`packages/warden-service`, `packages/warden-service-api`,
`packages/evals`, and `apps/warden-service`.
- New `pnpm.overrides` entry `"zod@>=4.0.0 <4.6.6": "4.6.7"` for the
transitive `[email protected]` pulled in by the Vercel CLI (`vercel`,
`@vercel/cli-auth`, `@vercel/cli-config`).
- `specs/jsonl-schema.json` regenerated. zod 4.6 emits slightly
different JSON Schema: a primitive union collapses to `type: [...]`, and
the `datetime` pattern now requires seconds.

## Behavior change to know about

`z.string().datetime()` in 4.6 rejects minute-precision timestamps
(`2026-01-01T00:00Z`). 4.4.3 accepted them. Every timestamp Warden and
the service client produce comes from `Date#toISOString()`, which always
includes seconds, so nothing in-repo should be affected. External
callers sending `from`/`to` to the history API without seconds would now
get a 400.

## Not covered

- `[email protected]` stays, via `@vercel/backends`, `@vercel/express`,
`@vercel/hono`, and `@vercel/python-analysis`. The advisory has no
patched 3.x release, and forcing those packages onto zod 4 is a
major-version jump inside Vercel's build tooling. That is a deploy-time
dependency and doesn't handle untrusted input at runtime.
- The advisory also recommends adding `.max()` bounds to collection
schemas that parse untrusted input. That needs per-schema limits and is
left for a follow-up.

## Verification

- `pnpm install --frozen-lockfile` succeeds. Every workspace package
resolves `zod 4.6.7`.
- `pnpm lint`, `pnpm build`, and typecheck pass.
- `pnpm test` passes except `src/skills/remote.test.ts`, which needs
network git and fails the same way on `main` in my environment.

<!-- junior-request-attribution:start -->
via **Jeffrey Hung**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AD0AH1TP6CHJ%3A1793816729.438159 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/slack%3AD0AH1TP6CHJ%3A1793816729.438159)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AD0AH1TP6CHJ%3A1793816729.438159/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Jeffrey Hung <[email protected]>
Move incremental review from action inputs to warden.toml. `incremental`
follows the usual trigger > skill > defaults merge, so each skill picks
its own mode. `defaults.incrementalApp` names the GitHub App whose checks
count as baselines; repo skills inherit it from a base config, and a repo
config cannot change the mode of base skills.

Co-Authored-By: Jeffrey Hung <[email protected]>
…kips

Include the PR base branch in the incremental external_id. Baselines are
rebuilt against the current base, so a check recorded before a retarget
would describe a diff it never reviewed.

Only path-based ignore skips keep a run eligible as a baseline. Generated
detection reads file content, so a file skipped as generated can become
reviewable later while its unchanged hunks still match the baseline.
…cremental

Skipped hunks contribute no findings, so a baseline recorded under a looser
policy never applies a stricter one to those hunks. Add requestChanges and
maxFindings to the incremental external_id, plus the auxiliary, synthesis,
and context settings that change what analysis finds.
@vercel
vercel Bot temporarily deployed to Preview – warden-prod November 4, 2026 21:20 Inactive
@Jeffreyhung
Jeffreyhung marked this pull request as ready for review November 4, 2026 22:21

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 47443a6. Configure here.

Comment thread packages/warden/src/sdk/prepare.ts Resolved
…tal review

GitHub drops the current line on outdated comments, and the Warden marker
keeps the line from the original post. After a rebase shifts a skipped hunk,
neither line lands in the carried range, so the stale pass could resolve a
finding that was never re-checked. Treat an outdated comment as carried when
its skill skipped any hunk in the same file.

Co-Authored-By: Jeffrey Hung <[email protected]>
Scan limits ran on the full PR diff before incremental review dropped
already-reviewed hunks. Unchanged hunks used up the file and changed-line
budgets, so a large PR could limit-skip files, which also stopped the run
from becoming a baseline. Count only hunks still to analyze, and keep fully
reviewed files out of the file budget.
The Warden marker keeps the line a finding was first posted on. After a
shift it can land inside an unrelated carried hunk while GitHub's current
line tracks the comment to a re-reviewed hunk, which kept fixed comments
open and blocked review dismissal. Carried ranges are in current-diff
lines, so use GitHub's current line when present and fall back to the
marker line only when it is missing.
…ed hunks

A failed or skipped comment fetch left the fetched list empty, so the
carried-comment guard saw nothing open and a prior CHANGES_REQUESTED
review could be dismissed while comments on skipped hunks stayed open.
Track whether the fetch succeeded and treat an unknown comment state as
open whenever any hunk was carried.
…he PR

Skill checks carried the baseline external_id from the moment they
completed, before the review was posted. If posting then failed, the head
moved, or findings were capped by maxFindings, the next push skipped the
unchanged hunks and those findings were never shown again.

Complete checks without external_id and mark the baseline after posting,
only when every reportable finding was posted or matched an existing
comment. A failed write leaves no baseline, so the next run is full.
@Jeffreyhung
Jeffreyhung merged commit f216179 into main Nov 5, 2026
22 checks passed
@Jeffreyhung
Jeffreyhung deleted the feat/incremental-pr-review branch November 5, 2026 01:07
sentry-junior Bot added a commit that referenced this pull request Nov 5, 2026
Resolve conflicts with incremental PR review (#561) by keeping both
features: alwaysScan and skipHunks scan options, hunkGate and
incremental report fields, and partialScopeSkills plus carriedRanges
for stale-comment resolution.

Co-Authored-By: Jeffrey Hung <[email protected]>
Jeffreyhung added a commit that referenced this pull request Nov 5, 2026
…t changes (#565)

Follow-up to #561. Fixes the medium `security-review` finding that
showed up only in the check summary on #561's last run
(`pr-workflow.ts:2122`).

**The gap.** With `requestChanges` and `failOn` on but `failCheck` off,
a run with a blocking finding gets a `neutral` check, so it could still
become an incremental baseline. On the next push its hunks were skipped.
If someone then resolved the blocking comment, Warden saw no current
findings and dismissed the earlier `CHANGES_REQUESTED` review without
checking the finding again.

**The fix.** A run that requested changes is never recorded as a
baseline, so the next push gets a full review and the finding is checked
again before the review can be dismissed. The request-changes check is
pulled into one `requestsChanges()` helper, which both baseline
recording and review dismissal now use, so the two can't drift apart.

**Tradeoff.** PRs with an open blocking finding don't get incremental
review until a run comes back clean. That matches how failed checks are
already handled.

Incremental review is off unless `warden.toml` turns it on, so nobody
running the default config sees any change.

**Tests.** I added a workflow-level regression test, `records no
baseline when the run requested changes`, and confirmed it fails without
the fix. I also added a line to the docs fallback list.

<!-- junior-request-attribution:start -->
via **Jeffrey Hung**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AD0AH1TP6CHJ%3A1793816729.438159 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/slack%3AD0AH1TP6CHJ%3A1793816729.438159)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AD0AH1TP6CHJ%3A1793816729.438159/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Jeffrey Hung <[email protected]>
@linear-code

linear-code Bot commented Nov 5, 2026

Copy link
Copy Markdown

SEC-2112

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – warden — 72a778fd Deployed Nov 5, 2026 by vercel[bot]
Preview – warden-prod — 72a778fd Deployed Nov 5, 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