Skip to content

feat(pnpr): share cargo compilation caches - #14620

Merged
zkochan merged 4 commits into
mainfrom
side-eff
Sep 6, 2026
Merged

zkochan merged 4 commits into
mainfrom
side-eff

Conversation

@zkochan

@zkochan zkochan commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Add an experimental pnpr WebDAV backend for sccache so Cargo builds can share compilation results between CI and developers while retaining a local disk cache.

  • Configure named caches with separate reader and publisher policies under artifacts.compilerCaches.
  • Reuse pnpr authentication and the existing filesystem/S3 artifact store, publication lifecycle, and quotas. Bound concurrent uploads before reading bodies, avoid copying upload payloads, and use metadata-only HEAD and duplicate checks.
  • Document setup, trust requirements, and sccache limitations. Install sccache 0.17.0 in Rust CI and developer tooling.

Validation:

  • just ready: 10,338 tests passed, 10 existing skips; formatting, spelling, checking, and Clippy passed. Full workspace Dylint and the pre-push checks also passed.
  • Automated integration test uses real Cargo/rustc/sccache with pnpr's HTTP router: CI population, a fresh developer cache remote hit, source/feature invalidation, and offline local backfill.
  • Integration test passed 50 consecutive stress runs. It waits for completed remote writes before shutting down the CI fixture, avoiding sccache's background-upload race during test teardown.
  • Manually built and launched the standalone pnpr binary with a YAML config, real htpasswd users, and SQLite tokens. Registered separate CI/developer accounts, restarted pnpr to verify token persistence, checked CI writes and developer reads, and confirmed developer writes and anonymous/invalid-token reads are rejected. Real Cargo/sccache builds verified remote hits with an empty developer disk cache, feature invalidation, and local hits after shutting pnpr down and cleaning Cargo output.

The standalone check used loopback HTTP and filesystem storage. Live S3, HTTPS deployment, and separate physical CI/developer machines have not been tested.

Squash Commit Body

Expose named compiler caches through the WebDAV subset used by sccache.
Apply pnpr account access and publication policies before buffering uploads,
including existing token restrictions. Entries are immutable and verified
against a digest bound to their cache scope, key, and bytes before serving.
Reuse the shared artifact store's filesystem/S3 selection, quota accounting,
publication lifecycle, and orphan reclamation.

Bound compiler uploads to two concurrent bodies per server and reject excess
requests before buffering. Store digest and payload as separate buffers in
one conditional object write. Use metadata-only HEAD and duplicate checks;
GET still verifies content before serving it.

Stock sccache trusts the server and allowed publishers; it does not verify
pnpm signed envelopes. Document trusted CI publication and HTTPS requirements.
Also document sccache 0.17's absolute Rust build-path requirement and its
read-only multilevel behavior: remote hits backfill disk, but new compilation
misses are not cached locally when a tier is read-only.

Add HTTP, policy, integrity, quota, and real Cargo integration coverage.
Install sccache for Rust CI and local test setup. Extract the existing
miette diagnostic normalization into a shared test helper to fix a shim
assertion exposed by the full suite's longer temporary paths.

Checklist

  • New feature is confined to the Rust pnpr server; no TypeScript v11 feature changes.
  • Added a changeset for @pnpm/pnpr.
  • Added or updated tests.
  • Updated the documentation.

Written by an agent (Codex, GPT-5).

Summary by CodeRabbit

  • New Features

    • Added experimental Cargo compilation cache sharing through sccache.
    • CI can publish compiler outputs, while authorized developers can reuse them through a remote cache.
    • Supports combining remote cache storage with sccache’s local disk cache.
    • Added separate read and publish permissions for named compiler caches.
    • Added validation, size limits, integrity checks, quota protections, and upload controls.
  • Documentation

    • Added configuration examples, setup requirements, cache behavior, security guidance, and usage limitations.

@coderabbitai

coderabbitai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: a28bfb90-6e43-465d-bde9-3c9c4f0c482f

📥 Commits

Reviewing files that changed from the base of the PR and between 5fbf89a and c7494d7.

