Skip to content

ci: stop the publish job's cache save from erroring on package scratch - #24

Merged
KeyCode17 merged 1 commit into
mainfrom
fix/publish-cache-cleanup-enoent
Aug 8, 2026
Merged

ci: stop the publish job's cache save from erroring on package scratch#24
KeyCode17 merged 1 commit into
mainfrom
fix/publish-cache-cleanup-enoent

Conversation

@KeyCode17

Copy link
Copy Markdown
Owner

Not a px-cache bug

The v1.10.0 publish job succeeded but posted failure annotations:

Error: ENOENT: no such file or directory, opendir
'/home/runner/work/px-solver/px-solver/target/package/pxsolver-cache-1.10.0/tests/trybuild'

Named crates: pxsolver-cache, pxsolver-camoufox, pxsolver-native — three of the six published crates that ship a tests/ directory. Nothing is wrong with any of them, and no manifest change fixes it.

Root cause

cargo publish leaves scratch in target/package/<crate>-<ver>/. For a crate shipping tests, that scratch contains a directory literally named tests. rust-cache's save-time cleanup treats any directory named tests under target/ as a possible nested test workspace and recurses into tests/target and tests/trybuild — a carve-out for trybuild and macrotest artifacts. This workspace has no trybuild dependency, so neither path exists.

From Swatinem/rust-cache src/cleanup.ts, cleanProfileTarget:

if (path.basename(profileDir) === "tests") {
  try {
    cleanTargetDir(path.join(profileDir, "target"), packages, checkTimestamp);   // not awaited
  } catch {}
  try {
    cleanTargetDir(path.join(profileDir, "trybuild"), packages, checkTimestamp); // not awaited
  } catch {}

The calls are async but not awaited, so the rejection never reaches the surrounding catch. It escapes as an unhandled rejection — which is why it renders as a failure annotation on a job that succeeded, and why it named an arbitrary subset of the eligible crates rather than all six.

Fix

save-if: false on the publish job's cache step. Publish scratch is single-use and worth nothing in the cache, and pre-flight already populates the same key, so the job restores as before and simply never runs the save-time cleanup. That removes the failing code path rather than racing it (an rm -rf target/package cleanup step would only cover the paths we know about today).

pre-flight and all three ci.yml jobs are untouched — none of them run cargo package, so none can hit this.

Verification

Workflow YAML parses; the with: save-if: false lands on crates-publish only, pre-flight unchanged.

Note this cannot be proven by a re-run: the publish loop skips crates already at the target version, so cargo publish never runs and target/package/ is never created. The next real publish (1.11.0) is the empirical confirmation. The fix is sound by construction — no save step means no cleanup walk.

The v1.10.0 publish job succeeded but posted red annotations:

  Error: ENOENT: no such file or directory, opendir
  '.../target/package/pxsolver-cache-1.10.0/tests/trybuild'

Nothing is wrong with those crates. `cargo publish` leaves scratch in
target/package/<crate>-<ver>/, and for any crate shipping a tests/ dir
that scratch contains a directory named `tests`. rust-cache's save-time
cleanup treats every such directory as a possible nested test workspace
and recurses into tests/target and tests/trybuild — a carve-out for
trybuild and macrotest. Neither path exists here; this workspace has no
trybuild dependency at all.

The recursion is not awaited inside its own try/catch
(Swatinem/rust-cache src/cleanup.ts, cleanProfileTarget), so the ENOENT
never reaches the catch and escapes as an unhandled rejection. That is
why it renders as a failure annotation on a job that succeeded, and why
it named a nondeterministic subset — cache, camoufox and native out of
the six published crates that carry tests/.

Publish scratch is single-use and worthless in the cache, and pre-flight
already populates the same key, so the job now restores without saving.
That removes the failing code path instead of racing it.
@KeyCode17
KeyCode17 merged commit 461aa9b into main Aug 8, 2026
6 checks passed
@KeyCode17
KeyCode17 deleted the fix/publish-cache-cleanup-enoent branch August 8, 2026 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant