Skip to content

[CI] Lint to detect duplicated test configs on CI - #203772

Closed
huydhn wants to merge 3 commits into
mainfrom
dynamo-wrapped-to-trunk/duplicate-job-linter
Closed

huydhn wants to merge 3 commits into
mainfrom
dynamo-wrapped-to-trunk/duplicate-job-linter

Conversation

@huydhn

@huydhn huydhn commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human written only)

This is to prevent similar mistake of having duplicated test configs on CI.

Agent details (if applicable)

Written with an AI assistant (Claude Code).

  • Adds a WORKFLOWDUP linter that fails when the same test config (build environment, config, runner) runs in two workflows that test main (push to main or schedule), including reusable workflows like dynamo-unittest.
  • It would have caught the py3.11 dynamo_wrapped overlap fixed below in this stack when Move pull and trunk CI jobs from Python 3.10 to 3.11 #198271 created it.
  • periodic's CUDA 13.2 default and distributed configs repeat trunk's on a schedule (~650 runner-hours a week) and are allowlisted for now.

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @aditew01 @voznesenskym @penguinwu @EikanWang @Guobing-Chen @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

@huydhn
huydhn added this pull request to stack #203770 November 6, 2026 08:37
@pytorch-bot

pytorch-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:

This PR adds a WORKFLOWDUP lintrunner linter, with tests. It fails when the same
test config (build-environment, config, runner) runs from two workflows that
test main. Recommendation: Approve, with no blocking issues; every point the
review raises is non-blocking, and the most useful follow-up is to also report
on the root (calling) workflow.

Findings (11):

[minor] tools/linter/adapters/workflow_duplicate_jobs_linter.py:189
Non-blocking: a change made only in a calling workflow gets no lint message. `if
o.path not in linted: continue` reports only on the file that defines the job,
and `o.root` (the workflow that triggers it) is never checked. On PRs lintrunner
gets only the changed files (lint.yml:37, .github/scripts/lintrunner.sh:16,
.spin/cmds.py:435). So a PR that only adds `uses:
./.github/workflows/dynamo-unittest.yml` to pull.yml gets no WORKFLOWDUP
annotation, even though trunk.yml:49 already calls that workflow. The same
happens when a `schedule:` is added to a workflow whose jobs live in a reusable
workflow. CI would still fail through test_repo_has_no_duplicates in test-tools,
but only as a raw dict diff with no file or line, and local lintrunner misses it
entirely. The PR body's claim that the lint "would have caught" the # 198271
overlap holds only if that PR also touched the called file. Fix: also emit a
message when `o.root` is among the linted files, anchored at the root's `uses:`
job.

[minor] tools/linter/adapters/workflow_duplicate_jobs_linter.py:193
Non-blocking: one problem can produce two messages that point at the wrong
places. When one reusable workflow is called from two roots (the
test_called_workflow_runs_from_two_workflows case), you get two errors on the
same line of the reusable file: one says "also runs from pull.yml", the other
"also runs from trunk.yml". The fix belongs in one of the callers, not in the
flagged file, so "Remove one" is misleading. The message also never says which
file and job define the other copy.

[minor] tools/linter/adapters/workflow_duplicate_jobs_linter.py:160
Non-blocking: the ALLOWLIST is broader than the duplicate key. It matches only
on (build_environment, config), with no runner and no workflows, so it would
also hide a future third workflow running cuda13.2 default/distributed on any
runner. Nothing fails when an entry goes stale, so the allowlist will not shrink
on its own. Consider keying it on the full TestConfig plus the set of roots, and
adding a test that each entry still matches something.

[minor] tools/linter/adapters/workflow_duplicate_jobs_linter.py:48
Non-blocking: real duplicates slip through. ENTRY strips only a leading `${{}}`,
so a literal `mt-` prefix stays in the runner key (inductor-periodic.yml:48,
slow.yml:61). But runner_determinator.py:96/:698 resolves the label-type prefix
to that same `mt-` by default, so `mt-l-x86aavx2-11-41-a10g` and `${{ label-type
}}l-x86aavx2-11-41-a10g` count as different machines. Separately (line 136), a
test-matrix written directly on a test job is never counted, because nothing
reads `needs.<job>.outputs.test-matrix`, e.g. trunk.yml:238-254
(cross-compile-linux-test-cuda132). Neither gap hides a duplicate today, but the
docstring mentions neither.

