CopilotForXcode icon indicating copy to clipboard operation
CopilotForXcode copied to clipboard

[Bug]: Language Server Installed and Running but does not work in a sandbox environment - Worked until 2 versions ago.

Open varyP opened this issue 1 year ago • 14 comments

Before Reporting

  • [X] I have checked FAQ, and there is no solution to my issue
  • [X] I have searched the existing issues, and there is no existing issue for my issue

What happened?

image image

Node path & installation paths are correct - verified.

From Console- Language server is not installed. Please install it in the host app. Try getting suggestions again: Language server error: Server error: -32602 D

How to reproduce the bug.

It just happened!

Relevant log output

No response

macOS version

13.6.1

Xcode version

15.2

Copilot for Xcode version

0.33.4

varyP avatar Jul 04 '24 14:07 varyP

What do you mean by sandbox environment? If you mean the App Sandbox capability, the service app doesn't work with it enabled because it has to run other processes, for example Node, to perform its jobs. App Sandbox will prevent this.

intitni avatar Jul 04 '24 14:07 intitni

@intitni i've node and other necessary services. Rolling back to a couple of versions ago works, the newer versions don't. Does the logs signal you anything?

Thanks for looking into.

varyP avatar Jul 11 '24 14:07 varyP

@varyP But what do you mean by sandbox environment?

intitni avatar Jul 11 '24 14:07 intitni

This error throws only when the app can't find or access the language server js file. Please make sure it has the right permission to access the files in the folder inside Application Support, If you are using my releases, it should be "~/Library/Application Support/com.intii.CopilotForXcode/GitHub Copilot/executable/copilot/dist/language-server.js"

intitni avatar Jul 11 '24 14:07 intitni

@intitni - got a sandboxed environment running at a work Macbook.

I don't see the language-server.js here. But the suggestions work outside sandbox on this version, but not inside.

Any other logs I can check?

image

varyP avatar Jul 11 '24 16:07 varyP

Update to .0.35, still works outside but doesn't inside.

I keep seeing errors that it is unable to access files opened in XCode inside the sandboxed environment.

Language server error: Server error: -32602 Document for URI could not be found: file:/

image

varyP avatar Jul 11 '24 16:07 varyP

The older versions of the language server uses agent.js.

But what is a sandboxed environment? How to enable the sandboxed environment?

intitni avatar Jul 11 '24 16:07 intitni

If it works before 0.33.0, the app was launched by launch agent as a mach service, and macOS may accidentally grant extra permissions to the app. But this method causes severe performance issues to the app so we will not go back.

intitni avatar Jul 11 '24 16:07 intitni

But it's still weird, because you can access language server from the host app.

intitni avatar Jul 11 '24 16:07 intitni

What happens if you quit and open the CopilotForXcodeExtensionService.app manually? If Copilot for Xcode.app has the permissions, the cause may be the way we launch the service app.

intitni avatar Jul 12 '24 08:07 intitni

@intitni

  1. Sandbox is an internal tool that we use at work.
  2. Importing the host app inside results in this error image
  3. The host app works fine because it's outside the sandbox.
  4. Manual trigger has no affect.
  5. Might be due to the way it was launched in the past, but if we can get to the root cause - might be helpful.

varyP avatar Jul 12 '24 10:07 varyP

I can't test it for you since it's an internal tool. But I can offer something that you can experiment with:

In the past the service app is launched by launch agent, now it's launched by the CoomunicationBridge target, which is launched by the launch agent.

Could it be that the old method is launching the service app outside of the sandbox?

If the service app is now launched inside the sandbox, two things may have changed:

  1. It may be looking for a different directory when it looks for the language server. You can verify it by creating an app that prints the path to the application supports folder
FileManager.default.urls(
            for: .applicationSupportDirectory,
            in: .userDomainMask
        )

  1. You need to verify if it can still run other processes. You can verify that by sending /run some_command in the chat.

intitni avatar Jul 12 '24 11:07 intitni

Or you can simply try installing the language server again in the sandboxed host app. It's fine that it can't register the launch agent.

intitni avatar Jul 12 '24 11:07 intitni

This has been happening for Me If project has build errors. So seems like if your project has some file references but File doesn't exists. Extension throws the error. So resolve all the file references and it starts working fine.

I my self would fix it. and will raise a PR.

sandeeprana011 avatar Aug 29 '24 06:08 sandeeprana011