Repository: stateful/vscode-runme
Pull request #1662 (2024-09-16 23:58:51)

Fix code-server login
This resolves the issue in code-server where a `Couldn't recognize command` error occurs during authentication against the Platform, because it expects the `windowId` URI parameter, which is missing.

The fix has been successfully tested in both code-server and standard VSCode environments.

sourishkrout: I'm wondering if `windowId` is something one can only expect from desktop (electron app) distributions of VS Code?
peraltafederico: > I'm wondering if `windowId` is something one can only expect from desktop (electron app) distributions of VS Code?

@sourishkrout It is definitely related to letting VSCode handle links in different or existing windows, as mentioned here: https://code.visualstudio.com/updates/v1_67#_handle-uri-in-new-window. However, I didn’t find any explicit information stating that this behavior is limited to desktop distributions only.

That said, `windowId` is not related to the authentication process, so I think it's safe to remove it.
sonarcloud[bot]: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=stateful_vscode-runme&pullRequest=1662) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=stateful_vscode-runme&pullRequest=1662&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=stateful_vscode-runme&pullRequest=1662&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=stateful_vscode-runme&pullRequest=1662&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [40.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=stateful_vscode-runme&pullRequest=1662&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=stateful_vscode-runme&pullRequest=1662&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=stateful_vscode-runme&pullRequest=1662)


sourishkrout: > That said, `windowId` is not related to the authentication process, so I think it's safe to remove it.

I'd like to hear @pastuxso's opinion. Also, why not check if it's defined and set it accordingly but not require it in the condition? Again, I haven't checked, but it seems important when multiple Windows (desktop apps) are running.
peraltafederico: > > That said, `windowId` is not related to the authentication process, so I think it's safe to remove it.
> 
> I'd like to hear @pastuxso's opinion. Also, why not check if it's defined and set it accordingly but not require it in the condition? Again, I haven't checked, but it seems important when multiple Windows (desktop apps) are running.

Totally! :100:

Regarding the condition and how the parameter is handled, it's only used as a validation to define if the URI is valid or not. The whole URI is then forwarded to the next handler, see https://github.com/stateful/vscode-runme/pull/1662/files#diff-35ad708e91026099e03a5b146676d059a44e4aab20fd04d76412c9c485ec73c4R73. 
sourishkrout: That sounds good, @peraltafederico. Since @pastuxso wrote this code initially, I assigned him as a reviewer. I'm using a build from this branch to unblock my development work. It'd be great to get his fixed soon but it's no emergency.

Patch:
diff --git a/package.json b/package.json
index c9d5461b..6995809a 100644
--- a/package.json
+++ b/package.json
@@ -599,12 +599,6 @@
             "scope": "window",
             "markdownDescription": "Relative path to a file within the workspace to open within a Runme notebook view, when VS Code starts (e.g. `./CONTRIBUTING.md`)."
           },