[minor] tools/linter/adapters/workflow_duplicate_jobs_linter.py:34
Non-blocking: stale comment and names. The comment says this cron becomes
"mem_leak_check and rerun_disabled_tests runs", but SUPPORTED_PERIODICAL_MODES
(.github/scripts/filter_test_configs.py:35-39) now holds only
rerun_disabled_tests. The names MEM_LEAK_CHECK_CRON and the test's
ON_MEM_LEAK_CHECK are misleading for the same reason. Add a pointer to
filter_test_configs.py:691 so the two copies of the cron string don't drift
apart.

(6 more not shown, see the review run)

Reviewed commit: f56bae4 (NOT the current head c6f9068)

Review run

🐛 Report a bad review

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/203772

Note: Links to docs will display an error until the docs builds have been completed.

⏳ No Failures, 1 Pending

As of commit c6f9068 with merge base 5f22867 (image):
💚 Looks good so far! There are no failures yet. 💚

🟡 GREEN LIGHT - OUTDATED (earlier commit) - PR requires human review:

  • Never trivial
    • New tools/linter/adapters/workflow_duplicate_jobs_linter.py adds a PEP 723 # /// script header pinning pyyaml==6.0.2 for the Lint job
  • Triviality
    • New WORKFLOWDUP linter in .lintrunner.toml is about 220 lines of new CI-gate logic, outside every trivial change class
    • It adds a repo-wide restriction: test_repo_has_no_duplicates fails on any duplicated test config, with an ALLOWLIST exemption policy
  • Socialization
    • Workflow authors need to know a new error-severity lint now blocks duplicate test configs across main-testing workflows

reason: not_trivial
Reviewed commit: f56bae4 (NOT the current head c6f9068)

Inference job

🐛 Report a wrong verdict

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@huydhn
huydhn requested review from a team and georgehong November 6, 2026 09:22
@huydhn

huydhn commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@claude Review this change

@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Claude finished @huydhn's task in 6m 0s —— View job


The linter looks like it never fires under lintrunner: it matches the file paths lintrunner passes in against repo-relative paths, and lintrunner passes absolute ones. Details below.

PR Review: #203772

Summary

This PR adds a WORKFLOWDUP lintrunner linter and unit tests. The linter flags a test config with the same build-environment, config and runner when it appears in two or more workflows that test main. No REVIEW.md applies. I found one blocking issue and a few non-blocking ones. I couldn't run the linter or its tests in this sandbox (python and uv need approval), so everything here comes from reading the code and the workflow files.

Code Quality

  • Blocking: under lintrunner the linter likely reports nothing. tools/linter/adapters/workflow_duplicate_jobs_linter.py:166-171 builds linted = {Path(f) for f in args.filenames} and skips any occurrence where o.path not in linted. o.path is repo-relative (load_workflows uses path.relative_to(REPO_ROOT), line 156). Lintrunner fills @{{PATHSFILE}} with absolute paths (see the note at tools/linter/adapters/raw_throw_linter.py:341; test_linter.py:154 and mypy_linter.py:122 convert to relative paths for the same reason). So the membership check never matches and no message is printed. Only a manual run with relative paths works. The only real check today is test_repo_has_no_duplicates in the test-tools job, which calls find_duplicates directly. Fix: linted = {Path(f).resolve().relative_to(REPO_ROOT) for f in args.filenames}, plus a test that runs main() (or a small helper) with absolute paths. I didn't verify this by running it. Fix this →
  • Non-blocking: duplicates are detected with len({o.path for o in occurrences}) > 1, and Occurrence.path is the workflow that defines the job, not the top-level caller (line 108). So one reusable workflow called from two main-testing workflows is never flagged. An example would be pull.yml and trunk.yml both calling dynamo-unittest.yml, which runs every config twice. This is the same class of mistake the linter is meant to catch. inductor-unittest.yml already hits this: it runs on its own schedule and is also called from inductor.yml. Today that's harmless, because its cron is the mem-leak/rerun-disabled mode. Recording the top-level workflow in Occurrence (passing the root path down the recursion) would close this gap.
  • Non-blocking: the runner is part of the detection key, but ALLOWLIST is keyed on (build_environment, config) only. A duplicate that changes only the runner label is missed. For example, trunk-rocm-sandbox.yml runs linux-noble-rocm-py3.11-mi350 default/inductor/distributed every 3 hours on linux.rocm.gpu.mi350.*. trunk.yml:399-412 runs the same configs on linux.rocm.gpu.gfx950.*. If the runner was left in on purpose, say so in the docstring. Separately, an allowlist entry silences every runner and every future workflow pair for that env/config.
  • Non-blocking: matrix_combos (line 85) treats strategy.matrix.include/exclude as ordinary axes. Keys that appear only under include are never substituted, and excluded combinations still count. A matrix given as a string (${{ fromJSON(...) }}) would crash on .items(). No build job with a test-matrix uses these today, but skipping the include/exclude keys would make this more robust.
  • Non-blocking: job_line (line 147) returns the first line whose stripped text is "<job_id>:". A key with the same name earlier in the file (under on: or env:) would point the lint message at the wrong line. Searching only after the jobs: line avoids this.
  • Non-blocking: tests_main counts every schedule as testing main, including the 29 8 * * * mem-leak cron used in pull.yml, trunk.yml and periodic.yml, which runs a different mode. Nothing hits this today. A workflow scheduled only on that cron would be a false positive.

