Skip to content

fix: [AI-734] route Windows upgrade/uninstall to altimate-code, not upstream opencode#735

Draft
anandgupta42 wants to merge 1 commit intomainfrom
fix/windows-upgrade-wrong-package
Draft

fix: [AI-734] route Windows upgrade/uninstall to altimate-code, not upstream opencode#735
anandgupta42 wants to merge 1 commit intomainfrom
fix/windows-upgrade-wrong-package

Conversation

@anandgupta42
Copy link
Copy Markdown
Contributor

@anandgupta42 anandgupta42 commented Apr 22, 2026

What does this PR do?

Fixes a production bug where Windows users were being auto-upgraded to 1.14.19 — the upstream sst/opencode version — because four code paths still referenced upstream package identifiers. Also closes the adjacent bug in altimate uninstall that had the same class of misrouting.

Observed in telemetry:

upgrade_attempted from=0.6.0 to=1.14.19 method=other status=error
  error="not running from an elevated command shell" × 5

Scope of the fix (packages/opencode/src/ paths):

  • installation/index.tsmethod() no longer auto-detects choco/scoop (sentinel entries keep the Method type union intact without matching); latest() falls through to GitHub releases; upgrade() synthesizes a helpful error result that flows through existing telemetry; extracted type UpgradeResult to replace a fragile as Awaited<ReturnType<...>> cast; telemetryMethod preserves choco/scoop granularity.
  • cli/cmd/upgrade.ts — removed choco/scoop from --method choices, removed dead "elevated command shell" branch.
  • cli/cmd/uninstall.ts — updated package names to @altimateai/altimate-code / altimate-code, dropped choco/scoop commands, removed UAC fallback.
  • cli/upgrade.ts + altimate/telemetry/index.ts — new upgrade_available telemetry event. Emitted only on proactive notification paths (NOT from the auto-upgrade error-recovery catch). Deduped per (correlationId:version) via a module-level Set. correlationId falls back sessionId → machineId → "cli". Telemetry failure never blocks the Bus.publish that shows the toast. Exposed machineId on Telemetry.getContext() return.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Observability / telemetry change
  • Documentation update

Issue for this PR

Closes #734

How did you verify your code works?

  • bun turbo typecheck — 5/5 packages pass
  • 88 relevant installation / upgrade / uninstall tests pass (6 files, 225 assertions)
  • Wider sweep: 2,856 altimate-area tests + 490 CLI tests pass (pre-existing tui-worker segfault unrelated)
  • Marker check: bun run script/upstream/analyze.ts --markers --base main --strict clean
  • Multi-model code review (9 models including Claude) — all blocking issues addressed before commit
  • Added runtime behavioral tests for Installation.upgrade("choco"/"scoop", ...) throwing with the expected message
  • Added source-level regression guards for --method choices, dead-branch removal, package names, telemetryMethod union, notify dedup, error-recovery suppression, machineId fallback, and UpgradeResult named type

Checklist

  • Followed conventional commit format (fix: [AI-734] ...)
  • Wrapped all changes to upstream-shared files in // altimate_change start / end markers
  • Updated existing tests that relied on old choco/scoop behavior
  • Added tests for new behavior (runtime + source-level)
  • Ran marker check locally before commit
  • Ran linters / typecheck locally before commit
  • Ran /consensus:code-review before commit (9-model panel)
  • Updated telemetry event type definition alongside the emission site
  • Verified the fix against production telemetry findings (stuck user 12c7c779)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Removed Features

    • Removed support for Chocolatey and Scoop package managers in upgrade and uninstall operations.
  • New Features

    • Added proactive upgrade availability tracking to notify users of new versions.
  • Changes

    • Updated package identifiers across package managers: npm-family packages now use @altimateai/altimate-code, Homebrew uses altimate-code.
    • Expanded upgrade method selection to support curl, npm, pnpm, bun, and brew.
    • Enhanced telemetry context to include machine-based correlation for better upgrade tracking.

Summary by cubic

Fixes Windows upgrade/uninstall routing to target @altimateai/altimate-code (npm-family) and altimate-code (Homebrew), preventing accidental upgrades to upstream opencode. Adds proactive upgrade_available telemetry to measure the notify → upgrade funnel. Addresses AI-734.

  • Bug Fixes

    • Removed choco/scoop from auto-detect and CLI --method choices; latest() now falls back to GitHub releases; upgrade() for choco/scoop returns a clear “not distributed here” error.
    • Updated uninstall commands to use @altimateai/altimate-code and altimate-code; removed Windows UAC branch tied to Chocolatey.
    • Preserved choco/scoop in upgrade telemetry method for analytics; propagate real stderr; introduced UpgradeResult type.
    • Expanded and updated tests to guard routing, CLI choices, telemetry, and fallbacks.
  • New Features

    • Added upgrade_available telemetry: emitted only on proactive notifications, deduped per (correlationId:version), with correlation falling back sessionId → machineId → "cli". Telemetry failures never block the toast.

Written for commit d2531c8. Summary will update on new commits.

…pstream `opencode`

Production telemetry showed Windows users being auto-upgraded to `1.14.19` —
the upstream `sst/opencode` version — and hitting "not running from an
elevated command shell" in a retry loop. Root cause: four code paths still
referenced upstream package identifiers (`opencode-ai` for npm/pnpm/bun/yarn,
`opencode` for brew/choco/scoop registries).

altimate-code is not distributed via chocolatey or scoop (verified against
`publish.ts` — only npm / Docker / AUR / Homebrew). Any match against those
managers was pointing at the wrong product.

### `packages/opencode/src/installation/index.ts`

- `method()`: choco/scoop entries reduced to sentinels (`Promise.resolve("")`)
  that never match. Keeps the `Method` type union intact for `--method=choco`
  callers but can never auto-detect.
- `latest()`: choco/scoop branches removed; these methods now fall through to
  the GitHub releases API. Returns `0.6.0` instead of `1.14.19`.
- `upgrade()`: choco/scoop cases synthesize an `UpgradeResult` with `code: 1`
  and a helpful stderr that points users to npm / Homebrew / altimate.ai/install.
  Flows through the existing `upgrade_attempted status=error` telemetry so we
  can measure how often users hit this.
- Extracted `type UpgradeResult = { code: number; stdout: Buffer; stderr: Buffer }`
  — replaces the fragile `as Awaited<ReturnType<typeof upgradeCurl>>` cast.
- `telemetryMethod` keeps choco/scoop as distinct values (not collapsed into
  `"other"`) so Windows misrouting is separable from generic failures.
- Removed the hardcoded `method === "choco" ? "not running from an elevated
  command shell" : ...` special case — real stderr now propagates.

### `packages/opencode/src/cli/cmd/upgrade.ts`

- `--method` `choices` array no longer exposes `choco` / `scoop` to users.
- Removed the unreachable `method === "choco" && stderr.includes("elevated
  command shell")` branch in the error handler.

### `packages/opencode/src/cli/cmd/uninstall.ts`

- Same class of bug. Package-name maps in `showRemovalSummary` and
  `executeUninstall` updated to `@altimateai/altimate-code` / `altimate-code`.
- choco/scoop entries dropped (not published there). Removed the choco-specific
  `["choco", "uninstall", "opencode", "-y", "-r"]` branch and the UAC fallback.

### `packages/opencode/src/cli/upgrade.ts` + `telemetry/index.ts`

New `upgrade_available` telemetry event, emitted from `notify()` when the user
is PROACTIVELY shown an "upgrade available" toast. Pair with `upgrade_attempted`
to compute the notification → action funnel (shown vs acted-on).

- Emitted ONLY on proactive paths (autoupdate=disabled, autoupdate=notify,
  method=unknown|yarn). NOT emitted from the auto-upgrade error-recovery
  catch handler — that path already signals via `upgrade_attempted status=error`,
  and emitting both inverts the natural funnel order.
- Deduped per `(correlationId:version)` via a module-level `Set` so repeated
  `upgrade()` calls in the same process don't inflate the notified-denominator.
- `correlationId` falls back `sessionId → machineId → "cli"` so the key is
  stable even when `upgrade()` runs before session_start.
- Telemetry wrapped in try/catch; failures never block the `Bus.publish` that
  shows the toast.
- Factored out `publishUpdate()` helper so the catch handler can show the
  toast without triggering telemetry.
- Exposed `machineId` on `Telemetry.getContext()` return.

### Tests

Added runtime behavioral tests (previously only source-level):

- `upgrade("choco", ...)` and `upgrade("scoop", ...)` throw `UpgradeFailedError`
  with the expected helpful message.
- Fall-through `latest("choco"/"scoop")` hits GitHub API, not upstream feeds.

Added source-level guards for: `--method` CLI choices excluding choco/scoop,
`cmd/upgrade.ts` dead-branch removal, `cmd/uninstall.ts` package names,
`telemetryMethod` union preserving choco/scoop, `notify()` dedup,
error-recovery suppression, machineId fallback, and `UpgradeResult` named
type replacing the loose cast.

Updated `test/altimate/telemetry-safety.test.ts` mock to include `machineId`
in the `getContext()` return shape.

### Verification

- `bun turbo typecheck` — 5/5 packages pass
- 88 relevant installation/upgrade/uninstall tests pass (225 assertions)
- 2,856 altimate-area tests + 490 CLI tests pass
- Marker check passes

Closes #734

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR fixes Windows users being routed to the upstream opencode package during upgrade and uninstall by removing Chocolatey and Scoop support (altimate-code is not distributed through those channels), updating CLI commands to use correct package identifiers, and introducing deduplication-aware upgrade_available telemetry tracking.

Changes

