Dashboard › cli › Distillation
c13d237e-1e88-486a-bd89-d84f1ba018b7["lore_tm_v1_0LtBPiKmvx7u4LKIF91hxqPdwELUbpW8nfEQ9fjo0UI","lore_tm_v1_yTMIJy_VvKSoifEr9w73SnFLJuSf2HZD2DF7RCECWDg"]
packages/cli/src/lib/delta-upgrade.ts as a 627-line binpatch-backed delta-upgrade adapter importing applyPatchChainInMemory, resolveAndApply, ghcrSource, githubReleaseSource, OciClient, cache/discovery helpers, telemetry types, chain validators, and constants from "binpatch", while preserving existing public exports such as extractSha256, getPatchFromVersion, getPatchTargetSha256, getStableTargetSha256, PATCH_TAG_PREFIX, ExtractStableChainOpts, GitHubAsset, GitHubRelease, PatchChain, and StableChainInfo.packages/cli/src/lib/delta-upgrade.ts: patchCacheKey(fromVersion, toVersion) returns patch-chain:${fromVersion}-${toVersion}; instrumentCache(base) wraps load() in a cache.get span with cache.key, cache.hit, and conditional cache.item_size, wraps non-empty save() in a cache.put span with total patch bytes, and delegates cleanup() and clear(); getPatchCache() uses makeCache(join(getConfigDir(), "patch-cache")).packages/cli/src/lib/delta-upgrade.ts: stableSource() calls githubReleaseSource() with GITHUB_RELEASES_URL, getPlatformBinaryName(), user agent sentry-cli/${CLI_VERSION}, customFetch, and an InstrumentHook backed by withTracing(name, "http.client", fn); nightlySource() calls ghcrSource() with registry https://ghcr.io, repo GHCR_REPO, the same binary name/user agent/fetch/instrumentation, targetTag: (version) => \nightly-${version}`, and compareVersions`.canAttemptDelta(targetVersion) rejects delta upgrades when CLI_VERSION === "0.0.0-dev", when current and target differ between stable/nightly channels, or when isDowngrade(CLI_VERSION, targetVersion) is true.packages/cli/src/lib/delta-upgrade.ts: fetchRecentReleases(signal?) requests ${GITHUB_RELEASES_URL}?per_page=12 with GitHub v3 accept headers and returns [] on non-OK, malformed non-array JSON, or exceptions; downloadStablePatch(url, signal?) returns bytes only for an OK response and otherwise null; extractStableChain(opts) converts binpatch’s classified failure result to null; filterAndSortChainTags(...) delegates to binpatch with local compareVersions.validateChainStep(manifest, opts) preserving richer nightly telemetry than binpatch: it first reports version-mismatch with expected and actual, delegates validation when versions match, then distinguishes size-exceeded with layerSize and budget from missing-layer with layerName; binpatch’s native failure classification is coarser ("malformed" or "over_budget").resolveNightlyChain(opts) in packages/cli/src/lib/delta-upgrade.ts using OciClient against https://ghcr.io and GHCR_REPO; it accepts token, currentVersion, targetVersion, fullGzSize, optional preloadedTags, and optional signal, filters tags by PATCH_TAG_PREFIX, rejects zero hops or chains exceeding MAX_NIGHTLY_CHAIN_DEPTH, fetches manifests in parallel, and silently returns null if manifest fetching throws.${getPlatformBinaryName()}.patch; each hop must start at the previous version and fit the remaining budget fullGzSize * SIZE_THRESHOLD_RATIO - totalSize; failures stamp active-span telemetry_reason; the final hop takes its expected hash from getPatchTargetSha256(manifest, binaryName); a final-version mismatch or missing expected SHA-256 stamps telemetry_reason="version-mismatch" and returns null; blobs are downloaded in parallel with downloadBlobBuffer(), and the resulting PatchChain contains patches, recomputed totalSize, expectedSha256, and ordered steps.applyPatchChain(chain, oldBinaryPath, destPath, onBytes?) wrapped in an "apply-patches" / "upgrade.delta.apply" span, recording patches.count and patches.total_bytes, applying all patch data through applyPatchChainInMemory(), and throwing SHA-256 mismatch after patching: got ${sha256}, expected ${chain.expectedSha256} when verification fails.makeProgressHandler(setMessage?) creating a fresh makeByteProgress() bar whenever the byte-event phase changes; "apply" uses label "Applying patch(es)" and { format: "pct" } because multi-hop apply totals can display 930 MB for a 310 MB install, while other phases use "Processing patch(es)" and { format: "bytes" }; progress deltas are computed as event.written - previousWritten, and "done" calls progress?.done().packages/cli/src/lib/delta-upgrade.ts: telemetry() captures the resolved source in private _source.current; onResolved({ source, chain }) sets delta.source and logs patch count plus formatted total size; onOfflineMiss() records source "offline_miss"; onUnavailable(reason) sets telemetry_reason; the captured source is intended to preserve source attribution when patch application fails after successful resolution.resolveDelta(source, targetVersion, oldBinaryPath, destPath, offline?, setMessage?) calling resolveAndApply() with currentVersion: CLI_VERSION, instrumented patch cache, makeProgressHandler(setMessage), and telemetry, then returning { result, source: tel._source.current }; resolveStableDelta() and resolveNightlyDelta() retain their existing public call shapes and return only the result.attemptDeltaUpgrade() tracing and fallback behavior: unsupported attempts immediately resolve to null; channel is "nightly" or "stable"; span "upgrade.delta" records delta.from_version, delta.to_version, and initial delta.channel; successful deltas record delta.patch_bytes, delta.chain_length, and Sentry distributions upgrade.delta.patch_bytes and upgrade.delta.chain_length with channel attributes; unavailable deltas set delta.result="unavailable"; successful execution sets span status code 1.attemptDeltaUpgrade(): exceptions are captured by Sentry at warning level with tags delta.from_version, delta.to_version, and delta.channel; a captured chainSource is applied as delta.source; warning text is Delta upgrade failed (${message}), falling back to full download; span status becomes code 2 with delta.result="error" and delta.error=message; the function then returns null to trigger full-download fallback.packages/cli/src/lib/delta-upgrade.ts: internal prefetch(source, targetVersion, signal?) exits if delta is ineligible or aborted, resolves a chain from CLI_VERSION, exits without chain.steps or after abort, and otherwise saves it to the patch cache; prefetchNightlyPatches() and prefetchStablePatches() dispatch to their respective source strategies.<binaryName> for the expected SHA-256 digest, <binaryName>.gz for the ratio-gate size, and <binaryName>.patch for the delta from the previous release; the oldest-first chain is capped by MAX_STABLE_CHAIN_DEPTH and SIZE_THRESHOLD_RATIO, with owner/repository URL, binary name, user agent, fetch implementation, and optional instrumentation injected by the consumer.GitHubAsset has name, size, optional digest, and browser_download_url; GitHubRelease has tag_name, assets, and optional body; extractSha256() accepts case-insensitive sha256:<hex> via /^sha256:([0-9a-f]+)$/i and lowercases the digest; getStableTargetSha256() finds the exact binary asset and returns its parsed hash or null.extractStableChain(opts) returning either StableChainInfo (patchUrls, expectedSha256, ordered steps) or StableChainFailure, with exact classifications "no_patches", "malformed_chain", "too_long", and "over_budget"; absent/misordered current or target releases are "no_patches", depth over MAX_STABLE_CHAIN_DEPTH is "too_long", a missing target binary digest or missing in-range patch asset is "malformed_chain", and cumulative declared patch size above fullGzSize * SIZE_THRESHOLD_RATIO is "over_budget".steps are built from currentVersion through reversed releases as { fromVersion, toVersion: release.tag_name }.GitHubReleaseSourceConfig fields releasesUrl, binaryName, userAgent, optional fetch, and optional instrument; InstrumentHook wraps individual async HTTP steps named "fetch-releases" and "download-patch", while omission runs requests directly without wrapping or behavioral overhead.githubReleaseSource() fetching ${releasesUrl}?per_page=${MAX_STABLE_CHAIN_DEPTH + 2} with Accept: application/vnd.github.v3+json and the configured User-Agent; network exceptions and non-OK responses return null, while successful JSON is treated as GitHubRelease[]."network"; missing target release reports "no_patches"; an existing target release missing ${binaryName}.gz reports "malformed_chain"; classified extraction failures report their specific reason; failure to download an already-listed patch asset reports "network" because it is treated as transient rather than a poisoned publication.Promise.all() calls with the configured User-Agent; each successful response becomes Uint8Array, and the final PatchChain contains downloaded { data, size: data.byteLength } links, actual downloaded totalSize, the extracted target expectedSha256, and generated version steps.