Recommendation

Request Changes

The path mismatch probably makes the lintrunner integration a no-op, so editing a workflow wouldn't catch a new duplicate until the test-tools job runs. The remaining points are non-blocking.

@huydhn huydhn changed the title [CI] Lint for test configs that run twice against main [CI] Lint to detect duplicated test configs on CI Nov 6, 2026
@huydhn
huydhn force-pushed the dynamo-wrapped-to-trunk/duplicate-job-linter branch 2 times, most recently from 235067d to f56bae4 Compare November 6, 2026 09:37
@huydhn
huydhn marked this pull request as ready for review November 6, 2026 09:37
@huydhn huydhn added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 6, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review of f56bae4: nothing blocking; ready for human review.

This PR adds a WORKFLOWDUP lintrunner linter, with tests. It fails when the same test config (build-environment, config, runner) runs from two workflows that test main. Recommendation: Approve, with no blocking issues; every point the review raises is non-blocking, and the most useful follow-up is to also report on the root (calling) workflow.

⚪ 11 non-blocking findings

Non-blocking: a change made only in a calling workflow gets no lint message. if o.path not in linted: continue reports only on the file that defines the job, and o.root (the workflow that triggers it) is never checked. On PRs lintrunner gets only the changed files (lint.yml:37, .github/scripts/lintrunner.sh:16, .spin/cmds.py:435). So a PR that only adds uses: ./.github/workflows/dynamo-unittest.yml to pull.yml gets no WORKFLOWDUP annotation, even though trunk.yml:49 already calls that workflow. The same happens when a schedule: is added to a workflow whose jobs live in a reusable workflow. CI would still fail through test_repo_has_no_duplicates in test-tools, but only as a raw dict diff with no file or line, and local lintrunner misses it entirely. The PR body's claim that the lint "would have caught" the # 198271 overlap holds only if that PR also touched the called file. Fix: also emit a message when o.root is among the linted files, anchored at the root's uses: job.


f'{key.build_environment} config "{key.config}" on {key.runner} also runs from '

Non-blocking: one problem can produce two messages that point at the wrong places. When one reusable workflow is called from two roots (the test_called_workflow_runs_from_two_workflows case), you get two errors on the same line of the reusable file: one says "also runs from pull.yml", the other "also runs from trunk.yml". The fix belongs in one of the callers, not in the flagged file, so "Remove one" is misleading. The message also never says which file and job define the other copy.


and (key.build_environment, key.config) not in ALLOWLIST

Non-blocking: the ALLOWLIST is broader than the duplicate key. It matches only on (build_environment, config), with no runner and no workflows, so it would also hide a future third workflow running cuda13.2 default/distributed on any runner. Nothing fails when an entry goes stale, so the allowlist will not shrink on its own. Consider keying it on the full TestConfig plus the set of roots, and adding a test that each entry still matches something.


ENTRY = re.compile(r'config:\s*"([^"]+)".*runner:\s*"(?:\$\{\{.*?\}\})?([^"]+)"')

