Skip to content

Commit 28dc247

Browse files
tadani3Tommaso AdaniCopilotCopilotCopilot
authored
CI: Run model detection on all events and disable shared_infra run_all (#192)
### Motivation Two problems with the current CI setup: 1. **Model detection was skipped on pushes to `main`.** The `detect-affected` job had `if: github.event_name == 'pull_request'`, so pushes to `main` bypassed detection entirely. Downstream jobs compensated with `github.event_name != 'pull_request'` fallbacks that ran *everything* unconditionally on main — wasting compute. 2. **Any touch to base infrastructure files triggered `run_all`.** Files like `_configs.py`, `_registry.py`, `_builder.py`, etc. were in `_SHARED_INFRA_PATTERNS`, causing every model's tests to run even for trivial or scoped changes. This made CI prohibitively slow for infrastructure work. ### Changes #### `main.yml` - Removed `if: github.event_name == 'pull_request'` from the `detect-affected` job — it now runs on PRs, pushes to `main`, and `workflow_dispatch`. - Added branch-aware diff logic: PRs diff against `origin/$BASE_REF`; pushes diff `HEAD~1...HEAD`. - Removed `github.event_name != 'pull_request'` fallbacks from `synthetic-parity`, `golden-comparison`, and `generation-e2e`. These jobs now rely purely on detection output (`has_affected` / `run_all`). #### `detect_affected_models.py` - Commented out all entries in `_SHARED_INFRA_PATTERNS`. Changes to `_configs.py`, `_registry.py`, `_builder.py`, `_weight_loading.py`, `_model_package.py`, `_exporter.py`, and `models/__init__.py` no longer trigger `run_all`. - These files now classify as `"other"` and do not trigger any model tests. #### `detect_affected_models_test.py` - Updated tests to match the new classification and detection behavior. ### What this means in practice | Scenario | Before | After | |---|---|---| | Push to `main` | Detection skipped, all tests run unconditionally | Detection runs, only affected models tested | | Change `_configs.py` | `run_all=true`, every model tested | No model tests triggered | | Change `_attention.py` | Traced via import graph (per-model) | Same — no change | | Change `models/falcon.py` | Falcon + dependents tested | Same — no change | ### How to restore `run_all` for infrastructure files Re-add entries to `_SHARED_INFRA_PATTERNS` in `scripts/detect_affected_models.py`: ```python _SHARED_INFRA_PATTERNS: tuple[str, ...] = ( "src/mobius/_configs.py", "src/mobius/_registry.py", # ... ) ``` ### Risk Changes to base files like `_configs.py` that break multiple models will not be caught until those models are independently modified. This is an accepted tradeoff for faster CI iteration on infrastructure. If a broad regression is suspected, use `workflow_dispatch` with a manual change list or re-enable the patterns. --------- Signed-off-by: Tommaso Adani <[email protected]> Co-authored-by: Tommaso Adani <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
1 parent e53af5d commit 28dc247

3 files changed

Lines changed: 48 additions & 51 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ jobs:
3030
detect-affected:
3131
name: Detect affected models
3232
runs-on: ubuntu-latest
33-
# Run on PRs and pushes to main. Skip on tag pushes — those go through release.
34-
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
3533
outputs:
3634
affected: ${{ steps.detect.outputs.affected }}
3735
run_all: ${{ steps.detect.outputs.run_all }}
@@ -44,18 +42,25 @@ jobs:
4442
id: changed
4543
env:
4644
BASE_REF: ${{ github.base_ref }}
47-
BEFORE_SHA: ${{ github.event.before }}
48-
AFTER_SHA: ${{ github.sha }}
45+
BEFORE: ${{ github.event.before }}
46+
SHA: ${{ github.sha }}
4947
run: |
5048
if [ "${{ github.event_name }}" = "pull_request" ]; then
5149
git diff --name-only origin/"$BASE_REF"...HEAD > changed_files.txt
50+
elif [ "${{ github.event_name }}" = "push" ] && \
51+
[ -n "$BEFORE" ] && \
52+
[ "$BEFORE" != "0000000000000000000000000000000000000000" ]; then
53+
# Push with a known previous commit: use the full push range so
54+
# multi-commit pushes don't silently miss changed files.
55+
git diff --name-only "$BEFORE"..."$SHA" > changed_files.txt
5256
else
53-
# push to main: diff the pushed range. Fall back to HEAD~1 when
54-
# `before` is the zero SHA (e.g. first push of a new branch).
55-
if [ -z "$BEFORE_SHA" ] || [ "$BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
57+
# workflow_dispatch, new-branch push (before=0000...), or unknown
58+
# event: fall back to HEAD~1 when it exists, or diff-tree for the
59+
# root commit of a new repository.
60+
if git rev-parse --verify HEAD~1 >/dev/null 2>&1; then
5661
git diff --name-only HEAD~1...HEAD > changed_files.txt
5762
else
58-
git diff --name-only "$BEFORE_SHA"..."$AFTER_SHA" > changed_files.txt
63+
git diff-tree --root --no-commit-id --name-only -r HEAD > changed_files.txt
5964
fi
6065
fi
6166
echo "Changed files:"
@@ -119,8 +124,7 @@ jobs:
119124
if: >-
120125
always() && !cancelled() &&
121126
(needs.detect-affected.result == 'failure' ||
122-
needs.detect-affected.outputs.has_affected == 'true' ||
123-
needs.detect-affected.result == 'skipped')
127+
needs.detect-affected.outputs.has_affected == 'true')
124128
steps:
125129
- uses: actions/checkout@v6
126130
- name: Setup Python
@@ -150,8 +154,7 @@ jobs:
150154
exit 0
151155
fi
152156
if [ "${{ needs.detect-affected.result }}" = "failure" ] || \
153-
[ "${{ needs.detect-affected.outputs.run_all }}" = "true" ] || \
154-
[ "${{ needs.detect-affected.result }}" = "skipped" ]; then
157+
[ "${{ needs.detect-affected.outputs.run_all }}" = "true" ]; then
155158
echo "Running all synthetic parity tests"
156159
pytest tests/synthetic_parity_test.py -v --tb=short -n auto \
157160
--cov=src --cov-report=xml --cov-branch --junitxml junit.xml
@@ -187,8 +190,7 @@ jobs:
187190
if: >-
188191
always() && !cancelled() &&
189192
(needs.detect-affected.result == 'failure' ||
190-
needs.detect-affected.outputs.has_affected == 'true' ||
191-
needs.detect-affected.result == 'skipped')
193+
needs.detect-affected.outputs.has_affected == 'true')
192194
uses: ./.github/workflows/gpu_l4_golden_parity.yml
193195
with:
194196
affected_models: ${{ needs.detect-affected.outputs.affected }}
@@ -202,8 +204,7 @@ jobs:
202204
if: >-
203205
always() && !cancelled() &&
204206
(needs.detect-affected.result == 'failure' ||
205-
needs.detect-affected.outputs.has_affected == 'true' ||
206-
needs.detect-affected.result == 'skipped')
207+
needs.detect-affected.outputs.has_affected == 'true')
207208
uses: ./.github/workflows/gpu_l5_generation_e2e.yml
208209
with:
209210
affected_models: ${{ needs.detect-affected.outputs.affected }}

