Skip to content

feat(upgrade): add --offline flag and automatic offline fallback#450

Merged
BYK merged 2 commits intomainfrom
feat/offline-upgrade
Mar 17, 2026
Merged

feat(upgrade): add --offline flag and automatic offline fallback#450
BYK merged 2 commits intomainfrom
feat/offline-upgrade

Conversation

@BYK
Copy link
Member

@BYK BYK commented Mar 17, 2026

Add --offline flag to sentry cli upgrade that uses only cached version info
(from background checks) and cached patches (from background prefetch) — no network
calls at all. When a normal upgrade encounters a network error, automatically falls
back to the offline path if cached data is available.

How it works

The infrastructure for offline upgrades already existed:

  • Background version checks store the latest version in SQLite
  • Background patch prefetch downloads and caches patch chains to disk
  • Delta upgrade already checks the cache before hitting the network

This change wires those pieces together:

  1. --offline → uses getVersionCheckInfo().latestVersion from SQLite instead of
    fetchLatestVersion(), then lets tryDeltaUpgrade() use cached patches only
  2. Auto-fallback → wraps resolveTargetVersion() with a catch for
    UpgradeError("network_error"), falling back to the cached version + patches
  3. When offline is true and no cached patches exist, throws a clear error instead
    of falling through to downloadFullBinary()

Flag interactions

Combo Behavior
--offline Use cached version + cached patches
--offline --check Show cached version info
--offline --method npm Error: offline only for curl
(no flag, network fails) Auto-fallback with warning

@github-actions
Copy link
Contributor

github-actions bot commented Mar 17, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (dashboard) Add dashboard list, view, and create commands by betegon in #406
  • (upgrade) Add --offline flag and automatic offline fallback by BYK in #450
  • Add sentry schema command for API introspection by BYK in #437

Bug Fixes 🐛

  • (dsn) Prevent hang during DSN auto-detection in repos with test fixtures by BYK in #445
  • (formatters) Pad priority labels for consistent TRIAGE column alignment by MathurAditya724 in #449
  • (upgrade) Remove hard chain depth cap for nightly delta upgrades by BYK in #444

Internal Changes 🔧

  • Cache org listing in listOrganizations + DSN shortcut for issue view by betegon in #446

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 17, 2026

Codecov Results 📊

111 passed | Total: 111 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 91.27%. Project has 1118 uncovered lines.
❌ Project coverage is 95.23%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
human.ts 96.37% ⚠️ 45 Missing
delta-upgrade.ts 95.38% ⚠️ 32 Missing
upgrade.ts 96.91% ⚠️ 12 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    95.25%    95.23%    -0.02%
==========================================
  Files          174       174         —
  Lines        23342     23433       +91
  Branches         0         0         —
==========================================
+ Hits         22234     22315       +81
- Misses        1108      1118       +10
- Partials         0         0         —

Generated by Codecov Action

@BYK BYK marked this pull request as ready for review March 17, 2026 21:48
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Autofix Details

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Auto-fallback incorrectly marks package manager upgrades as offline
    • Auto-fallback now only sets offline=true for curl installs; package managers correctly set offline=false since they always hit the network.
  • ✅ Fixed: Offline check result missing offline field
    • Added offline parameter to buildCheckResult and updated both call sites to pass the offline value in check results.

Create PR

Or push these changes by commenting:

@cursor push c8d1dcb547
Preview (c8d1dcb547)
diff --git a/src/commands/cli/upgrade.ts b/src/commands/cli/upgrade.ts
--- a/src/commands/cli/upgrade.ts
+++ b/src/commands/cli/upgrade.ts
@@ -167,7 +167,9 @@
     }
     return { kind: "target", target: resolved.target, offline: false };
   } catch (error) {
-    // Automatic offline fallback: if the network fails, try the cache
+    // Automatic offline fallback: if the network fails, try the cache.
+    // Only mark as offline for curl installs — package managers can't do
+    // offline upgrades and will still hit the network.
     if (!(error instanceof UpgradeError && error.reason === "network_error")) {
       throw error;
     }
@@ -175,7 +177,8 @@
       const target = resolveOfflineTarget(versionArg);
       log.warn("Network unavailable, falling back to cached upgrade target");
       log.info(`Using cached target: ${target}`);
-      return { kind: "target", target, offline: true };
+      const isOffline = resolveOpts.method === "curl";
+      return { kind: "target", target, offline: isOffline };
     } catch {
       // No cached version either — re-throw original network error
       throw error;
@@ -255,7 +258,14 @@
   if (flags.check) {
     return {
       kind: "done",
-      result: buildCheckResult({ target, versionArg, method, channel, flags }),
+      result: buildCheckResult({
+        target,
+        versionArg,
+        method,
+        channel,
+        flags,
+        offline: false,
+      }),
     };
   }
 
@@ -300,8 +310,9 @@
   method: InstallationMethod;
   channel: ReleaseChannel;
   flags: UpgradeFlags;
+  offline?: boolean;
 }): UpgradeResult {
-  const { target, versionArg, method, channel, flags } = opts;
+  const { target, versionArg, method, channel, flags, offline } = opts;
   const result: UpgradeResult = {
     action: "checked",
     currentVersion: CLI_VERSION,
@@ -309,6 +320,7 @@
     channel,
     method,
     forced: flags.force,
+    offline: offline || undefined,
   };
 
   // When already on target, no update hint needed
@@ -620,7 +632,14 @@
     // --check with offline just reports the cached version
     if (flags.check) {
       return yield new CommandOutput(
-        buildCheckResult({ target, versionArg, method, channel, flags })
+        buildCheckResult({
+          target,
+          versionArg,
+          method,
+          channel,
+          flags,
+          offline,
+        })
       );
     }

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

@BYK BYK force-pushed the feat/offline-upgrade branch from bcba4ee to 8d6b6e9 Compare March 17, 2026 22:01
@BYK BYK force-pushed the feat/offline-upgrade branch from 1114da8 to 1f6a025 Compare March 17, 2026 22:12
@BYK BYK force-pushed the feat/offline-upgrade branch from 4a322ef to e285ac3 Compare March 17, 2026 22:24
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Add --offline flag to 'sentry cli upgrade' that uses only cached version
info (from background checks) and cached patches (from background
prefetch) — no network calls at all.

When a normal upgrade encounters a network error during version
discovery, automatically falls back to the offline path if cached
data is available, logging a warning about the fallback.

The infrastructure for offline upgrades already existed:
- Background version checks store latest version in SQLite
- Background patch prefetch caches patch chains to disk
- Delta upgrade already checks cache before network

This change wires those pieces together with a new entry point.

Changes:
- Add --offline flag to upgrade command
- Add resolveOfflineTarget() for cached version lookup
- Add resolveTargetWithFallback() for auto network→cache fallback
- Thread offline param through executeUpgrade/downloadBinaryToTemp
  to prevent full-binary download fallback when offline
- Show '(offline, from cache)' in human output for offline upgrades
- Validate --offline is only used with curl-installed binaries
@BYK BYK force-pushed the feat/offline-upgrade branch from a83119c to 37604f9 Compare March 17, 2026 22:33
@BYK BYK merged commit d8c0589 into main Mar 17, 2026
22 checks passed
@BYK BYK deleted the feat/offline-upgrade branch March 17, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant