Skip to content

refactor(pnpr): put SQL metadata behind a database adapter - #17577

Merged
zkochan merged 4 commits into
mainfrom
pnpr/sql-metadata-adapters
Nov 3, 2026
Merged

zkochan merged 4 commits into
mainfrom
pnpr/sql-metadata-adapters

Conversation

@zkochan

@zkochan zkochan commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

First of a stack that adds shared SQL metadata backends to pnpr, as designed in pnpm/rfcs#66 ("Backend adapters" and "Shared deployments"). Task list: pnpm/tasks#244.

This PR changes no behavior. It splits the SQLite metadata backend into a shared SQL layer and an Adapter trait, so the libSQL adapter later in the stack runs the same schema and queries.

  • Shared layer (metadata/sql/): schema, queries, removed-version refusal, generations, publication outcomes, release notes, render caches. It runs every statement through Connection with ?N placeholders and owned Param/Value types.
  • Adapter trait (metadata/sql/adapter.rs) supplies what differs: connections (one writer, readers that never wait for it), the begin statements for write and read transactions (BEGIN IMMEDIATE / BEGIN on SQLite), which errors are retryable conflicts, placeholder and type translation in its Connection, and where a read runs (ReadSource::Primary or Replica).
  • SqliteAdapter (metadata/sql/sqlite.rs) is the existing connection handling, moved.
  • Each operation names the freshness it needs: Current for reads that decide a write or answer a retry (read-for-update, recorded outcomes, catalog generation), Bounded for views and listings. SQLite reads its one database either way.

Queries now stay in the subset SQLite, libSQL and PostgreSQL share. INSERT OR IGNORE became ON CONFLICT DO NOTHING. Removals delete rows explicitly instead of relying on a per-connection foreign_keys cascade. A taken publication name is found by a lookup inside the write transaction instead of by decoding a SQLite constraint error.

Stack:

  1. this PR: adapter split
  2. metadata.url config, SQLite by default
  3. libSQL connection code moved out of pnpr-auth
  4. libSQL metadata adapter
  5. conformance suite over every adapter

Squash Commit Body

Split the SQLite metadata backend into a shared SQL layer and an adapter
per database, as pnpm/rfcs#66 describes under "Backend adapters". The
shared layer keeps the schema, the queries, removed-version refusal,
generations, publication outcomes, release notes, and the render caches.
The `Adapter` trait supplies what differs between databases: connections,
the statements that begin a write or a read transaction, which errors are
conflicts a rerun of the whole transaction clears, placeholders and types
(translated by its `Connection`), and where a read runs, the primary or a
replica.

The shared layer stays synchronous on the blocking pool and runs every
statement through `Connection` with `?N` placeholders and owned
`Param`/`Value` types. Each operation names the freshness it needs:
`Current` for reads that decide a write or answer a retry, `Bounded` for
views. SQLite reads its one database either way.

Queries stay in the subset SQLite, libSQL, and PostgreSQL share:
`INSERT OR IGNORE` became `ON CONFLICT DO NOTHING`, removals delete rows
explicitly instead of relying on a per-connection foreign-key cascade, and
a taken publication name is found by a lookup inside the write
transaction. A write that the adapter reports as a conflict (SQLITE_BUSY
or SQLITE_LOCKED) runs again from its start, up to four times. Every read
runs in one read transaction.

`SqliteMetadata` is renamed `SqlMetadata` (opened with `open_sqlite`), and
`Storage::sqlite_metadata` is `Storage::sql_metadata`.

Related to pnpm/tasks#244.

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • Added or updated tests.

Tests: pnpm test:rust over every pnpr-* crate plus pnpm-registry-mock (1802 passed). The existing SQLite metadata tests pass with renames only. The test that held the write connection now holds it through the adapter. New tests cover the SQLite conflict classification, a failed COMMIT being rolled back, and a writer or reader left inside a transaction not being reused as one. No changeset: nothing a pnpr user sees changes.

Written by an agent (Claude Code, claude-opus-5-5).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements
    • Notes, publications, package metadata, and tag operations retain their existing behavior with SQLite-backed storage.
    • Improved resilience during concurrent writes by retrying temporary database conflicts.
    • Some reads can use replica data when appropriate, while write-related decisions continue to use current data.

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 3ec74f7 and cc9b1db.

Files selected for processing: 3
  • pnpr/crates/storage/src/metadata/sql/batch.rs
  • pnpr/crates/storage/src/metadata/sql/sqlite.rs
  • pnpr/crates/storage/src/metadata/sql/tests/concurrency.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

Walkthrough

The change adds a shared SQL adapter interface and moves SQLite connection handling into a SQLite adapter. Metadata operations and callers now use SqlMetadata and sql_metadata(). Reads select freshness levels, and writes retry adapter-reported conflicts.

Changes: SQL Metadata Adapter

Layer / File(s) Summary
Adapter contracts and SQLite backend
pnpr/crates/storage/src/metadata/sql/adapter.rs, params.rs, sqlite.rs, tests/concurrency.rs
Adds shared connection, adapter, parameter, and row interfaces. Implements them for SQLite and adds tests for retryable errors and transaction cleanup.
SQL metadata lifecycle and read freshness
pnpr/crates/storage/src/metadata.rs, pnpr/crates/storage/src/metadata/sql.rs, schema.rs
Renames the metadata facade and accessor. Routes reads and writes through the adapter, applies freshness and retry rules, and prepares the schema in an adapter transaction.
Transactional metadata operations and queries
pnpr/crates/storage/src/metadata/sql/{batch,commit,notes,publications,publish,render,tags,versions}.rs, tests.rs, tests/notes.rs, tests/publications.rs
Moves batch, package, note, publication, rendering, tag, and version operations to adapter connections. Updates deletion behavior and related tests.
Server and storage API callers
pnpr/crates/pnpr/src/server/{notes,publications,publishing}.rs, publishing/{atomic,notes}.rs, pnpr/crates/storage/src/journal/tests.rs
Updates server handlers and a journal test to use SqlMetadata and sql_metadata(). The described unavailable-storage outcomes remain unchanged.

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

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant SqlMetadata
  participant Adapter
  participant SQLiteConnection
  SqlMetadata->>Adapter: run read or write operation
  Adapter->>SQLiteConnection: begin transaction and execute queries
  SQLiteConnection-->>Adapter: rows or operation result
  Adapter-->>SqlMetadata: result
Loading

Possibly related PRs

  • pnpm/pnpm#17551: Introduces the SQLite metadata backend that this change refactors behind the shared SQL adapter.
  • pnpm/pnpm#17553: Adds atomic publication commits and outcome lookups that this change moves behind the adapter.
  • pnpm/pnpm#17552: Adds archive-manifest records in SQLite metadata, which this change updates to use adapter connections.

Suggested labels: product: pnpr

Suggested reviewers: qodo-code-review

Merge Risk: Minimal · up to cc9b1

No material new merge-blocking risk was identified.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Same-run regression check

HEAD and main are measured on the same runner. The tolerance is 5% of the main median or 2 ms, whichever is larger. A regression requires both the median slowdown and the gap between the fastest retained HEAD sample and slowest retained main sample to exceed this tolerance, after trimming up to 10% from each tail. Suspected regressions are rerun once with target order reversed and only fail if reproduced. This conservative noise guard is not a statistical confidence interval.

Inconclusive rows do not fail the check. They remain visible for performance review. Bencher retains absolute minimum timings for historical tracking; historical alerts do not gate this PR. Sequential measurements can still be affected by runner drift.

Scenario Engine main median HEAD median Change Tolerance Result
isolated-fresh-restore-cold-cache-cold-store pacquet 2450.53 ms 2414.10 ms -1.5% 122.53 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store pnpr 1459.30 ms 1477.08 ms 1.2% 72.96 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pacquet 222.39 ms 232.31 ms 4.5% 11.12 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pnpr 241.19 ms 229.64 ms -4.8% 12.06 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pacquet 11.31 ms 11.29 ms -0.3% 2.00 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pnpr 11.39 ms 11.40 ms 0.1% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pacquet 8.11 ms 9.34 ms 15.2% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pnpr 7.43 ms 7.92 ms 6.6% 2.00 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pacquet 2601.54 ms 2667.28 ms 2.5% 130.08 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pnpr 1554.73 ms 1529.06 ms -1.7% 77.74 ms Within tolerance
isolated-fresh-install-hot-cache-hot-store pacquet 609.05 ms 657.48 ms 8.0% 30.45 ms Inconclusive (overlapping samples)
isolated-fresh-install-hot-cache-hot-store pnpr 350.80 ms 349.68 ms -0.3% 17.54 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pacquet 1577.41 ms 1570.02 ms -0.5% 78.87 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pnpr 260.22 ms 259.78 ms -0.2% 13.01 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pacquet 378.91 ms 357.27 ms -5.7% 18.95 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pnpr 106.77 ms 120.70 ms 13.1% 5.34 ms Inconclusive (overlapping samples)
isolated-peer-heavy-resolve-hot-cache-offline pacquet 259.49 ms 302.24 ms 16.5% 12.97 ms Inconclusive (overlapping samples)
isolated-linked-workspace-resolve-hot-cache-offline pacquet 87.06 ms 86.85 ms -0.2% 4.35 ms Within tolerance
isolated-injected-workspace-repeat-install-hot-cache-hot-store pacquet 113.47 ms 131.92 ms 16.3% 5.67 ms Inconclusive (overlapping samples)
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pacquet 4550.72 ms 4622.43 ms 1.6% 227.54 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pnpr 3558.78 ms 3515.53 ms -1.2% 177.94 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pacquet 141.09 ms 154.38 ms 9.4% 7.05 ms Inconclusive (overlapping samples)
gvs-fresh-restore-hot-cache-hot-store pnpr 181.38 ms 164.98 ms -9.0% 9.07 ms Within tolerance
store-only-unlocked-direct-deps-cold-cache-hot-store pacquet 1263.60 ms 1323.06 ms 4.7% 63.18 ms Within tolerance
cargo-repeat-install-hot-cache-hot-store pacquet 30.35 ms 31.75 ms 4.6% 2.00 ms Within tolerance

Same-run syscall check

Each install runs 2 more times per revision, untimed, under strace --follow-forks --summary-only. A file syscall regresses when HEAD's fewest calls exceed main's most by more than 2% of main or 50 calls, whichever is larger. mkdir and mkdirat count only the calls that created a directory, since concurrent installs fail a varying number with EEXIST. A syscall whose identical runs differ by more than that tolerance is reported unstable and not gated, unless HEAD's fewest calls also exceed main's most by more than the tolerance plus that difference. Each scenario lists its largest change relative to its tolerance and every row that is not within tolerance.

Scenario Engine Syscall main calls (max) HEAD calls (min) Change Tolerance Identical-run spread Result
isolated-fresh-restore-cold-cache-cold-store pacquet access 11 11 +0.0% 50 0 Within tolerance
isolated-fresh-restore-cold-cache-cold-store pnpr access 11 11 +0.0% 50 0 Within tolerance
isolated-fresh-restore-hot-cache-hot-store pacquet access 11 11 +0.0% 50 0 Within tolerance
isolated-fresh-restore-hot-cache-hot-store pnpr access 11 11 +0.0% 50 0 Within tolerance
isolated-repeat-install-hot-cache-hot-store pacquet access 8 8 +0.0% 50 0 Within tolerance
isolated-repeat-install-hot-cache-hot-store pnpr access 8 8 +0.0% 50 0 Within tolerance
isolated-repeat-install-cold-cache-hot-store pacquet access 8 8 +0.0% 50 0 Within tolerance
isolated-repeat-install-cold-cache-hot-store pnpr access 8 8 +0.0% 50 0 Within tolerance
isolated-fresh-install-cold-cache-cold-store pacquet access 11 11 +0.0% 50 0 Within tolerance
isolated-fresh-install-cold-cache-cold-store pacquet readlink 16808 16065 -4.4% 336 679 Unstable (identical runs differ by 679, not gated)
isolated-fresh-install-cold-cache-cold-store pnpr access 11 11 +0.0% 50 0 Within tolerance
isolated-fresh-install-hot-cache-hot-store pacquet access 11 11 +0.0% 50 0 Within tolerance
isolated-fresh-install-hot-cache-hot-store pnpr access 11 11 +0.0% 50 0 Within tolerance
isolated-fresh-install-cold-cache-hot-store pacquet access 11 11 +0.0% 50 0 Within tolerance
isolated-fresh-install-cold-cache-hot-store pacquet readlink 15946 15547 -2.5% 318 408 Unstable (identical runs differ by 408, not gated)
isolated-fresh-install-cold-cache-hot-store pnpr access 11 11 +0.0% 50 0 Within tolerance
isolated-fresh-resolve-hot-cache-offline pacquet access 8 8 +0.0% 50 0 Within tolerance
isolated-fresh-resolve-hot-cache-offline pnpr access 8 8 +0.0% 50 0 Within tolerance
isolated-peer-heavy-resolve-hot-cache-offline pacquet access 8 8 +0.0% 50 0 Within tolerance
isolated-linked-workspace-resolve-hot-cache-offline pacquet access 8 8 +0.0% 50 0 Within tolerance
isolated-injected-workspace-repeat-install-hot-cache-hot-store pacquet access 11 11 +0.0% 50 0 Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pacquet access 11 11 +0.0% 50 0 Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pnpr access 11 11 +0.0% 50 0 Within tolerance
gvs-fresh-restore-hot-cache-hot-store pacquet access 11 11 +0.0% 50 0 Within tolerance
gvs-fresh-restore-hot-cache-hot-store pnpr access 11 11 +0.0% 50 0 Within tolerance
store-only-unlocked-direct-deps-cold-cache-hot-store pacquet access 8 8 +0.0% 50 0 Within tolerance
cargo-repeat-install-hot-cache-hot-store pacquet access 22 22 +0.0% 50 0 Within tolerance

Integrated-Benchmark Report (Linux)

Commit: cc9b1dbf3d51

Compared against main at: 6f4bb3951ac4

Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm; the linked, injected, and Cargo workspace scenarios compare current Rust against main Rust. Bencher consumes pacquet@HEAD and pnpr@HEAD.