Non-blocking: real duplicates slip through. ENTRY strips only a leading ${{}}, so a literal mt- prefix stays in the runner key (inductor-periodic.yml:48, slow.yml:61). But runner_determinator.py:96/:698 resolves the label-type prefix to that same mt- by default, so mt-l-x86aavx2-11-41-a10g and ${{ label-type }}l-x86aavx2-11-41-a10g count as different machines. Separately (line 136), a test-matrix written directly on a test job is never counted, because nothing reads needs.&lt;job&gt;.outputs.test-matrix, e.g. trunk.yml:238-254 (cross-compile-linux-test-cuda132). Neither gap hides a duplicate today, but the docstring mentions neither.


# filter_test_configs.py turns this schedule into mem_leak_check and

Non-blocking: stale comment and names. The comment says this cron becomes "mem_leak_check and rerun_disabled_tests runs", but SUPPORTED_PERIODICAL_MODES (.github/scripts/filter_test_configs.py:35-39) now holds only rerun_disabled_tests. The names MEM_LEAK_CHECK_CRON and the test's ON_MEM_LEAK_CHECK are misleading for the same reason. Add a pointer to filter_test_configs.py:691 so the two copies of the cron string don't drift apart.


path.relative_to(REPO_ROOT): yaml.load(path.read_text(), Loader=yaml.SafeLoader)

Non-blocking: a malformed or empty file anywhere under .github/workflows crashes the linter. Every workflow is loaded with no guard; an empty file gives None, and tests_main(None) then raises AttributeError. The crash is reported as an opaque linter failure on whichever PR touches a workflow. gha_linter.py:59-75 shows the sibling pattern of turning load errors into a LintMessage.


Non-blocking: test-matrix is parsed with a line regex, not the way CI parses it. CI reads the same string with yaml.safe_load and iterates include (filter_test_configs.py:636). The regex silently skips any entry that isn't on one line with config before runner in double quotes, and entries with no runner (e.g. trunk.yml:151). Parsing the substituted string with yaml.safe_load and walking ["include"] would match CI and remove these silent false negatives if matrices are reformatted.


def test_lint_takes_absolute_paths(self) -> None:

Non-blocking: test_lint_takes_absolute_paths reads the real file from disk. lint() calls job_line(), which reads the real .github/workflows/pull.yml even though the test passes made-up workflow contents. The real pull.yml has no build: job, so line comes back None. The test doesn't check line, so job_line is untested, and the test breaks if pull.yml is renamed.


self.assertEqual(find_duplicates(load_workflows()), {})

Non-blocking: test_repo_has_no_duplicates cannot catch a broken parser. It asserts {}, which is also what a parser that finds nothing returns, e.g. if the regex stops matching or called workflows stop resolving. Also asserting that, without the ALLOWLIST, the two cuda13.2 pairs are still found would make it a real check.


"trunk": workflow(ON_MAIN, {"dynamo": {"uses": "./dynamo.yml"}}),

Non-blocking: the unit tests use simplified forms that don't match the real workflows. Called workflows use ./dynamo.yml instead of ./.github/workflows/. The matrix key is version, while real workflows use the hyphenated python-version (dynamo-unittest.yml:40), so a regression in MATRIX_REF's \[w-\]+ would not be caught.


path.relative_to(REPO_ROOT): yaml.load(path.read_text(), Loader=yaml.SafeLoader)

Non-blocking: the linter uses pure-Python yaml.SafeLoader and parses every workflow on every run, including the ~2k-line generated binary workflows. It is registered in VERY_FAST_LINTERS (.spin/cmds.py, documented as under 3s of CPU time). The siblings workflow_consistency_linter.py:33-36 and no_workflows_on_fork.py:41-44 use CSafeLoader with a SafeLoader fallback; use the same block here. (Not timed offline.)

This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Nov 6, 2026
@huydhn

huydhn commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot review

@pytorch-bot

pytorch-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown

The automated review only re-runs on PRs labeled in progress and neither ready for review nor no automated review.

@pytorchgreenlight pytorchgreenlight Bot added the GL/human GreenLight marked as needing human review label Nov 6, 2026

@georgehong georgehong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Change makes sense to me! Looks great for reducing redundantly run test configs.

