Skip to content

Commit 9988221

Browse files
committed
Improve the Pixi lockfile freshness check so PRs are not blamed for lockfile drift that already exists on their base commit.
Closes NVIDIA#2926 Description For stale lockfiles in pull requests, the workflow now: - runs the same pinned Pixi version against the PR candidate and base SHA; - records the original and repaired lockfile blob hashes for both trees; - classifies the failure as PR-induced, base maintenance, or mixed/ambiguous; - provides category-specific remediation in annotations and the job summary; - links to the open maintenance refresh PR when available, otherwise to the refresh workflow. The aggregate check remains failing for every stale classification. Push and manual runs retain their existing strict behavior, while timeouts and other operational failures remain distinct from staleness. A small Python helper contains the classification logic, with focused tests covering each outcome. Testing - `83 passed, 36 subtests passed` for `ci/tools/tests` - Ruff passes - actionlint v1.7.12 passes - `git diff --check` passes
1 parent 1d956e8 commit 9988221

3 files changed

Lines changed: 307 additions & 13 deletions

File tree

‎.github/workflows/ci-pixi-lockfile-freshness-check.yml‎

Lines changed: 156 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
# Fails when a committed pixi.lock is out of date with its pixi.toml, or when
6-
# its bytes are not what the pinned pixi version generates.
7-
# Remediation for both: regenerate and commit the lockfile with that pixi
8-
# version, e.g.
9-
# pixi lock --manifest-path <path>
10-
# Keep this check advisory during its initial rollout. Before making it
11-
# required, expose a stable aggregate check, account for the path filters, and
12-
# record the decision in #2804 after the workflow has operational history.
13-
# See #2298.
6+
# its bytes are not what the pinned pixi version generates. Pull requests also
7+
# check stale workspaces at the base SHA so diagnostics can distinguish changes
8+
# introduced by the PR from maintenance already needed on the base branch.
9+
# Attribution changes remediation only; the aggregate job remains strict for
10+
# every stale classification. See #2298 and #2926.
1411

1512
name: "CI: pixi lockfile freshness check"
1613

@@ -30,6 +27,7 @@ on:
3027
- "**/pixi.toml"
3128
- "**/pixi.lock"
3229
- "**/pyproject.toml"
30+
- "ci/tools/classify_pixi_lockfile_freshness.py"
3331
- "ci/tools/list_pixi_workspaces.py"
3432
- "ci/pixi-version.env"
3533
- ".github/actions/setup-pixi/action.yml"
@@ -60,24 +58,52 @@ jobs:
6058
timeout-minutes: 135
6159
permissions:
6260
contents: read
61+
pull-requests: read
6362
steps:
6463
- name: Checkout ${{ github.event.repository.name }}
6564
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
6665
with:
67-
fetch-depth: 1
66+
fetch-depth: 0
6867
persist-credentials: false
6968

7069
- name: Setup pixi
7170
id: setup-pixi
7271
uses: ./.github/actions/setup-pixi
7372