The tables below show mean ± σ. Bencher tracks absolute minimum latency; PR regression checks compare HEAD and main samples from the same runner. Historical timing alerts do not gate PRs.

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.470 ± 0.109 2.350 2.622 1.70 ± 0.13
pacquet@main 2.453 ± 0.163 2.233 2.730 1.69 ± 0.16
pnpr@HEAD 1.468 ± 0.123 1.285 1.666 1.01 ± 0.11
pnpr@main 1.454 ± 0.093 1.297 1.631 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.46991277068,
      "stddev": 0.10905136677377729,
      "median": 2.41409812968,
      "user": 2.54569542,
      "system": 1.7419095599999994,
      "min": 2.3500816051799998,
      "max": 2.62233891818
    },
    {
      "command": "pacquet@main",
      "mean": 2.4532615697799995,
      "stddev": 0.1632977961624998,
      "median": 2.45053211868,
      "user": 2.26352802,
      "system": 1.56507836,
      "min": 2.23312581718,
      "max": 2.72983447718
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.46804292918,
      "stddev": 0.12326899107896912,
      "median": 1.47707763518,
      "user": 2.15855332,
      "system": 1.5342725599999998,
      "min": 1.28546717518,
      "max": 1.66623905818
    },
    {
      "command": "pnpr@main",
      "mean": 1.45352928798,
      "stddev": 0.09282580148526151,
      "median": 1.45929943918,
      "user": 2.0809892199999998,
      "system": 1.4059588599999997,
      "min": 1.29709697618,
      "max": 1.63137609318
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 233.0 ± 11.7 216.3 254.6 1.04 ± 0.07
pacquet@main 223.4 ± 10.8 210.9 241.9 1.00
pnpr@HEAD 229.0 ± 9.1 212.3 239.8 1.03 ± 0.06
pnpr@main 241.6 ± 9.4 229.0 262.7 1.08 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.23295320896,
      "stddev": 0.011682568677800518,
      "median": 0.23231303976,
      "user": 0.26902297999999997,
      "system": 0.5944721599999999,
      "min": 0.21627362176,
      "max": 0.25463567776
    },
    {
      "command": "pacquet@main",
      "mean": 0.22337729345999996,
      "stddev": 0.010776652157402243,
      "median": 0.22238899526,
      "user": 0.27693668,
      "system": 0.55508976,
      "min": 0.21094325976,
      "max": 0.24189527276
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.22900020756,
      "stddev": 0.009135076560868807,
      "median": 0.22963962325999998,
      "user": 0.26377338,
      "system": 0.53815336,
      "min": 0.21232226576,
      "max": 0.23981765776
    },
    {
      "command": "pnpr@main",
      "mean": 0.24155896836,
      "stddev": 0.009397080028098224,
      "median": 0.24118629376,
      "user": 0.2756544799999999,
      "system": 0.57218456,
      "min": 0.22900455776,
      "max": 0.26274169176
    }
  ]
}

Scenario: Isolated linker: repeat install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 11.4 ± 1.2 8.4 15.2 1.00 ± 0.15
pacquet@main 11.4 ± 1.3 8.6 17.0 1.01 ± 0.16
pnpr@HEAD 11.3 ± 1.3 8.1 16.7 1.00
pnpr@main 11.4 ± 1.2 8.1 14.8 1.01 ± 0.15
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.011365137264388184,
      "stddev": 0.0011742063147172318,
      "median": 0.011285214180000001,
      "user": 0.00660221417721519,
      "system": 0.00583281637130802,
      "min": 0.00842196218,
      "max": 0.015185594180000003
    },
    {
      "command": "pacquet@main",
      "mean": 0.01142725579632653,
      "stddev": 0.0012845575070365033,
      "median": 0.01131485018,
      "user": 0.007156418775510207,
      "system": 0.0053567446530612284,
      "min": 0.008587241180000002,
      "max": 0.01703437318
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.011322000646346161,
      "stddev": 0.0012811337454043837,
      "median": 0.011402614680000001,
      "user": 0.006972302115384609,
      "system": 0.00537690576923077,
      "min": 0.008122307180000002,
      "max": 0.01668695218
    },
    {
      "command": "pnpr@main",
      "mean": 0.01143559327923664,
      "stddev": 0.0011533183069760346,
      "median": 0.01138776218,
      "user": 0.007255651755725191,
      "system": 0.0052399845801526755,
      "min": 0.008146073180000001,
      "max": 0.014773330180000002
    }
  ]
}

Scenario: Isolated linker: repeat install, cold cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 9.4 ± 0.7 7.8 12.4 1.26 ± 0.10
pacquet@main 8.2 ± 0.6 7.3 11.8 1.10 ± 0.09
pnpr@HEAD 8.0 ± 0.5 7.2 10.6 1.07 ± 0.08
pnpr@main 7.5 ± 0.3 7.0 9.7 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.009439243491755723,
      "stddev": 0.0006565028546893525,
      "median": 0.009342990320000001,
      "user": 0.005410358473282443,
      "system": 0.004769183358778625,
      "min": 0.00781030432,
      "max": 0.01244630432
    },
    {
      "command": "pacquet@main",
      "mean": 0.00823073467789474,
      "stddev": 0.0006118163980951226,
      "median": 0.00811009432,
      "user": 0.005119148070175438,
      "system": 0.0037590056140350864,
      "min": 0.007313263320000001,
      "max": 0.01181662732
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.008019535766945335,
      "stddev": 0.00045907247563838695,
      "median": 0.00791688432,
      "user": 0.0050302698392282975,
      "system": 0.0036620770418006408,
      "min": 0.0071769083200000005,
      "max": 0.01060355432
    },
    {
      "command": "pnpr@main",
      "mean": 0.007491864816774192,
      "stddev": 0.00030933162422905607,
      "median": 0.007428468320000001,
      "user": 0.004624190967741936,
      "system": 0.0035164940645161305,
      "min": 0.00696428832,
      "max": 0.00974336032
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.669 ± 0.054 2.587 2.742 1.72 ± 0.13
pacquet@main 2.609 ± 0.051 2.512 2.672 1.68 ± 0.13
pnpr@HEAD 1.554 ± 0.115 1.435 1.810 1.00
pnpr@main 1.581 ± 0.140 1.411 1.744 1.02 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.6686782418600004,
      "stddev": 0.05381825017739883,
      "median": 2.66727615916,
      "user": 2.8255332999999996,
      "system": 1.7952424999999999,
      "min": 2.58686717966,
      "max": 2.7420588726600004
    },
    {
      "command": "pacquet@main",
      "mean": 2.60855897996,
      "stddev": 0.05104408733492739,
      "median": 2.6015435616600002,
      "user": 2.7734805,
      "system": 1.6531683000000001,
      "min": 2.51177815466,
      "max": 2.6721570256600002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.55443227386,
      "stddev": 0.11469818868067823,
      "median": 1.52905634666,
      "user": 2.1276665999999995,
      "system": 1.5316707,
      "min": 1.43468776466,
      "max": 1.80953945966
    },
    {
      "command": "pnpr@main",
      "mean": 1.58148883146,
      "stddev": 0.13985628749762793,
      "median": 1.5547279236599998,
      "user": 1.9676766,
      "system": 1.4458986,
      "min": 1.4107431606599998,
      "max": 1.7439081946600001
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 648.9 ± 58.0 539.6 741.8 1.83 ± 0.19
pacquet@main 632.4 ± 56.1 575.8 751.4 1.78 ± 0.18
pnpr@HEAD 354.9 ± 17.8 325.6 384.3 1.00
pnpr@main 367.5 ± 47.1 336.9 490.9 1.04 ± 0.14
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6488724366800002,
      "stddev": 0.05802274230778738,
      "median": 0.65748126038,
      "user": 0.99226248,
      "system": 1.3944745599999997,
      "min": 0.53955455488,
      "max": 0.7417972258800001
    },
    {
      "command": "pacquet@main",
      "mean": 0.63243817198,
      "stddev": 0.056061979767179256,
      "median": 0.60905496588,
      "user": 0.97005208,
      "system": 1.35777246,
      "min": 0.57583663188,
      "max": 0.75137844488
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.35489084538000004,
      "stddev": 0.017833709992566466,
      "median": 0.34967811888,
      "user": 0.34465657999999993,
      "system": 0.67604446,
      "min": 0.32560639288000004,
      "max": 0.38425628288
    },
    {
      "command": "pnpr@main",
      "mean": 0.36745035218000005,
      "stddev": 0.0471097324161457,
      "median": 0.35080171788000003,
      "user": 0.39221087999999993,
      "system": 0.6985153599999999,
      "min": 0.33688278888,
      "max": 0.49094175488
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.567 ± 0.016 1.534 1.585 6.01 ± 0.19
pacquet@main 1.575 ± 0.017 1.548 1.602 6.04 ± 0.19
pnpr@HEAD 0.262 ± 0.014 0.249 0.295 1.01 ± 0.06
pnpr@main 0.261 ± 0.008 0.253 0.277 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.5668287293399998,
      "stddev": 0.015791223260863702,
      "median": 1.57001938084,
      "user": 0.7827694599999999,
      "system": 0.8185014199999999,
      "min": 1.53400961584,
      "max": 1.58472037984
    },
    {
      "command": "pacquet@main",
      "mean": 1.5747109057400002,
      "stddev": 0.016622229580601933,
      "median": 1.57741154634,
      "user": 0.7835807599999999,
      "system": 0.79339902,
      "min": 1.5478165338399998,
      "max": 1.60166674884
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.2622766509400001,
      "stddev": 0.013916269098758293,
      "median": 0.25977734884000003,
      "user": 0.23825225999999997,
      "system": 0.5109961199999999,
      "min": 0.24873007884000004,
      "max": 0.29534332384
    },
    {
      "command": "pnpr@main",
      "mean": 0.26068042594,
      "stddev": 0.007647909709102386,
      "median": 0.26021844334,
      "user": 0.25117406,
      "system": 0.49288621999999993,
      "min": 0.25301466284,
      "max": 0.27674165084
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 361.4 ± 32.4 307.8 419.2 3.38 ± 0.36
pacquet@main 377.1 ± 15.9 354.5 396.9 3.53 ± 0.26
pnpr@HEAD 117.7 ± 9.4 95.5 131.5 1.10 ± 0.11
pnpr@main 106.9 ± 6.4 97.7 123.5 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.36139158644,
      "stddev": 0.032405243599010335,
      "median": 0.35726610804000003,
      "user": 0.39906389999999997,
      "system": 0.24589686,
      "min": 0.30782256254,
      "max": 0.41921974454000005
    },
    {
      "command": "pacquet@main",
      "mean": 0.37707199654000007,
      "stddev": 0.015904739467826754,
      "median": 0.37891369054,
      "user": 0.4143316,
      "system": 0.27632216,
      "min": 0.35453532354,
      "max": 0.39692071654000005
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.11772521078999999,
      "stddev": 0.00937499995736697,
      "median": 0.12070216504,
      "user": 0.05368846666666668,
      "system": 0.031544901666666667,
      "min": 0.09546874654000001,
      "max": 0.13153023854
    },
    {
      "command": "pnpr@main",
      "mean": 0.10688904857448278,
      "stddev": 0.006360147362953228,
      "median": 0.10676514554000001,
      "user": 0.04687066206896552,
      "system": 0.022751428965517243,
      "min": 0.09772128054000001,
      "max": 0.12345727454000001
    }
  ]
}

