Skip to content

Commit dea0067

Browse files
committed
fix(webview): keep recovery warnings and probe results retryable
1 parent 361a48b commit dea0067

3 files changed

Lines changed: 46 additions & 8 deletions

File tree

‎apps/vscode-e2e/src/visual/sceneController.ts‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,22 @@ export async function run(): Promise<void> {
159159
} catch {
160160
return
161161
}
162-
let fixture: WebviewThemeFixture
162+
const resultPath = `${request}.result`
163+
const temporaryResultPath = `${resultPath}.tmp`
163164
try {
164-
fixture = await api.captureWebviewThemeFixture()
165+
const fixture = await api.captureWebviewThemeFixture()
166+
await fs.writeFile(
167+
temporaryResultPath,
168+
JSON.stringify({ fixture, taskIds: api.getCurrentTaskStack() }),
169+
"utf8",
170+
)
171+
await fs.rename(temporaryResultPath, resultPath)
172+
// Acknowledge only after publishing a complete result. Repeating this
173+
// write after a failed acknowledgement is safe for this read-only probe.
174+
await fs.unlink(request)
165175
} catch (error) {
166-
await log(`theme probe will retry: ${String(error)}`)
167-
return
176+
await fs.rm(temporaryResultPath, { force: true }).catch(() => undefined)
177+
await log(`theme probe will retry: ${String(error)}`).catch(() => undefined)
168178
}
169-
await fs.unlink(request)
170-
await fs.writeFile(`${request}.result`, JSON.stringify({ fixture, taskIds: api.getCurrentTaskStack() }), "utf8")
171179
})
172180
}

‎src/core/webview/ClineProvider.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,7 @@ export class ClineProvider
16381638

16391639
// Check if local dev server is running.
16401640
try {
1641-
await axios.get(`http://${localServerUrl}`)
1641+
await axios.get(`http://${localServerUrl}`, { timeout: 5_000 })
16421642
} catch {
16431643
vscode.window.showErrorMessage(t("common:errors.hmr_not_running"))
16441644
return this.getHtmlContent(webview)
@@ -3572,6 +3572,9 @@ export class ClineProvider
35723572
}
35733573
this.lastReceivedWebviewHeartbeatAt = now
35743574
this.webviewHeartbeatCount++
3575+
// A new heartbeat invalidates the old warning action. Allow a fresh warning
3576+
// if this renderer stalls again, without replenishing its retry budget.
3577+
this.webviewRecoveryFailureReported = false
35753578
if (this.webviewRecoveryConfirmation) {
35763579
this.log("[Zoo Code] Webview heartbeat returned after recovery")
35773580
}

‎src/core/webview/__tests__/ClineProvider.spec.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,33 @@ describe("ClineProvider", () => {
14091409
expect(vscode.commands.executeCommand).not.toHaveBeenCalledWith("workbench.action.reloadWindow")
14101410
})
14111411

1412+
test("offers a fresh actionable warning when one heartbeat is followed by another stall", async () => {
1413+
await provider.resolveWebviewView(mockWebviewView)
1414+
vi.mocked(vscode.commands.getCommands).mockResolvedValue([])
1415+
let chooseOld: (value: string) => void = () => {
1416+
throw new Error("Notification not shown")
1417+
}
1418+
const oldChoice = new Promise<string>((resolve) => {
1419+
chooseOld = resolve
1420+
})
1421+
vi.mocked(vscode.window.showWarningMessage).mockImplementationOnce(vi.fn().mockReturnValue(oldChoice))
1422+
await vi.advanceTimersByTimeAsync(130_000)
1423+
expect(vscode.window.showWarningMessage).toHaveBeenCalledTimes(1)
1424+
1425+
provider.updateWebviewHeartbeat()
1426+
expect(provider["webviewRecoveryAttempts"]).toBe(3)
1427+
chooseOld("Reload Window")
1428+
await vi.advanceTimersByTimeAsync(0)
1429+
expect(vscode.commands.executeCommand).not.toHaveBeenCalledWith("workbench.action.reloadWindow")
1430+
1431+
vi.mocked(vscode.window.showWarningMessage).mockImplementation(vi.fn().mockResolvedValue("Reload Window"))
1432+
await vi.advanceTimersByTimeAsync(170_000)
1433+
expect(vscode.window.showWarningMessage).toHaveBeenCalledTimes(2)
1434+
expect(vscode.commands.executeCommand).toHaveBeenCalledWith("workbench.action.reloadWindow")
1435+
await vi.advanceTimersByTimeAsync(240_000)
1436+
expect(vscode.window.showWarningMessage).toHaveBeenCalledTimes(2)
1437+
})
1438+
14121439
test("keeps the Reload Window action available after visibility grace resets", async () => {
14131440
await provider.resolveWebviewView(mockWebviewView)
14141441
vi.mocked(vscode.commands.getCommands).mockResolvedValue([])
@@ -2304,7 +2331,7 @@ describe("ClineProvider", () => {
23042331
// Pin the health-check URL itself: the mock resolves for any URL, so only
23052332
// this assertion keeps the probe from silently drifting back to
23062333
// `localhost` (the IPv6 resolution failure this branch fixes).
2307-
expect(axios.get).toHaveBeenCalledWith("http://127.0.0.1:5173")
2334+
expect(axios.get).toHaveBeenCalledWith("http://127.0.0.1:5173", { timeout: 5_000 })
23082335

23092336
const html = mockWebviewView.webview.html
23102337
// The dev server URL must be baked into the module script tag and CSP directives.

0 commit comments

Comments
 (0)