73+
- name: Find open lockfile refresh PR
74+
id: maintenance
75+
if: ${{ github.event_name == 'pull_request' }}
76+
env:
77+
GH_TOKEN: ${{ github.token }}
78+
GH_REPO: ${{ github.repository }}
79+
run: |
80+
lookup_status=0
81+
refresh_url="$(
82+
gh pr list \
83+
--state open \
84+
--head ci/pixi-lock-refresh/all \
85+
--limit 1 \
86+
--json url \
87+
--jq '.[0].url // ""'
88+
)" || lookup_status=$?
89+
if ((lookup_status != 0)); then
90+
echo "::warning::Could not look up the open Pixi lockfile refresh PR; using the refresh workflow link instead."
91+
fi
92+
if [[ -z "${refresh_url}" ]]; then
93+
refresh_url="${REFRESH_WORKFLOW_URL}"
94+
fi
95+
echo "url=${refresh_url}" >> "${GITHUB_OUTPUT}"
96+
7497
# `pixi lock --check` exits 0 on a semantically current lock even when it
7598
# rewrites the file into the pinned version's canonical form (lockfile
7699
# format upgrades, platform alias renames). Without this guard that drift
77100
# is invisible: the check prints "Updated lock file" and still passes,
78101
# while every later pixi run keeps rewriting the committed file (#2298).
79102
- name: Check all lockfiles
80103
env:
104+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
105+
EVENT_NAME: ${{ github.event_name }}
106+
MAINTENANCE_URL: ${{ steps.maintenance.outputs.url || env.REFRESH_WORKFLOW_URL }}
81107
PIXI_VERSION: ${{ steps.setup-pixi.outputs.pixi-version }}
82108
WORKSPACE_TIMEOUT: 20m
83109
run: |
@@ -100,28 +126,145 @@ jobs:
100126
' <<<"${workspaces}"
101127
)"
102128
failed=0
129+
base_ready=0
130+
base_parent=""
131+
base_worktree=""
132+
133+
{
134+
echo "### Pixi lockfile freshness"
135+
echo
136+
echo "| Workspace | Result |"
137+
echo "| --- | --- |"
138+
} >> "${GITHUB_STEP_SUMMARY}"
139+
140+
if [[ "${EVENT_NAME}" == "pull_request" ]]; then
141+
if [[ -z "${BASE_SHA}" ]]; then
142+
echo "::error::The pull request base SHA is unavailable; cannot attribute stale lockfiles."
143+
exit 1
144+
fi
145+
base_parent="$(mktemp -d "${RUNNER_TEMP}/pixi-lockfile-base.XXXXXX")"
146+
base_worktree="${base_parent}/tree"
147+
fi
103148
104149
while IFS= read -r workspace; do
105150
manifest="$(jq -r '.manifest' <<<"${workspace}")"
106151
lockfile="$(jq -r '.lockfile' <<<"${workspace}")"
107152
echo "::group::pixi lock --check (${manifest})"
108153
154+
candidate_original="$(git hash-object "${lockfile}")"
109155
check_status=0
110156
timeout --kill-after=1m "${WORKSPACE_TIMEOUT}" \
111157
pixi lock --check --manifest-path "${manifest}" \
112158
|| check_status=$?
159+
candidate_repaired="$(git hash-object "${lockfile}")"
160+
113161
if ((check_status == 124 || check_status == 137)); then
114162
echo "::error::Timed out after ${WORKSPACE_TIMEOUT} while checking '${manifest}'."
163+
echo "| \`${manifest}\` | Operational error: candidate check timed out. |" >> "${GITHUB_STEP_SUMMARY}"
115164
failed=1
116-
elif ((check_status != 0)); then
117-
echo "::error::Lockfile is stale for '${manifest}'. Regenerate with: pixi lock --manifest-path ${manifest}. For default-branch dependency drift, maintainers can run ${REFRESH_WORKFLOW_URL}"
165+
echo "::endgroup::"
166+
continue
167+
elif ((check_status != 0)) && [[ "${candidate_original}" == "${candidate_repaired}" ]]; then
168+
echo "::error::pixi ${PIXI_VERSION} failed while checking '${manifest}' (exit ${check_status}) without producing a repaired lockfile."
169+
echo "| \`${manifest}\` | Operational error: candidate check failed with exit ${check_status}. |" >> "${GITHUB_STEP_SUMMARY}"
118170
failed=1
119-
elif ! git diff --exit-code -- "${lockfile}"; then
120-
echo "::error::pixi ${PIXI_VERSION} rewrote ${lockfile} during the check, so the committed bytes are not what it generates. Regenerate with pixi ${PIXI_VERSION}: pixi lock --manifest-path ${manifest}. For default-branch dependency drift, maintainers can run ${REFRESH_WORKFLOW_URL}"
171+
echo "::endgroup::"
172+
continue
173+
elif ((check_status == 0)) && [[ "${candidate_original}" == "${candidate_repaired}" ]]; then
174+
echo "| \`${manifest}\` | Fresh |" >> "${GITHUB_STEP_SUMMARY}"
175+
echo "::endgroup::"
176+
continue
177+
fi
178+
179+
if [[ "${EVENT_NAME}" != "pull_request" ]]; then
180+
echo "::error title=Stale Pixi lockfile::Lockfile '${lockfile}' is stale. Regenerate and commit it with pixi ${PIXI_VERSION}: pixi lock --manifest-path ${manifest}."
181+
echo "| \`${manifest}\` | Stale: regenerate and commit the lockfile. |" >> "${GITHUB_STEP_SUMMARY}"
121182
failed=1
183+
echo "::endgroup::"
184+
continue
122185
fi
123186
187+
if ((base_ready == 0)); then
188+
git worktree add --detach "${base_worktree}" "${BASE_SHA}"
189+
base_ready=1
190+
fi
191+
192+
base_manifest="${base_worktree}/${manifest}"
193+
base_lockfile="${base_worktree}/${lockfile}"
194+
if [[ ! -f "${base_manifest}/pixi.toml" || ! -f "${base_lockfile}" ]]; then
195+
base_result="missing"
196+
base_original=""
197+
base_repaired=""
198+
else
199+
base_original="$(git -C "${base_worktree}" hash-object "${lockfile}")"
200+
base_status=0
201+
timeout --kill-after=1m "${WORKSPACE_TIMEOUT}" \
202+
pixi lock --check --manifest-path "${base_manifest}" \
203+
|| base_status=$?
204+
base_repaired="$(git -C "${base_worktree}" hash-object "${lockfile}")"
205+
206+
if ((base_status == 124 || base_status == 137)); then
207+
echo "::error::Timed out after ${WORKSPACE_TIMEOUT} while checking '${manifest}' at base ${BASE_SHA}."
208+
echo "| \`${manifest}\` | Operational error: base check timed out. |" >> "${GITHUB_STEP_SUMMARY}"
209+
failed=1
210+
echo "::endgroup::"
211+
continue
212+
elif ((base_status != 0)) && [[ "${base_original}" == "${base_repaired}" ]]; then
213+
echo "::error::pixi ${PIXI_VERSION} failed while checking '${manifest}' at base ${BASE_SHA} (exit ${base_status}) without producing a repaired lockfile."
214+
echo "| \`${manifest}\` | Operational error: base check failed with exit ${base_status}. |" >> "${GITHUB_STEP_SUMMARY}"
215+
failed=1
216+
echo "::endgroup::"
217+
continue
218+
elif ((base_status == 0)) && [[ "${base_original}" == "${base_repaired}" ]]; then
219+
base_result="fresh"
220+
else
221+
base_result="stale"
222+
fi
223+
fi
224+
225+
classifier_args=(
226+
--candidate-original "${candidate_original}"
227+
--candidate-repaired "${candidate_repaired}"
228+
--base-result "${base_result}"
229+
)
230+
if [[ "${base_result}" != "missing" ]]; then
231+
classifier_args+=(
232+
--base-original "${base_original}"
233+
--base-repaired "${base_repaired}"
234+
)
235+
fi
236+
classification="$(
237+
python3 ci/tools/classify_pixi_lockfile_freshness.py "${classifier_args[@]}"
238+
)"
239+
240+
case "${classification}" in
241+
pr-induced)
242+
echo "::error title=PR-induced Pixi lockfile change::Lockfile '${lockfile}' became stale in this PR. Regenerate and commit it with pixi ${PIXI_VERSION}: pixi lock --manifest-path ${manifest}."
243+
echo "| \`${manifest}\` | PR-induced: regenerate and commit the lockfile in this PR. |" >> "${GITHUB_STEP_SUMMARY}"
244+
;;
245+
base-maintenance)
246+
echo "::error title=Base-maintenance Pixi lockfile change::Lockfile '${lockfile}' was already stale on the PR base; its original and repaired blobs match the candidate. Do not add this refresh to the feature PR. Resolve the base maintenance using ${MAINTENANCE_URL}, update the branch, and rerun CI."
247+
echo "| \`${manifest}\` | Base maintenance: not introduced by this PR. Resolve the base [maintenance refresh](${MAINTENANCE_URL}), update the branch, and rerun CI. |" >> "${GITHUB_STEP_SUMMARY}"
248+
;;
249+
mixed-or-ambiguous)
250+
echo "::error title=Mixed or ambiguous Pixi lockfile change::Lockfile '${lockfile}' is stale on both the PR base and candidate, but their original or repaired blobs differ. Refresh the base via ${MAINTENANCE_URL}, update the branch, then address any remaining PR-specific change."
251+
echo "| \`${manifest}\` | Mixed or ambiguous: refresh the base via the [maintenance refresh](${MAINTENANCE_URL}), update the branch, then address any remaining PR-specific change. |" >> "${GITHUB_STEP_SUMMARY}"
252+
;;
253+
*)
254+
echo "::error::Unknown lockfile freshness classification '${classification}' for '${manifest}'."
255+
echo "| \`${manifest}\` | Operational error: unknown classification \`${classification}\`. |" >> "${GITHUB_STEP_SUMMARY}"
256+
;;
257+
esac
258+
failed=1
259+
124260
echo "::endgroup::"
125261
done <<<"${workspace_rows}"
126262
263+
if ((base_ready != 0)); then
264+
git worktree remove --force "${base_worktree}"
265+
fi
266+
if [[ -n "${base_parent}" ]]; then
267+
rmdir "${base_parent}"
268+
fi
269+
127270
exit "${failed}"
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""Classify a stale candidate Pixi lockfile relative to its PR base."""
5+
6+
from __future__ import annotations
7+
8+
import argparse
9+
import sys
10+
from dataclasses import dataclass
11+
from enum import Enum
12+
13+
14+
class Classification(str, Enum):
15+
"""Possible attributions for a stale candidate lockfile."""
16+
17+
PR_INDUCED = "pr-induced"
18+
BASE_MAINTENANCE = "base-maintenance"
19+
MIXED = "mixed-or-ambiguous"
20+
21+
22+
@dataclass(frozen=True)
23+
class LockfileCheck:
24+
"""Original and post-check Git blobs for one lockfile."""
25+
26+
stale: bool
27+
original_blob: str
28+
repaired_blob: str
29+
30+
def __post_init__(self) -> None:
31+
if not self.original_blob or not self.repaired_blob:
32+
raise ValueError("lockfile blob hashes must be non-empty")
33+
if not self.stale and self.original_blob != self.repaired_blob:
34+
raise ValueError("a fresh lockfile cannot have different original and repaired blobs")
35+
36+
37+
def classify(candidate: LockfileCheck, base: LockfileCheck | None) -> Classification:
38+
"""Attribute a stale candidate lockfile using its base check, if any."""
39+
if not candidate.stale:
40+
raise ValueError("candidate lockfile must be stale")
41+
if base is None or not base.stale:
42+
return Classification.PR_INDUCED
43+
if (
44+
base.original_blob == candidate.original_blob
45+
and base.repaired_blob == candidate.repaired_blob
46+
):
47+
return Classification.BASE_MAINTENANCE
48+
return Classification.MIXED
49+
50+
51+
def _parse_args() -> argparse.Namespace:
52+
parser = argparse.ArgumentParser(description=__doc__)
53+
parser.add_argument("--candidate-original", required=True)
54+
parser.add_argument("--candidate-repaired", required=True)
55+
parser.add_argument("--base-result", choices=("missing", "fresh", "stale"), required=True)
56+
parser.add_argument("--base-original")
57+
parser.add_argument("--base-repaired")
58+
return parser.parse_args()
59+
60+
61+
def main() -> int:
62+
"""Print the classification for workflow consumption."""
63+
args = _parse_args()
64+
candidate = LockfileCheck(
65+
stale=True,
66+
original_blob=args.candidate_original,
67+
repaired_blob=args.candidate_repaired,
68+
)
69+
70+
if args.base_result == "missing":
71+
if args.base_original or args.base_repaired:
72+
raise ValueError("a missing base lockfile cannot have blob hashes")
73+
base = None
74+
else:
75+
if not args.base_original or not args.base_repaired:
76+
raise ValueError("base blob hashes are required for a checked base lockfile")
77+
base = LockfileCheck(
78+
stale=args.base_result == "stale",
79+
original_blob=args.base_original,
80+
repaired_blob=args.base_repaired,
81+
)
82+
83+
print(classify(candidate, base).value)
84+
return 0
85+
86+
87+
if __name__ == "__main__":
88+
sys.exit(main())
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
from __future__ import annotations
5+
6+
import sys
7+
from pathlib import Path
8+
9+
import pytest
10+
11+
sys.path.insert(0, str(Path(__file__).parent.parent))
12+
from classify_pixi_lockfile_freshness import Classification, LockfileCheck, classify
13+
14+
15+
def _check(*, stale: bool, original: str, repaired: str) -> LockfileCheck:
16+
return LockfileCheck(stale=stale, original_blob=original, repaired_blob=repaired)
17+
18+
19+
@pytest.mark.agent_authored(model="gpt-5")
20+
def test_fresh_base_is_pr_induced():
21+
candidate = _check(stale=True, original="candidate-old", repaired="candidate-new")
22+
base = _check(stale=False, original="base-current", repaired="base-current")
23+
24+
assert classify(candidate, base) is Classification.PR_INDUCED
25+
26+
27+
@pytest.mark.agent_authored(model="gpt-5")
28+
def test_workspace_missing_from_base_is_pr_induced():
29+
candidate = _check(stale=True, original="candidate-old", repaired="candidate-new")
30+
31+
assert classify(candidate, None) is Classification.PR_INDUCED
32+
33+
34+
@pytest.mark.agent_authored(model="gpt-5")
35+
def test_matching_stale_blobs_are_base_maintenance():
36+
candidate = _check(stale=True, original="shared-old", repaired="shared-new")
37+
base = _check(stale=True, original="shared-old", repaired="shared-new")
38+
39+
assert classify(candidate, base) is Classification.BASE_MAINTENANCE
40+
41+
42+
@pytest.mark.parametrize(
43+
("base_original", "base_repaired"),
44+
[
45+
("base-old", "shared-new"),
46+
("shared-old", "base-new"),
47+
("base-old", "base-new"),
48+
],
49+
)
50+
@pytest.mark.agent_authored(model="gpt-5")
51+
def test_different_stale_blobs_are_mixed_or_ambiguous(base_original, base_repaired):
52+
candidate = _check(stale=True, original="shared-old", repaired="shared-new")
53+
base = _check(stale=True, original=base_original, repaired=base_repaired)
54+
55+
assert classify(candidate, base) is Classification.MIXED
56+
57+
58+
@pytest.mark.agent_authored(model="gpt-5")
59+
def test_fresh_candidate_is_rejected():
60+
candidate = _check(stale=False, original="current", repaired="current")
61+
62+
with pytest.raises(ValueError, match="candidate lockfile must be stale"):
63+
classify(candidate, None)

0 commit comments

Comments
 (0)