Scenario: Isolated linker: peer-heavy resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 305.9 ± 29.4 246.9 348.0 1.15 ± 0.16
pacquet@main 265.3 ± 26.3 232.1 314.5 1.00
pnpm@HEAD 5030.2 ± 200.2 4637.5 5286.6 18.96 ± 2.03
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.30587048881333334,
      "stddev": 0.029402269693417173,
      "median": 0.30224211448,
      "user": 0.32443044,
      "system": 0.08421620222222222,
      "min": 0.24686523648,
      "max": 0.34799874948000004
    },
    {
      "command": "pacquet@main",
      "mean": 0.2652642611466666,
      "stddev": 0.026296120766867624,
      "median": 0.25948556648,
      "user": 0.29727066222222226,
      "system": 0.07288809111111111,
      "min": 0.23205050148,
      "max": 0.31447065848
    },
    {
      "command": "pnpm@HEAD",
      "mean": 5.030170701035555,
      "stddev": 0.20023498769381826,
      "median": 5.03775160848,
      "user": 8.003541773333332,
      "system": 0.49398409111111113,
      "min": 4.637471490479999,
      "max": 5.28658022648
    }
  ]
}

Scenario: Isolated linker: linked-workspace resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 87.6 ± 3.5 81.5 97.9 1.00
pacquet@main 88.4 ± 3.9 83.5 99.6 1.01 ± 0.06
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.08763667228322583,
      "stddev": 0.003536237843159389,
      "median": 0.08684829138,
      "user": 0.07408365354838711,
      "system": 0.059199883870967744,
      "min": 0.08152545238,
      "max": 0.09785779238
    },
    {
      "command": "pacquet@main",
      "mean": 0.08841662567411765,
      "stddev": 0.0038922667465194445,
      "median": 0.08706348538,
      "user": 0.08166469529411766,
      "system": 0.05422875294117646,
      "min": 0.08346494838,
      "max": 0.09956874838
    }
  ]
}

Scenario: Isolated linker: injected workspace repeat install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 130.1 ± 9.1 108.7 141.6 1.12 ± 0.12
pacquet@main 116.5 ± 9.2 101.9 136.0 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.13007826264857142,
      "stddev": 0.009083859069329075,
      "median": 0.13192401922000002,
      "user": 0.048675454285714286,
      "system": 0.09209495714285715,
      "min": 0.10873601222,
      "max": 0.14160418222
    },
    {
      "command": "pacquet@main",
      "mean": 0.11653417067833333,
      "stddev": 0.009162438834217737,
      "median": 0.11347106772,
      "user": 0.04190282333333333,
      "system": 0.08449164166666666,
      "min": 0.10190063822,
      "max": 0.13603424022000002
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.663 ± 0.191 4.450 4.944 1.30 ± 0.08
pacquet@main 4.618 ± 0.161 4.478 4.872 1.29 ± 0.07
pnpr@HEAD 3.582 ± 0.175 3.406 3.896 1.00 ± 0.06
pnpr@main 3.576 ± 0.150 3.426 3.922 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.66310842368,
      "stddev": 0.1910174781237814,
      "median": 4.622425310880001,
      "user": 2.2826004400000004,
      "system": 1.70981238,
      "min": 4.44980321788,
      "max": 4.943701083880001
    },
    {
      "command": "pacquet@main",
      "mean": 4.61792239348,
      "stddev": 0.16146023478775118,
      "median": 4.55072229238,
      "user": 2.2657643399999996,
      "system": 1.7119788800000002,
      "min": 4.4782956918800005,
      "max": 4.87165200188
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.5816580304800008,
      "stddev": 0.17461821961646357,
      "median": 3.5155343558800003,
      "user": 1.9384179400000001,
      "system": 1.48343958,
      "min": 3.40587640488,
      "max": 3.89597527488
    },
    {
      "command": "pnpr@main",
      "mean": 3.57644720448,
      "stddev": 0.14997444221455708,
      "median": 3.55878219138,
      "user": 1.9880281400000002,
      "system": 1.49619418,
      "min": 3.4262789808800003,
      "max": 3.92162493988
    }
  ]
}

Scenario: GVS linker: fresh restore, hot cache + hot store

Same install as the isolated fresh-restore hot/hot scenario, into the shared virtual store, the layout pnpm 12 installs into by default. Scenarios run on separate machines, so compare main and branch within each table.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 155.1 ± 12.9 138.3 188.9 1.05 ± 0.16
pacquet@main 147.8 ± 19.7 129.9 206.4 1.00
pnpr@HEAD 189.8 ± 36.1 146.1 235.3 1.28 ± 0.30
pnpr@main 187.1 ± 26.3 162.0 235.5 1.27 ± 0.25
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.15510998062666667,
      "stddev": 0.012885246332314379,
      "median": 0.15438253396,
      "user": 0.19472602,
      "system": 0.16978968,
      "min": 0.13832146796000003,
      "max": 0.18889341696000003
    },
    {
      "command": "pacquet@main",
      "mean": 0.14779490232842107,
      "stddev": 0.019712040041342624,
      "median": 0.14109313396000003,
      "user": 0.19141547263157893,
      "system": 0.14581871157894738,
      "min": 0.12989577596000002,
      "max": 0.20641226296000004
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.1898159881418182,
      "stddev": 0.03612118385781003,
      "median": 0.16498408996000002,
      "user": 0.23373469272727274,
      "system": 0.16535780727272725,
      "min": 0.14613930996000002,
      "max": 0.23530272196000002
    },
    {
      "command": "pnpr@main",
      "mean": 0.1871469501418182,
      "stddev": 0.02628845615141267,
      "median": 0.18138066596000002,
      "user": 0.22330314727272726,
      "system": 0.16128044363636362,
      "min": 0.16198768296000002,
      "max": 0.23545700096000002
    }
  ]
}