@huydhn

huydhn commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merged refs/remotes/origin/viable/strict into dynamo-wrapped-to-trunk/duplicate-job-linter, please pull locally before adding more changes (for example, via git checkout dynamo-wrapped-to-trunk/duplicate-job-linter && git pull --rebase)

@pytorchgreenlight pytorchgreenlight Bot added GL/superseded GreenLight review is superseded by changes and removed GL/human GreenLight marked as needing human review labels Nov 26, 2026
@huydhn
huydhn force-pushed the dynamo-wrapped-to-trunk/duplicate-job-linter branch from f6831f9 to 90477f5 Compare November 26, 2026 23:46
@huydhn
huydhn removed this pull request from stack #203770 November 26, 2026 23:46
@huydhn
huydhn changed the base branch from dynamo-wrapped-to-trunk/py314 to main November 26, 2026 23:46
@huydhn
huydhn force-pushed the dynamo-wrapped-to-trunk/duplicate-job-linter branch from 90477f5 to 5dc4a2a Compare November 26, 2026 23:47
@huydhn huydhn removed ciflow/mps Run MPS tests (subset of trunk) ciflow/inductor ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/h100 ciflow/b200 ciflow/torchtitan Run TorchTitan integration tests ciflow/periodic-strict labels Nov 26, 2026
#198271 moved pull from py3.10 to py3.11 without noticing that trunk's
dynamo-unittest already ran py3.11 dynamo_wrapped, so the same shards ran twice
on every commit for six weeks. Nothing flagged it because no check compares
test configs across workflows.

WORKFLOWDUP collects (build-environment, test config, runner) from every
workflow that runs on a push to main or on a schedule, including the reusable
workflows they call, and fails when the same triple runs from two of them. A reusable workflow
called from two such workflows counts twice. The 29 8 * * * schedule is not
counted, since filter_test_configs.py turns it into mem_leak_check and
rerun_disabled_tests runs. A build
job's test-matrix only counts when a test job reads it. Different runners count
as different configs, which keeps trunk's Graviton3 aarch64 shards (run for
SVE256 coverage) apart from pull's Graviton4 ones. periodic.yml's CUDA 13.2
default and distributed configs repeat trunk's on a schedule and are
allowlisted for now.

Test Plan:

```
PYTHONPATH=$(pwd) python3 -m pytest -q tools/test/test_workflow_duplicate_jobs_linter.py
uv run --python 3.11 --script tools/linter/adapters/workflow_duplicate_jobs_linter.py -- .github/workflows/pull.yml
```

The linter is clean on this stack. With main's pull.yml restored,
`lintrunner --take WORKFLOWDUP .github/workflows/pull.yml` flags its py3.11 and
py3.14 dynamo_wrapped jobs.

Authored with an AI assistant (Claude Code).
@huydhn
huydhn force-pushed the dynamo-wrapped-to-trunk/duplicate-job-linter branch from 5dc4a2a to 0dda8b9 Compare November 26, 2026 23:49
@huydhn huydhn removed module: cpu CPU specific problem (e.g., perf, algorithm) module: inductor labels Nov 26, 2026
cpp-faketensor-weekly.yml reruns trunk, pull and inductor-unittest configs with
fake_tensor: "cpp", which sets CPP_FAKETENSOR=1 and so tests a different code
path. Keying only on build-environment, config and runner flagged all six as
duplicates and failed test_repo_has_no_duplicates.
#203884 moved dynamo-unittest's build and test jobs into
_dynamo-unittest-python.yml, which takes the Python version and runner as
inputs. The linter treated every _ workflow as a leaf and never filled in
${{ inputs.* }}, so it no longer saw those configs and a py3.11 dynamo_wrapped
re-added to pull.yml went unflagged.

Follow any local workflow call until a job passes a test-matrix, carrying the
caller's with: values as inputs. Also handle matrix include: entries and the
${{ x || 'default' }} form, which dynamo-unittest.yml uses to put 3.14t on a
bigger runner. Drop the lint message tweak from the previous commit.
@huydhn

huydhn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -f 'Linter only'

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/docker GL/superseded GreenLight review is superseded by changes Merged ready for review Automated review passed, ready for a final review by a maintainer. topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants