Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 62 additions & 21 deletions pnpr/text/0000-atomic-workspace-publication.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ Existing releases never change their bytes. An identical request retry may
return its earlier result, but a new transaction cannot quietly adopt another
publisher's competing release to make its batch appear successful.

Clients supply an idempotency key scoped to the organization and publisher
identity. Bind that key to a digest of the complete request. Reusing it with a
Clients supply an idempotency key scoped to the hosted catalog and publisher
identity. The catalog identifies the organization as well as the transaction
boundary; a key from another catalog is a different key. Bind that key to a
digest of the complete request. Reusing it with a
different request is a conflict. The request identity is scoped to a stable
principal, not a bearer-token string that changes during token rotation.
A publication's name is not an idempotency key. The name is chosen to be read
Expand All @@ -192,18 +194,31 @@ same archive with different tag changes is a conflict, not a replay. A
different archive for the same version is still a conflict.

A batch without a key is keyed the same way, by a digest over every entry's
archive integrity and accepted manifest and every tag or revision-selection
change in the request. A retry with the same digest returns the recorded
outcome; a request that shares versions with a committed batch but has a
different digest is a conflict.
identity, archive integrity, accepted manifest, and version note, the
publication name and publication note, and every tag or revision-selection
change in the request. An entry's identity is every field of its publication
member: registry, ecosystem, name, version, and revision where applicable, plus
a Python distribution's filename and an OCI manifest's repository, so two
requests that differ only in which package or file an archive is published as
never share a digest. Note absence and note text are distinct digest inputs;
notes are not part of the accepted manifest. This whole-request rule also
applies to a single-package publication without a key. A retry with the same
digest returns the recorded outcome; a request that shares versions with a
committed batch but has a different digest is a conflict.

A timed-out commit has an unknown outcome to the client. The client queries or
retries the same transaction to learn its durable state. Idempotency results
must survive crashes and the retry period, which is at least 7 days, well
past any client's retry window. A retry must not create another catalog
generation for an already committed transaction. Content-keyed outcomes need
no separate record after that period: the committed releases themselves
decide whether a later identical request is a replay.
generation for an already committed transaction. During the retry period,
compare against the stored whole-request digest and outcome, never against
current tags or edited notes. After that record expires, an existing
publication may still carry enough information to recover the original
outcome; otherwise return an explicit conflict. Release bytes alone cannot
establish a replay: they do not identify the original tag changes, publication
name, notes, or batch membership. Expiry must never cause selections to be
reapplied or success to be inferred from matching archives. This uses the
existing outcome-retention policy, without permanent retry-record storage.

### Publication visibility and read consistency

Expand Down Expand Up @@ -231,26 +246,36 @@ claim the stronger guarantees without a protocol-version change.

### Publications

A committed transaction that publishes at least one package version is also
recorded as a **publication**, which clients can read. A single-package
publish is a publication with one member, so every version belongs to
exactly one publication. A publication has:
A committed transaction that accepts at least one new release artifact is
also recorded as a **publication**, which clients can read. A single-package
publish is a publication with one member. Each version has one **initial
publication**, the transaction that first introduced it; every accepted
artifact belongs to the publication that introduced that artifact. These
coincide for npm and Cargo, but Python permits later distribution uploads
for an existing version. A publication has:

- an identifier that pnpr assigns, and optionally a name the publisher
chooses, such as `v12.0.0`, unique within the organization;
- its members: the ecosystem, name, version, and revision of every package
version it published, whatever ecosystem each belongs to;
- its members: registry, ecosystem, name, version, revision where applicable,
and the accepted artifact identity. A Python member names its distribution
filename and digest; an OCI member names its repository and manifest digest.
The membership records what this transaction added, not all files that may
eventually share a Python version. OCI tag moves alone remain selections;
- the identity that published it, with the source repository and commit of
a workload identity, the commit time, and the catalog generation it
created.

