Repository navigation
feat: handle multiple registries serving the same driver name - #584
Conversation
|
Of course, another solution would be to have a separate entry for the migrated driver. The question becomes which behavior is more confusing. In an ideal world, I think the approach in this PR is better so long as the migrated driver only publishes prerelease versions until it is "fully" compatible with the existing driver. If there's a possibility of divergence, it may be better to bite the bullet and have two names for the driver. |
eitsupi
left a comment
There was a problem hiding this comment.
I had Claude and Codex go through this PR together with the lockfile v2 implementation.
This is a short summary of what came out of that.
Falling back to a later registry makes sense for the migration case. The one thing that conflicts with lockfile v2 is that the registry choice depends on the host platform.
A v2 lock entry has one source and one version per driver, and the artifacts for all platforms come from that registry. Replay only uses the recorded registry, including when it adds an artifact for a platform that is missing from the lock.
In this PR, a missing package for the host platform also triggers the fallback.
GetWithConstraint filters by platform before it reports that no version satisfies the constraint, so that path falls back as well.
If registry A has 1.0.0 for Linux only and registry B has it for macOS only, dbc sync locks A on Linux and B on macOS, and the second machine then fails to complete the entry.
Suggestion: split the selection into two steps.
- Choose the registry without looking at the platform: the first registry with a version that matches the constraint (or the exact version) and the prerelease setting.
- Select the package in that registry only. A missing package for the platform is an error, not a fallback.
Both cases in the PR description (a first registry with only prereleases, and superfast=0.9.0) still work with this.
This also fixes the edge case: pkginfo: [] moves on to the next registry, while a matching version with packages: [] is an error. A test for that would help, together with a dbc sync test that the fallback registry is recorded in the lock and kept on replay.
| return candidate.GetPackage(nil, config.PlatformTuple(), m.Pre) | ||
| }) | ||
| if err != nil { | ||
| if !m.Pre && !d.HasNonPrerelease() { |
There was a problem hiding this comment.
For any error from ResolvePackage, this checks HasNonPrerelease() on the first entry and may replace the error with the --pre hint.
An invalid-metadata error from a later registry is hidden that way. add.go uses pkg.Driver and does not have this problem.
| and download or verification failures do not trigger fallback. Existing | ||
| lockfiles retain their registry binding. |
There was a problem hiding this comment.
"Existing lockfiles retain their registry binding" is true for v2 only. A v1 lock keeps the version and resolves the registry again.
The docs could also say that a higher-priority registry no longer hides a driver of the same name in later registries, since that differs from 0.3.1.
|
Ok. That is going to be a more major refactor, because currently we resolve both version and platform at the same time. |
|
Updated (thanks to GPT): resolve the version, then the platform; treat a lack of a package for a platform as a fatal error to avoid fallback |
There was a problem hiding this comment.
Reviewed with ChatGPT.
The previous concerns about registry selection and lockfile v2 consistency have been addressed. No remaining blockers.
One follow-up is recommended before 0.4.0: dbc install should select the latest host-compatible version within the requested constraint.
For example, if 3.0.0 does not support macOS x86_64 but 2.5.0 does, dbc install 'driver=>=2.0.0' should select 2.5.0.
It seems that other package managers like uv take the platform into consideration when directly installing.
Registry selection should remain platform-independent, with no fallback to another registry due to missing platform support.
Project lockfile resolution should remain host-independent.
This can be addressed in a separate PR. (I can take)
zeroshade
left a comment
There was a problem hiding this comment.
The approach is sound: choosing the registry without looking at the platform, then requiring the package to exist in that registry, keeps lockfile v2 consistent. Two things I'd block on, plus some cleanups.
Should fix before merge
- Version ranges no longer fall back to an older version that supports this platform (
GetWithConstraint). The platform check was removed from that filter. So in a single registry,install 'x>=2.0.0'used to pick 2.5.0 when 3.0.0 has no build for this platform; now it fails. That affectsinstall,add,GetDriverListandsync_plan.resolve(with a constraint). This is a regression against the base branch, not just a missing feature, so I'd rather not split it out. The fix fits the design: pick the registry from the version constraint alone, then pick the newest version in that registry that has a build for this platform. Choosing the registry still ignores the platform. internal/api/ops.goResolvemixes registries.out.Pathand the initialout.Versionscome from the first entry,d, and are only replaced whenResolvePackagesucceeds. On failure the caller gets the first registry's versions with noLatest; on success, a different registry's versions. Suggest resolving once before the loop and building the whole result frompkg.Driver.
Cleanups
findDriveranddmapare now only used to check that the driver exists (inadd.go,install.go,driver_list.goandsync_plan.go), andsync_plan.resolvecomputessourceURLtwice. Either drop the pre-checks or keep them only to attach the registry error context. (Side note:dmapindriver_list.gokeeps the last entry for each name, so the old code effectively resolved from the lowest-priority registry. That's fixed here; deletingdmapmakes it obvious.)install.go's!m.Pre && !pkg.Driver.HasNonPrerelease()is correct only because a non-miss error implies a version was already selected. Checking forpackageMissexplicitly (e.g. through an exporteddbc.IsPackageMiss) would make that invariant visible.ResolvePackagebecomes part of the root package's public API. The doc comment's "artifact error" should say that it means any error that isn't a selection miss, e.g. an invalid hash or URL.TestPlanFallbackRegistryReplaytakes&f.registries[1]and then swaps the contents off.registries, so that pointer silently changes target. It only passes because replay never reloads the index. Copying the registry value instead would be safer.- Docs: there's a stray comma in "requested version, or prerelease settings". It's also worth stating that with
--pre, a first registry that only has prereleases wins over a stable version in a later registry.
|
Ok, tried to address the feedback again 😅 |
zeroshade
left a comment
There was a problem hiding this comment.
Thanks, this addresses everything. Splitting selection by command is the right call: install/Client.Install/Resolve pick the newest version with a build for this machine within the constraint, while sync/lock/add pick the version without looking at the platform and then require a build for this machine, so a project lock is the same on every machine. The registry choice never falls back on missing platform support in either case. Resolve now builds its whole result from one registry's entry, the findDriver pre-checks are gone, ErrPackageMiss makes the fallback rule explicit at the call sites, and withPrerelease() stops the planner from mutating the user's constraint. Two nits, fine to leave for later: the TODO in selectionMiss about platforms no longer applies since that check ignores the platform, and the "only prereleases" miss still suggests dbc install --pre when it surfaces from sync/GetDriverList (pre-existing). The three open threads are all outdated and addressed, so they can be resolved. LGTM.
dbc will now scan each registry and take the first registry with a matching driver. So for example, if the first registry only has prereleases, now dbc will fall down to the second registry; or if there's a version selector, the first registry with a matching version will be taken. dbc will not search all registries to determine the newest driver version. Assisted-by: GPT-6.1 Sol
|
Rebased |
…uiltin_registries` (#598) Follow-up to #360. `replace_defaults` is named for replacing the built-in registries, which is no longer needed: with #595 a third-party registry can name its signing key and works like the built-in ones, and with #577 the built-in registries can be reached through a mirror. What the setting does is remove the built-in registries (the public and the private Columnar registry) while keeping the `[[registries]]` entries, so this renames it to `exclude_builtin_registries`. The user config now wins when it excludes them. ```toml exclude_builtin_registries = true [[registries]] url = "https://drivers.example.com" name = "example" ``` - **Semantics:** the built-in registries are excluded when either the user `config.toml` or the project's `dbc.toml` sets `exclude_builtin_registries = true`, and a project's `false` no longer adds them back. The CLI warns when a `dbc.toml` sets `false` that the user config overrides, and keeps that `false` when it writes the file back. The setting only stops dbc from adding the built-in registries to the list; it is not an access control, so a `[[registries]]` entry with a built-in registry's URL is still used. Omitting the key and `false` now mean the same thing in both files. - **Migration:** `replace_defaults` has not been released, so there is no alias. The old key is ignored like any other unknown key, so a `replace_defaults = true` written for a development build has to be renamed or the built-in registries are used again. - **Go API:** `GlobalConfig.ReplaceDefaults` becomes `ExcludeBuiltinRegistries`. `LoadProjectRegistries` returns a `bool` instead of a `*bool`, and `WithProjectRegistries` takes a `bool`, since there is no longer an "inherit" state. - **Docs:** adds a "Configuring registries" section to the driver registry concepts page and a "Registries" section to the driver list reference with the same content as #393, updated for the new key and semantics, so this supersedes #393. For drivers that several registries publish, they describe the behavior since #584 (the highest-priority registry that has a matching version).
Stacked on #598. Since #584, a driver comes from the highest-priority registry that has a matching version, so which registry serves a driver depends on the order of the registries and on what each one publishes at the time. This lets a driver list name the one registry a driver comes from, like a dependency's registry in Cargo or `[tool.uv.sources]` in uv. ```toml [[registries]] url = "https://drivers.acme.example.com" name = "acme" [drivers.snowflake] source = { type = "registry", name = "acme" } [drivers.flightsql] source = { type = "registry", url = "https://dbc-cdn.columnar.tech" } ``` - **Selection:** `name` refers to a `[[registries]]` entry in the same file (a project cannot refer to a name from the user config); `url` selects a configured registry by the identity `dbc.lock` records (no user information, query or fragment). The source must bind to exactly one configured registry, since registries that differ only in query cannot be told apart in the lockfile. `type` is required so other source types can be added later (#497). - **Built-in registries:** `https://dbc-cdn.columnar.tech` and `https://dbc-cdn-private.columnar.tech` have no configured name, so a source selects them by `url`, as `flightsql` does above. Declaring one in `[[registries]]` with a `name` also works. - **No fallback:** the driver is resolved from that registry's index alone. A missing driver, a missing version or a failed fetch is an error, and the merged index is not fetched when every driver has a source. - **Lockfile:** nothing new is recorded; the lock keeps the registry identity. If the source selects another registry than the lock entry, `dbc sync` stops and `dbc lock` resolves the driver again (the pinned signer is still compared as before). Naming the same registry another way keeps the entry. - **CLI:** `dbc add --registry <name|url>` records the source, and `dbc add` without it keeps a driver's existing source. `dbc install --registry <name|url>` installs from one registry of the user config, and installs again when the same version is already installed, since an installed driver does not record its registry. `GetDriverList` honors the source too. `Client.Install` and the bindings have no registry option yet. - **Names:** a registry name must be unique within its file, and a configured name now takes precedence over the name a registry's index gives itself, so the name used in `source` is also the one `dbc search` shows.
Part of #592. As noted in the review of #575, `dbc lock` required a build for the current platform, so a Linux CI runner could not lock a macOS-only driver. If the selected version has no build for the current platform, `dbc lock` records builds with published archive hashes. It downloads no archives for other platforms and fails if it cannot record any. If an existing entry lacks an artifact for the current platform and the locked version has no build for it, `dbc lock` keeps the entry. Version and registry selection remain independent of the current platform (#584). If the selected version lacks a build for that platform, `dbc sync` fails without switching versions or registries. Upgrading a v1 entry also fails if its library checksum was recorded for the current platform and there is no build to check it against. #608 adds declared platforms to `dbc.toml`.
Close #592, and the project-side answer to the first review point of #584: instead of falling back to an older version that has a build for the machine running the command, a project can declare the platforms its drivers must support. ```toml platforms = ["linux_amd64", "macos_arm64", "macos_amd64"] ``` - **Selection.** `dbc add`, `dbc lock` and `dbc sync` choose the newest allowed version with a build for every listed platform, on every machine. A missing build does not trigger registry fallback. If the selected version lists more than one package for a listed platform that needs an artifact, dbc reports an error instead of selecting an older version. The list must contain at least one valid, distinct platform (an alias such as `darwin_arm64` counts as a duplicate), and the current platform is not added implicitly. `dbc sync` requires the current platform to be listed. - **Lockfile.** `dbc.lock` records the declaration and an artifact for each listed platform. A listed platform is handled like the current one: for a new artifact, dbc records the published hash when available, and otherwise downloads the archive, checks it with the installation's extraction safeguards, verifies its signature unless `--no-verify` is set, and records the measured hash. Other platforms are still recorded from published hashes. - **Changes.** When the declaration is added or changed, dbc fills missing listed platforms from the locked version and registry. If all are already recorded, it skips the index. Extending an entry keeps every recorded artifact, even if the registry no longer lists it. This follows normal lock replay, much like [Cargo keeps using locked crates after a yank](https://doc.rust-lang.org/cargo/commands/cargo-yank.html). If the locked version lacks a build needed to extend the entry, dbc resolves the driver again and warns if its version or registry changes. Completion fails if the locked registry uses a query string or no longer lists the driver. Removing the declaration returns to normal lock replay. - **Warnings.** `dbc lock` warns once when the current platform is not listed, because `dbc sync` will refuse it. It also warns when a v1 pin is dropped because its version lacks a listed platform, even if there was no checksum. **Without `platforms`,** the implicit platform means two different things, on purpose: - for version selection, no platform counts, so every machine resolves the same version (#592); - for what the lock records, the current platform is the one required platform when the selected version has a build for it: its archive is measured when no hash is published, as v1 lock files and #607 already do, while other platforms are recorded from published hashes only. Treating the undeclared case as "every platform" would download every platform's archive to measure the hashes a registry does not publish; treating it as "the current platform" for selection would make the locked version depend on the machine. `dbc add` now also accepts a version without a build for the current platform. `dbc install`, `dbc search -v`, `dbc info` and `dbc list` ignore `platforms`: `install` picks the newest version with a build for the current platform (#584), `search -v` lists the versions available for it, `info` shows the latest version's packages for every platform, and `list` shows installed drivers.
Addresses the review of #595: with #584, a registry that serves a driver name also serves it for every driver list that does not pin it, so adding a registry with its own key adds a code signer for every name it lists. This keeps the #584 fallback, which is what lets a driver move between the built-in registries, but only between registries with the same signer, and makes the choice fail when it cannot be checked. - **Same signer:** when several registries list a driver name, whatever their versions and platforms, they must all verify their packages with the same signer. Otherwise `ResolvePackage` returns a `SignerConflictError` that names the registries and their signers, before any package is selected or downloaded, and the CLI suggests a `source` in `dbc.toml` (#599) or `--registry`. Registry priority stays project → user → built-in. - **Missing index:** a registry whose index cannot be fetched or read might list the driver too. Its signer is known from its configuration, so `ResolvePackage` returns `ErrIncompleteIndex` only if that signer differs from the signer of the registries that list the driver (or, if none does, from another failed registry's signer), or if it cannot identify the failed registry or its signer. A failed registry with the same signer is skipped, as before this PR. This applies to new resolution in `dbc add`, `dbc install`, `dbc lock`, `dbc sync`, `Client.Install` and `Resolve` in the bindings. Replaying a lock entry that still satisfies the driver list, drivers with a `source` and `dbc install --registry` only need the registries they use. - **API:** `ResolvePackage` (unreleased, from #584) takes the error that `Search` returned with the drivers. `Search` reports each failed registry as a `RegistryIndexError` with the registry's configuration; its message leaves out the user information and query of the registry URL, also where the HTTP error repeats the request URL. - **Bindings' `Resolve`:** invalid registry metadata during package selection, such as a malformed archive hash or a missing version, now returns an error. If a listed driver has no eligible version, `Resolve` still returns its versions without `latest`. Previously both cases returned the same kind of result, even though `Install` already rejected the same invalid metadata on the host platform. - **Relation to #595:** there is no per-registry key setting yet, so every registry is verified with the built-in Columnar key: no conflict can occur and no failed index fails the signer check until #595 lands. #595 will derive the identity from each registry's signing policy (the digest of the configured certificate for a key, and an identity of its own for each unsigned registry), marked with TODO comments. Once #595 lands, a failed registry with a different signer can block resolution of drivers without a `source`. This should not be released before #595.
Follow-up to #576. Custom registries (#360) can name the key their packages are signed with, so drivers from them no longer need `--no-verify`. This also turns on the signer check of #601 for these keys. Closes #613. ```toml [signing_keys.acme] type = "openpgp" public_key_file = "keys/acme.asc" # or public_key = "-----BEGIN PGP PUBLIC KEY BLOCK-----..." [[registries]] url = "https://drivers.acme.example.com" signing_key = "acme" # omitted: built-in Columnar key; false: unsigned registry ``` - **Config:** in the user `config.toml` and in `dbc.toml`. A `signing_key` name is resolved only in the file that declares the registry, so adding a key to the user config never changes what a project trusts. A project cannot declare a registry from the user config or a default registry (compared without query, user information or default port) with a different signing policy; that is an error. An omitted `signing_key` always means the built-in Columnar key. `columnar` is reserved. Registry URLs in these files reject empty interior path segments, `.` or `..` segments even when escaped, and escaped slashes, so that another spelling of a trusted registry's path cannot get past this check. Registry identities, including lockfile sources, omit default ports and normalize path escapes by decoding unreserved characters and uppercasing the remaining hex digits, preserving the distinction between escaped and literal reserved characters. - **Keys:** exactly one public certificate, armored (or binary in a file). Private keys, several keys or armor blocks, unknown packets and trailing data are rejected instead of skipped. A relative `public_key_file` is relative to the file that defines it; in `dbc.toml` it must stay inside the project directory (no absolute or UNC paths or `..` that leaves it, read through `os.Root`). The file is read only when its key is needed, also for the signer check, and the certificate read is reused for the rest of the operation; a failure is an error, never a fallback to another key. - **Signer check:** when several registries list a driver, or an index is missing, their signers must match (#601). Keys match only when their certificates are identical, and every unsigned registry is a signer of its own, so a missing index of an unsigned registry, or of one with a key the others do not share, stops new resolution of drivers without a `source`. The signer check, the verification and the lock pin of one operation use the same certificate, even if a `public_key_file` changes meanwhile. - **Lockfile:** the selected key's fingerprint is pinned as in #576, or `type = 'none'` for `signing_key = false`. Replay requires the registry's current configuration to select the same signer, also with `--no-verify`, so a lock entry can neither switch keys nor turn verification off on its own. Each unsigned registry counts as a separate signer, so a driver locked from one is not resolved again from another unsigned registry, even with a changed `source`. - **Install:** `dbc install` and `Client.Install` select the key from the registry of the chosen package before downloading it, so a driver that a later registry with the same key serves (#584) is verified with that registry's key. `--no-verify` / `AllowUnsigned` skip the signature check, but not the signer check of an implicit selection; local archives keep using the Columnar key. The `install` and `sync` JSON report `signature_verified`, and `verify.start` / `verify.complete` are only emitted when a signature is checked. - **API:** `Registry.Signing` (`RegistrySigningPolicy`, zero value = Columnar key) with `SignWith` / `Unsigned`, plus `NewSigningKey` and `Registry.ResolveSigningKey`. `RegistrySigningOperation` keeps the keys of one operation; its `ResolvePackage` replaces the unreleased function of the same name (#584, #601). The unreleased `LoadProjectRegistries` / `WithProjectRegistries` become `LoadProjectConfig` / `WithProjectConfig`, so key definitions and their file path travel with the registries. Bindings take `signingKey` on explicit registries (`registry.<n>.signing_key` in the C API). The policy only covers detached OpenPGP signatures of registry packages; another source such as Packslip would get its own policy and lock signer type.
dbc used registry priority for overrides (#360), and #584 kept that order when choosing the first registry with a matching version. This gave order precedence over version, much as uv's default `first-index` does to limit dependency confusion. The review of per-registry signing keys (#595) showed that registry order could also determine the signer, so #601 made cross-signer name collisions an error during implicit resolution. Within that signer boundary, dbc now picks the highest eligible version across registries, as pip does across indexes, so drivers keep getting updates after moving to another registry. - **Selection.** A candidate must satisfy the version requirements and have builds for every required target in one record. Registry order breaks ties at the highest SemVer precedence. In the winning registry, a second eligible record of the same precedence or any duplicate of the winning full version is an error. Exact requests include build metadata and reject duplicate exact records even when none covers all required targets. Errors in a selected artifact stop resolution. - **CLI.** New resolutions can select a newer version from a lower-priority registry. To take a driver from a specific registry, set its `source`. Compatible lock entries still replay from their recorded source. Successful CLI selections warn on stderr when a same-signer index was skipped. Registry version constraints now reject build metadata. - **v1 lock files.** If the recorded version is no longer listed, migration stops with or without `platforms`. A recorded version that lacks a build for a declared platform is still resolved again. - **Go API.** `Client.FetchIndex`, `Client.FetchRegistryIndex`, and `SelectRegistry` replace `SigningOperation.ResolvePackage`. Requests take a constraint or an exact version. The project planner decides whether to keep a locked version. `Index` aliases an internal type so public callers get complete snapshots from the client and cannot pass filtered search results; tests outside the module can serve an index through `NewClient` with `WithRegistries` and `WithHTTPClient`. - **Bindings.** `Resolve` reports the highest eligible stable version as `latest` and lists versions for the requested platform across reachable same-signer registries, including prereleases. Go and npm-wasm expose skipped indexes in `warning`. C and Rust warning support follows in #633. `Client.FetchRegistryIndex` requires exactly one configured endpoint match before fetching. This prevents it from picking a signing policy by list order when `WithRegistries` lists the same endpoint under different policies. The released `Driver` methods remain single-driver lookups. #634 aligns `GetPackage` with exact version matching and deprecates `GetWithConstraint`.
dbc will now scan each registry and take the first registry with a matching driver. So for example, if the first registry only has prereleases, now dbc will fall down to the second registry; or if there's a version selector, the first registry with a matching version will be taken. dbc will not search all registries to determine the newest driver version.
The use case is to handle migrating a driver from one registry to another; the idea is that newer versions will go to the primary registry, but we still want to be able to install drivers from the existing registry.
Current behavior:
$ ./dbc search -v --pre • superfast [local-a] Title: Demo Description: Demo driver License: Apache-2.0 Available Versions: ╰── 1.0.0-beta.1 • superfast [private] Title: Demo Description: Demo driver License: Apache-2.0 Available Versions: ├── 0.8.0 ╰── 0.9.0 $ ./dbc install superfast Error: driver `superfast` not found (but prerelease versions filtered out); try: dbc install --pre superfast $ ./dbc install 'superfast=0.9.0' Error: no package found for driver superfast that satisfies constraints =0.9.0dbc searches for the driver, finds it in the first registry, but filters out all versions, and then fails - it doesn't search the second registry. Explicit version filters don't help because again, we never look at the second registry in the first (second?) place.
Assisted-by: GPT-6.1 Sol