@@ -223,6 +223,10 @@ export class ClineProvider
223223 private taskEventListeners : WeakMap < Task , Array < ( ) => void > > = new WeakMap ( )
224224 private currentWorkspacePath : string | undefined
225225 private _disposed = false
226+ private lastWebviewHeartbeatAt = 0
227+ private webviewWatchdogInterval : ReturnType < typeof setInterval > | null = null
228+ private static readonly WEBVIEW_WATCHDOG_TICK_MS = 60_000
229+ private static readonly WEBVIEW_HEARTBEAT_STALE_MS = 90_000
226230 private readonly _postStateToWebviewThrottled = debounce (
227231 async ( ) => {
228232 try {
@@ -842,6 +846,10 @@ export class ClineProvider
842846
843847 this . _disposed = true
844848 this . _postStateToWebviewThrottled . cancel ( )
849+ if ( this . webviewWatchdogInterval ) {
850+ clearInterval ( this . webviewWatchdogInterval )
851+ this . webviewWatchdogInterval = null
852+ }
845853 this . log ( "Disposing ClineProvider..." )
846854
847855 // Reject any tasks still waiting for a scheduler permit so they don't
@@ -1082,6 +1090,9 @@ export class ClineProvider
10821090 // and executes code based on the message that is received.
10831091 this . setWebviewMessageListener ( webviewView . webview )
10841092
1093+ // Detect a dead webview renderer process (gray screen) via heartbeat timeout.
1094+ this . startWebviewWatchdog ( )
1095+
10851096 // Initialize code index status subscription for the current workspace.
10861097 this . updateCodeIndexStatusSubscription ( )
10871098
@@ -1100,6 +1111,9 @@ export class ClineProvider
11001111 // for this visibility listener panel.
11011112 const viewStateDisposable = webviewView . onDidChangeViewState ( ( ) => {
11021113 if ( this . view ?. visible ) {
1114+ // Hidden webviews throttle timers, so grant a fresh grace
1115+ // window instead of counting throttled heartbeats as a crash.
1116+ this . updateWebviewHeartbeat ( )
11031117 void this . postMessageToWebview ( { type : "action" , action : "didBecomeVisible" } )
11041118 } else {
11051119 this . logWebviewHiddenDiagnostics ( )
@@ -1111,6 +1125,9 @@ export class ClineProvider
11111125 // sidebar
11121126 const visibilityDisposable = webviewView . onDidChangeVisibility ( ( ) => {
11131127 if ( this . view ?. visible ) {
1128+ // Hidden webviews throttle timers, so grant a fresh grace
1129+ // window instead of counting throttled heartbeats as a crash.
1130+ this . updateWebviewHeartbeat ( )
11141131 void this . postMessageToWebview ( { type : "action" , action : "didBecomeVisible" } )
11151132 } else {
11161133 this . logWebviewHiddenDiagnostics ( )
@@ -3381,6 +3398,39 @@ export class ClineProvider
33813398 )
33823399 }
33833400
3401+ /** Records that the webview renderer is alive; called on every webviewHeartbeat message. */
3402+ public updateWebviewHeartbeat ( ) : void {
3403+ this . lastWebviewHeartbeatAt = Date . now ( )
3404+ }
3405+
3406+ /**
3407+ * Starts (or restarts) the watchdog that detects a dead webview renderer
3408+ * process. Hidden webviews throttle timers, so becoming visible resets the
3409+ * grace window instead of counting throttled heartbeats as a crash.
3410+ */
3411+ private startWebviewWatchdog ( ) : void {
3412+ this . updateWebviewHeartbeat ( )
3413+ if ( this . webviewWatchdogInterval ) {
3414+ clearInterval ( this . webviewWatchdogInterval )
3415+ }
3416+ this . webviewWatchdogInterval = setInterval ( ( ) => {
3417+ if ( this . view ?. visible !== true ) {
3418+ return
3419+ }
3420+ if ( Date . now ( ) - this . lastWebviewHeartbeatAt <= ClineProvider . WEBVIEW_HEARTBEAT_STALE_MS ) {
3421+ return
3422+ }
3423+ this . log ( "[Zoo Code] Webview heartbeat stale while visible; reloading webview (dead renderer?)" )
3424+ void Promise . resolve ( vscode . commands . executeCommand ( "workbench.action.webview.reloadWebviewAction" ) ) . catch (
3425+ ( error ) => {
3426+ this . log (
3427+ `[Zoo Code] Failed to reload webview: ${ error instanceof Error ? error . message : String ( error ) } ` ,
3428+ )
3429+ } ,
3430+ )
3431+ } , ClineProvider . WEBVIEW_WATCHDOG_TICK_MS )
3432+ }
3433+
33843434 public getRecentTasks ( ) : string [ ] {
33853435 if ( this . recentTasksCache ) {
33863436 return this . recentTasksCache
0 commit comments