‎scripts/detect_affected_models.py‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,13 @@
3535
_SRC_ROOT = _PROJECT_ROOT / "src" / "mobius"
3636

3737
# ----------------------------------------------------------------
38-
# Shared infrastructure paths — any change triggers run_all
38+
# Shared infrastructure paths — any change triggers run_all.
39+
# Currently empty: core infra files (e.g. _configs.py, _registry.py)
40+
# are NOT under _TRACEABLE_PREFIXES and therefore classify as "other",
41+
# triggering no model tests. Add entries here to re-enable run_all for
42+
# specific paths when broader regression coverage is needed.
3943
# ----------------------------------------------------------------
40-
_SHARED_INFRA_PATTERNS = (
41-
"src/mobius/_configs.py",
42-
"src/mobius/_registry.py",
43-
"src/mobius/_builder.py",
44-
"src/mobius/_weight_loading.py",
45-
"src/mobius/_model_package.py",
46-
"src/mobius/_exporter.py",
47-
# Re-export hub for all model classes — any change here affects all models
48-
"src/mobius/models/__init__.py",
49-
)
44+
_SHARED_INFRA_PATTERNS: tuple[str, ...] = ()
5045

5146
_SHARED_INFRA_PREFIXES: tuple[str, ...] = ()
5247

‎scripts/detect_affected_models_test.py‎

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ class TestClassifyFile:
4040
def test_model_file(self):
4141
assert classify_file("src/mobius/models/falcon.py") == "model"
4242

43-
def test_model_init_is_shared_infra(self):
44-
"""models/__init__.py is the re-export hub — classify as shared_infra."""
45-
assert classify_file("src/mobius/models/__init__.py") == "shared_infra"
43+
def test_model_init_is_model(self):
44+
"""models/__init__.py classifies as model (shared_infra disabled)."""
45+
assert classify_file("src/mobius/models/__init__.py") == "model"
4646

4747
def test_component_file(self):
4848
assert classify_file("src/mobius/components/_attention.py") == "traceable"
@@ -51,16 +51,16 @@ def test_task_file(self):
5151
assert classify_file("src/mobius/tasks/_causal_lm.py") == "traceable"
5252

5353
def test_configs_file(self):
54-
assert classify_file("src/mobius/_configs.py") == "shared_infra"
54+
assert classify_file("src/mobius/_configs.py") == "other"
5555

