Skip to content

ci(refactor-tasks): Judge PR patches against conventions - #126894

Closed
ryan953 wants to merge 3 commits into
masterfrom
ryan953/refactor-tasks-prevention
Closed

ryan953 wants to merge 3 commits into
masterfrom
ryan953/refactor-tasks-prevention

Conversation

@ryan953

@ryan953 ryan953 commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Adds a [NOT REQUIRED] refactor tasks prevention workflow. On each PR it runs the .sentry-refactor-tasks conventions against the PR's patch and lists the violations the patch adds. This is the prevention arm from the sentry-refactor-tasks README (CI → patch → LLM judge → accept/block). refactor-tasks.yml stays the scheduled fixes arm, which reports to Sentry for Seer.

The goal is to stop new violations in review, so that the fixes loop does not have to clean them up later. For now the workflow only collects data: violations fail the Judge patch step, but continue-on-error keeps the check green. We can then compare its output to real PRs before it blocks anything.

Trust model

The job holds the OpenRouter key, so no code from a PR may run in it. The workflow uses pull_request_target, which runs this workflow file and its script from master, the same pattern as getsentry-dispatch.yml. The PR is only data:

  • The merge commit (from wait-for-merge-commit.js) is checked out into pr-merge/ with persist-credentials: false. Nothing in it is executed. pnpm runs from the master checkout, so the PR's .npmrc or package.json are never read.
  • Conventions contain shell prefilter commands, so they are copied in from master, and the PR's own .sentry-refactor-tasks/ is never checked out. One consequence: a change to a convention applies to PRs only after it merges.
  • Symlinks in the patch are removed before the scan. Otherwise they could point the scanner at files outside the checkout and send their contents to the LLM and the logs.
  • Output that quotes PR code is printed between ::stop-commands:: markers, so it cannot issue workflow commands.

Fork PRs are skipped. They could now be judged safely, but every judged PR spends OpenRouter credit.

How the patch is judged

  1. The merge commit is fetched with fetch-depth: 2 and filter: blob:none. HEAD^1..HEAD is then the patch exactly as it would land, and no blobs outside the patch are downloaded.
  2. refactor-tasks-prevention.ts parses git diff -U0 HEAD^1 HEAD and narrows the sparse checkout to the files the PR adds lines to. The prefilter greps and include globs then see only the patch, so the conventions and the CLI stay unchanged.
  3. pnpm dlx @sentry/refactor-tasks scan --cwd pr-merge runs once. The judge reads each changed file whole, so it sees the patch in context. For the same reason it also finds the violations that the file already had. Those are the fixes loop's job, and they must not block an unrelated PR.
  4. A finding is reported only when the patch adds a line that its snippet quotes. Elisions such as { ... } and punctuation-only lines do not count. When the model collapses a multi-line snippet onto one line, a line of 10 or more characters that the snippet contains still counts. It is not enough for a finding's span to overlap an added line: a PR that edits one line in the body of an existing class component would then report the whole class again.
  5. The findings go to the log and to the job summary, and the step exits 1.

Lint-path conventions (detect_command: knip cycles, oxlint no-deprecated) are left out. They need the full tree and node_modules, and the repo's own lint is already their prevention.

Approaches I did not use:

  • pull_request with the scripts read from master. Under pull_request the workflow file itself comes from the PR, so a PR could change the step that holds the key.
  • A --files flag on the CLI. This would need a change and release in sentry-refactor-tasks. The sparse checkout gets the same scope from what exists today.
  • A full scan, then filter to the diff. This runs every convention across the whole codebase on each PR.
  • A second scan of the base version, with base findings subtracted. This doubles the LLM cost. Also, LLM results are not deterministic, so a problem that the base scan misses would show up as "new".
  • Job-level continue-on-error. The job's check still shows as failed on the PR. Step-level keeps the check green.

The workflow uses the REFACTOR_TASKS_OPENROUTER_API_KEY secret (also used by refactor-tasks.yml) and haiku. No feature flags.

Testing

Because it uses pull_request_target, the workflow does not run on this PR. It starts after it merges. I ran the script locally against a copy of that layout: my branch as the trusted checkout, and a sparse, blob-less clone of each PR's merge ref as pr-merge/.

Possible next steps: inline annotations on the diff, a decision about which severity/confidence should block, and making the check required.

Add a non-required pull_request workflow that runs the
.sentry-refactor-tasks conventions against each PR's patch, the
prevention half of the refactor-tasks loop. refactor-tasks.yml stays
the scheduled fixes half.

The workflow checks out the merge commit sparsely and narrows the tree
to the conventions plus the files the PR adds lines to, so the existing
prefilters only see the patch. Findings are kept only when they touch an
added line. Violations fail the step but not the check while we measure
how accurate the judge is.
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Oct 8, 2026
The judge reads each changed file whole, so it also finds violations the
base branch already had. Keeping any finding whose span overlaps an added
line re-reported those whenever a PR edited inside them, such as one line
in the body of an existing class component.

Report a finding only when the patch adds a line that its snippet quotes.
Abbreviations and punctuation-only lines in the snippet are ignored, since
they cannot locate the violation.
Under pull_request, the workflow, its script and the convention prefilters
all came from the PR, and the OpenRouter key was in the environment while
they ran. A PR could change any of them to send the key elsewhere.

Move to pull_request_target, which runs this workflow and its script from
master. The PR's merge commit is checked out into its own directory without
credentials and is only read: conventions are copied in from master, the
PR's own .sentry-refactor-tasks/ is never checked out, symlinks in the patch
are removed, and workflow commands are stopped while PR-quoted output is
printed. Forks stay excluded to bound inference cost.

Also count a line as quoted when the model collapses a multi-line snippet
onto one line, which had dropped a real violation.
@getsantry

getsantry Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you add the label WIP, I will leave it alone unless WIP is removed ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry Bot added the Stale label Oct 30, 2026
@getsantry getsantry Bot closed this Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant