Skip to content

fix(upgrade): fallback to --legacy-peer-deps on npm ERESOLVE error during OpenCode plugin upgrades#977

Open
decode2 wants to merge 2 commits into
Gentleman-Programming:mainfrom
decode2:fix/issue-831-npm-eresolve-fallback
Open

fix(upgrade): fallback to --legacy-peer-deps on npm ERESOLVE error during OpenCode plugin upgrades#977
decode2 wants to merge 2 commits into
Gentleman-Programming:mainfrom
decode2:fix/issue-831-npm-eresolve-fallback

Conversation

@decode2

@decode2 decode2 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #831

Adds automatic fallback to --legacy-peer-deps when an OpenCode plugin upgrade fails due to an npm ERESOLVE peer dependency conflict.

Problem

When running gentle-ai upgrade for OpenCode plugins (such as opencode-sdd-engram-manage or opencode-subagent-statusline), npm 7+ enforces strict peer dependency checks. Upstream peer conflicts (e.g., between @opentui/keymap and @opentui/solid) cause npm install to fail with ERESOLVE could not resolve, leaving the plugin in a failed upgrade state.

Solution

In internal/update/upgrade/strategy.go, when npm returns an execution error during plugin upgrade:

  1. Check if the command output contains ERESOLVE or --legacy-peer-deps.
  2. Automatically retry the upgrade command with --legacy-peer-deps appended (npm install --save --no-audit --no-fund --legacy-peer-deps ...).
  3. Added unit test TestRunStrategyOpenCodePluginNpmERESOLVERetriesWithLegacyPeerDeps in strategy_test.go to verify the retry flow.

Test Plan

  • Ran go test ./internal/update/upgrade/... -run TestRunStrategyOpenCodePluginNpmERESOLVERetriesWithLegacyPeerDeps — unit test passes.
  • Ran go build ./... — builds cleanly.

Summary by CodeRabbit

  • Bug Fixes
    • Improved npm-based package upgrade handling when dependency resolution fails.
    • The updater now detects peer-dependency conflict errors and automatically retries using a compatibility-focused install option to complete more upgrades successfully.
    • Upgrade error messages now include clearer captured command output when retries still fail.
  • Tests
    • Added coverage to verify the retry behavior and confirm the retry command arguments.

…ring OpenCode plugin upgrades

When upgrading OpenCode plugins via npm, conflicting peer dependencies in upstream
packages can cause npm to fail with an ERESOLVE error.

This change catches ERESOLVE errors during npm plugin upgrades and automatically retries
the command with --legacy-peer-deps, resolving issue Gentleman-Programming#831.

Closes Gentleman-Programming#831
@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 344187fc-9f77-4f84-bd6e-6cb224ee56ba

📥 Commits

Reviewing files that changed from the base of the PR and between 1b314f9 and 4c4d1e1.

📒 Files selected for processing (1)
  • internal/update/upgrade/strategy.go

📝 Walkthrough

Walkthrough

opencodePluginUpgrade now captures npm failure output, retries with --legacy-peer-deps for ERESOLVE-related failures, and returns the retry result. A new test verifies the retry path and command arguments.

npm ERESOLVE retry

Layer / File(s) Summary
ERESOLVE retry logic and test
internal/update/upgrade/strategy.go, internal/update/upgrade/strategy_test.go
opencodePluginUpgrade inspects npm failure output, retries with --legacy-peer-deps when ERESOLVE markers are present, and clears the error on success. The test stubs two exec calls, fails the first with an ERESOLVE message, succeeds the second, and asserts the retry includes --legacy-peer-deps.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the OpenCode upgrade fallback to --legacy-peer-deps on npm ERESOLVE errors.
Linked Issues check ✅ Passed The change retries OpenCode plugin upgrades on npm ERESOLVE with --legacy-peer-deps, matching #831.
Out of Scope Changes check ✅ Passed The diff stays focused on the upgrade strategy and its test, with no obvious unrelated changes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/update/upgrade/strategy.go`:
- Around line 154-159: The npm retry path in strategy.go can still start after
the caller has already cancelled the operation. Re-check ctx with a ctx.Done()
guard immediately before constructing and launching the fallback install in the
npm/ERESOLVE branch inside the upgrade strategy logic, so the retry path exits
early instead of continuing work after cancellation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 39bbc4e7-753c-4d96-89f8-0c49bfdd0c35

📥 Commits

Reviewing files that changed from the base of the PR and between 8df34cd and 1b314f9.

📒 Files selected for processing (2)
  • internal/update/upgrade/strategy.go
  • internal/update/upgrade/strategy_test.go

Comment thread internal/update/upgrade/strategy.go
@Alan-TheGentleman Alan-TheGentleman added the type:bug Bug fix label Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error upgrading gentle-ai

2 participants