Skip to content

Lint CI: scope the import-hoist check to the PR's own commits - #7738

Merged
danielhanchen merged 1 commit into
mainfrom
fix-lint-ci-import-hoist-diff-range
Aug 2, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix-lint-ci-import-hoist-diff-range

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

The Import-hoist / alias-rename safety step in lint-ci.yml computes its file list as:

git diff --name-only --diff-filter=M "$MERGE_BASE" HEAD -- '*.py'

On a pull_request event the checkout is refs/pull/N/merge, i.e. merge(PR head, base tip). So $MERGE_BASE..HEAD spans 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 (AttentionMaskConverter moving to unsloth/models/_attn_mask_compat):

[BLOCKER] unsloth/models/_utils.py: TARGET-CHANGED name 'AttentionMaskConverter' ...
[BLOCKER] unsloth/models/llama.py:  TARGET-CHANGED name 'AttentionMaskConverter' ...
[BLOCKER] unsloth/models/qwen3.py:  HOISTED-IMPORT-UNUSED '_prepare_4d_causal_attention_mask_for_sdpa' ...
OVERALL: FAIL (blockers found)

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.sha so the range is exactly the PR's own commits, and fetch that SHA via refs/pull/N/head (which exists for fork PRs too). The verifier reads each revision with git show REF:path, so no checkout is needed and fetch-depth: 1 still holds.

Validation

Three PRs on a staging fork, same branch point, differing only as noted:

arm lint-ci.yml branch touches .py? files checked result
buggy current no 67 fail (3 blockers belonging to main)
fixed this PR no 0 pass ("no in-place-modified Python files to check")
catch this PR yes, one unused hoisted import injected 1 fail, correctly

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:

PR current fixed
#7717 5 files 5 files
#7735 2 files 2 files
#7721 27 files 2 files

Coverage of each PR's own Python changes is unchanged; only the inherited files drop out.

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.
@danielhanchen
danielhanchen merged commit f0d88d7 into main Aug 2, 2026
6 checks passed
@danielhanchen
danielhanchen deleted the fix-lint-ci-import-hoist-diff-range branch August 2, 2026 08:27

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment on lines +139 to +140
git fetch --no-tags --depth=1 origin \
"refs/pull/${{ github.event.pull_request.number }}/head"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment on lines 154 to +155
python scripts/verify_import_hoist.py \
--before "$MERGE_BASE" --after HEAD "${CHANGED[@]}"
--before "$MERGE_BASE" --after "$HEAD_SHA" "${CHANGED[@]}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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.

2 participants