Skip to content

fix(lsp): surface gopls spawn failure reasons to LLM via tool output#26864

Closed
LinuxForYQH wants to merge 2 commits into
anomalyco:devfrom
LinuxForYQH:fix/lsp-error-message-improvement
Closed

fix(lsp): surface gopls spawn failure reasons to LLM via tool output#26864
LinuxForYQH wants to merge 2 commits into
anomalyco:devfrom
LinuxForYQH:fix/lsp-error-message-improvement

Conversation

@LinuxForYQH

@LinuxForYQH LinuxForYQH commented May 11, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #26865

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When gopls fails to start (e.g. Go not installed), Gopls.spawn() silently returns undefined. The .catch() in lsp.ts swallows it, so the LLM only sees "No LSP server available for this file type." — no clue what's actually wrong.

This PR:

  • Makes Gopls.spawn() throw descriptive errors instead of silent return (2 cases: missing Go runtime, failed go install)
  • Changes broken from Set<string> to Map<string, string> so failure reasons are stored alongside broken keys
  • Adds failureReason(file) to the LSP service
  • tool/lsp.ts queries failureReason() when LSP is unavailable and passes the actual error to the LLM

Now the LLM gets "Go runtime not found. Please install Go first — gopls will then be installed automatically." and can guide the user accordingly.

How did you verify your code works?

  • npx tsc --noEmit --project packages/opencode/tsconfig.json — zero new compilation errors
  • Traced the full call chain: server.ts throw → lsp.ts .catch() stores err.message in broken Map → tool/lsp.ts queries failureReason() → error surfaces to LLM

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels May 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels May 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

When gopls fails to start (e.g. Go runtime not installed), the error was
silently swallowed, causing the LLM to only see a generic 'No LSP server
available' message with no actionable guidance.

Changes:
- server.ts: Gopls.spawn() now throws descriptive errors instead of
  silently returning undefined when Go is missing or installation fails
- lsp.ts: broken set -> map to store failure reasons; add failureReason()
  method to query stored reasons by file
- tool/lsp.ts: query failureReason() when LSP unavailable, pass specific
  error message to LLM (e.g. 'Go runtime not found. Please install Go
  first')
@LinuxForYQH LinuxForYQH force-pushed the fix/lsp-error-message-improvement branch from a599728 to 437bf66 Compare June 1, 2026 09:08
@LinuxForYQH

Copy link
Copy Markdown
Author

Rebased this PR onto the latest dev and cleaned it up to a single commit.\n\nLocal verification:\n- bun --cwd packages/opencode test --timeout 30000 test/tool/lsp.test.ts\n- bun run --cwd packages/opencode typecheck\n\nI also tried the broader related session tests, but they currently fail locally while starting the test server with Failed to start server. Is port 0 in use?; the LSP tool tests pass and the package typecheck passes.

@LinuxForYQH

Copy link
Copy Markdown
Author

Hi @nexxeln, gentle ping on this one when you have a moment. The PR is now rebased onto the latest dev, cleaned up to a single commit, linked to #26865, and the GitHub checks are passing. Would appreciate a review whenever it fits your queue. Thanks!

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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.

LSP tool returns generic error when gopls fails to start due to missing Go runtime

1 participant