Skip to content

Version resolution internals ​

This page describes how osdk turns project declarations or CLI input into an installable exact version. Version resolution chooses a tool and version only; source ranking and installation transactions happen in later stages.

From request to exact version ​

The entry point is gather_requests. Explicit arguments such as node@20 are parsed by ToolRequest::parse. With no explicit tools, the CLI combines [tools] configuration, project package-manager declarations, and Node project metadata. Selecting npm, pnpm, Yarn, or a dynamic npm:<package> tool makes inject_node_dependency include Node in the same operation; it uses latest when the project has no Node declaration.

npm:<package> is parsed before the generic tool@version split so scoped npm:@scope/name@version requests remain intact. Its dynamic backend ID is canonicalized to npm:<package>, while bare npm remains the package-manager backend. See npm developer tool implementation.

cargo: uses the same URL-aware syntax parser with a stricter namespace schema. Registry subjects accept exact/latest/numeric-prefix selectors; canonical HTTPS Git subjects accept only latest, tag, branch, or a full lowercase revision. A Cargo request also injects or preserves exactly one configured/explicit exact Rust request. Rust is resolved first and its exact version is bound to every Cargo request before Cargo resolution continues. See Cargo developer tool implementation.

go: has a dedicated namespace schema for canonical module/command paths, semantic or pseudo-versions, tags, and a restricted build environment. It injects or preserves one managed Go request, resolves that runtime first, and then discovers the longest module root through the native Go policy or ranked Go proxy metadata. See Go developer tool implementation.

version/mod.rs defines VersionSpec:

  • empty, latest, stable, and current mean the newest stable release;
  • lts and lts/<name> mean the newest or named LTS line;
  • a complete semver, including prerelease or build metadata, is exact;
  • a leading =, as in =android-36, is a verbatim pin: it requires a character-for-character match among the published versions, never falls back to a looser tier, and does not require the text to be valid semver. This is distinct from "exact", which still degrades through the tiers below when the literal does not match. It exists because some catalogues use identifiers that are not versions and are not mutually exclusive under prefix matching: android-36 and android-36.1 are two different API levels, and dotted-component prefix matching makes the former match the latter. A verbatim pin also counts as an explicit request, so it can reach a pre-release without widening the policy for anything else;
  • incomplete numbers such as 20 or 20.11 are component prefixes;
  • Node project metadata may produce npm-style semver ranges with ||;
  • system is a reserved version spec. Generic backends do not currently resolve it to a PATH executable, and the Rust backend currently maps it to stable; this version-spec spelling does not enable the distinct opt-in tool_order system execution source.

Candidate lists are expected in ascending order. select_version scans backwards for the highest match: latest and ranges select stable releases, while prefix matching compares dotted components rather than raw string prefixes. A verbatim pin is compared character-for-character and fails to resolve when nothing matches. Exact requests match in three tiers: literal equality first, then semver core comparison ignoring build metadata (21.0.12 matches 21.0.12+8, prerelease identifiers must agree, and the highest build wins), and finally a dotted-component prefix fallback so 21.0.12 reaches a four-part PSU such as 21.0.12.1+1 only when no same-core release exists. The last tier mainly serves Java with its build numbers and PSU fourth segments; strict three-part semver backends never reach it. Before the component-prefix scan runs, the request text is checked against the published versions outright and a hit is returned directly: otherwise android-36 would select android-36.1 whenever both exist. select_version_with_prerelease provides the documented policy semantics for backends that opt into it; a verbatim pin counts as explicit, just like an exact version carrying a prerelease identifier. Python, GitHub, and npm-package-backed custom resolvers apply prerelease policy explicitly; the generic resolver and some backends still use select_version, so current policy behavior is backend-specific.

Configurable declaration precedence ​

The user reference owns the source enum, default order, inheritance, per-tool applicability and examples. selection::candidates collects eligible declarations before ranking, retains overridden locations without validating inactive values, and checks managed conflicts. execution::resolve adds the optional external target. The diagnostic module shares these collectors and the backend idiomatic filenames; its filesystem inventory is deliberately separate from resolution evidence. It uses resolve_without_probes by default and marks deferred system compatibility rather than silently relaxing strict policy. --probe uses the actual resolver and bounded native verification. Failed collection marks the inventory incomplete; strict conflicts retain candidates without reporting a valid winner.

Backend resolution and exceptions ​

After applying version aliases and one-shot backend options, the CLI calls Backend::resolve_version. The default implementation returns exact versions without querying a remote list and preserves every request option; non-exact requests call list_remote_versions and select_version. Skipping the version list for an exact request does not itself establish a cryptographic guarantee: installation applies the active checksum/attestation policy and may proceed with no evidence when require_checksums=false.

