Storage, CAS, Cache, and Cleanup Implementation
osdk separates persistent installation state, content-addressed objects, and disposable caches. Directory resolution is in dirs.rs, CAS behavior in store/mod.rs, and link selection in store/link.rs.
Directory boundaries
The default layout is below. The data and cache roots are overridable, while store and installs also have dedicated overrides; the remaining paths are derived subdirectories:
<installs>/<tool>/<version>: materialized fixed-backend SDKs;<installs>defaults to<data>/installsand can be overridden byOSDK_INSTALL_DIR.<installs>/<dynamic-tool>/<version>/b3-v2-<digest>: fingerprinted roots for osdk-owned isolated dynamic tools.<installs>/npm-global/<package>/<version>/b3-v2-<digest>: fingerprinted roots foruse --global npm:<package>. Older version-only roots containing.osdk-tool.jsonare detected as legacy state but never reused or executed.<data>/models/<name>/snapshots/<snapshot>: materialized model snapshots.<data>/model-refs/<root-id>.json: exact model snapshot references by project.<data>/store/<aa>/<bb>/<blake3>: CAS shared by SDK and model files.<data>/shims: command shims.<cache>/downloads: downloaded tool archives and checksum/source/attestation sidecars.<cache>/tmp: installation extraction scratch space.<cache>/remoteand<cache>/sources: remote metadata and source-probe caches.<cache>/pkg: native downstream package-manager and model-client caches.<cache>/npm/v1/cacheand<data>/store/npm: the cache/store shared by npm-backed isolated, project, and global npm tools; each real project or controlled install root still keeps its own native lock.
Dirs::ensure creates the core tree during CLI initialization. Store and installs default to the same data volume so hardlinks work. OSDK_STORE_DIR may put the store on another volume, which can force materialization to fall back to reflink or copy. Each dynamic root contains .osdk-install.json schema 1. Its nested identity contains tool, version, platform, scope, material_options, dependencies, materials, and canonical b3-v2: install_id. This identity drives reuse, activation, shim dispatch, where, uninstall, and reshim; sibling identities may coexist. Project-managed npm state under .osdk/npm-bin remains a separate project-owned layout. For Cargo developer tools, the fingerprint also binds the exact managed Rust tree and registry/Git materials. Installation uses a sibling stage with private home, cargo-home, target, and tmp directories; those workspaces are deleted before only the validated bin output and native metadata are published. For Go developer tools, the fingerprint binds the exact managed Go runtime, selected proxy/module root, tags, and allowlisted build environment. Private home/GOPATH/temp directories stay in the sibling stage, while module and build caches are shared under <cache>/pkg/go-mod and <cache>/pkg/go-build.
SDK pipeline and locking
Archive backends enter pipeline::run_with_attestation in this order:
- Fixed backends acquire a blocking exclusive process lock at
installs/<tool>/.locks/<version>.lock. Dynamic backends acquire an identity-qualified lock and keep it through backend-specific finalization. - Under the lock, check
.osdk-complete. A complete install is reused, although requested attestation is still reverified and receipt evidence merged. - Remove a stale partial directory for that version.
- Reuse or download the
<cache>/downloads/...archive and verify checksum/attestation. - Extract under
<cache>/tmp/...-<pid>. - Ingest regular files into CAS, materialize the install tree, and write
.osdk-manifest.json. - Write the artifact receipt, then write
.osdk-completelast.
The lock covers download, verification, extraction, CAS writes, materialization, and the complete marker. Fixed backends serialize the same tool/version; dynamic backends serialize only the same full install identity, so sibling identities can proceed independently. FileLock is held until the function returns and released on drop. Delegate backends that invoke an upstream manager do not necessarily enter this shared archive pipeline, so this lock is not an unconditional guarantee for every backend.
CAS writes and materialization
Each regular file is addressed by its BLAKE3 content hash under a two-level fan-out path. SDK ingest_file first tries to rename the extracted source to the final object. Across filesystems it copies to .tmp and then renames. Concurrent ingests rely on final-object existence and rename races rather than per-object locks. One implementation detail is that the SDK path shares the <hash>.tmp name: a failed final rename is ignored, and if no winner actually produced the object, the code proceeds until materialization reports a missing object or I/O failure rather than returning a dedicated ingest-race error.
Models use ModelStore::publish. It acquires models/<name>/.locks/<snapshot>.lock, verifies size and optional SHA-256, uses ingest_preserve so downloaded sources remain intact, materializes into a PID-scoped temporary snapshot, writes both CAS and model manifests plus a completion marker, renames into the final snapshot, and updates current.json through a temporary file plus rename. This lock serializes one model snapshot, not a model-wide or global store operation. Different snapshots of one model can publish concurrently and race with last-writer-wins behavior on current.json; model removal takes no corresponding model-wide lock and can also race with publication. These renames have no fsync/durability or portable replace-atomicity guarantee.
materialize uses hardlink, then reflink, then copy in auto mode on one filesystem. Across filesystems it tries reflink and then copy. Explicit hardlink and reflink modes also fall back to copy. Symlink is opt-in only. The manifest records each regular file's CAS hash and mode, plus symlink targets, and supplies GC reachability.
No cross-manager package CAS
The CAS deduplicates verified, extracted SDK files and model files. It does not parse, ingest, or deduplicate project dependency packages across npm, pnpm, Yarn, Bun, Deno, pip, Go, Cargo, Maven, or Gradle. npm-backed npm:<package> operations share <cache>/npm/v1/cache and <data>/store/npm, while pnpm uses its downstream cache/store paths; none of those package contents enter the BLAKE3 SDK CAS. Cargo developer-tool source and build data is likewise stage-private and is not promoted to a shared Cargo cache or the CAS; the final fingerprinted root retains only published binaries and osdk metadata. Go module and build data use the Go-owned caches above and likewise never enter the BLAKE3 SDK CAS; a published Go-tool root retains only validated binaries and osdk metadata.
cache_env and backend exec_env methods only redirect each manager's native cache to a separate child of <cache>/pkg, including npm, the pnpm store, Yarn, Bun, and Deno. Variables are injected only when the user has not set them, except that a value managed by a previous osdk hook can be refreshed. Sharing a parent directory does not unify content protocols: there is no cross-manager package CAS or cross-manager blob deduplication.
Download policy and cleanup
See Caches and Cleanup. cache/downloads.rs records exact consumed download paths, last use and successful commit status. The shared lease at <cache>/download-policy-v1/active.lock is never deleted with downloads. Exclusive trim only unlinks regular files and fixed sidecars after boundary checks. The backend install wrapper includes post-processing; model leases cover resolve, concurrent downloads and publication. Existing per-model-file locks still serialize identical downloads.
Policy never invokes CAS GC or removes store blobs, installations, native manager stores or metadata. Cache-root/download symlinks and reparse points, and overlap with persistent roots, are rejected. Processes running this version coordinate; older versions and external writers do not follow this new lock protocol. Model ingest_preserve copies the original into CAS; default snapshots hardlink CAS, commonly giving two physical entities at three paths. Copy/cross-volume materialization can create more copies; logical path sizes cannot measure hardlink/reflink physical usage.
Offline model replay scans canonical snapshot paths, cross-checks both manifests and identity/path/hash/size, then verifies CAS BLAKE3 and available SHA-256. CAS sources are never registered as downloads. Missing materialization is rebuilt in a sibling stage after rejecting extra/edited data. The old tree stays in a unique rollback location until replacement and the current record commit; failure restores it (or reports the retained location if rollback itself fails). Original unique content and blobs are preserved. Only recorded file sets can be replayed; removal/GC does not permanently pin orphan content for offline reinstall.
cache clean validates the download, uv, and pip paths before cleaning them in that order. The downloads stage takes osdk's own exclusive lease and exits immediately if an osdk install holds it.
uv 0.8.19 introduced a shared lock on <cache>/pkg/uv/.lock during installation. Native clean preserves the cache root and lock file starting in uv 0.13.1, so osdk delegates clean from that version onward. If managed uv cannot launch or is between 0.8.19 and 0.13.0, osdk tries an exclusive lock on the same file without waiting, then removes the entries while preserving the root and lock. A detected version older than 0.8.19 produces an upgrade message. 0.8.18 initialization · 0.8.19 shared lock · 0.13.1 clean
cache prune leaves entry selection to managed uv 0.8.19 or later. For both delegated commands, osdk resolves the validated cache path to an absolute path in its own working directory and passes it to uv through --cache-dir and UV_CACHE_DIR. Both commands ignore uv configuration files and UV_NO_CACHE. Native failures surface uv's diagnostics and stop cleanup. Coordination depends on other processes participating in the cache lock and on filesystem support for that lock.
Downstream cache cleanup scope
| Cache and default location | cache clean | cache prune | Native command and concurrency evidence |
|---|---|---|---|
osdk downloads, <cache>/downloads | Clean under an exclusive downloads lease | Preserve | osdk installs and pulls hold shared leases |
uv, <cache>/pkg/uv | Delegate to uv or clear entries under the same lock | Delegate to uv | Lock protocol and version boundaries above |
pip, <cache>/pkg/pip | Warn, then clear directly | Preserve | pip 26.2.1 cache purge unlinks files individually and does not wait for external pip installs. pip source |
npm, <cache>/pkg/npm, <cache>/npm/v1/cache, and <data>/store/npm | Preserve | Preserve | npm 11.4.2 offers cache clean --force and cache verify. Its documentation describes cache integrity. Waiting for concurrent installs was not verified. npm documentation |
pnpm store, <cache>/pkg/pnpm-store | Preserve | Preserve | pnpm 10.12.4 offers store prune. Cleanup during external installs was not tested. pnpm documentation |
PNPM_HOME, <data>/global/pnpm in managed execution and <cache>/pkg/pnpm in cache env | Preserve | Preserve | Installation root for global packages and commands |
Cargo, <cache>/pkg/cargo, and <data>/cargo for Rust shims and exec | Preserve | Preserve | Cargo home holds executables and configuration. cargo clean clears build output. Cargo documentation |
Gradle, <cache>/pkg/gradle | Preserve | Preserve | Gradle User Home holds configuration, wrappers, and runtime state. Concurrent cleanup was not verified. Gradle documentation |
Go, <cache>/pkg/go-mod and <cache>/pkg/go-build | Preserve | Preserve | go clean -modcache and go clean -cache clean these separately. Concurrent cleanup was not tested. Go documentation |
Yarn, Classic cache at <cache>/pkg/yarn-classic and managed global folder at <data>/global/yarn. Berry follows project configuration. | Preserve | Preserve | Both generations offer yarn cache clean. Concurrent cleanup was not tested. Classic · Berry |
Bun, <cache>/pkg/bun | Preserve | Preserve | bun pm cache rm can remove files that projects using Bun's global store link to. Concurrent cleanup was not tested. Bun documentation |
Deno, <cache>/pkg/deno | Preserve | Preserve | deno clean clears shared execution and compilation caches. Concurrent cleanup was not tested. Deno documentation |
Both commands preserve alternate cache directories chosen by users, model-client caches under <cache>/pkg/models, and installed content.
GC, removal, and the concurrency caveat
Cas::gc_roots is a mark-and-sweep pass. It recursively scans every .osdk-manifest.json under installs and models, collects hashes into a live set, then walks the store and removes regular files outside that set. A corrupt manifest fails the entire GC closed before deletion. Directory traversal errors are skipped. Files whose names end exactly in .tmp are opportunistically deleted before liveness checking; other temporary forms such as .tmp-<pid> receive no special protection and are handled as ordinary unreferenced files.
osdk prune, post-SDK-uninstall cleanup, and post-model-remove cleanup call this function directly. Uninstall removes the install tree before GC, and model removal does the same for its model tree. The current implementation has no claim/lease mechanism and acquires no global GC lock. Although the module comment in lock.rs mentions guarding store GC, no GC call site actually uses FileLock. It is therefore incorrect to claim that claim GC is globally serialized, or that GC is mutually exclusive with installation/publication of a different version or model.
Model sync registration and snapshot removal share <data>/model-refs/registry.lock. Project pruning considers only that project's retired keys. Fresh snapshot manifests record prune_eligible. For older snapshots the field defaults to false. Registering or repairing an older snapshot leaves this protection in place. An unreadable registration or a lock that cleanup cannot read stops pruning. Removing the current snapshot requires all snapshots under the name to be eligible and no view membership. Retained snapshot manifests continue to protect CAS objects. A missing or moved project directory does not expire its registration. Unuse with --keep-snapshot atomically records the kept snapshot keys in .osdk-kept.json under the model directory. Explicit model remove clears the record when it removes the directory.
This leaves a real race window: another process can create a reference between GC's live-set scan and deletion, and an installer can create CAS objects before writing its manifest, allowing concurrent GC to regard those objects as unreachable. Per-version and per-snapshot locks do not close that global window. Production guidance should treat concurrent prune/removal and installation as uncoordinated operations.
Finally, GC removes object files only, leaving empty fan-out directories. Individual deletion failures are silently skipped and do not increase the removed-object count, but their sizes may already be included in the reported byte total.