Skip to content

refactor(tools): simplify the lockfile runner - #351

Merged
sweepies merged 3 commits into
mainfrom
refactor/simplify-tools
Nov 22, 2026
Merged

sweepies merged 3 commits into
mainfrom
refactor/simplify-tools

Conversation

@sweepies

@sweepies sweepies commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Simplification pass over crates/tools, items 1–12 of the tools review. Tests (patchula-tools including test:tools real-tool runs, patchula-process, patchula-update, patchula-lockfiles), clippy and the state/derive parity tests pass locally.

Done

  1. Output hiding inside tool() (security: stronger). held_tool and refusable_tool are gone. tool() itself withholds the output of any failed run that holds registry credentials, so a credentialed call can no longer skip hiding by calling tool() directly. The refusal check runs first through Invocation::refused: Option<fn>, and Python wraps the refusal text in its lock-specific message. credentials::Held::of(entries) replaces the 9 scopes + secrets pairs. It sorts and dedups the scopes once, so use_caches no longer sorts them again. Nix and actions.lock use Held::masking(secrets): they have secrets to hide but no scopes.
  2. One restore-on-drop guard. pin::Pinned and context::Replaced are now one type, context::Replaced. It keeps Pinned's rule: a file is forgotten only after it is written back, so a failure leaves the rest for Drop to retry (the old Replaced::restore lost the retry with mem::take). pin::apply returns the guard.
  3. node::canonical removed. dependencies() returns the projected serde_json::Value. Value's equality ignores key order with or without preserve_order (IndexMap's PartialEq also ignores order).
  4. validate_targets reads Cargo.lock through cargo::crates_io_entries instead of parsing it by hand. Same rule: the same name, a crates.io source and the same release.
  5. GOFLAGS merge removed. No call sets GOFLAGS, so caches::acquire loses its call env parameter and the merge. go.rs sets GOFLAGS=-modcacherw directly, with caches on or off, because a read-only module cache (0555/0444) cannot be removed by TempDir or an operator's rm -rf (our own eviction already runs make_writable). A test checks both cache settings.
  6. Runner.usage mutex removed. record_use and prune take a flock on USAGE_LOCK through a new open each time, and flock locks each open file, so threads in one process already exclude each other. seed runs only under the exclusive store lock.
  7. Fail-closed public_only (security: stronger). A partition is public only when the run reads at least one file that steers its ecosystem and every such file decided public-only. Before, an ecosystem with no steering files (empty steers), or a snapshot with none of them, was public by vacuous truth. Terraform, APM, nix and actions.lock now pass context.public instead of a hard-coded false. For them the value is always false by construction (empty steers, or Actions' verdict, which is always false), and none of their binaries keeps a cache.
  8. Tool.versions removed (approved edge change). A run resolves and checks only the pins of its own descriptor's tools. A bad pin for another ecosystem's tool no longer fails the job, and Gradle wrapper, mise, nix, dotnet and actions jobs read no pins. gh-actions-lock stays out of the pinnable set: its descriptor has tools: &[] and installs through the new Install::Fixed(ACTIONS_LOCK_SPEC). Documented under "Which tool version" in guide/lockfiles.md.
  9. One mise declaration grammar. arguments() does not reject a table whose version is an array (bracketed skips the version key). Simply swapping in request_list would therefore have skipped the specifier check for that form. Instead, request_list now accepts an array version as one request per version with shared options, and requests() is gone. The specifier check covers every form it covered before that arguments() admits. Side effect: merged() can now merge a task's tool into such a declaration instead of refusing it, writing one table per version.
  10. Per-tool@version install locks shared by every runner and process replace the nix-only nix_install mutex; the race applied to every tool. Each lock is a flock file under mise_data/patchula-install-locks/, named by a hash of the spec, taken in sorted order through spawn_blocking. hold_installed takes the shared store lock and returns at once when every tool is installed; otherwise it drops it, takes the install locks, then the store exclusively for first use and shared for mise install. Install locks are never taken while holding the store lock, and install() only runs with them held. concurrent_runners_install_a_tool_once runs two Runner::new on one store and checks mise install runs once.
  11. patchula_process::redact is now public, and actions.lock uses it instead of its own copy. The copy lacked longest-first ordering and the empty-secret filter. The mask text is now [redacted] everywhere. The larger executor option (status plus streams, removing Run::Shell) was skipped: it touches patchula-process and is not small.
  12. One first-use step. first_use (clear unproven installs, then seed) is shared by tool() and prewarm. prewarm holds the exclusive store lock across first use, mise install and recording the use, as before. checkout_paths replaces the two chunked checkout loops.

After review (Gemini 4 Neon, adversarial)

Fixed in 5142ce0:

  • prewarm had lost its exclusive store hold during mise install (regression): restored.
  • The per-version install lock was an in-memory map per Runner, so runners of different installations, or other processes, sharing one tool store were not serialized, and a prune between the check and the lock left install() unguarded: now flock files under the store (item 10).
  • Dropping -modcacherw left Go module caches undeletable by TempDir/rm -rf: restored directly in go.rs (item 5).
  • Tests added for array version in request_list/merged(), a bad pin failing only its own ecosystem (directly and through a Go job with a bad Node pin), and gh-actions-lock being unpinnable yet still prewarmed.

Fixed in 9e029c2, after a focused re-check of the locking:

  • prewarm took only the exclusive store lock, so it could run between another runner's first_use and its install; a prewarm killed mid-install then left a half-written directory that the other runner installed over without clearing it, and recorded as proven. prewarm now takes every default's install lock first, in the same INSTALL_LOCKS → STORE_LOCK → USAGE_LOCK order as hold_installed.
  • prune waited for USAGE_LOCK and read and wrote the usage record on the async runtime; that block now runs on the blocking pool, like every other store lock.

Dropped

None. Left alone as asked: the CredentialCheck test in lockfiles/tests.rs, which another PR removes.

Follow-ups

  • The executor option from item 11 (one call that returns status and streams), which would remove Run::Shell and the actions.lock shell wrapper.
  • Lock files under patchula-install-locks/ are never pruned: one tiny file per tool version ever installed. A safe sweep needs try_lock removal in prune plus an inode-identity retry in lock_installs, like the same() loop in caches.rs.

View guided diff Turn on auto-fix

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
count-patchula acc1f82 Commit Preview URL

Branch Preview URL
Nov 22 2026, 07:47 PM

- tool() hides a credentialed run's output itself and reads refusals
  through Invocation::refused; held_tool and refusable_tool are gone,
  and credentials::Held carries a run's scopes and secrets.
- One restore-on-drop guard (context::Replaced) for transient pins and
  sanitized settings files, keeping the pin rule: a file is forgotten
  only once written back.
- Node manifest dependencies compare as JSON values, not canonical text.
- validate_targets reads Cargo.lock through cargo::crates_io_entries.
- Drop the GOFLAGS -modcacherw merge: eviction makes a partition
  writable before removing it.
- Drop the tool usage mutex: the per-open flock on the usage lock and
  the exclusive store lock already serialise writers.
- A cache partition is public only when the run reads at least one file
  that steers its ecosystem and every such file decided public-only;
  Terraform, APM, nix and actions.lock pass the run's verdict.
- Drop Tool::versions: a run resolves and checks only its own tools'
  pins. gh-actions-lock installs as Install::Fixed, outside them.
- mise.rs reads declarations with one grammar (request_list), which now
  takes a table whose version is an array.
- Per tool@version install locks in tool() replace the nix-only one.
- prewarm and tool() share hold_store; checkout_paths replaces two
  chunked checkout loops.
- actions.lock output is masked with patchula_process::redact.
…sive

- Install locks are flock files per tool@version under the tool store,
  taken in sorted order before the store lock, so runners of different
  installations and separate processes never install one version twice
  or clear each other's install, and install() only runs while they are
  held, even after a prune between checks.
- prewarm holds the store exclusively across clearing, seeding, mise
  install and recording again.
- Go runs with GOFLAGS=-modcacherw, cached or not, so its module cache
  stays removable by scratch cleanup and rm -rf.
- Tests: two runners on one store install once; array `version` in
  request_list and merged(); a bad pin holds only its own ecosystem;
  gh-actions-lock is not pinnable; Go keeps its module cache writable.
… off the runtime

prewarm takes every default's install lock before the exclusive store
lock, in the order hold_installed uses, so it cannot run between another
runner's first use and its install. prune rewrites the usage record
under USAGE_LOCK on the blocking pool, like every other store lock.
@sweepies
sweepies force-pushed the refactor/simplify-tools branch from 9e029c2 to acc1f82 Compare November 22, 2026 19:47
@sweepies
sweepies merged commit 1fe1a5a into main Nov 22, 2026
13 checks passed
@sweepies
sweepies deleted the refactor/simplify-tools branch November 22, 2026 19:57
@sweepies-ops sweepies-ops Bot mentioned this pull request Nov 22, 2026
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