Some backends override the default. Node handles target architecture and npm ranges; Python handles implementations, variants, catalogs, and prerelease policy; Java handles distributions and JDK/JRE; Rust passes channels or versions to its isolated rustup. Cargo registry tools fetch paired metadata/index source data, remove yanked releases, and resolve exact/latest/numeric-prefix selectors, while Cargo Git selectors are retained verbatim. Go command tools resolve exact/latest/numeric-prefix/pseudo-version selectors through ranked Go proxies and bind the discovered module root. See node.rs, python.rs, java.rs, rust.rs, cargo_package.rs, and go_package.rs.

Installation reuse and update resolution ​

Installation distinguishes local reuse from update resolution. Ordinary execution, bare use, and lock replay retain the dynamic inventory fast path. An explicitly selected use or upgrade resolves floating requests through the backend first; the highest installed version must not substitute for remote resolution. Exact requests and verbatim =... pins can still reuse local installations directly. After resolution, the exact version and full dynamic identity are matched again, so checking for updates does not force another download or installation. Runtime, scope, public options, and artifact identity must still match. --force skips reuse, while offline resolution cannot guarantee upstream freshness.

Lockfile fast path and boundary ​

osdk install with neither explicit tools nor extra options first reads the nearest osdk.lock. locked_requests restores saved version strings, public options, and locked artifact data for the current platform; normal project resolution is used when that platform section is absent. Most backends save an exact version. Floating Rust values such as stable, beta, and nightly remain channel names, so a later rustup install may obtain a newer toolchain. Platform-specific sections let Linux, macOS, and Windows resolutions coexist.

After a successful fallback to project configuration, install records that exact resolution in the current-platform section; replaying an existing lock does not rewrite it. Project use upserts the selected tool and injected runtimes after installation, rolling its [tools] edit back if the lock cannot be written. Explicit install TOOL... changes no project declaration and therefore writes no lock.

The lock records a resolution and artifact identity, not a claim that existing bytes are trusted. Reinstallation reruns any available or policy-required checksum/attestation checks. If the lock has no digest/evidence and require_checksums=false, installation may still proceed without cryptographic integrity verification. Supplying tools or -o bypasses the lockfile read fast path; the latter still records new results after a successful bare project install.

User-global upgrade scope ​

upgrade -g excludes project configuration before App initialization and carries the user-only context through global npm reloads. Requests come directly from user tool declarations rather than the current directory's active resolver. Managed Node/Rust/Go dependencies are supplied from global declarations as well, keeping project version files out of injection. Ordinary tools share update resolution and upsert the user lock with global scope. npm/pnpm retains its controlled global transaction without rewriting selection metadata. Version and option changes belong to use -g, so global upgrade rejects selector overrides and -o. Batch upgrades can partially succeed: a later failure does not roll back tools and locks that were already published successfully.

Tool IDs and configured aliases take priority. Only otherwise-unrecognized names are looked up among commands of the currently selected global installs. Lookup selects installed versions and uses the same dynamic identity validation and bin filtering as shims, without guessing package-name suffixes, searching PATH, or executing program probes. npm candidates are restricted to global scope and retain the selected Node/installer identity. A unique match returns the original configured request. Multiple selections fail before installation and list their keys and full IDs. Older installed versions do not create extra owners, but separate aliases of one backend can have different constraints and must not be silently merged.

Global requests bind configured selectors and options before namespace validation. HTTP requires both its exact selector and sha256 during parsing. Explicit global upgrade arguments are parsed as names, so a bare HTTP ID is not mistaken for a new installation missing its options. Tests cover every static registry entry, declarative backends, and all seven dynamic namespaces. Cargo/Go fixtures are published through the production lifecycle with metadata seals; PyPI, Conda, and HTTP fixtures validate interpreters or artifact records. Damaged state and command collisions across backend namespaces are covered as well.

Verifiable invariants ​

  • Precedence, ancestor walking, structured files, and invalid package-manager values are covered by the resolver unit tests.
  • Prefix, range, LTS, and prerelease behavior is covered by the version unit tests.
  • The exact-version option-preservation regression test is in backend/mod.rs.
  • Package-manager auto-selection, Node injection, and lock restoration are covered by isolated_cli.rs and lockfile.rs.

The shared execution adapter is package_sources.rs; version policy is in version/resolver.rs. Native file discovery is candidate evidence, not a claim about the native effective winner. See package managers.

Opt-in external execution ​

tool_order also accepts system, only when explicitly listed. Defaults and [] keep it disabled. The system-tool reference defines supported adapters, home-before-PATH search, Windows .exe limits, probing and examples. External tools are absolute execution targets rather than managed versions or installations. Explicit CLI versions, managed lock replay and frozen deps retain authority. Non-frozen deps can use unpinned external tools, revalidates each run under this policy and does not write portable receipts for external paths. Dynamic package-tool runtime receipts remain managed; mixing them with system execution is rejected.

Released under the MIT License