Page MenuHomePhabricator

Castor publishes a corrupt npm cache when a save is interrupted, breaking every subsequent build in the namespace
Open, Needs TriagePublic

Description

As the Test Platform team, we are trying to understand why npm cache keeps getting corrupted. This is an explainer of initial findings as we try to understand the problem, have a discussion around it, and solve it for good.

What happens

A castor save can start rsyncing a workspace cache to the central instance, and then have that workspace deleted underneath it while the rsync is still running. The rsync fails partway through, but it has already been changing the live central cache, so what is left published is an npm _cacache whose index-v5 entries reference content-v2 blobs that no longer exist.

npm ci does not treat a missing content blob as a cache miss. It fails with ENOENT. So every build that loads that namespace afterwards dies at npm install, and keeps dying until something happens to rewrite the cache. On 2026-09-15 that was 3h21m.

The ordering, expected versus actual

This is the main issue,

Expected. The post-build publishers on a Quibble job run one after another:

1. npm cache verify
2. trigger castor-save-workspace-cache, and BLOCK until it finishes
     -> save job rsyncs /srv/jenkins/workspace/<job>/cache
                     to /srv/castor/<namespace>
3. clear the workspace cache: find /cache -mindepth 1 -delete

Step 3 must not start before step 2 finishes. The only thing enforcing that is block: true on the trigger in jjb/castor.yaml, and the comment there says so explicitly:

  1. Must be blocking or the next publisher will kick in and delete the cache while it is being saved.

Actual, when the wait is interrupted.

1. npm cache verify
2. trigger castor-save-workspace-cache  -> save job starts rsyncing
     the blocking wait is interrupted
     PostBuildScript turns it into PostBuildScriptException / FAILURE
     step 2 gives up  ...  BUT THE SAVE JOB IS STILL RUNNING
3. clear runs NOW, deleting the directory the rsync is reading from

The important detail is that the downstream save is a separate Jenkins build. Interrupting the wait does not stop the save. Step 2 returns, Jenkins proceeds to step 3, and the rsync loses its source mid-transfer.

The trace

Three builds, in order.

(a) The build whose wait was interrupted — quibble-with-gated-extensions-vendor-mysql-php83 #57281, console in log order:

npm cache verified less than a day ago, skipping npm cache verify
[PostBuildScript] - [INFO] Executing post build scripts.
Waiting for the completion of castor-save-workspace-cache
castor-save-workspace-cache #6977607 started.
[PostBuildScript] - [ERROR] An error occured during post-build processing.
org.jenkinsci.plugins.postbuildscript.PostBuildScriptException: java.lang.InterruptedException
	at ...TriggerBuilder.perform(TriggerBuilder.java:175)
...
+ echo 'Clearing /srv/jenkins/workspace/quibble-with-gated-extensions-vendor-mysql-php83/cache'
Clearing /srv/jenkins/workspace/quibble-with-gated-extensions-vendor-mysql-php83/cache

The clear publisher is build-on: SUCCESS, UNSTABLE, FAILURE, ABORTED, so the build being marked FAILURE does not stop it.

(b) The save that was still running — castor-save-workspace-cache #6977607, started by #57281:

Defined: CASTOR_NAMESPACE="castor-mw-ext-and-skins/master/quibble-with-gated-extensions-vendor-mysql-php83"
Syncing cache
From.. 172.16.18.155:/srv/jenkins/workspace/quibble-with-gated-extensions-vendor-mysql-php83/cache
To.... /srv/castor/castor-mw-ext-and-skins/master/quibble-with-gated-extensions-vendor-mysql-php83
>>> Start: castor-save rsync
directory has vanished: "/cache/npm/_cacache/index-v5/c7/da"
file has vanished: "/cache/npm/_cacache/index-v5/59/ac/f997d249a439237f8cf4c9cdcd0734d9955ad7f28a426da82d329b36a9c4"
[... 2551 more ...]

Number of files: 17,690 (reg: 7,697, dir: 9,993)
Number of created files: 0
Number of deleted files: 179 (reg: 179)
Number of regular files transferred: 0
Total transferred file size: 0 bytes
Literal data: 0 bytes

rsync warning: some files vanished before they could be transferred (code 24) at main.c(1874) [generator=3.2.7]
castor-save rsync failed (exit code 24)
<<< Finish: Failed: castor-save rsync, in 6.113 s

2443 files and 110 directories vanished mid-transfer, 2437 of the files under index-v5 and 6 under content-v2.

The stats block is where the damage shows, and it is worth being precise about which part of rsync caused it. Zero files were transferred. 179 were deleted. That run copied nothing into the central cache, the only thing it did was delete 179 files from it.

rsync lists the source first, then makes the destination match that list. The workspace was being deleted while it was still listing, so 179 files came back missing from the list, and rsync read that as "these were removed on purpose" and deleted them from /srv/castor at the end of the transfer. The vanished warnings are a separate set, files that were in the list but already gone by the time rsync tried to read them.

This matters because it rules out the option you would reach for first. --delay-updates is already in use on the save, and it did not help:

  • It only covers files being updated. The man page describes it as putting "the temporary file from each updated file into a holding directory until the end of the transfer". This transfer updated nothing. Deletions do not go through it at all, they go through --delete-delay, which computes them during the transfer and applies them to the live directory afterwards.
  • Even for updates it is "renamed into place in rapid succession", which is N separate renames rather than one. The man page calls it "a little closer to atomic", not atomic, so an interruption during that rename burst would leave a partly updated tree.

