Repository navigation
Lint CI: scope the import-hoist check to the PR's own commits - #7738
Conversation
The import-hoist step diffed $MERGE_BASE against HEAD. On a pull_request event HEAD is refs/pull/N/merge, so that range spans every base commit since the branch point, and the step lints files the PR never touched. It fails PRs that change no Python at all. #7734 touches only TypeScript and CSS and was failed by 3 blockers from #6880; the run reported "checking 78 file(s)". Pin the AFTER end to the PR head SHA so the range is the PR's own commits. The head is fetched via refs/pull/N/head, which exists for fork PRs too, and the verifier reads revisions with git show, so the shallow clone stands. A failure here also short-circuits the rest of the job, so every later lint step (debugger calls, shell parse, YAML/JSON parse, codespell, shellcheck, ruff format) is skipped.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 369aeab7de
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| git fetch --no-tags --depth=1 origin \ | ||
| "refs/pull/${{ github.event.pull_request.number }}/head" |
There was a problem hiding this comment.
Fetch the pinned event head instead of the moving PR ref
When an older workflow run is rerun after another commit has been pushed, HEAD_SHA remains the SHA from that run's event payload, while refs/pull/N/head now resolves to the latest PR commit. With this depth-1 fetch, the old $HEAD_SHA is therefore not guaranteed to exist locally, and the subsequent git diff fails with an invalid-object error instead of running the lint check. The git-fetch refspec documentation confirms that the source ref is resolved on the remote; fetch the immutable $HEAD_SHA (as is already done for $MERGE_BASE) or explicitly verify that the fetched ref still matches it.
Useful? React with 👍 / 👎.
| python scripts/verify_import_hoist.py \ | ||
| --before "$MERGE_BASE" --after HEAD "${CHANGED[@]}" | ||
| --before "$MERGE_BASE" --after "$HEAD_SHA" "${CHANGED[@]}" |
There was a problem hiding this comment.
Verify the merged result rather than the isolated PR head
When the base branch and PR edit different hunks of the same Python file, GitHub can merge them cleanly even though a base-side binding changes the meaning of the PR's hoisted import. Passing $HEAD_SHA as --after analyzes only the isolated PR branch, so it cannot detect a clash that exists in the checked-out merge result; for example, a base-side local assignment added later in a function can shadow a module import hoisted by the PR and produce an UnboundLocalError, while this comparison reports clean. Keep the changed-file list scoped to $MERGE_BASE..$HEAD_SHA, but compare the current base SHA with the checked-out merge commit so the verifier checks the code that would actually be merged.
Useful? React with 👍 / 👎.
Problem
The
Import-hoist / alias-rename safetystep inlint-ci.ymlcomputes its file list as:On a
pull_requestevent the checkout isrefs/pull/N/merge, i.e.merge(PR head, base tip). So$MERGE_BASE..HEADspans every commit that landed on main since the PR branched, not just the PR's own. The step then lints, and can fail on, files the PR never touched.The existing comment shows the merge-base was chosen precisely to avoid this class of false positive. Pinning only the BEFORE end fixed half of it; the AFTER end still pulls the base branch back in.
It is failing PRs today
#7734 changes only TypeScript and CSS, zero Python files. Its Source lint run reported
checking 78 file(s)and failed with 3 blockers that all originate from #6880 (AttentionMaskConvertermoving tounsloth/models/_attn_mask_compat):Any PR that branched before #6880 and has not rebased hits this, whatever it touches. It also short-circuits the job, so every later step in the same job (debugger calls, shell parse, YAML/JSON parse, codespell, shellcheck, ruff format drift) is skipped and never runs.
Fix
Pin the AFTER end to
github.event.pull_request.head.shaso the range is exactly the PR's own commits, and fetch that SHA viarefs/pull/N/head(which exists for fork PRs too). The verifier reads each revision withgit show REF:path, so no checkout is needed andfetch-depth: 1still holds.Validation
Three PRs on a staging fork, same branch point, differing only as noted:
The third arm is the important one: it confirms the narrower range still catches a genuine blocker rather than silently disabling the check.
Cross-checked against open PRs that do change Python, comparing the current range with the fixed one:
Coverage of each PR's own Python changes is unchanged; only the inherited files drop out.