Skip to content

Loom ID registry: keys and content gates

See also: Loom ID registry (declare, create and harvest a registry), Wheel SBOMs and Python API (loom.Run).

A registry entry maps a key to an spdxId. What a run looks up, and what id generate, id import and a harvest write, is the key below. One helper computes every key, so the surfaces agree.

What a key is

Element Key
software_File Its path from the registry's project root. A directory is the exception: it is keyed by its distribution path (demo, not src/demo), and id generate does not index directories
An AI model that has a file The same path, the key of the model file's own software_File
A loom.Run dataset package whose path exists below the root when declared Its path from the root
A package (dependency or the project's own) Its name and version: <PEP 503 name>@<PEP 440 version> (Package keys)
A Hugging Face or other pathless model, a remote, missing or outside-the-root dataset Its name

A path key is /-separated and relative to the project root the registry stores. It is Unicode NFC and is never case-folded. A path you type (a loom.Run path, the model or enrich argument, id generate PATH, -e) keeps the spelling the file has on disk, so Data/T.txt typed for data/t.txt finds the same entry on a case-insensitive file system. Two files whose names differ only by NFC/NFD are both skipped by id generate, with one WARNING:; a key read from a registry in NFD loads as NFC.

One model file is one id on every surface: project, --allow-build, wheel, embed-wheel, the Hatchling hook, the library API, model, enrich, loom.Run (set_model/use_model), id generate and id import. Two models with the same file stem are two models with two keys. A model has no key of its own beside its file's: a loom name that differs from the file's stem adds none (the merged ai_AIPackage takes the loom name and keeps the file key's id).

Package keys

A software_Package key is its PEP 503 name, @ and its canonical PEP 440 version: requests 2.31.0 is requests@2.31. Each release of a package is its own entry, so it keeps its id, and another release gets its own; going back to a release gets that release's id again. Old releases stay in the registry.

  • The version is the one the SBOM states: a pin (==, ===), else the lock file's, else the installed one, as the package's software_packageVersion shows it. A range (requests>=2) is keyed by the version it resolves to.
  • Spellings of one release are one key: 1.0, 1.0.0, v1.0 and 01.00 are 1, 1.0c1 is 1rc1. An epoch, a pre-, post- or dev-release and a local label (+cu121) are part of the release, so 1.0+cu121 and 1.0 are two keys.
  • A version that is not PEP 440 (a === text, an overlong number) is kept as given, NFC.
  • A package that states no version (unknown, NOASSERTION, none) has the bare name as its key. A bare key never stands for a versioned one, nor the reverse: there is no fallback.
  • The first @ separates the name from the version; an @ or % in a name that is not PEP 508 is written %40 or %25 (%40scope/pkg@1).

A project run of a project whose version is dynamic states unknown for its own package, so it keys it bare, while a wheel or Hatchling hook run states the real version: the two runs give the project's own package two ids.

Content gates

A model lookup is gated by content. The ai_AIPackage carries the model file's SHA-256 (and its SHA-512) as verifiedUsing (every route that reads the file; enrich, which makes no ai_AIPackage, uses only the gate), and the registry entry records the SHA-256. Retrained bytes at the same path get a new id. project, wheel, model and the other generating routes say INFO: ID registry: model <name>: no registry entry records its SHA-256; a new id is used when an entry exists under the key but records no, or another, hash; id generate and loom.Run say content changed instead (log lines). An entry with no hash never matches a model.

A Git LFS pointer is gated by its oid, the SHA-256 of the content it stands for, on every route, so its id survives git lfs pull and is shared by project, --allow-build, wheel, an sdist, the Hatchling hook and id generate, in any order. The registry records the oid for it whatever the SBOM states: a wheel, an sdist or the hook ships the pointer text itself, so their SBOM states the digest of that text, not the oid. id import records what the SBOM states, so an imported wheel or sdist SBOM holds the text's digest, and the next run misses once for each pointer (a new id), then holds; a registry written by an earlier Pitloom release does the same. The document id, taken from the package's Merkle root, differs between the hook and loom project for a project with pointers; the file ids do not. A merged loom fragment that names the pointer (loom.add_dataset) states the oid: an --allow-build or hook SBOM then lists the path twice, the fragment's element beside its own, and its own element keeps the registry's id.

A dataset package has a hybrid gate:

  • An entry with a SHA-256 is content-gated: the file's SHA-256, or a directory's Merkle root, the digest the package's verifiedUsing holds. A refreshed dataset is a new package id, and adding a file to a directory dataset changes its root, so it is a new id too.
  • An entry with no SHA-256 is a pin made before the data existed (or by an older registry) and hits any content, with INFO: ID registry: dataset <x> matched a pin without SHA-256; content not checked.

Scenario. loom id generate -e data/train.csv:dataset_DatasetPackage before data/train.csv exists pins the name with no hash: the first run that writes the file keeps the pinned id whatever its content. Pinning a file that already exists gates it: id generate -e stores the canonical path key and the digest, so a later change to the file is a new package. Running the same -e again once the file exists adopts its digest into the hash-less pin and keeps the id (INFO: ID registry: dataset <key> pin now gated by its SHA-256); an entry that records another digest gets a new id (content changed). id import of a loom.Run fragment likewise records the dataset package digests (a run's own harvest never writes a dataset).

One package exists per key and digest in a run when the path exists below the registry root at declaration: data/t.txt, ./data/t.txt, ../data/t.txt from scripts/, an absolute path, another case and NFC or NFD spellings are all one package. A missing, remote or outside-the-root dataset is keyed by the exact string, so two spellings of it are two packages.

input_datasets= is not matched through the key: it matches the spellings the input was declared under. After add_input_dataset("../data/t.txt"), input_datasets=["data/t.txt"] logs a WARNING: and skips the link.

Layout alias

A wheel or built archive names demo/x.py where the project holds src/demo/x.py. To reuse one id for both, a lookup may also try the other layout's key, under these rules:

  • Only a leading src/ or lib/ part is cut or added, one part, with two parts left. python/, packages/ and others get no alias: a wheel-only run mints its own ids for those files (two keys).
  • The two keys must hold equal SHA-256 digests. A key with no hash never hits through an alias.
  • The candidate must be unique. A tie is a miss, with one INFO:.
  • The shorter key must not exist as a real file or directory under the registry root: two real files are never aliases.
  • *.data wheel members are never aliased.

Worked example, wheel first. loom wheel of a built wheel mints and records demo/x.py. A later loom project, which looks up src/demo/x.py by its canonical key, hits the held demo/x.py (same SHA-256), keeps its id and the harvest replaces the held key with src/demo/x.py; one key per id, always. Reverse: loom id generate records src/demo/x.py; a later loom wheel looks up demo/x.py, hits the held key through the alias and leaves the held key as it is, with one INFO: ID registry: <number> element(s) matched a registry key through the src/lib layout alias per document. id generate over a registry that holds an alias key promotes it to the canonical key (INFO: ID registry: <number> key(s) promoted from a layout alias). It does so too when the canonical key holds older content and the alias the current one (an edit a wheel run saw first), as a loom project lookup would: the alias's id replaces the changed key's, so project and wheel keep one id (INFO: ID registry: <number> key(s) of changed content took their layout alias's id). Typed paths (loom.Run, model, enrich) look up the canonical key, so they reuse a wheel-minted id.

Monorepo

When the registry's root is above the project (pkgs/demo below it), project on a directory, the hook, --allow-build, and wheel, project <sdist> (generate on either) and embed-wheel given --project-dir pkgs/demo (project_dir=) key below the project's prefix (pkgs/demo/src/demo/x.py), and the layout alias applies below it. A member only the archive holds (PKG-INFO, a wheel's .data file) is keyed below the prefix too.

An archive read without --project-dir has no project: it keys by the archive's own paths, which miss a registry rooted above the project, with no INFO: and root-level keys harvested. A registry whose root is the project's root works on every surface. A file the build force-includes from outside the project but inside the root is keyed from the root. Under --allow-build, a built file with no source path cannot match its id generate key.

When a document's files cannot be keyed from the root, they are keyed by the path as read, with one INFO: ID registry: <number> file(s) keyed by their path as read: <reason>; a --project-dir outside the registry's root is one such reason (the project is outside the registry's root).

-e NAME[:TYPE]

NAME resolves against --project-dir, not the directory the script ran in. For dataset_DatasetPackage, ai_AIPackage and software_File, a NAME that is an existing regular file (a dataset: a file or a directory) below the project root is stored under its canonical path key, with its digest. When the key differs from the text typed, INFO: ID registry: -e <name> stored as <key>, said once the registry is written (a save that fails says only its error). Any other software_File or ai_AIPackage name is stored by name with INFO: ID registry: -e <name> stored by name: <reason> (not found, outside the project root, not a regular file; an ai_AIPackage name applies only to a model with no file, a Hugging Face id). A dataset that is missing, outside the root or cannot be hashed is stored by name with no hash, with INFO: ID registry: dataset <name> pinned without SHA-256: <reason>; one over the hash ceiling (--max-dataset-hash-bytes, else the project's max-dataset-hash-bytes, else 4 GiB) is such a dataset, as in loom.Run. A software_Package is NAME@VERSION, stored as its package key (-e Requests@2.31.0:software_Package is requests@2.31, with INFO: ID registry: -e <name> stored as <key>); a NAME with no @VERSION holds only a package that states no version, with INFO: ID registry: -e <name> stored without a version: holds only a package that states none. A package NAME that is not a PEP 508 name (foo==1.0, foo 1.0) is a usage error (exit 2); == adds a hint to write NAME@VERSION. The other types are stored verbatim. A script that runs from scripts/ and declares ../data/t.txt is looked up as data/t.txt: pin -e data/t.txt:dataset_DatasetPackage, the path from the project root. The script's own string matters only for a dataset with no path below the root.

id import

  • The registry's root is --project-dir (default: the current directory), as for id generate, and the SBOM's file names are keys below it. An SBOM does not record its project's directory, so import from above the project without --project-dir gives keys that a run of the project does not look up. An existing registry keeps its root: --project-dir naming another one is an ERROR:.
  • A model takes the key of the unique software_File in the same SBOM with the same SHA-256; else the key of the one registry file entry recording that SHA-256 (INFO: ID registry: model <name> keyed by the registry's file with its SHA-256: <key>); otherwise it is imported under its name, with INFO: ID registry: model <name> imported under its name: no unique file with its SHA-256.
  • A dataset package is keyed by the path of its one same-hash file in the SBOM, else by its name, when that exists below the root or the current directory; it gets its digest. When the key differs from the name, one INFO: ID registry: dataset <name> keyed by its path: <key> says so. A name found nowhere stays a name key: dataset <name> keyed by its name: not found: declare paths relative to the registry root (id import --project-dir) or run id import from the directory the script ran in.
  • A file whose key is not held with its SHA-256, but whose layout alias is (one held key with its SHA-256), is imported under that held key, counted in the layout-alias INFO:. When its own key holds other content, that key keeps its entry and one INFO: ID registry: <number> file(s) imported under their layout alias: their own key holds other content says so.
  • An element whose id is held under another key of its type, one no other element of the SBOM moves, is not imported: INFO: ID registry: '<type>' <key> not imported: its id is held under <held key>. This is decided before anything is written, so importing the same SBOM again changes nothing.
  • A package is keyed by the version it states (Package keys); one with none, or NOASSERTION, by its bare name.
  • A key held by several elements is skipped (see What a registry pins).

Fallbacks print INFO:

Every deviation from the key rules prints one INFO: ID registry: ... per document, element or pin, never per file in a loop. grep 'ID registry:' over stderr lists them:

Event Line (after INFO: ID registry:)
Files not keyable from the root <number> file(s) keyed by their path as read: <why>
Layout alias used <number> element(s) matched a registry key through the src/lib layout alias
id generate promotes a held alias <number> key(s) promoted from a layout alias
id generate replaces a changed key by its alias <number> key(s) of changed content took their layout alias's id
Model refused by the gate (project, model, wheel, ...) model <name>: no registry entry records its SHA-256; a new id is used
Content changed (id generate, loom.Run) content changed for <key>; minting a new spdxId (old: <id>)
loom.Run or model hashed model keyed by its name model <name> keyed by its name: <why>
Dataset by name, or ungated dataset <key> keyed by its name: <why>, dataset <key> looked up ungated: not hashed
Pin with no hash dataset <name> pinned without SHA-256: <why>, dataset <key> matched a pin without SHA-256; content not checked
Pin adopts a digest dataset <key> pin now gated by its SHA-256
-e decisions -e <name> stored as <key>, -e <name> stored by name: <why>, -e <name> stored without a version: holds only a package that states none
id import decisions the model and dataset lines above, '<type>' <key> not imported: its id is held under <held key>, <number> file(s) imported under their layout alias: their own key holds other content
Harvest leaves a gated entry content gate kept for '<type>' <key>: harvested id <id> not recorded over <held> (or element id <id> with an older SHA-256 not recorded over <held>)
Hashed model not recorded model <name> not recorded: no unique file with its SHA-256

A loom.Run lookup that finds an entry whose SHA-256 no longer matches says WARNING: ID registry: <kind> <key>: its SHA-256 no longer matches the entry; minting a new spdxId [registry-hash-conflict], <kind> naming the element (model, dataset package, file, entity) because a dataset package and its file share a key.

Merged fragments and harvest

A harvest writes each element under the key its lookup used. An element with no recorded key (a merged loom fragment, id import) follows three rules:

  • It never moves an id held under another key of its type.
  • A stale element, whose SHA-256 is older than the entry's, never rolls the newer entry back: the entry stays and the line above says so.
  • A hashed model is recorded only under the key of its one same-hash file in the document; with none, it is not recorded.

id import of a loom fragment keys its datasets and models by their same-hash file, as above. Each document (project, wheel, env, model, enrich, the hook and embed-wheel) reserves every id the registry holds for a file, package, AI package or dataset package, whether it looked it up or not, so an id minted on a miss is never one another key holds. Not reserved: agents and tools, whose ids are the same every run; the id held under a model card dataset's name; and, for model and enrich, the id held under the model's own name (the key id import writes for a loom model SBOM).

What changed for an existing registry

Pitloom 0.22.0 and later write version 4, whose package keys hold the version. A version 3 file is refused on every command, with one ERROR: loom <command>: ID registry: FILE=<path>: version 3, expected 4 (no migration support) [registry-wrong-format], and is left as it is: nothing is dropped or rewritten. To keep its ids, delete it and loom id import the last SBOM a run made with it (every file, model and dataset keeps its id, and each package is keyed by the version that SBOM states); loom id generate alone starts afresh, with new ids.

Credentials in a key

A key is stored as written, so a key that, as a whole value, is a URL, a PURL or an scp-style address (alice:password@host:path, a dotless one such as build:42@ci:linux too) and holds user information, a secret query value (token, api_key, signature...) or an access token (ghp_...), or a query nested or encoded too deeply to read (more than 16 ?, or a PURL qualifier still encoded after five decodes), is stored with a WARNING: for -e and register() by default (WARNING: URL=<url>: ...; the ID registry stores the key as written [credentials-unsafe/registry]), and refused in the refuse mode (--refuse-url-credentials, url-credentials = "refuse", refuse_credentials=True); it is skipped, with a warning, in either mode, for an SBOM element that id import or a run's harvest reads (its key or its spdxId). loom id generate and loom id import read the project's url-credentials when no -o is given, as for the registry's location, or when --project-dir is given (with -o, a config that cannot be read is warned of and the warn mode applies). A credential percent-encoded in a PURL qualifier counts, and so does a URL or an access token anywhere in a key or an id (a key is an identifier, never prose: urn:x:https://user:pw@host/ns, src/https:/user:pw@host/x). A code, session, ticket, sid or otp parameter, and a user name alone on an ssh or git URL (git+ssh://git@github.com/o/r, a repository's address), are kept as written. A software_File key is a file name, not an address, so it is never refused as an scp-style address.

A registry file that already holds such a key or spdxId (written by hand, by a run in the warn mode, or by Pitloom 0.24.0 or earlier) is loaded as it is by default, with one WARNING: per entry (...; ID registry file '<path>' is loaded as it is; remove the entry). In the refuse mode it is not loaded, and is left as it is: nothing is dropped or rewritten. IdRegistry.load() and IdRegistry.rebase() (the re-read before a save) raise, and every command that reads the registry stops with one ERROR:, shown masked: ERROR: URL=https://***:***@host/model: holds user information, a secret query value or an access token, or a query nested or encoded too deeply to read; ID registry file '<path>' is not loaded; remove the entry [credentials-unsafe/registry]. Remove that entry from the file yourself (the first in key order is named, the key's when both the key and the id hold one), and run again. The credential is still in the file's version history: rotate it. A file whose namespace holds one does not load, in either mode. The same rule, and the fields of an SBOM it covers: Credentials in URLs.