5656
def test_registry_file(self):
57-
assert classify_file("src/mobius/_registry.py") == "shared_infra"
57+
assert classify_file("src/mobius/_registry.py") == "other"
5858

5959
def test_builder_file(self):
60-
assert classify_file("src/mobius/_builder.py") == "shared_infra"
60+
assert classify_file("src/mobius/_builder.py") == "other"
6161

6262
def test_exporter_file(self):
63-
assert classify_file("src/mobius/_exporter.py") == "shared_infra"
63+
assert classify_file("src/mobius/_exporter.py") == "other"
6464

6565
def test_test_file_in_src(self):
6666
assert classify_file("src/mobius/models/_models_test.py") == "test"
@@ -194,9 +194,11 @@ def test_task_change_does_not_trigger_run_all(self):
194194
assert result["run_all"] is False
195195
assert result["affected"] == []
196196

197-
def test_configs_change_triggers_run_all(self):
197+
def test_configs_change_no_run_all(self):
198+
"""_configs.py no longer triggers run_all (shared_infra disabled)."""
198199
result = detect_affected_models(["src/mobius/_configs.py"])
199-
assert result["run_all"] is True
200+
assert result["run_all"] is False
201+
assert result["affected"] == []
200202

201203
def test_unrelated_file_no_affected(self):
202204
result = detect_affected_models(["README.md"])
@@ -249,20 +251,21 @@ def test_mixed_model_and_unrelated(self):
249251
assert result["run_all"] is False
250252
assert "falcon" in result["affected"]
251253

252-
def test_shared_infra_overrides_model(self):
253-
"""If any shared infra changes, run_all even with model files."""
254+
def test_infra_does_not_override_model(self):
255+
"""Infra files no longer trigger run_all (shared_infra disabled)."""
254256
result = detect_affected_models(
255257
[
256258
"src/mobius/models/falcon.py",
257259
"src/mobius/_configs.py",
258260
]
259261
)
260-
assert result["run_all"] is True
262+
assert result["run_all"] is False
263+
assert "falcon" in result["affected"]
261264

262-
def test_models_init_triggers_run_all(self):
263-
"""models/__init__.py is the re-export hub — must trigger run_all."""
265+
def test_models_init_no_run_all(self):
266+
"""models/__init__.py no longer triggers run_all (shared_infra disabled)."""
264267
result = detect_affected_models(["src/mobius/models/__init__.py"])
265-
assert result["run_all"] is True
268+
assert result["run_all"] is False
266269

267270
def test_deleted_model_file_triggers_run_all(self):
268271
"""A model file that doesn't exist on disk triggers run_all."""
@@ -281,21 +284,18 @@ def test_component_common_affects_many_models(self):
281284
# _common.py defines Linear, Embedding, LayerNorm — used everywhere
282285
assert len(result["affected"]) > 10
283286

284-
def test_shared_infra_still_triggers_run_all(self):
285-
"""True shared_infra files (_configs, _registry, etc.) still trigger run_all."""
287+
def test_former_shared_infra_no_run_all(self):
288+
"""Former shared_infra files no longer trigger run_all."""
286289
for path in [
287290
"src/mobius/_configs.py",
288291
"src/mobius/_registry.py",
289292
"src/mobius/_builder.py",
290293
"src/mobius/_weight_loading.py",
291294
"src/mobius/_model_package.py",
292-
"src/mobius/_exporter.py",
293295
"src/mobius/models/__init__.py",
294-
"tests/conftest.py",
295-
"tests/_test_configs.py",
296296
]:
297297
result = detect_affected_models([path])
298-
assert result["run_all"] is True, f"{path} should trigger run_all but didn't"
298+
assert result["run_all"] is False, f"{path} should NOT trigger run_all"
299299

300300
def test_traceable_and_model_combined(self):
301301
"""A component + model file change returns union of affected types."""
@@ -310,15 +310,16 @@ def test_traceable_and_model_combined(self):
310310
# _attention.py dependents should also be included
311311
assert len(result["affected"]) > 2
312312

313-
def test_traceable_overridden_by_shared_infra(self):
314-
"""If both traceable and shared_infra change, run_all wins."""
313+
def test_traceable_and_infra_no_run_all(self):
314+
"""Component + infra files no longer trigger run_all."""
315315
result = detect_affected_models(
316316
[
317317
"src/mobius/components/_attention.py",
318318
"src/mobius/_configs.py",
319319
]
320320
)
321-
assert result["run_all"] is True
321+
assert result["run_all"] is False
322+
assert len(result["affected"]) > 0
322323

323324
def test_deleted_traceable_file_triggers_run_all(self):
324325
"""A deleted component file triggers run_all (conservative)."""

0 commit comments

Comments
 (0)