📒 Files selected for processing (9)
  • pnpm/crates/testing-utils/src/diagnostics.rs
  • pnpr/crates/pnpr/README.md
  • pnpr/crates/pnpr/src/server.rs
  • pnpr/crates/pnpr/src/server/compiler_cache.rs
  • pnpr/crates/pnpr/src/server/routing.rs
  • pnpr/crates/pnpr/src/server/tests/compiler_cache.rs
  • pnpr/crates/shared-artifacts/src/compiler_cache.rs
  • pnpr/crates/shared-artifacts/src/compiler_cache/tests.rs
  • pnpr/crates/shared-artifacts/src/lib.rs
💤 Files with no reviewable changes (1)
  • pnpm/crates/testing-utils/src/diagnostics.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The PR adds experimental sccache-backed Cargo compiler caches to pnpr. It adds configuration policies, persistent storage, authorized WebDAV-compatible endpoints, quota handling, documentation, tooling setup, and integration tests.

Changes

Cargo compiler cache

Layer / File(s) Summary
Compiler cache configuration and documentation
pnpr/crates/config/*, pnpr/crates/pnpr/README.md, pnpr/crates/config/config.yaml, .changeset/rust-compilation-cache.md
Adds artifacts.compilerCaches with separate access and publish policies. Documents sccache setup, endpoint behavior, key rules, and storage limits.
Compiler cache storage and quota handling
pnpr/crates/shared-artifacts/src/*
Validates cache keys, stores immutable digest-prefixed entries, verifies reads, and reconciles quota and publication state.
Authorized compiler cache HTTP surface
pnpr/crates/pnpr/src/server/*
Adds GET, PUT, HEAD, and PROPFIND handling with authorization, body limits, key validation, upload concurrency limits, and cache-control headers.
Endpoint and sccache integration tests
pnpr/crates/pnpr/src/server/tests/*, pnpr/crates/shared-artifacts/src/tests.rs
Tests authorization, limits, disabled caches, HTTP responses, quota handling, and sccache reuse across CI and developer checkouts.
Tooling and shared diagnostic support
.github/workflows/*, justfile, pnpm/CONTRIBUTING.md, cspell.json, pnpm/crates/testing-utils/*, pnpm/crates/cli/tests/suite/*
Installs pinned sccache versions, updates spelling and setup documentation, and centralizes diagnostic assertions.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: ⚪ Minimal · up to c7494

This adds an experimental authenticated sccache WebDAV backend with bounded uploads, quota handling, and integrity checks. The supplied validation and test coverage support merge readiness with no concrete unresolved current-head risk.

Suggested labels: product: pacquet, product: pnpr

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch side-eff

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Add shared Cargo compilation caches to pnpr

✨ Enhancement 🧪 Tests 📝 Documentation ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Adds authenticated WebDAV compiler caches for sharing sccache results across CI and developers.
• Enforces reader/publisher policies, immutable entries, integrity verification, size limits, and
 shared quotas.
• Documents operational constraints and validates behavior with HTTP, storage, and real Cargo tests.
Diagram

sequenceDiagram
    actor CI as CI Builder
    actor Dev as Developer
    participant SCC as sccache
    participant Router as pnpr Router
    participant Policy as Access Policy
    participant Store as Artifact Store
    participant Quota as Quota Ledger
    CI->>SCC: Cargo compile miss
    SCC->>Router: PUT cache entry
    Router->>Policy: Authenticate publisher
    Policy-->>Router: Publication allowed
    Router->>Quota: Reserve bytes
    Router->>Store: Create immutable entry
    Store-->>Router: Entry created
    Router->>Quota: Commit usage
    Dev->>SCC: Cargo build
    SCC->>Router: GET cache entry
    Router->>Policy: Authorize reader
    Policy-->>Router: Read allowed
    Router->>Store: Read and verify digest
    Store-->>Router: Compiled bytes
    Router-->>SCC: Remote cache hit
    SCC-->>Dev: Backfill local cache
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use sccache's native S3 backend
  • ➕ Avoids implementing and maintaining a WebDAV compatibility surface.
  • ➕ Allows clients to communicate directly with object storage.
  • ➖ Requires distributing cloud credentials or building separate credential brokering.
  • ➖ Bypasses pnpr account policies, token restrictions, quotas, and publication lifecycle.
  • ➖ Couples developers and CI directly to a specific storage provider.
2. Deploy a dedicated cache service
  • ➕ Separates compiler-cache traffic and scaling from the package registry.
  • ➕ Could provide eviction and cache-specific observability independently.
  • ➖ Introduces another service, authentication system, and operational deployment.
  • ➖ Duplicates pnpr's existing filesystem/S3 abstraction, quotas, and access controls.
  • ➖ Makes unified account and token policy enforcement more difficult.

Recommendation: The PR's WebDAV adapter over the existing artifact store is the best fit for an experimental integration: it supports stock sccache while reusing pnpr authentication, policy, storage, quota, and reclamation infrastructure. Native S3 or a dedicated service may be appropriate at larger scale, but both add credential or operational complexity before usage patterns justify it.

Files changed (25) +1009 / -54

Enhancement (6) +346 / -14
lib.rsParse compiler-cache access policies +40/-5

Parse compiler-cache access policies

• Adds named compiler caches under 'artifacts.compilerCaches', validates cache names, and resolves required read and publication access specifications. Policies remain available even when artifact routes are disabled by an override.

pnpr/crates/config/src/lib.rs

server.rsRegister the compiler-cache server module +1/-0

Register the compiler-cache server module

• Adds the compiler-cache implementation to the pnpr server module tree.

pnpr/crates/pnpr/src/server.rs

compiler_cache.rsImplement authenticated sccache WebDAV handlers +138/-0

Implement authenticated sccache WebDAV handlers

• Implements GET, PUT, and virtual collection PROPFIND behavior with key validation, private cache headers, and separate read/publication authorization. Unauthorized writes are rejected before request bodies are buffered.

pnpr/crates/pnpr/src/server/compiler_cache.rs

routing.rsExpose compiler-cache WebDAV routes +23/-8

Expose compiler-cache WebDAV routes

• Registers artifact-gated compiler-cache routes, supported methods, authorization middleware, and the 256 MiB request-body limit.

pnpr/crates/pnpr/src/server/routing.rs

compiler_cache.rsPersist immutable, integrity-bound compiler entries +130/-0

Persist immutable, integrity-bound compiler entries

• Adds validated compiler keys and quota-managed publication into the existing artifact backend. Entries are namespaced, first-writer-wins, capped at 256 MiB, and verified with a scope/key/content SHA-512 digest before serving.

pnpr/crates/shared-artifacts/src/compiler_cache.rs

lib.rsIntegrate compiler caches with artifact publication lifecycle +14/-1

Integrate compiler caches with artifact publication lifecycle

• Exports compiler-cache APIs and extracts shared publication completion and reclamation handling for both side effects and compiler entries.

pnpr/crates/shared-artifacts/src/lib.rs

Tests (6) +350 / -6
global_shims.rsUse shared diagnostic assertions for shim tests +2/-4

Use shared diagnostic assertions for shim tests

• Replaces direct wrapped-text matching with the common miette-aware diagnostic assertion helper.

pnpm/crates/cli/tests/suite/global_shims.rs

tests.rsValidate compiler-cache policy configuration +32/-0

Validate compiler-cache policy configuration

• Tests reader/publisher separation, anonymous denial, empty policies, invalid names, incomplete declarations, unsupported teams, and unknown fields.

pnpr/crates/config/src/tests.rs

tests.rsRegister compiler-cache server tests +2/-0

Register compiler-cache server tests

• Adds the compiler-cache test module to the pnpr server test suite.

pnpr/crates/pnpr/src/server/tests.rs

compiler_cache.rsTest compiler-cache HTTP policy and protocol behavior +149/-0

Test compiler-cache HTTP policy and protocol behavior

• Covers publishing, reading, HEAD behavior, immutability, authorization, token restrictions, undeclared caches, invalid keys, and upload limits. It also verifies unauthorized bodies are not consumed.

pnpr/crates/pnpr/src/server/tests/compiler_cache.rs

tests.rsTest compiler-cache storage guarantees +110/-0

Test compiler-cache storage guarantees

• Covers path validation, persistence, namespace isolation, concurrent immutable publication, quota accounting, retries, and rejection of corrupted or relocated objects.

pnpr/crates/shared-artifacts/src/compiler_cache/tests.rs

tests.rsTest shared quota and reclamation behavior +55/-2

Test shared quota and reclamation behavior

• Verifies compiler entries survive side-effect reclamation, share owner quota, and reconcile accounting when object-store writes fail before or after remote commit.

pnpr/crates/shared-artifacts/src/tests.rs

Documentation (3) +104 / -0
rust-compilation-cache.mdDeclare the pnpr compiler-cache feature release +5/-0

Declare the pnpr compiler-cache feature release

• Adds a minor pnpr changeset describing shared Cargo compilation caches and separate access policies.

.changeset/rust-compilation-cache.md

CONTRIBUTING.mdDocument compiler-cache test prerequisites +4/-0

Document compiler-cache test prerequisites

• Explains that pnpr compiler-cache tests require sccache and run isolated Cargo builds with separate daemons.

pnpm/CONTRIBUTING.md

README.mdDocument sccache WebDAV deployment and limitations +95/-0

Document sccache WebDAV deployment and limitations

• Documents configuration, credentials, local/remote cache behavior, matching build paths, trust requirements, quotas, immutability, supported methods, and sccache 0.17 limitations.

pnpr/crates/pnpr/README.md

Other (10) +209 / -34
pacquet-ci.ymlInstall sccache in Rust CI +1/-1

Install sccache in Rust CI

• Pins and installs sccache 0.17.0 alongside cargo-nextest so compiler-cache integration tests can run in CI.

.github/workflows/pacquet-ci.yml

pacquet-codecov.ymlInstall sccache in coverage CI +1/-1

Install sccache in coverage CI

• Adds the pinned sccache binary to the code coverage workflow's Rust tools.

.github/workflows/pacquet-codecov.yml

cspell.jsonRecognize compiler-cache terminology +5/-0

Recognize compiler-cache terminology

• Adds WebDAV, sccache, rustc, PROPFIND, and basedirs terminology to the spelling dictionary.

cspell.json

justfileInstall sccache during developer setup +1/-1

Install sccache during developer setup

• Adds pinned sccache 0.17.0 installation to the local initialization recipe.

justfile

package_manager_check.rsDeduplicate diagnostic normalization helpers +4/-15

Deduplicate diagnostic normalization helpers

• Uses the shared diagnostic assertion utility instead of maintaining local normalization functions.

pnpm/crates/cli/tests/suite/package_manager_check.rs

workspace_settings_check.rsShare wrapped-diagnostic matching logic +3/-15

Share wrapped-diagnostic matching logic

• Replaces duplicated miette normalization code with the reusable testing utility.

pnpm/crates/cli/tests/suite/workspace_settings_check.rs

diagnostics.rsAdd miette-aware diagnostic assertion helper +11/-0

Add miette-aware diagnostic assertion helper

• Introduces an assertion that normalizes continuation bars and whitespace before matching diagnostic text.

pnpm/crates/testing-utils/src/diagnostics.rs

lib.rsExport diagnostic testing utilities +1/-0

Export diagnostic testing utilities

• Exposes the new diagnostics module to test suites.

pnpm/crates/testing-utils/src/lib.rs

config.yamlShow named compiler-cache configuration +5/-1

Show named compiler-cache configuration

• Extends the sample artifact configuration with a named cache and distinct reader and publisher accounts.

pnpr/crates/config/config.yaml

cargo.rsVerify cache reuse with real Cargo and sccache +177/-0

Verify cache reuse with real Cargo and sccache

• Runs isolated sccache daemons and Cargo builds to verify CI publication, fresh developer remote hits, feature/source invalidation, and offline disk backfill. The test waits for asynchronous remote writes before stopping the CI fixture.

pnpr/crates/pnpr/src/server/tests/compiler_cache/cargo.rs

@qodo-code-review

qodo-code-review Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Parallel uploads can exhaust memory ✓ Resolved 🐞 Bug ➹ Performance
Description
publish_compiler_cache copies the already-buffered Bytes request into a second allocation of up
to 256 MiB before passing it to the object store. Because body buffering happens before quota
reservation and requests have no concurrency or aggregate-memory bound, parallel CI uploads—or
repeated over-quota uploads from one authorized publisher—can consume hundreds of MiB each and
terminate pnpr.
Code

pnpr/crates/shared-artifacts/src/compiler_cache.rs[R71-74]

+                let mut stored = Vec::with_capacity(size as usize);
+                stored.extend_from_slice(&compiler_cache_digest(&owner, key, &bytes));
+                stored.extend_from_slice(&bytes);
+                let created = self.create_object(&path, stored).await?;
Relevance

●● Moderate

Memory-allocation concerns have mixed outcomes; similar eager full-buffering feedback was recently
rejected.

PR-#12922
PR-#14222

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The route accepts entries up to 256 MiB into a Bytes extractor, while publication allocates a
Vec sized for the complete payload plus digest and copies the payload into it. The store's 1 GiB
owner quota is reserved only after extraction, so it cannot prevent many request bodies from
residing in memory concurrently.

pnpr/crates/pnpr/src/server/compiler_cache.rs[39-52]
pnpr/crates/pnpr/src/server/routing.rs[154-166]
pnpr/crates/shared-artifacts/src/compiler_cache.rs[12-12]
pnpr/crates/shared-artifacts/src/compiler_cache.rs[60-74]
pnpr/crates/shared-artifacts/src/lib.rs[36-38]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Compiler-cache PUT requests buffer as much as 256 MiB in Axum and then allocate and copy the entire entry again when constructing the digest-prefixed object. Quota checks do not limit the number of request bodies buffered concurrently, so normal parallel compilation or an authorized client can exhaust pnpr's memory.

## Issue Context
The per-owner quota is 1 GiB, but it is enforced only after request extraction; rejected and concurrent requests therefore still consume their full request buffers. Preserve immutable creation, digest verification, and quota accounting while imposing a safe aggregate memory bound, streaming/spooling entries, or otherwise avoiding the second full-size allocation.

## Fix Focus Areas
- pnpr/crates/pnpr/src/server/compiler_cache.rs[39-52]
- pnpr/crates/pnpr/src/server/routing.rs[154-166]
- pnpr/crates/shared-artifacts/src/compiler_cache.rs[43-83]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Two stalled uploads block all writers 🐞 Bug ☼ Reliability ⭐ New
Description
authorize_request acquires one of only two permits before body extraction and holds it until
next.run completes, without imposing a body-read deadline. An authorized publisher can leave two
PUT bodies open indefinitely, causing every legitimate compiler-cache upload on that server to
receive HTTP 503 until those connections are cancelled.
Code

pnpr/crates/pnpr/src/server/compiler_cache.rs[R108-110]

+    let _upload = if request.method() == Method::PUT {
+        match state.inner.compiler_cache_uploads.try_acquire() {
+            Ok(permit) => Some(permit),
Relevance

●●● Strong

Recent reviews accept concrete resource-exhaustion fixes involving bounded concurrency and stalled
request handling.

PR-#14222
PR-#14544

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The middleware holds the semaphore permit across next.run(request).await. The new test creates two
bodies whose streams remain permanently pending, observes that a third upload receives 503, and only
restores capacity by explicitly aborting both tasks, directly demonstrating the indefinite
server-wide writer blockage.

pnpr/crates/pnpr/src/server/compiler_cache.rs[108-120]
pnpr/crates/pnpr/src/server/tests/compiler_cache.rs[22-60]
pnpr/crates/pnpr/src/server/routing.rs[157-168]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Compiler-cache upload permits can be held indefinitely by request bodies that never finish, blocking all subsequent writers with HTTP 503.

## Issue Context
The server has two upload permits and holds each permit across downstream body extraction. The concurrency test demonstrates that permanently pending bodies retain both permits until the tasks are explicitly cancelled.

## Fix Focus Areas
- pnpr/crates/pnpr/src/server/compiler_cache.rs[108-120]
- pnpr/crates/pnpr/src/server/routing.rs[159-168]
- pnpr/crates/pnpr/src/server/tests/compiler_cache.rs[16-62]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Cache probes download entire entries ✓ Resolved 🐞 Bug ➹ Performance
Description
read handles HEAD through read_compiler_cache, which fetches the complete stored object and
computes its content digest even though Axum discards the response body. For cache entries up to 256
MiB, each metadata probe incurs a full object-store transfer, allocation, and hash operation, making
routine or repeated probes unnecessarily expensive.
Code

pnpr/crates/pnpr/src/server/compiler_cache.rs[R24-27]

+            .as_ref()
+            .expect("compiler cache routes require an artifact store")
+            .read_compiler_cache(&cache, &key)
+            .await
Relevance

●●● Strong

Recent accepted precedent flags full object downloads and buffering in artifact reads, including
redundant GETs.

PR-#14222

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Axum's GET route also services HEAD, and the new test confirms that HEAD reaches this endpoint. The
invoked storage method calls read_object_bounded, whose implementation obtains all object bytes
and converts them to a Vec, after which read_compiler_cache hashes the complete payload before
returning it.

pnpr/crates/pnpr/src/server/routing.rs[154-166]
pnpr/crates/pnpr/src/server/tests/compiler_cache.rs[75-79]
pnpr/crates/shared-artifacts/src/compiler_cache.rs[88-109]
pnpr/crates/shared-artifacts/src/lib.rs[1463-1473]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
HEAD requests currently execute the same full-read and integrity-verification path as GET requests. This downloads, allocates, and hashes as much as 256 MiB solely to return headers.

## Issue Context
Add a dedicated HEAD path backed by object metadata and return the payload length after accounting for the stored digest prefix. Keep GET's full integrity verification unchanged, and preserve authorization and private cache-control headers.

## Fix Focus Areas
- pnpr/crates/pnpr/src/server/routing.rs[154-166]
- pnpr/crates/pnpr/src/server/compiler_cache.rs[15-37]
- pnpr/crates/shared-artifacts/src/compiler_cache.rs[86-110]
- pnpr/crates/shared-artifacts/src/lib.rs[1463-1473]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

4. Cache uploads add avoidable latency ✓ Resolved 🐞 Bug ➹ Performance
Description
publish_compiler_cache calls read_compiler_cache before issuing its conditional create_object
write, even though create_object already reports an existing object as Ok(false). Every newly
compiled cache entry therefore adds a remote read before its upload, and retries for an existing
large entry download and buffer that entry merely to return an idempotent success.
Code

pnpr/crates/shared-artifacts/src/compiler_cache.rs[54]

+        if self.read_compiler_cache(cache, key).await?.is_some() {
Relevance

● Weak

Recent precedent rejected avoiding full existing-object downloads during immutable publication
conflict checks.

PR-#14310

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The added existence check invokes the read path before every publication. That read path uses
store.get and materializes the whole object, while the subsequent create uses PutMode::Create
and explicitly converts an existing-object conflict to Ok(false), so it can provide the same
immutable-write decision without the preliminary payload read.

pnpr/crates/shared-artifacts/src/compiler_cache.rs[52-75]
pnpr/crates/shared-artifacts/src/compiler_cache.rs[92-109]
pnpr/crates/shared-artifacts/src/lib.rs[1447-1473]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Remove the pre-write `read_compiler_cache` existence check from compiler-cache publication, or replace it with a metadata-only check if preserving the quota fast path is required. The existing conditional create already safely implements first-writer-wins semantics.

## Issue Context
`read_compiler_cache` fully fetches and verifies the stored object. As a result, duplicate PUTs can transfer up to the full 256 MiB entry before the endpoint responds that the immutable key already exists, while cache misses always make an unnecessary extra object-store request.

## Fix Focus Areas
- pnpr/crates/shared-artifacts/src/compiler_cache.rs[52-75]
- pnpr/crates/shared-artifacts/src/lib.rs[1447-1460]
- pnpr/crates/shared-artifacts/src/lib.rs[1463-1473]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Compliance rules (platform): 46 rules
Review mode: ⚖️ Balanced: This push changes security-sensitive compiler-cache authorization, integrity verification, storage publication, and upload concurrency across multiple paths, warranting a complete single-pass review but not redundant extended passes.

Grey Divider

Tip of the day
💡 Did you know, you can show, collapse, or hide each part of a finding: code, evidence, and all

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous reviews

Review updated until commit c7494d7

Results up to commit 5fbf89a 🧠 Deep


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required
1. Parallel uploads can exhaust memory ✓ Resolved 🐞 Bug ➹ Performance
Description
publish_compiler_cache copies the already-buffered Bytes request into a second allocation of up
to 256 MiB before passing it to the object store. Because body buffering happens before quota
reservation and requests have no concurrency or aggregate-memory bound, parallel CI uploads—or
repeated over-quota uploads from one authorized publisher—can consume hundreds of MiB each and
terminate pnpr.
Code

pnpr/crates/shared-artifacts/src/compiler_cache.rs[R71-74]

+                let mut stored = Vec::with_capacity(size as usize);
+                stored.extend_from_slice(&compiler_cache_digest(&owner, key, &bytes));
+                stored.extend_from_slice(&bytes);
+                let created = self.create_object(&path, stored).await?;
Relevance

●● Moderate

Memory-allocation concerns have mixed outcomes; similar eager full-buffering feedback was recently
rejected.

PR-#12922
PR-#14222

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The route accepts entries up to 256 MiB into a Bytes extractor, while publication allocates a
Vec sized for the complete payload plus digest and copies the payload into it. The store's 1 GiB
owner quota is reserved only after extraction, so it cannot prevent many request bodies from
residing in memory concurrently.

pnpr/crates/pnpr/src/server/compiler_cache.rs[39-52]
pnpr/crates/pnpr/src/server/routing.rs[154-166]
pnpr/crates/shared-artifacts/src/compiler_cache.rs[12-12]
pnpr/crates/shared-artifacts/src/compiler_cache.rs[60-74]
pnpr/crates/shared-artifacts/src/lib.rs[36-38]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Compiler-cache PUT requests buffer as much as 256 MiB in Axum and then allocate and copy the entire entry again when constructing the digest-prefixed object. Quota checks do not limit the number of request bodies buffered concurrently, so normal parallel compilation or an authorized client can exhaust pnpr's memory.

## Issue Context
The per-owner quota is 1 GiB, but it is enforced only after request extraction; rejected and concurrent requests therefore still consume their full request buffers. Preserve immutable creation, digest verification, and quota accounting while imposing a safe aggregate memory bound, streaming/spooling entries, or otherwise avoiding the second full-size allocation.

## Fix Focus Areas
- pnpr/crates/pnpr/src/server/compiler_cache.rs[39-52]
- pnpr/crates/pnpr/src/server/routing.rs[154-166]
- pnpr/crates/shared-artifacts/src/compiler_cache.rs[43-83]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. Cache probes download entire entries ✓ Resolved 🐞 Bug ➹ Performance
Description
read handles HEAD through read_compiler_cache, which fetches the complete stored object and
computes its content digest even though Axum discards the response body. For cache entries up to 256
MiB, each metadata probe incurs a full object-store transfer, allocation, and hash operation, making
routine or repeated probes unnecessarily expensive.
Code

pnpr/crates/pnpr/src/server/compiler_cache.rs[R24-27]

+            .as_ref()
+            .expect("compiler cache routes require an artifact store")
+            .read_compiler_cache(&cache, &key)
+            .await
Relevance

●●● Strong

Recent accepted precedent flags full object downloads and buffering in artifact reads, including
redundant GETs.

PR-#14222

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Axum's GET route also services HEAD, and the new test confirms that HEAD reaches this endpoint. The
invoked storage method calls read_object_bounded, whose implementation obtains all object bytes
and converts them to a Vec, after which read_compiler_cache hashes the complete payload before
returning it.

pnpr/crates/pnpr/src/server/routing.rs[154-166]
pnpr/crates/pnpr/src/server/tests/compiler_cache.rs[75-79]
pnpr/crates/shared-artifacts/src/compiler_cache.rs[88-109]
pnpr/crates/shared-artifacts/src/lib.rs[1463-1473]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
HEAD requests currently execute the same full-read and integrity-verification path as GET requests. This downloads, allocates, and hashes as much as 256 MiB solely to return headers.

## Issue Context
Add a dedicated HEAD path backed by object metadata and return the payload length after accounting for the stored digest prefix. Keep GET's full integrity verification unchanged, and preserve authorization and private cache-control headers.

## Fix Focus Areas
- pnpr/crates/pnpr/src/server/routing.rs[154-166]
- pnpr/crates/pnpr/src/server/compiler_cache.rs[15-37]
- pnpr/crates/shared-artifacts/src/compiler_cache.rs[86-110]
- pnpr/crates/shared-artifacts/src/lib.rs[1463-1473]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational
3. Cache uploads add avoidable latency ✓ Resolved 🐞 Bug ➹ Performance
Description
publish_compiler_cache calls read_compiler_cache before issuing its conditional create_object
write, even though create_object already reports an existing object as Ok(false). Every newly
compiled cache entry therefore adds a remote read before its upload, and retries for an existing
large entry download and buffer that entry merely to return an idempotent success.
Code

pnpr/crates/shared-artifacts/src/compiler_cache.rs[54]

+        if self.read_compiler_cache(cache, key).await?.is_some() {
Relevance

● Weak

Recent precedent rejected avoiding full existing-object downloads during immutable publication
conflict checks.

PR-#14310

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The added existence check invokes the read path before every publication. That read path uses
store.get and materializes the whole object, while the subsequent create uses PutMode::Create
and explicitly converts an existing-object conflict to Ok(false), so it can provide the same
immutable-write decision without the preliminary payload read.

pnpr/crates/shared-artifacts/src/compiler_cache.rs[52-75]
pnpr/crates/shared-artifacts/src/compiler_cache.rs[92-109]
pnpr/crates/shared-artifacts/src/lib.rs[1447-1473]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Remove the pre-write `read_compiler_cache` existence check from compiler-cache publication, or replace it with a metadata-only check if preserving the quota fast path is required. The existing conditional create already safely implements first-writer-wins semantics.

## Issue Context
`read_compiler_cache` fully fetches and verifies the stored object. As a result, duplicate PUTs can transfer up to the full 256 MiB entry before the endpoint responds that the immutable key already exists, while cache misses always make an unnecessary extra object-store request.

## Fix Focus Areas
- pnpr/crates/shared-artifacts/src/compiler_cache.rs[52-75]
- pnpr/crates/shared-artifacts/src/lib.rs[1447-1460]
- pnpr/crates/shared-artifacts/src/lib.rs[1463-1473]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@greptile-apps

greptile-apps Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

The PR should not merge until replacement uploads stop reporting success while a corrupt, unreadable cache entry remains stored.

Metadata-only duplicate detection accepts a valid replacement upload without repairing an existing object that fails integrity verification, leaving the cache key unusable while signaling success to the publisher. The two previous threads were manually resolved without explanatory replies; the diagnostic comment was removed, and compiler upload buffering is now bounded by a semaphore.

Files Needing Attention: pnpr/crates/shared-artifacts/src/compiler_cache.rs

Reviews (2): Last reviewed commit: "fix(pnpr): bound compiler cache upload m..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     11.4±0.06ms    32.7 MB/sec    1.06     12.1±0.07ms    30.9 MB/sec
packument/parse                                  1.04     39.4±0.09µs  1683.1 MB/sec    1.00     38.0±0.32µs  1747.1 MB/sec
tarball/download_dependency                      1.00      3.7±0.09ms  1174.5 KB/sec    1.08      4.0±0.37ms  1088.0 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.01    182.4±2.40ms 87.7 KElem/sec    1.00    181.3±1.02ms 88.3 KElem/sec
workspace_resolution/hoist_heavy                 1.00    239.0±6.87ms        ? ?/sec    1.03    245.0±0.90ms        ? ?/sec
workspace_sort/chained_projects                  1.00     14.1±0.56ms        ? ?/sec    1.01     14.3±0.76ms        ? ?/sec

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Sep 6, 2026
@codecov-commenter

codecov-commenter commented Sep 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.05263% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.30%. Comparing base (eb01846) to head (c7494d7).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pnpr/crates/pnpr/src/server/compiler_cache.rs 93.57% 9 Missing ⚠️
pnpr/crates/shared-artifacts/src/compiler_cache.rs 97.19% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14620      +/-   ##
==========================================
+ Coverage   89.28%   89.30%   +0.01%     
==========================================
  Files         754      757       +3     
  Lines      135070   135403     +333     
==========================================
+ Hits       120592   120916     +324     
- Misses      14478    14487       +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit c7494d7

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@zkochan
zkochan merged commit 6ba99fb into main Sep 6, 2026
45 checks passed
@zkochan
zkochan deleted the side-eff branch September 6, 2026 13:35
@qodo-code-review qodo-code-review Bot mentioned this pull request Sep 6, 2026
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet product: pnpr reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants