Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(desktop): skip renderer recovery during shutdown (#88835)

Adam Leithb1c1727d6167
diff --git a/products/desktop/apps/code/src/main/index.ts b/products/desktop/apps/code/src/main/index.ts
index ae32ffa93253..daacac479758 100644
--- a/products/desktop/apps/code/src/main/index.ts
+++ b/products/desktop/apps/code/src/main/index.ts
@@ -171,6 +171,9 @@ const RECOVERABLE_RENDER_REASONS = new Set([
const CRASH_LOOP_WINDOW_MS = 30_000;
const CRASH_LOOP_THRESHOLD = 3;
const recentCrashTimestamps: number[] = [];
+// Electron reports renderers torn down during quit as "killed", which is also
+// a recoverable reason, so recovery has to be gated on shutdown state instead.
+let shutdownStarted = false;
function isCrashLoop(): boolean {
const now = Date.now();
@@ -213,6 +216,13 @@ app.on("render-process-gone", (_event, webContents, details) => {
);
posthogNodeAnalytics.flush().catch(() => {});
+ if (shutdownStarted) {
+ log.info("Skipping renderer recovery during shutdown", {
+ reason: details.reason,
+ });
+ return;
+ }
+
if (RECOVERABLE_RENDER_REASONS.has(details.reason)) {
if (isCrashLoop()) {
log.error("Crash loop detected, stopping auto-recovery", {
@@ -468,6 +478,7 @@ const teardownContainer = async (): Promise<void> => {
};
app.on("before-quit", async (event) => {
+ shutdownStarted = true;
try {
container.get<WorkspaceServerService>(WORKSPACE_SERVER_SERVICE).stop();
} catch {}
@@ -499,6 +510,7 @@ app.on("before-quit", async (event) => {
const handleShutdownSignal = async (signal: string) => {
log.info(`Received ${signal}, starting shutdown`);
+ shutdownStarted = true;
try {
const lifecycleService = container.get<AppLifecycleService>(
APP_LIFECYCLE_SERVICE,