Scenario: Store only: unlocked direct deps, cold cache + hot store

Store-only install (enableModulesDir: false, per-file store index, trusted lockfile) against a lockfile missing the direct dependencies that have peers, with the metadata cache wiped per iteration: the install resolves those from the registry, reuses their subtrees from the lockfile and checks the store, linking nothing. Direct installs only.

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.333 ± 0.055 1.255 1.423 1.05 ± 0.06
pacquet@main 1.273 ± 0.050 1.216 1.354 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.33317759512,
      "stddev": 0.054762789122714185,
      "median": 1.32306388752,
      "user": 0.71484656,
      "system": 0.2776143,
      "min": 1.25500138902,
      "max": 1.4234265550199998
    },
    {
      "command": "pacquet@main",
      "mean": 1.27310590582,
      "stddev": 0.04970729693993395,
      "median": 1.26360401752,
      "user": 0.6322277600000001,
      "system": 0.23801859999999997,
      "min": 1.21572402002,
      "max": 1.35414252102
    }
  ]
}

Scenario: Cargo: repeat install, hot cache + hot store

Frozen repeat install of a Cargo workspace (cargo.enabled: true) whose crates are already materialized in <storeDir>/v11/crates/ and linked into .pnpm/crates/crates-io. Direct installs only.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 32.1 ± 2.2 29.2 39.7 1.05 ± 0.08
pacquet@main 30.6 ± 1.1 28.8 35.1 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.03214994685391305,
      "stddev": 0.0022312159670178798,
      "median": 0.031750905680000004,
      "user": 0.023453026086956527,
      "system": 0.01811198673913044,
      "min": 0.02922501568,
      "max": 0.039730218680000005
    },
    {
      "command": "pacquet@main",
      "mean": 0.030609644927422686,
      "stddev": 0.0011347782020033424,
      "median": 0.030352524680000003,
      "user": 0.02138354536082475,
      "system": 0.01858291422680413,
      "min": 0.028780944680000003,
      "max": 0.03514496668
    }
  ]
}

@codecov-commenter

codecov-commenter commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.45283% with 44 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.74%. Comparing base (2e27cd2) to head (cc9b1db).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pnpr/crates/storage/src/metadata/sql.rs 88.99% 12 Missing ⚠️
pnpr/crates/storage/src/metadata/sql/adapter.rs 83.33% 11 Missing ⚠️
pnpr/crates/storage/src/metadata/sql/notes.rs 89.83% 6 Missing ⚠️
...pr/crates/storage/src/metadata/sql/publications.rs 92.40% 6 Missing ⚠️
pnpr/crates/storage/src/metadata/sql/commit.rs 93.33% 3 Missing ⚠️
pnpr/crates/storage/src/metadata/sql/sqlite.rs 97.89% 2 Missing ⚠️
pnpr/crates/storage/src/metadata/sql/tags.rs 92.59% 2 Missing ⚠️
pnpr/crates/storage/src/metadata/sql/render.rs 97.36% 1 Missing ⚠️
pnpr/crates/storage/src/metadata/sql/versions.rs 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17577      +/-   ##
==========================================
- Coverage   92.76%   92.74%   -0.02%     
==========================================
  Files        1990     1992       +2     
  Lines      258000   258187     +187     
==========================================
+ Hits       239332   239465     +133     
- Misses      18668    18722      +54     

☔ 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.

zkochan and others added 2 commits November 3, 2026 00:44
Split the SQLite metadata backend into a shared SQL layer and an adapter
per database, as pnpm/rfcs#66 describes under "Backend adapters". The
shared layer keeps the schema, the queries, removed-version refusal,
generations, publication outcomes, release notes, and the render caches.
The `Adapter` trait supplies what differs between databases:

- connections: one writer, readers that never wait for it;
- the statements that begin a write or a read transaction;
- which errors are conflicts a rerun of the whole transaction clears;
- placeholders and types, translated by its `Connection`;
- where a read runs, the primary or a replica.

The shared layer runs every statement through `Connection` with `?N`
placeholders and owned `Param`/`Value` types, so a libSQL adapter can run
the same code. It stays synchronous on the blocking pool. Each operation
names the freshness it needs (`Current` for reads that decide a write or
answer a retry, `Bounded` for views), which an adapter with a replica maps
to the primary or the replica; SQLite reads its one database either way.

Queries now stay in the subset SQLite, libSQL, and PostgreSQL share:
`INSERT OR IGNORE` became `ON CONFLICT DO NOTHING`, removing a version or
package deletes its rows explicitly instead of relying on a
connection-level foreign-key cascade, and a taken publication name is
found by a lookup inside the write transaction instead of by decoding a
driver-specific constraint error. A write that the adapter reports as a
conflict (SQLITE_BUSY or SQLITE_LOCKED for SQLite) runs again from its
start, up to four times. Every read now runs in one read transaction.

`SqliteMetadata` is `SqlMetadata`, opened with `SqlMetadata::open_sqlite`,
and `Storage::sqlite_metadata` is `Storage::sql_metadata`. The existing
tests pass with renames only; the test that held the write connection now
holds it through the adapter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zkochan
zkochan marked this pull request as ready for review November 2, 2026 23:53
@zkochan
zkochan force-pushed the pnpr/sql-metadata-adapters branch from be10844 to 3ec74f7 Compare November 2, 2026 23:53
Copilot AI balanced review requested due to automatic review settings November 2, 2026 23:53

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Refactor pnpr SQL metadata behind a database adapter

✨ Enhancement 🕐 40+ Minutes

Grey Divider

AI Description

• Separate shared metadata schema and queries from SQLite connection management for future SQL
 backends.
• Add adapter-managed transactions, conflict retries, and read freshness without changing SQLite
 behavior.
• Make queries portable while preserving publication, removal, rendering, and concurrency
 guarantees.
Diagram

graph TD
  H["Server handlers"] --> S["Storage"] --> M["SQL metadata"] --> A["Adapter"] --> Q["SQLite adapter"] --> D[("SQLite database")]
  M --> C["Render cache"]
Loading
High-Level Assessment

The adapter boundary is appropriate for the planned backend stack: it keeps metadata rules and SQL in one place while isolating connection, transaction, and error differences. Keeping rusqlite calls in the shared layer or duplicating those rules per backend would make the subsequent adapter harder to implement consistently.

Files changed (26) +992 / -467

Enhancement (2) +369 / -0
adapter.rsDefine the database adapter contract +213/-0

Define the database adapter contract

• Introduces connection, transaction, retryability, and read-source interfaces. Defines database-neutral parameters, returned values, rows, and typed column conversion.

pnpr/crates/storage/src/metadata/sql/adapter.rs

sqlite.rsImplement the SQLite metadata adapter +156/-0

Implement the SQLite metadata adapter

• Moves writer and reader connection management into SqliteAdapter. It implements parameter and row translation, SQLite transaction starts, and busy or locked conflict classification.

pnpr/crates/storage/src/metadata/sql/sqlite.rs

Refactor (19) +577 / -438
notes.rsUse backend-neutral metadata for notes +3/-3

Use backend-neutral metadata for notes

• Notes requests obtain and retain SqlMetadata instead of the SQLite-specific type.