Note the destination: the rsync writes and deletes straight into the live /srv/castor/<namespace>. A failed save does not mean the previous cache was kept.

Two further details from jjb/castor-save-workspacecache.bash that matter for what happens next:

  • The generation counter is bumped before the rsync runs, so the damaged tree is published under a fresh generation and sibling builds that loaded the previous one skip their own save rather than overwriting it.
  • The script's comment claims an interrupted save is safe because "a later build that loads this generation heals the content with its own full sync". That does not happen, see the next section.

(c) The next build in that namespace — #57349. The load reports success:

>>> Start: castor-load rsync
Number of files: 17,691 (reg: 7,698, dir: 9,993)
Total file size: 253,722,087 bytes
<<< Finish: Success: castor-load rsync, in 4.414 s

Then:

npm warn tarball tarball data for which-typed-array@... seems to be corrupted. Trying again.
npm warn tarball tarball data for @babel/core@... seems to be corrupted. Trying again.
[... ~50 more ...]
npm error code ENOENT
npm error syscall stat
npm error path /cache/npm/_cacache/content-v2/sha512/5d/36/6ce8c20b06a67a1498b9a60e667dd7baaf6a3432dedcad5b896a05ba6f3f3a4ccd8cfd93b11a007ac9ef922c1bce860b8d31a36db717b55f1f8cd67ab526
npm error enoent Invalid response body while trying to fetch https://registry.npmjs.org/test-exclude: ENOENT: no such file or directory
<<< Failed: npm install in /workspace/src, in 41.395 s

The seems to be corrupted warnings are integrity mismatches, which npm retries past. The ENOENT is fatal.

Why the damage sticks for hours

Both the npm cache verify publisher and the castor save publisher are build-on: SUCCESS. A build that dies at npm install runs neither, so it never repairs or replaces the cache that killed it. The only builds that could rewrite the cache are exactly the builds the cache is breaking.

The way out is accidental, eventually a build whose dependency set happens to miss the damaged entries succeeds and saves a repaired cache. That is why 09-15 recovered at ~17:48 rather than never, and why recovery time looks arbitrary.

How to recognise it

The signature is distinctive, and worth knowing because the symptom appears on changes that have nothing to do with each other.

  1. A Quibble build fails with npm error code ENOENT and a path under /cache/npm/_cacache/content-v2/.
  2. Several unrelated repositories fail the same way, in the same job, within a short window. The castor namespace is castor-mw-ext-and-skins/<branch>/<job> for all extensions and skins, so the blast radius follows the job name, not the repo. On 09-14/15 it spanned 24 different extension repositories.
  3. Look at castor-save-workspace-cache builds shortly before the first failure, filtered to TRIGGERED_JOB_NAME = the failing job. Look for file has vanished and rsync ... (code 24).
  4. In the upstream build that triggered that save, look for PostBuildScriptException followed by Clearing ....

Two instances found this way:

2026-09-15, quibble-with-gated-extensions-vendor-mysql-php83. Save #6977607 failed at 14:27:01. Builds in that namespace, by hour:

hour (UTC)failsucc
13:00019
14:001411
15:00132
16:0088
17:0055
18:0016

2026-09-14, quibble-vendor-mysql-php83. Save failed at 21:03:43. Then, 33 seconds later:

timerepobuild
21:04:16mediawiki/extensions/GrowthExperiments#111744
21:04:21mediawiki/extensions/WikiLambda#111745
21:04:49mediawiki/extensions/InlineComments#111746

Why it surfaced now

The race is not new, there were 48 npm install phase failures on 2026-08-29. What changed is that the thing quietly repairing the damage was throttled.

npm cache verify prunes index entries whose content is missing. It used to run on every gate-and-submit and postmerge build. It was throttled to once per day per cache on 2026-09-11, for good reasons (T437377): verifying on every build rewrote the whole index and made saves impossible to skip as unchanged.

Build #57281 logged exactly that, moments before triggering the save that broke the cache:

npm cache verified less than a day ago, skipping npm cache verify

npm install phase failures per day:

datefailures
2026-08-2948
2026-09-037
2026-09-081
2026-09-1411
2026-09-1536

Impact

  • 34 distinct changes affected on 09-14/15, 21 of them gate builds. Each was voted Verified-1 and dropped from the merge queue, requiring a full gate cycle to re-enter, with a Zuul reset for everything behind them.
  • Separately, the same interrupted wait marks fully green builds as FAILURE: 25 to 51 builds per day in gate and postmerge are FAILURE with no Quibble phase reporting a failure. Tracked as T352319.

Related

T352319, T437377, T295351, T426741, T436173

Details

Event Timeline

@pwangai I'm thinking like this: push your changes to self heal it so @hashar can review. There's some bug somewhere and I'm thinking we don't need to fix it now if our plan is to move to a proxy. Self healing is faster.

I looked at the problems and if I get it right, save castor jobs get an abort from Zuul, and then it seems like the flag --delay-updates do not help (my understanding was that it should create files as tmp files and swap, but it obviously do not help). Thinking maybe rsync have other flags that can make it safer?

Change #1342828 had a related patch set uploaded (by Pwangai; author: Pwangai):

[integration/quibble@master] Recover from an npm cache that has lost files

https://gerrit.wikimedia.org/r/1342828