Repository: cypress-io/cypress
File: packages/server/lib/project-base.ts (TypeScript)

Code before:
            this.protocolManager.setupProtocol()
            this.protocolManager.beforeSpec({
              ...this.spec,
              instanceId: v4(),
            })

            telemetryManager.mark(INITIALIZATION_MARK_NAMES.CONNECT_PROTOCOL_TO_BROWSER_START)
            await browsers.connectProtocolToBrowser({ browser: this.browser, foundBrowsers: this.options.browsers, protocolManager: studio.protocolManager })
            telemetryManager.mark(INITIALIZATION_MARK_NAMES.CONNECT_PROTOCOL_TO_BROWSER_END)

            if (!studio.protocolManager.dbPath) {
              debug('Protocol database path is not set after initializing protocol manager')

              endTelemetry({ status: 'protocol-db-path-not-set', canAccessStudioAI: false })

              return { canAccessStudioAI: false, cloudStudioSessionId }
            }

            telemetryManager.mark(INITIALIZATION_MARK_NAMES.INITIALIZE_STUDIO_AI_START)
            await Promise.all([
              studio.initializeStudioAI({
                protocolDbPath: studio.protocolManager.dbPath,
              }),
              // Reset browser state on initialization to avoid issues
              // with cached assets from previous test executions.
              await this.resetBrowserState(),
            ])

            telemetryManager.mark(INITIALIZATION_MARK_NAMES.INITIALIZE_STUDIO_AI_END)

            endTelemetry({ status: 'success', canAccessStudioAI: true })

            return { canAccessStudioAI: true, cloudStudioSessionId }
          }

          this.protocolManager = undefined

          endTelemetry({ status: 'success', canAccessStudioAI: false })

          return { canAccessStudioAI: false, cloudStudioSessionId }
        } catch (error) {
          endTelemetry({ status: 'exception', canAccessStudioAI: false })

          return { canAccessStudioAI: false, cloudStudioSessionId }
        }
      },

      onStudioDestroy: async () => {
        const isStudioReady = await this.ctx.coreData.studioLifecycleManager?.isStudioReady()

        if (!isStudioReady) {

Review comment (suggestion):
```suggestion
              this.resetBrowserState(),
```

Code after:
            this.protocolManager.setupProtocol()
            this.protocolManager.beforeSpec({
              ...this.spec,
              instanceId: v4(),
            })

            telemetryManager.mark(INITIALIZATION_MARK_NAMES.CONNECT_PROTOCOL_TO_BROWSER_START)
            await browsers.connectProtocolToBrowser({ browser: this.browser, foundBrowsers: this.options.browsers, protocolManager: studio.protocolManager })
            telemetryManager.mark(INITIALIZATION_MARK_NAMES.CONNECT_PROTOCOL_TO_BROWSER_END)

            if (!studio.protocolManager.dbPath) {
              debug('Protocol database path is not set after initializing protocol manager')

              endTelemetry({ status: 'protocol-db-path-not-set', canAccessStudioAI: false })

              return { canAccessStudioAI: false, cloudStudioSessionId }
            }

            telemetryManager.mark(INITIALIZATION_MARK_NAMES.INITIALIZE_STUDIO_AI_START)
            await Promise.all([
              studio.initializeStudioAI({
                protocolDbPath: studio.protocolManager.dbPath,
              }),
              // Reset browser state on initialization to avoid issues
              // with cached assets from previous test executions.
              this.resetBrowserState(),
            ])

            telemetryManager.mark(INITIALIZATION_MARK_NAMES.INITIALIZE_STUDIO_AI_END)

            endTelemetry({ status: 'success', canAccessStudioAI: true })

            return { canAccessStudioAI: true, cloudStudioSessionId }
          }

          this.protocolManager = undefined

          endTelemetry({ status: 'success', canAccessStudioAI: false })

          return { canAccessStudioAI: false, cloudStudioSessionId }
        } catch (error) {
          endTelemetry({ status: 'exception', canAccessStudioAI: false })

          return { canAccessStudioAI: false, cloudStudioSessionId }
        }
      },

      onStudioDestroy: async () => {
        const isStudioReady = await this.ctx.coreData.studioLifecycleManager?.isStudioReady()

        if (!isStudioReady) {