All of this is fixed at commit. Versions published before publications are
recorded receive them when the catalog is first built: each such version
becomes a publication of one member, with its publish time and, where pnpr
recorded receive initial publications when the catalog is first built: each
existing version becomes a synthetic publication containing its known artifacts,
with its publish time and, where pnpr
recorded one, its publisher, and with no name. Versions of an earlier
batch become separate publications too; grouping them would need a record
of the batch that the storage does not promise to keep. The invariant
therefore holds for every version, old or new. Tag moves and revision
of the batch that the storage does not promise to keep. Synthetic publications
are marked as imported history, not evidence that all of a version's files
originally arrived in one transaction. The initial
publication invariant holds for every version, old or new. Tag moves and
revision
selections that commit alone are transactions but not publications; they
change selections, not the set of published versions.

Expand All @@ -262,8 +287,19 @@ GET <pnpr>/-/publications/<org>/<id-or-name>
GET <pnpr>/-/publications/<org>?member=<ecosystem>:<name>@<version>
```

The second form finds the publication of one package version. A caller sees
only the members whose packages it may read, and a publication with none
The second form finds the initial publication of one package version.
For Python it also accepts `filename=<filename>` to find the publication
that introduced that distribution. Each distribution record and its publication
evidence refer to that introducing publication; later uploads do not rewrite
the initial publication or another file's evidence. For imported history,
the lookup returns a best-known historical link marked `origin: imported`,
not a claim that this transaction introduced the distribution. Such a link
must not produce a verified publication statement or a trusted-publisher rank.
Where original introduction evidence is unavailable, report it as unavailable;
known historical publisher fields remain explicitly unverified observations.
The same restriction applies to synthetic publications in every ecosystem.
A caller sees only the members whose packages it may read, and a publication
with none
answers `404`, so a publication never discloses a package to a caller who
cannot read it. A version's entry in an ecosystem view may name its
publication where the view has room for it, as pnpr's release record does
Expand Down Expand Up @@ -370,6 +406,11 @@ cache and journal. Readers pinned to old and new generations must each see a
complete batch. Garbage collection must never delete an active transaction's
objects or a retained generation. Test existing clients separately from
snapshot-aware clients and report their actual consistency guarantees.
Test an identical retry within the retention period and one after its outcome
record expires; the latter must return a conflict unless the original request
and outcome remain recoverable. Neither may reapply tags. Python uploads of
two files in separate transactions must preserve each file's publication and
the version's initial publication.

Run the same publication conformance suite against each SQL backend, including
replica lag and policy write skew. Verify that replacing a backend through
Expand Down
117 changes: 89 additions & 28 deletions pnpr/text/0000-platform-variants.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,32 @@ For a host, the client keeps the variants with a platform whose every field
matches, then picks one in this order, comparing each variant by its best
matching platform:

1. Variants with more matched fields, without `wasm32`.
2. Among those, the highest `libcVersion`, then the highest `osVersion`, then
the highest `napi`.
3. A `wasm32` variant.
4. The primary archive, if the version has one.

If two variants still tie, publication should have rejected the version. The
client fails rather than pick one.
1. Native targets rank above `wasm32`. Among native targets, prefer the
greatest number of explicit constraints after normalization. Count `os`,
`cpu`, Linux `libc` (including implicit glibc), each version floor, and the
ABI constraint once each; do not count absent fields.
2. Among equal counts, compare `libcVersion`, then `osVersion`, with absent
floors below every present floor. Compare numeric `(major, minor)` pairs,
never strings.
3. Among remaining ties, prefer an exact `nodeAbi` match over a `napi` match,
and a `napi` match over no ABI constraint. For two `napi` matches, prefer
the greatest numeric N-API floor. `napi` and `nodeAbi` are mutually
exclusive within one target. Two matching `nodeAbi` values must be equal
because the host has one runtime family and ABI.
4. A `wasm32` variant ranks below every matching native target, and above the
primary archive. The primary is selected only when no variant matches.

A variant's score is the maximum of its matching target scores under this
lexicographic rule. When choosing the archive to link, an unknown floor or ABI
value cannot satisfy an explicit constraint: linking an archive the host may not
run is worse than linking the primary. A platform named in
`supportedArchitectures` states its floors and ABI in the platform tag syntax,
such as `linux-x64-manylinux_2_26-node127`; any it does not state are unknown.
Fetching is looser (see [Install](#install)). Targets normalize implicit Linux
glibc before counting or comparing fields, so spelling it explicitly cannot
change specificity. Reject a publication if distinct variants can share the
highest score on any host. Clients also reject ties in malformed metadata rather
than use array order or a tag as an arbitrary tie-breaker.

### Metadata

Expand Down Expand Up @@ -407,8 +425,20 @@ unchanged across revisions is stored once.
### Lockfile

pnpm records a package with variants using the existing `variations`
resolution, ordered by the selection rule so that its first-match semantics
pick the best variant:
resolution shape, extended with the selection rule above. Serialize variants
in byte order of their derived tags for a platform-neutral lockfile; array
order does not choose the archive. At install time, evaluate every variant's
best matching target for the actual host and rank those matches.
Comment thread
zkochan marked this conversation as resolved.
Resolved

The current first-match implementation cannot express this rule for all hosts.
For example, variant A can list `linux-x64` and `darwin-arm64-napi9`, while B
lists `linux-x64-napi8` and `darwin-arm64`. Linux with N-API 9 must prefer B;
macOS arm64 with N-API 9 must prefer A. No single ordering of A and B works.
Reuse the resolution type and matching utilities, but extend the selector for
these records; older runtime lockfiles retain their existing selection behavior.
The required lockfile version marker distinguishes the new semantics.

For example:

```yaml
packages:
Expand All @@ -417,11 +447,12 @@ packages:
type: variations
variants:
- resolution:
integrity: sha512-<linux-x64 musl digest>
integrity: sha512-<darwin universal digest>
targets:
- os: linux
- os: darwin
cpu: arm64
- os: darwin
cpu: x64
libc: musl
- resolution:
integrity: sha512-<linux-x64 glibc digest>
targets:
Expand All @@ -430,12 +461,11 @@ packages:
libcVersion: '2.17'
napi: 8
- resolution:
integrity: sha512-<darwin universal digest>
integrity: sha512-<linux-x64 musl digest>
targets:
- os: darwin
- os: linux
cpu: x64
- os: darwin
cpu: arm64
libc: musl
fallback:
integrity: sha512-<primary digest>
```
Expand Down Expand Up @@ -491,9 +521,12 @@ lockfile is still the same on every machine, because every archive's
dependencies are resolved on every machine, as every platform package is in pnpm
today.

Five changes to the lockfile are needed:
Six changes to the lockfile and its interpretation are needed:

- `targets` gain the floor and ABI fields from the tag table.
- The selector ranks the best matching target of every variant at install
time, independently of serialization order, instead of stopping at the first
match. The lockfile version distinguishes this from existing runtime entries.
- A `fallback` resolution holds the primary archive. It is absent when the
version has no primary.
- `VariationsResolution` gains an optional `revision` (including `0` for
Expand Down Expand Up @@ -525,12 +558,18 @@ as a new `lockfileVersion`.
so CLIs need no spawning shim.
- `supportedArchitectures` decides which variants are fetched into the store,
for `pnpm fetch`, Docker images, and Lambda bundles: every variant that
matches one of its platforms, and the primary when one of those platforms
matches none. Its list form names each platform; its `os`, `cpu`, and
`libc` form stands for every combination of its values. Only one variant
can be linked under a package's name. The linked one is the host's, or, if
`supportedArchitectures` lists exactly one platform and omits `current`,
that platform's.
matches one of its platforms, and the primary when no variant can be linked
for one of those platforms under the linking rule below. For a platform other
than the host, a variant matches when its `os`, `cpu`, and `libc` match,
whatever its floors and ABI, unless the platform states them: fetching an
archive the eventual host cannot use only costs disk, while skipping the one
it needs makes an offline install fail. Its list form names each platform; its
`os`, `cpu`, and `libc` form stands for every combination of its values. Only
one variant can be linked under a package's name. The linked one is the
host's, or, if `supportedArchitectures` lists exactly one platform and omits
`current`, that platform's, chosen by the linking rule: a variant whose floor
or ABI that platform does not state is not linked, so a Lambda bundle built on
another machine names its target's floors, such as `linux-x64-manylinux_2_26`.
- For a package with variants, the installer walks the selected variant's
snapshot (`<name>@<version>/variants/<tag>`, falling back to
`<name>@<version>`), or `<name>@<version>` when the primary archive is
Expand All @@ -539,9 +578,11 @@ as a new `lockfileVersion`.
optional packages today. `supportedArchitectures` fetches the dependencies of
every archive it fetches.
- The linked variant depends on the host, so the virtual store directory of a
package with variants is keyed by the selected archive's integrity, not only
by name and version. That key also covers the archive's dependencies,
which follow from the selection. A global virtual store shared by an arm64
package with variants includes the selected archive's integrity in addition
to the existing resolved dependency-graph and peer-context identity. Archive
integrity alone does not identify dependencies: the same archive's ranges
may resolve differently in two projects or after an update. A global virtual
store shared by an arm64
Node.js and an x64 Node.js under Rosetta, or by two Node.js versions that
select different `nodeAbi` variants, then keeps both.
- The installer records which archive it linked for each package with
Expand All @@ -559,7 +600,14 @@ as a new `lockfileVersion`.
`supportedArchitectures` from the store through an API that this RFC leaves
open; they are not linked under the package's name.
- Server-side resolution through pnpr already produces platform-neutral
lockfiles. It writes `variations` entries without change to its protocol.
lockfiles. Reuse the request's existing `acceptedLockfileFormats` field:
the new lockfile version covers host-ranked selection, per-variant snapshots,
and fallback semantics together. When the selected graph requires variants
and the client has not explicitly accepted that format, return the existing
HTTP 400 `ERR_PNPR_INCOMPATIBLE_LOCKFILE_FORMAT` error. The returned
lockfile's version identifies its semantics; no separate capability or echo
is needed. Never silently downgrade to the primary. Clients accepting only
older formats can still resolve graphs that require no variants.

### Publication

Expand Down Expand Up @@ -780,6 +828,19 @@ records its own `transitivePeerDependencies`), and variants under a registry
revision (including a frozen install rebuilding `+r<revision>` variant and
fallback routes).

Also test the A/B multi-target example above on both hosts after reversing
lockfile array order, and two projects selecting identical archive bytes but
different versions of a ranged dependency. Their virtual store entries must
preserve the different resolved graphs. Cover equal constraint counts with an
absent versus present libc floor, numeric floor ordering, exact ABI versus N-API
overlaps, implicit versus explicit glibc, rejected score ties, and missing or
incompatible `acceptedLockfileFormats`. Unsupported clients must receive the
existing incompatibility error without a downgraded lockfile. Also cover
`supportedArchitectures` naming another platform without floors: every variant
matching its `os`, `cpu`, and `libc` is fetched, none with a floor is linked
for it, and the primary is fetched and linked when no variant without a floor
matches it.

## Prior Art

- PyPI: one release holds many wheels named with
Expand Down
7 changes: 6 additions & 1 deletion pnpr/text/0000-publish-manifest-verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ The profile defines each of these as a normalization, applied to both sides
before comparison. The `gypfile` step is the one case where the normalized
sides still differ: the submitted manifest claims a build that the archive
cannot run. That direction is benign. pnpr accepts it, serves the
archive-derived verdict, and reports the difference to the publisher. The
archive-derived verdict, and reports the difference to the publisher. This
exception applies only to an added `install: "node-gyp rebuild"` and its
associated `gypfile` flag, when the submitted manifest has no other lifecycle
script difference and archive inspection proves no implicit build would run.
It does not allow arbitrary added scripts, changed script bodies, or additional
dependencies just because they overstate what the archive requires. The
reverse direction, where the archive declares a script or dependency that the
submitted manifest omits, is the attack and is always rejected.

Expand Down
Loading