pnpr/crates/pnpr/src/server/notes.rs

publications.rsUse SQL metadata for publication endpoints +7/-7

Use SQL metadata for publication endpoints

• Publication and publication-note handlers use the backend-neutral metadata accessor and type.

pnpr/crates/pnpr/src/server/publications.rs

publishing.rsSelect the SQL publication path +1/-1

Select the SQL publication path

• Publishing checks for SQL metadata rather than a SQLite-specific backend.

pnpr/crates/pnpr/src/server/publishing.rs

atomic.rsRoute atomic publishing through SQL metadata +3/-3

Route atomic publishing through SQL metadata

• Publication requests, outcome replay, and commits use the renamed SQL metadata accessor.

pnpr/crates/pnpr/src/server/publishing/atomic.rs

notes.rsCheck SQL metadata availability for release notes +1/-1

Check SQL metadata availability for release notes

• Release-note validation checks the backend-neutral accessor. Its existing user-facing error text is unchanged.

pnpr/crates/pnpr/src/server/publishing/notes.rs

metadata.rsExpose SQL metadata through Storage +11/-12

Expose SQL metadata through Storage

• Renames the metadata module, source variant, exported type, and Storage accessor. SQLite configuration now opens SqlMetadata through its SQLite constructor.

pnpr/crates/storage/src/metadata.rs

sql.rsCoordinate shared SQL operations +172/-101

Coordinate shared SQL operations

• Replaces embedded connection ownership with an Adapter, adds write-conflict retries and read freshness selection, and runs reads in adapter-managed snapshot transactions. Package views and catalog generations use the appropriate freshness.

pnpr/crates/storage/src/metadata/sql.rs

batch.rsMake write batches adapter-backed +49/-10

Make write batches adapter-backed

• Adds a write-transaction wrapper that begins through Connection, commits explicitly, and rolls back when dropped. Catalog batches and package commits use it instead of rusqlite transactions.

pnpr/crates/storage/src/metadata/sql/batch.rs

cache.rsMove render cache into shared SQL module +0/-0

Move render cache into shared SQL module

• The existing cache implementation moves with the metadata module without substantive changes.

pnpr/crates/storage/src/metadata/sql/cache.rs

commit.rsPort package commits to shared SQL +56/-44

Port package commits to shared SQL

• Uses adapter queries and rows for package reconciliation. Replaces SQLite-only ignore inserts and cascade-dependent removals with portable conflict handling and explicit row deletion.

pnpr/crates/storage/src/metadata/sql/commit.rs

notes.rsPort release-note operations to the adapter +67/-71

Port release-note operations to the adapter

• Note lookups and mutations use database-neutral rows and connections. Mutations retain transactional subject checks; view-oriented note reads request bounded freshness.

pnpr/crates/storage/src/metadata/sql/notes.rs

packument.rsMove packument decomposition into shared SQL module +0/-0

Move packument decomposition into shared SQL module

• The existing packument decomposition code moves with the metadata module without substantive changes.

pnpr/crates/storage/src/metadata/sql/packument.rs

params.rsProvide database-neutral SQL parameter bindings +9/-0

Provide database-neutral SQL parameter bindings

• Adds a shared params! macro that converts statement arguments into adapter Param values.

pnpr/crates/storage/src/metadata/sql/params.rs

publications.rsPort publication queries and name checks +96/-79

Port publication queries and name checks

• Converts publication and outcome queries to adapter rows, uses portable conflict handling for members, and checks taken names inside the write transaction instead of decoding SQLite errors.

pnpr/crates/storage/src/metadata/sql/publications.rs

publish.rsUse adapter connections for publication commits +2/-3

Use adapter connections for publication commits

• The shared publication commit operation accepts the database-neutral Connection interface.

pnpr/crates/storage/src/metadata/sql/publish.rs

render.rsRender metadata from adapter-backed snapshots +44/-43

Render metadata from adapter-backed snapshots

• Replaces rusqlite row handling with adapter queries. Rendering now uses the read transaction established by the shared SQL layer while retaining its caches.

pnpr/crates/storage/src/metadata/sql/render.rs

schema.rsPrepare the shared schema transactionally +19/-25

Prepare the shared schema transactionally

• Creates and checks schema tables through the adapter connection in a write transaction. SQLite-specific connection pragmas and reader setup move to the SQLite adapter.

pnpr/crates/storage/src/metadata/sql/schema.rs

tags.rsPort tag queries to shared connections +30/-24

Port tag queries to shared connections

• Tag reads, history, and mutations use adapter connections and database-neutral row conversion.

pnpr/crates/storage/src/metadata/sql/tags.rs

versions.rsCheck removed versions through the adapter +7/-11

Check removed versions through the adapter

• Removed-version refusal uses a database-neutral optional query instead of rusqlite-specific row handling.

pnpr/crates/storage/src/metadata/sql/versions.rs

Tests (5) +46 / -29
tests.rsUpdate journal test metadata access +1/-1

Update journal test metadata access

• The recovery test reads tag history through the renamed SQL metadata accessor.

pnpr/crates/storage/src/journal/tests.rs

tests.rsUpdate SQL metadata test helpers +2/-2

Update SQL metadata test helpers

• Test helpers and tag-history assertions use the renamed SQL metadata accessor.

pnpr/crates/storage/src/metadata/sql/tests.rs

concurrency.rsExercise adapter-backed SQLite concurrency +29/-12

Exercise adapter-backed SQLite concurrency

• Updates transaction and restart tests to use the adapter-backed metadata type. Adds checks that SQLite busy and locked errors are retryable but constraint errors are not.

pnpr/crates/storage/src/metadata/sql/tests/concurrency.rs

notes.rsUpdate release-note tests for SQL metadata +3/-3

Update release-note tests for SQL metadata

• Existing note tests use the renamed metadata accessor.

pnpr/crates/storage/src/metadata/sql/tests/notes.rs

publications.rsUpdate publication tests for SQL metadata +11/-11

Update publication tests for SQL metadata

• Existing publication, idempotency, and competing-writer tests use the renamed metadata type and accessor.

pnpr/crates/storage/src/metadata/sql/tests/publications.rs

@qodo-code-review

qodo-code-review Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. A failed commit leaves every later write stuck ✓ Resolved
Description
WriteTransaction::commit sets open = false before executing COMMIT, so a failed commit
prevents Drop from rolling back a transaction that may still be active; run_read can likewise
return a reader to the pool after a failed COMMIT or ROLLBACK. When SQLite reports a busy or
locked commit, run_write retries on the same long-lived writer connection, where the next `BEGIN
IMMEDIATE` fails because a transaction is already open; later writes can fail and the write lock can
remain held until pnpr restarts.
Code

pnpr/crates/storage/src/metadata/sql/batch.rs[R23-26]

+    pub(super) fn commit(mut self) -> Result<()> {
+        self.open = false;
+        self.connection.execute_batch("COMMIT")
+    }
Relevance

●●● Strong

Concrete transaction-poisoning reliability bug; recent metadata reviews accepted similarly specific
state-corruption findings.

PR-#17551
PR-#17557

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
commit clears open before executing SQL, while Drop rolls back only when open is true. The
SQLite adapter reuses a single writer connection and treats busy and locked failures as retryable,
so a failed commit can lead to another begin_write on a connection still inside a transaction. The
reader path has a related gap: after a failed COMMIT or ROLLBACK, run_read can return a
connection still inside a transaction to the idle pool, where its next begin_read fails.

pnpr/crates/storage/src/metadata/sql/batch.rs[10-45]
pnpr/crates/storage/src/metadata/sql/sqlite.rs[68-98]
pnpr/crates/storage/src/metadata/sql.rs[301-350]
pnpr/crates/storage/src/metadata/sql/batch.rs[16-43]
pnpr/crates/storage/src/metadata/sql.rs[301-326]
pnpr/crates/storage/src/metadata/sql/sqlite.rs[68-70]
pnpr/crates/storage/src/metadata/sql/sqlite.rs[91-96]

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

