Skip to content

Commit

Permalink
Restart Cody in case of webview renderer crash (#2645)
Browse files Browse the repository at this point in the history
## Changes

Looks like webview renderer process crashes from time to time for some
users - especially in cases like long running IDE or
suspending/unsuspending OS.

We might not be able to fully fix the root cause, but we should handle
the crash and recover from it.
For now, I'm just restarting the agent which also restarts the webview.
I was trying to only restart the webviews and keep the agent running,
but I did not managed to do it on the first try.
Let's merge this as it improves current situation significantly, and I
will work on better/quicker restoration of the state in the followup
PR(s).

## Test plan

1. Start IntelliJ with Cody panel opened
2. Open process explorer and kill `jcef Helper (Renderer)`
3. Go back to IntelliJ - Cody panel should restart itself
  • Loading branch information
pkukielka authored Nov 15, 2024
1 parent 713f4ab commit f66c994
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/main/kotlin/com/sourcegraph/cody/ui/web/WebUIProxy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import com.google.gson.JsonParser
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.ide.CopyPasteManager
import com.intellij.openapi.project.ProjectManager
import com.intellij.ui.jcef.JBCefBrowserBase
import com.intellij.ui.jcef.JBCefBrowserBuilder
import com.intellij.ui.jcef.JBCefJSQuery
import com.sourcegraph.cody.agent.CodyAgent
import com.sourcegraph.cody.agent.CodyAgentService
import com.sourcegraph.cody.agent.protocol.WebviewOptions
import com.sourcegraph.cody.config.CodyApplicationSettings
import com.sourcegraph.cody.sidebar.WebTheme
import com.sourcegraph.cody.telemetry.TelemetryV2
import com.sourcegraph.common.BrowserOpener
import java.awt.Component
import java.awt.datatransfer.StringSelection
Expand Down Expand Up @@ -325,6 +328,8 @@ private class ExtensionRequestHandler(
private val proxy: WebUIProxy,
private val apiScript: String
) : CefRequestHandler {
private val logger = Logger.getInstance(ExtensionRequestHandler::class.java)

override fun onBeforeBrowse(
browser: CefBrowser?,
frame: CefFrame?,
Expand Down Expand Up @@ -393,17 +398,27 @@ private class ExtensionRequestHandler(
sslInfo: CefSSLInfo?,
callback: CefCallback?
): Boolean {
// TODO: Add Telemetry here.
proxy.openDevTools()
logger.warn(
"""Certificate error occurred while loading URL: $request_url
Error code: ${cert_error?.name}
SSL Info: $sslInfo"""
.trimIndent())
ProjectManager.getInstance().openProjects.forEach { project ->
TelemetryV2.sendTelemetryEvent(project, "cody.webview.request", "certError")
}
return false
}

override fun onRenderProcessTerminated(
browser: CefBrowser?,
status: CefRequestHandler.TerminationStatus?
) {
// TODO: Add Telemetry here.
// TODO: Logging.
// TODO: Trigger a reload.
logger.warn("Browser render process terminated: ${status?.name}")
ProjectManager.getInstance().openProjects.forEach { project ->
TelemetryV2.sendTelemetryEvent(project, "cody.webview.request", "renderProcessTerminated")
CodyAgentService.getInstance(project).restartAgent(project)
}
}
}

Expand Down

0 comments on commit f66c994

Please sign in to comment.