Cohort / File(s) Summary
Telemetry Infrastructure
packages/opencode/src/altimate/telemetry/index.ts, packages/opencode/test/altimate/telemetry-safety.test.ts
Extended upgrade_attempted method discriminator to include "choco" and "scoop"; added new upgrade_available event type with timestamp, session_id, current_version, latest_version; updated getContext() return shape to include machineId for correlation when session not available.
Installation & Upgrade Logic
packages/opencode/src/installation/index.ts, packages/opencode/src/cli/upgrade.ts
Introduced explicit UpgradeResult type; modified method() auto-detection to prevent matching choco/scoop (returns empty string); updated upgrade() to reject unsupported choco/scoop methods with user-facing error messages; added _notifiedVersions deduplication set in upgrade flow; replaced synchronous notify helper with async version that emits upgrade_available telemetry with correlation-ID fallback logic.
CLI Commands
packages/opencode/src/cli/cmd/upgrade.ts, packages/opencode/src/cli/cmd/uninstall.ts
Removed "choco" and "scoop" from --method option choices in upgrade command; updated uninstall commands to use @altimateai/altimate-code for npm-family and altimate-code for brew; simplified error handling by removing special-case choco/scoop branches.
Installation Behavior Tests
packages/opencode/test/installation/installation.test.ts, packages/opencode/test/installation/version.test.ts
Updated latest() tests for choco/scoop to assert fallthrough to GitHub Releases API instead of upstream package registries; added upgrade() tests validating choco/scoop rejection with specific error messages; replaced mock responses with GitHub releases format.
New Telemetry Contract Tests
packages/opencode/test/installation/upgrade-available-telemetry.test.ts
Added comprehensive new test suite validating upgrade_available telemetry type definition, emission behavior, lazy-import pattern, current/latest version normalization, correlation-ID fallback priority (sessionId → machineId → "cli"), deduplication key derivation, and publish-without-telemetry behavior in error-recovery paths.
CLI & Upgrade Method Tests
packages/opencode/test/install/upgrade-method.test.ts
Added tests asserting no auto-detection via choco/scoop package lists, no upstream version queries for those managers, rejection with guidance errors on upgrade attempts, and absence of choco/scoop uninstall logic in CLI; validates telemetry includes choco/scoop in method set.
Repository Metadata
.github/meta/commit.txt
Updated commit message to document altimate_change marker wrapping for post-push processing context.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested labels

contributor

Poem

🐰 Hops through package registries with glee,
No more wrong products for Windows to see!
Choco and Scoop bid goodbye with a sigh,
While altimate-code reaches npm sky.
Dedup telemetry tracks every hop,
This upgrade adventure won't ever stop! 🚀

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is comprehensive and follows the template structure with What/Why, Test Plan, and Checklist sections. However, it does not include the required word 'PINEAPPLE' at the top as mandated by the template for AI-generated contributions. Add 'PINEAPPLE' at the very top of the PR description before any other content, as required by the template for AI-generated contributions (indicated by the '🤖 Generated with [Claude Code]' attribution).
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: routing Windows upgrade/uninstall to altimate-code instead of upstream opencode. It's specific, relates directly to the changeset, and is appropriately concise.
Linked Issues check ✅ Passed The PR comprehensively addresses all coding requirements from issue #734: prevents choco/scoop auto-detection, routes package operations to altimate-code identifiers, removes choco/scoop from CLI choices, synthesizes clear error messages, adds upgrade_available telemetry with deduplication, and preserves telemetry granularity with machineId fallback.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the requirements in #734. Modified files target the identified root causes (installation/index.ts, cli/cmd/upgrade.ts, cli/cmd/uninstall.ts, cli/upgrade.ts, telemetry), added comprehensive tests with runtime and source-level regression guards, and updated related test files accordingly.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/windows-upgrade-wrong-package

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

👋 This PR was automatically closed by our quality checks.

Common reasons:

  • New GitHub account with limited contribution history
  • PR description doesn't meet our guidelines
  • Contribution appears to be AI-generated without meaningful review

If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you.

@github-actions github-actions Bot closed this Apr 22, 2026
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 11 files

@anandgupta42 anandgupta42 reopened this Apr 23, 2026
@github-actions
Copy link
Copy Markdown

👋 This PR was automatically closed by our quality checks.

Common reasons:

  • New GitHub account with limited contribution history
  • PR description doesn't meet our guidelines
  • Contribution appears to be AI-generated without meaningful review

If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you.

@github-actions github-actions Bot closed this Apr 23, 2026
@anandgupta42 anandgupta42 reopened this Apr 23, 2026
@github-actions
Copy link
Copy Markdown

👋 This PR was automatically closed by our quality checks.

Common reasons:

  • New GitHub account with limited contribution history
  • PR description doesn't meet our guidelines
  • Contribution appears to be AI-generated without meaningful review

If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you.

@anandgupta42 anandgupta42 marked this pull request as draft April 23, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Windows upgrade + uninstall route to upstream opencode package

1 participant