Skip to content

fix(amazonq): prevent file link click from crashing language server#2718

Open
laileni-aws wants to merge 1 commit intoaws:feature/file-link-not-workingfrom
laileni-aws:origin/feature/file-link-not-working
Open

fix(amazonq): prevent file link click from crashing language server#2718
laileni-aws wants to merge 1 commit intoaws:feature/file-link-not-workingfrom
laileni-aws:origin/feature/file-link-not-working

Conversation

@laileni-aws
Copy link
Copy Markdown
Contributor

Problem

Clicking a file link in agentic chat for a file created by fsWrite crashes the language server
and loses all chat context. Two bugs combine to cause this:

  1. #resolveAbsolutePath assumes any .md file not found in workspace folders is a user prompt
    file and returns ~/.aws/amazonq/prompts/<filename> without checking if it exists there.
  2. onFileClicked has no error handling — when showDocument rejects because the file doesn't
    exist, the unhandled promise rejection crashes the language server process.

The fsWrite file link also never passes fullPath through the click handler data, so even when
the toolUseLookup fails to match, the fallback path resolution receives only the basename.

Solution

  • Wrap onFileClicked in try/catch so a failed showDocument logs an error instead of crashing
    the server
  • Add fs.exists check in #resolveAbsolutePath before returning the prompts directory path
  • Fall back to description (which already contains the full absolute path) as fullPath in
    the chat-client file list mapping, reusing existing data instead of adding a redundant field

Testing

  • tsc --noEmit passes for both aws-lsp-codewhisperer and chat-client packages
  • Existing contextUtils tests pass
  • Manual: create a .md file via fsWrite in agentic chat, click the link — should open
    correctly or log an error gracefully without crashing

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Add error handling to onFileClicked to catch exceptions from
showDocument when the target file doesn't exist. Fix
resolveAbsolutePath to verify the file exists in the prompts
directory before returning the path, preventing incorrect fallback
for .md files created by fsWrite. Use description as fullPath
fallback in the chat-client file list mapping so fsWrite file links
resolve correctly without duplicating path data.

Fixes: aws/amazon-q-vscode#59
@laileni-aws laileni-aws requested a review from a team as a code owner May 7, 2026 21:37
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 12.50000% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.54%. Comparing base (71c53d1) to head (5632299).
⚠️ Report is 4 commits behind head on feature/file-link-not-working.

Files with missing lines Patch % Lines
...nguage-server/agenticChat/agenticChatController.ts 4.54% 21 Missing ⚠️
Additional details and impacted files
@@                        Coverage Diff                        @@
##           feature/file-link-not-working    #2718      +/-   ##
=================================================================
- Coverage                          60.57%   60.54%   -0.04%     
=================================================================
  Files                                279      279              
  Lines                              66275    66284       +9     
  Branches                            4253     4253              
=================================================================
- Hits                               40149    40131      -18     
- Misses                             26041    26068      +27     
  Partials                              85       85              
Flag Coverage Δ
unittests 60.54% <12.50%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

3 participants