-          "runme.experiments.aiLogs": {
-            "type": "boolean",
-            "scope": "window",
-            "default": false,
-            "markdownDescription": "If set to `true`, enable logging server logs used for training AIs."
-          },
           "runme.experiments.aiAutoCell": {
             "type": "boolean",
             "scope": "window",
diff --git a/src/extension/extension.ts b/src/extension/extension.ts
index a779d12f..73deb38a 100644
--- a/src/extension/extension.ts
+++ b/src/extension/extension.ts
@@ -95,14 +95,12 @@ export class RunmeExtension {
     const grpcSerializer = kernel.hasExperimentEnabled('grpcSerializer')
     const grpcServer = kernel.hasExperimentEnabled('grpcServer')
     const grpcRunner = kernel.hasExperimentEnabled('grpcRunner')
-    const aiLogs = kernel.hasExperimentEnabled('aiLogs')
 
     const server = new KernelServer(
       context.extensionUri,
       {
         retryOnFailure: true,
         maxNumberOfIntents: 10,
-        aiLogs: aiLogs,
       },
       !grpcServer,
       grpcRunner,
diff --git a/src/extension/handler/uri.ts b/src/extension/handler/uri.ts
index cb09ec8a..94d9d27a 100644
--- a/src/extension/handler/uri.ts
+++ b/src/extension/handler/uri.ts
@@ -57,7 +57,6 @@ export class RunmeUriHandler implements UriHandler, Disposable {
   async handleUri(uri: Uri) {
     log.info(`triggered RunmeUriHandler with ${uri}`)
     const params = new URLSearchParams(uri.query)
-    const windowId = params.get('windowId')
     const state = params.get('state')
     const code = params.get('code')
     const command = params.get('command')
@@ -66,7 +65,7 @@ export class RunmeUriHandler implements UriHandler, Disposable {
       window.showErrorMessage('No query parameter "command" provided')
       return
     }
-    if (command === 'auth' && windowId && state && code) {
+    if (command === 'auth' && state && code) {
       TelemetryReporter.sendTelemetryEvent('extension.uriHandler', {
         command,
         type: AuthenticationProviders.Stateful,
@@ -133,7 +132,7 @@ export class RunmeUriHandler implements UriHandler, Disposable {
       }
     }
 
-    window.showErrorMessage(`Couldn't recognise command "${command}"`)
+    window.showErrorMessage(`Couldn't recognize command "${command}"`)
   }
 
   private async _setupProject(fileToOpen: string, repository?: string | null) {
diff --git a/src/extension/kernel.ts b/src/extension/kernel.ts
index 4c20e68d..9f0c5432 100644
--- a/src/extension/kernel.ts
+++ b/src/extension/kernel.ts
@@ -158,7 +158,6 @@ export class Kernel implements Disposable {
     this.#experiments.set('grpcRunner', config.get<boolean>('grpcRunner', true))
     this.#experiments.set('grpcServer', config.get<boolean>('grpcServer', true))
     this.#experiments.set('smartEnvStore', config.get<boolean>('smartEnvStore', false))
-    this.#experiments.set('aiLogs', config.get<boolean>('aiLogs', false))
     this.#experiments.set('shellWarning', config.get<boolean>('shellWarning', false))
     this.#experiments.set('reporter', config.get<boolean>('reporter', false))
 
diff --git a/src/extension/server/kernelServer.ts b/src/extension/server/kernelServer.ts
index 6c307dd0..f7e823e8 100644
--- a/src/extension/server/kernelServer.ts
+++ b/src/extension/server/kernelServer.ts
@@ -33,7 +33,6 @@ export interface IServerConfig {
     intents: number
     interval: number
   }
-  aiLogs?: boolean
 }
 
 const log = getLogger('KernelServer')
@@ -65,7 +64,6 @@ class KernelServer implements IServer {
   #transport?: GrpcTransport
   #serverDisposables: Disposable[] = []
   #forceExternalServer: boolean
-  #aiLogs: boolean
 
   readonly #onClose = this.register(new EventEmitter<{ code: number | null }>())
   readonly #onTransportReady = this.register(
@@ -96,7 +94,6 @@ class KernelServer implements IServer {
     this.#acceptsIntents = options.acceptsConnection?.intents || 50
     this.#acceptsInterval = options.acceptsConnection?.interval || 200
     this.#forceExternalServer = externalServer
-    this.#aiLogs = options.aiLogs || false
   }
 
   dispose() {
@@ -235,11 +232,6 @@ class KernelServer implements IServer {
       args.push('--runner')
     }
 
-    if (this.#aiLogs) {
-      log.info('AI logs enabled')
-      args.push('--ai-logs=true')
-    }
-
     if (getTLSEnabled()) {
       args.push('--tls', this.getTLSDir())
     } else {


Test patch:
diff --git a/tests/extension/handler/uri.test.ts b/tests/extension/handler/uri.test.ts
index 53c4caf7..b63529ca 100644
--- a/tests/extension/handler/uri.test.ts
+++ b/tests/extension/handler/uri.test.ts
@@ -63,7 +63,7 @@ describe('RunmeUriHandler', () => {
     it('should fail if no command was recognised', async () => {
       vi.mocked(Uri.parse).mockReturnValue({ query: { command: 'foobar' } } as any)
       expect(await handler.handleUri(Uri.parse('vscode://stateful.runme?foo=bar'))).toBe(undefined)
-      expect(window.showErrorMessage).toBeCalledWith('Couldn\'t recognise command "foobar"')
+      expect(window.showErrorMessage).toBeCalledWith('Couldn\'t recognize command "foobar"')
     })
 
     it('runs _setupProject if command was "setup"', async () => {