## Issue description
A failed `COMMIT` can leave the shared writer inside a transaction because `WriteTransaction::commit` marks its guard closed before the SQL succeeds. A retry then attempts `BEGIN IMMEDIATE` on that connection. The read path can also pool a connection after a failed `COMMIT` or `ROLLBACK` while its transaction remains open.

## Fix Focus Areas
- pnpr/crates/storage/src/metadata/sql/batch.rs[23-43]
- pnpr/crates/storage/src/metadata/sql.rs[301-350]
- pnpr/crates/storage/src/metadata/sql/sqlite.rs[73-89]

## Recommended Fix
Execute `COMMIT` before setting `open = false`, and clear the flag only on success so `Drop` rolls back after a failed commit. Ensure a failed commit is rolled back before retrying; if rollback fails, do not reuse the writer as though its transaction had ended. In `run_read`, attempt `ROLLBACK` when `COMMIT` fails, and in `SqliteAdapter::read`, discard rather than pool a connection when `connection.is_autocommit()` is false. In `SqliteAdapter::write`, defensively roll back a writer that is not in autocommit mode before running the next operation.

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


2. Failed cleanup can poison later reads ✓ Resolved
Description
SqliteAdapter::read returns a connection to its idle pool even when run_read fails to commit or
roll back its transaction. If transaction cleanup fails and leaves it open, the next request reuses
that connection and its BEGIN fails instead of starting a fresh read.
Code

pnpr/crates/storage/src/metadata/sql/sqlite.rs[R83-87]

+        let output = operation(&connection);
+        let mut readers = lock(&self.readers);
+        if readers.len() < IDLE_READERS {
+            readers.push(connection);
+        }
Relevance

●●● Strong

Concrete pooled-connection cleanup bug causing repeat read failures; aligns with accepted recent
storage reliability findings.

PR-#17551
PR-#17557

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
run_read returns a cleanup error, but the adapter pools the connection regardless of that result.
A later read takes an idle connection and issues BEGIN on it.

pnpr/crates/storage/src/metadata/sql.rs[330-346]
pnpr/crates/storage/src/metadata/sql/sqlite.rs[73-89]
pnpr/crates/storage/src/metadata/sql/sqlite.rs[128-134]

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

## Issue description
A failed read-transaction cleanup can leave an active transaction on a connection that is returned to the idle pool.

## Fix Focus Areas
- pnpr/crates/storage/src/metadata/sql.rs[330-349]
- pnpr/crates/storage/src/metadata/sql/sqlite.rs[73-89]

## Recommended Fix
Ensure the read callback distinguishes successful transaction cleanup from cleanup failure, and discard the SQLite connection whenever cleanup cannot be confirmed. Do not pool a connection that might still have an active transaction.

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


3. Large packuments use extra memory 🐞 Bug ➹ Performance
Description
Connection::query makes the SQLite adapter collect owned generic rows for the entire version query
before version_entries constructs its final entries. On an uncached npm packument with many
versions, rendering retains this additional row set and allocates per-column values where the
previous query mapped rows directly into entries.
Code

pnpr/crates/storage/src/metadata/sql/sqlite.rs[R113-119]

