Repository navigation
Conversation
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.
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.
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 "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
[NOT REQUIRED] refactor tasks preventionworkflow. On each PR it runs the.sentry-refactor-tasksconventions 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.ymlstays 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 patchstep, butcontinue-on-errorkeeps 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 frommaster, the same pattern asgetsentry-dispatch.yml. The PR is only data:wait-for-merge-commit.js) is checked out intopr-merge/withpersist-credentials: false. Nothing in it is executed.pnpmruns from the master checkout, so the PR's.npmrcorpackage.jsonare never read.prefiltercommands, 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.::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
fetch-depth: 2andfilter: blob:none.HEAD^1..HEADis then the patch exactly as it would land, and no blobs outside the patch are downloaded.refactor-tasks-prevention.tsparsesgit diff -U0 HEAD^1 HEADand narrows the sparse checkout to the files the PR adds lines to. Theprefiltergreps andincludeglobs then see only the patch, so the conventions and the CLI stay unchanged.pnpm dlx @sentry/refactor-tasks scan --cwd pr-mergeruns 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.{ ... }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.Lint-path conventions (
detect_command: knip cycles, oxlintno-deprecated) are left out. They need the full tree andnode_modules, and the repo's own lint is already their prevention.Approaches I did not use:
pull_requestwith the scripts read from master. Underpull_requestthe workflow file itself comes from the PR, so a PR could change the step that holds the key.--filesflag 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.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_KEYsecret (also used byrefactor-tasks.yml) andhaiku. 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 aspr-merge/.renderPreviousTraceLookuphelper asno-custom-render-helperand exits 1. In one run the model collapsed this snippet onto one line, and the earlier exact-line rule dropped it. That snippet is now a unit test.api.requestinprobeOtherRegionsand arenderGridhelper, which were both already on master. Both are filtered out, and the step exits 0.no-class-components.yamlso that its prefilter wouldtoucha marker file. It also added a symlink to/etc/hosts, and a class component with a::warning::comment. Master's prefilter ran and the marker file was not created. The symlink was skipped, the output stayed between the stop-commands markers, and the class component was still flagged.Possible next steps: inline annotations on the diff, a decision about which severity/confidence should block, and making the check required.