fix(ci): clear the pinned corepack cache before every install (#16351)

* fix(ci): clear the pinned corepack cache before every install

The Linux test shards have been dying seconds into Install dependencies
with MODULE_NOT_FOUND on the cached pnpm's bin/pnpm.mjs since #16328
pinned COREPACK_HOME to runner.temp (main runs 41876940141, 41889761157,
41927887452; six different self-hosted hosts). The pin assumed runner.temp
is per-run, but self-hosted runners keep _work/_temp across jobs — the
lint job's isolated-HOME step already documents this. corepack trusts an
existing cache entry without re-verifying its files, so a partial pnpm
tree left by an earlier job fails every later job on that host.

Clear the pinned cache at the start of the shared install body in all
three jobs that copy it, enforcing the per-run contract the pin
documents. The guard keeps the reset a no-op where COREPACK_HOME is
unset (test_build) or already run-unique (lint). The test step still
reuses the cache install warms in the same job, and poisoned hosts
self-heal on their next job without manual cleanup.

Pin the reset and the install/test COREPACK_HOME match in the workflow
meta-test, and bump the size baseline for the added lines.

* fix(ci): scope the corepack cache reset to the shard-owned path

Review found two over-deletion shapes in the nonempty guard: a runner
that exports COREPACK_HOME would lose its entire shared cache in the
build job, and hosted lint would lose the cache its pnpm-store step had
just warmed, re-exposing the install to a registry outage. Match only
the exact shard-owned path instead; the build and lint copies become
unconditional no-ops and the three install bodies stay byte-identical.

Add an execution test that runs the shipped guard fragment under a
scrubbed environment across five cache shapes: it kills the dead-guard
mutant the string pins survived, and a widened-guard mutant dies on the
shared-cache survival cell. State the incident as observations with the
corruption source undetermined, and correct the stale per-run rationale
beside the pin.
This commit is contained in:
Shaojin Wen authored and GitHub committed 2026-11-05 09:27:53 +08:00
1 parent f3488b47fa
commit ef9c891b8f
3 files changed
+193 -11

No files matched your search

+1 -1
View File
@@ -19,7 +19,7 @@
9551 build-and-publish-image.yml
55276 cd-cua-driver.yml
2222 cd-mobile-mcp.yml
192263 ci.yml
195906 ci.yml
4193 codeql.yml
9389 comment-attachment-guard.yml
2090 desktop-packaging-check.yml
+40 -5
View File
@@ -679,6 +679,17 @@ jobs:
( while sleep 10; do sample_disk; done ) &
SAMPLER_PID=$!
trap 'pkill -TERM -P "$SAMPLER_PID" 2>/dev/null || true; kill "$SAMPLER_PID" 2>/dev/null || true' EXIT
# Observed: the pinned cache entry existed with its pnpm binary
# missing, corepack trusts an existing entry without re-verifying
# its files, and the install died instantly with MODULE_NOT_FOUND
# (main run 41927887452). What left the entry incomplete is
# undetermined; _work/_temp survives across jobs on self-hosted
# runners, so such state persists. Start the shard-owned cache
# empty — and only that exact path, so a runner-exported shared
# cache and lint's already-warmed run-unique home stay untouched.
if [ "${COREPACK_HOME:-}" = "${RUNNER_TEMP:-}/qwen-ci-corepack" ]; then
rm -rf -- "${COREPACK_HOME}"
fi
corepack pnpm install --frozen-lockfile --prefer-offline --reporter=append-only
- name: 'Report npm cache usage (self-hosted)'
@@ -1078,11 +1089,13 @@ jobs:
env:
QWEN_SKIP_PREPARE: '1'
QWEN_SKIP_NOTICE_GENERATION: '1'
# Pin COREPACK_HOME to a per-run path so the corepack cache written
# here is visible to the test step below, which overrides HOME for
# isolation. corepack does not re-verify extracted entries on cache
# hit, so this must NOT be a shared/persistent path (poisoning
# channel) — per-run is safe and sufficient.
# Pin COREPACK_HOME to a fixed path under runner.temp so the
# corepack cache written here is visible to the test step below,
# which overrides HOME for isolation. runner.temp survives across
# jobs on self-hosted runners, and corepack does not re-verify
# extracted entries on cache hit, so the install body below clears
# this exact path before use; the test step then reuses the cache
# this step warms within the same job.
COREPACK_HOME: '${{ runner.temp }}/qwen-ci-corepack'
run: |-
DISK_SAMPLES="${RUNNER_TEMP}/disk-pressure-samples.log"
@@ -1097,6 +1110,17 @@ jobs:
( while sleep 10; do sample_disk; done ) &
SAMPLER_PID=$!
trap 'pkill -TERM -P "$SAMPLER_PID" 2>/dev/null || true; kill "$SAMPLER_PID" 2>/dev/null || true' EXIT
# Observed: the pinned cache entry existed with its pnpm binary
# missing, corepack trusts an existing entry without re-verifying
# its files, and the install died instantly with MODULE_NOT_FOUND
# (main run 41927887452). What left the entry incomplete is
# undetermined; _work/_temp survives across jobs on self-hosted
# runners, so such state persists. Start the shard-owned cache
# empty — and only that exact path, so a runner-exported shared
# cache and lint's already-warmed run-unique home stay untouched.
if [ "${COREPACK_HOME:-}" = "${RUNNER_TEMP:-}/qwen-ci-corepack" ]; then
rm -rf -- "${COREPACK_HOME}"
fi
corepack pnpm install --frozen-lockfile --prefer-offline --reporter=append-only
# Eight shards pull this same artifact at once, so the cap has to clear
@@ -1873,6 +1897,17 @@ jobs:
( while sleep 10; do sample_disk; done ) &
SAMPLER_PID=$!
trap 'pkill -TERM -P "$SAMPLER_PID" 2>/dev/null || true; kill "$SAMPLER_PID" 2>/dev/null || true' EXIT
# Observed: the pinned cache entry existed with its pnpm binary
# missing, corepack trusts an existing entry without re-verifying
# its files, and the install died instantly with MODULE_NOT_FOUND
# (main run 41927887452). What left the entry incomplete is
# undetermined; _work/_temp survives across jobs on self-hosted
# runners, so such state persists. Start the shard-owned cache
# empty — and only that exact path, so a runner-exported shared
# cache and lint's already-warmed run-unique home stay untouched.
if [ "${COREPACK_HOME:-}" = "${RUNNER_TEMP:-}/qwen-ci-corepack" ]; then
rm -rf -- "${COREPACK_HOME}"
fi
corepack pnpm install --frozen-lockfile --prefer-offline --reporter=append-only
- name: 'Report npm cache usage (self-hosted)'