+        let mut rows = statement.query(rusqlite::params_from_iter(params))?;
+        let mut collected = Vec::new();
+        while let Some(row) = rows.next()? {
+            let values = (0..columns)
+                .map(|index| Ok(to_value(row.get_ref(index)?)))
+                .collect::<rusqlite::Result<_>>()?;
+            collected.push(Row::new(values));
Relevance

●● Moderate

Recommendation generated with fallback mode.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The adapter allocates and collects all rows and their converted columns into Vec<Row>.
version_entries subsequently iterates that vector to allocate its output, and uncached packument
assembly invokes this query for every version.

pnpr/crates/storage/src/metadata/sql/sqlite.rs[110-122]
pnpr/crates/storage/src/metadata/sql/render.rs[54-78]
pnpr/crates/storage/src/metadata/sql/render.rs[130-151]

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

## Issue description
The new query abstraction fully materializes generic rows before hot-path packument rendering can turn them into version entries.

## Fix Focus Areas
- pnpr/crates/storage/src/metadata/sql/adapter.rs[29-53]
- pnpr/crates/storage/src/metadata/sql/sqlite.rs[110-122]
- pnpr/crates/storage/src/metadata/sql/render.rs[54-78]

## Recommended Fix
Provide an adapter query interface that maps or visits rows as they are read, then build version entries directly from that interface without retaining an intermediate generic row set. Preserve the transaction snapshot and adapter-neutral value conversions.

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

Dismiss ↗ | View ↗


Grey Divider

Context sources
✅ Compliance rules (platform): 61 rules
✅ Cross-repo context — repo relationships
Review mode: Auto: 🧠 Deep: Large SQL refactor spans transactions, concurrency, queries, adapters, and performance-sensitive paths.
✅ Fix-loop round: fix loop

Grey Divider

Tip of the day
💡 Did you know, you can tweak Display settings with a live preview to see your comment before it ships

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous reviews

Review updated until commit cc9b1db

Results up to commit be10844 🧠 Deep


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


Remediation recommended
1. Failed cleanup can poison later reads ✓ Resolved
Description
SqliteAdapter::read returns a connection to its idle pool even when run_read fails to commit or
roll back its transaction. If transaction cleanup fails and leaves it open, the next request reuses
that connection and its BEGIN fails instead of starting a fresh read.
Code

pnpr/crates/storage/src/metadata/sql/sqlite.rs[R83-87]

+        let output = operation(&connection);
+        let mut readers = lock(&self.readers);
+        if readers.len() < IDLE_READERS {
+            readers.push(connection);
+        }
Relevance

●●● Strong

Concrete pooled-connection cleanup bug causing repeat read failures; aligns with accepted recent
storage reliability findings.

PR-#17551
PR-#17557

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
run_read returns a cleanup error, but the adapter pools the connection regardless of that result.
A later read takes an idle connection and issues BEGIN on it.

pnpr/crates/storage/src/metadata/sql.rs[330-346]
pnpr/crates/storage/src/metadata/sql/sqlite.rs[73-89]
pnpr/crates/storage/src/metadata/sql/sqlite.rs[128-134]

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

## Issue description
A failed read-transaction cleanup can leave an active transaction on a connection that is returned to the idle pool.

## Fix Focus Areas
- pnpr/crates/storage/src/metadata/sql.rs[330-349]
- pnpr/crates/storage/src/metadata/sql/sqlite.rs[73-89]

## Recommended Fix
Ensure the read callback distinguishes successful transaction cleanup from cleanup failure, and discard the SQLite connection whenever cleanup cannot be confirmed. Do not pool a connection that might still have an active transaction.

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


2. A failed commit leaves every later write stuck ✓ Resolved
Description
WriteTransaction::commit sets open = false before executing COMMIT, so a failed commit
prevents Drop from rolling back a transaction that may still be active; run_read can likewise
return a reader to the pool after a failed COMMIT or ROLLBACK. When SQLite reports a busy or
locked commit, run_write retries on the same long-lived writer connection, where the next `BEGIN
IMMEDIATE` fails because a transaction is already open; later writes can fail and the write lock can
remain held until pnpr restarts.
Code

pnpr/crates/storage/src/metadata/sql/batch.rs[R23-26]

+    pub(super) fn commit(mut self) -> Result<()> {
+        self.open = false;
+        self.connection.execute_batch("COMMIT")
+    }
Relevance

●●● Strong

Concrete transaction-poisoning reliability bug; recent metadata reviews accepted similarly specific
state-corruption findings.

PR-#17551
PR-#17557

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
commit clears open before executing SQL, while Drop rolls back only when open is true. The
SQLite adapter reuses a single writer connection and treats busy and locked failures as retryable,
so a failed commit can lead to another begin_write on a connection still inside a transaction. The
reader path has a related gap: after a failed COMMIT or ROLLBACK, run_read can return a
connection still inside a transaction to the idle pool, where its next begin_read fails.

pnpr/crates/storage/src/metadata/sql/batch.rs[10-45]
pnpr/crates/storage/src/metadata/sql/sqlite.rs[68-98]
pnpr/crates/storage/src/metadata/sql.rs[301-350]
pnpr/crates/storage/src/metadata/sql/batch.rs[16-43]
pnpr/crates/storage/src/metadata/sql.rs[301-326]
pnpr/crates/storage/src/metadata/sql/sqlite.rs[68-70]
pnpr/crates/storage/src/metadata/sql/sqlite.rs[91-96]

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

## Issue description
A failed `COMMIT` can leave the shared writer inside a transaction because `WriteTransaction::commit` marks its guard closed before the SQL succeeds. A retry then attempts `BEGIN IMMEDIATE` on that connection. The read path can also pool a connection after a failed `COMMIT` or `ROLLBACK` while its transaction remains open.

## Fix Focus Areas
- pnpr/crates/storage/src/metadata/sql/batch.rs[23-43]
- pnpr/crates/storage/src/metadata/sql.rs[301-350]
- pnpr/crates/storage/src/metadata/sql/sqlite.rs[73-89]

## Recommended Fix
Execute `COMMIT` before setting `open = false`, and clear the flag only on success so `Drop` rolls back after a failed commit. Ensure a failed commit is rolled back before retrying; if rollback fails, do not reuse the writer as though its transaction had ended. In `run_read`, attempt `ROLLBACK` when `COMMIT` fails, and in `SqliteAdapter::read`, discard rather than pool a connection when `connection.is_autocommit()` is false. In `SqliteAdapter::write`, defensively roll back a writer that is not in autocommit mode before running the next operation.

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


3. Large packuments use extra memory 🐞 Bug ➹ Performance
Description
Connection::query makes the SQLite adapter collect owned generic rows for the entire version query
before version_entries constructs its final entries. On an uncached npm packument with many
versions, rendering retains this additional row set and allocates per-column values where the
previous query mapped rows directly into entries.
Code

pnpr/crates/storage/src/metadata/sql/sqlite.rs[R113-119]

+        let mut rows = statement.query(rusqlite::params_from_iter(params))?;
+        let mut collected = Vec::new();
+        while let Some(row) = rows.next()? {
+            let values = (0..columns)
+                .map(|index| Ok(to_value(row.get_ref(index)?)))
+                .collect::<rusqlite::Result<_>>()?;
+            collected.push(Row::new(values));
Relevance

●● Moderate

Recommendation generated with fallback mode.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The adapter allocates and collects all rows and their converted columns into Vec<Row>.
version_entries subsequently iterates that vector to allocate its output, and uncached packument
assembly invokes this query for every version.

pnpr/crates/storage/src/metadata/sql/sqlite.rs[110-122]
pnpr/crates/storage/src/metadata/sql/render.rs[54-78]
pnpr/crates/storage/src/metadata/sql/render.rs[130-151]

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

## Issue description
The new query abstraction fully materializes generic rows before hot-path packument rendering can turn them into version entries.

## Fix Focus Areas
- pnpr/crates/storage/src/metadata/sql/adapter.rs[29-53]
- pnpr/crates/storage/src/metadata/sql/sqlite.rs[110-122]
- pnpr/crates/storage/src/metadata/sql/render.rs[54-78]

## Recommended Fix
Provide an adapter query interface that maps or visits rows as they are read, then build version entries directly from that interface without retaining an intermediate generic row set. Preserve the transaction snapshot and adapter-neutral value conversions.

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

Dismiss ↗ | View ↗


Grey Divider

Qodo Logo

@garnet-runtime-review

garnet-runtime-review Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

No runtime changes

Nothing new in your workflow's 1 job
1 job recorded at the kernel (Linux x86_64)
At cc9b1db, compared with your previous push 2e27cd2

1 job · nothing new
TS CI / test · only runner activity outside your workflow changed
TS CI / test · runner activity outside your workflow · +8 −9 · not counted
  systemd
    ├─ chronyd
-   │  ├─ ○ 142.248.192[.]33
-   │  ├─ ○ 144.202.0[.]197
-   │  ├─ ○ 162.254.225[.]151
-   │  ├─ ○ 51.81.226[.]229
+   │  ├─ ○ 172.235.60[.]8
+   │  ├─ ○ 209.148.110[.]236
+   │  ├─ ○ 38.45.67[.]7
+   │  └─ ○ 45.79.82[.]45
    ├─ … (1)
    │  └─ nginx
-   │     ├─ ○ 140.82.112[.]22
-   │     ├─ ○ 140.82.113[.]21
-   │     ├─ ○ 140.82.113[.]22
-   │     ├─ ○ results-receiver.actions[.]githubusercontent (github infra)
+   │     ├─ ○ 140.82.112[.]21
+   │     ├─ ○ 140.82.114[.]21
+   │     └─ ○ 140.82.114[.]22
    ├─ snapd
    │  └─ ○ api.snapcraft[.]io
    └─ systemd-resolve
-      ├─ ○ 8.8.8[.]8
+      └─ ○ 8.8.4[.]4

Full record in Garnet ↗


How to read this
Runner.Worker     ← process on a path
└─ curl           ← process that acted
   └─ ○ example[.]com ← observed action

Read down: what ran, then what it reached. + only in this commit · − only in the compared run. Capture is best-effort. · Docs ↗

Runtime behavior, recorded by Garnet. Add it to your CI ↗

@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.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

zkochan and others added 2 commits November 3, 2026 01:09
A failed `COMMIT` can leave its transaction open, but the write
transaction marked itself closed before running it, so its drop skipped
the rollback and the writer's next `BEGIN IMMEDIATE` failed inside the
open transaction. It is now marked closed only once the commit succeeds.

The SQLite adapter also ends a transaction its writer was left in before
the next write, and closes a reader still in its transaction instead of
returning it to the idle readers, where every read on it would fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 3, 2026 00:15

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@zkochan

zkochan commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

Replies to the Qodo review:

  1. Failed cleanup can poison later reads: fixed in caf3495. SqliteAdapter::read returns a reader to the idle pool only when it is back in autocommit mode, so a reader whose COMMIT or ROLLBACK failed is closed. Covered by a_read_left_in_its_transaction_is_not_reused. The libSQL pool later in the stack already closes such connections.
  2. A failed commit leaves every later write stuck: fixed in caf3495, the same finding as CodeRabbit's thread on batch.rs. WriteTransaction::commit marks itself closed only after COMMIT succeeds, and the SQLite writer is rolled back before reuse if it is still inside a transaction. Covered by a_failed_commit_is_rolled_back and a_write_left_in_its_transaction_does_not_block_the_next.
  3. Large packuments use extra memory: not acting. The owned rows of one query live only until version_entries maps them, and that runs only for a view the render cache does not hold. A row-visiting query interface would have to be implemented by every adapter, including libSQL's async rows later in the stack, to save one transient allocation per uncached render.

Written by an agent (Claude Code, claude-opus-5-5).

@qodo-code-review

Copy link
Copy Markdown

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

@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.

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Nov 3, 2026
@zkochan
zkochan added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit e092130 Nov 3, 2026
75 checks passed
@zkochan
zkochan deleted the pnpr/sql-metadata-adapters branch November 3, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pnpr reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants