Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 辅助窗口 shell 未就绪超时不再展示空白窗口 (#5478)
lengjingxucb6f43e3e44f
diff --git a/apps/desktop/src/main/ghost-panel-window/__tests__/controller.test.ts b/apps/desktop/src/main/ghost-panel-window/__tests__/controller.test.tsindex 88108b5946..6aa3db7aea 100644--- a/apps/desktop/src/main/ghost-panel-window/__tests__/controller.test.ts+++ b/apps/desktop/src/main/ghost-panel-window/__tests__/controller.test.ts@@ -592,6 +592,50 @@ describe('crash recovery', () => {});});+describe('open timeout (window rule §3.1)', () => {+ it('renderer shell not ready at timeout: invalidates and rebuilds with bounded recovery', () => {+ vi.useFakeTimers();+ try {+ const h = makeHarness(new Set(['a']));+ h.controller.open('a');+ const win1 = h.created[0].win;++ vi.advanceTimersByTime(5000);++ // shell 未就绪:不得展示空白窗口;作废缓存并重建重开(有界恢复)。+ expect(win1.isDestroyed()).toBe(true);+ expect(h.created).toHaveLength(2);+ expect(h.created[1].win.show).not.toHaveBeenCalled();+ expect(h.created[1].win.focus).not.toHaveBeenCalled();++ // 恢复额度耗尽:重建窗口再次超时后不再重建,也不展示。+ vi.advanceTimersByTime(5000);+ expect(h.created).toHaveLength(2);+ expect(h.created[1].win.show).not.toHaveBeenCalled();+ } finally {+ vi.useRealTimers();+ }+ });++ it('renderer ready but content pending at timeout: shows the mounted shell', () => {+ vi.useFakeTimers();+ try {+ const h = makeHarness(new Set(['a']));+ h.controller.open('a');+ const win = h.created[0].win;+ h.controller.markRendererReady(win.webContents as unknown as WebContents);++ vi.advanceTimersByTime(5000);++ // 仅 shell 就绪、内容未到:展示已挂载的 Loading 壳(基线允许)。+ expect(win.show).toHaveBeenCalledTimes(1);+ expect(win.focus).toHaveBeenCalled();+ } finally {+ vi.useRealTimers();+ }+ });+});+describe('dispose', () => {it('dispose destroys all windows', () => {const h = makeHarness(new Set(['a', 'b']));diff --git a/apps/desktop/src/main/ghost-panel-window/controller.ts b/apps/desktop/src/main/ghost-panel-window/controller.tsindex f3f1c6cac6..02a27f6324 100644--- a/apps/desktop/src/main/ghost-panel-window/controller.ts+++ b/apps/desktop/src/main/ghost-panel-window/controller.ts@@ -446,6 +446,12 @@ export class GhostPanelWindowsController {slot.openTimeout = setTimeout(() => {slot.openTimeout = null;if (slot.win.isDestroyed() || !slot.pendingOpen) return;+ // 窗口规则 §3.1:shell(rendererReady)未就绪时展示可能是空白窗口;按资源用量+ // 窗口基线作废缓存并走有界恢复(重建重开),恢复额度耗尽才放弃。+ if (!slot.rendererReady) {+ this.invalidateSlot(ghostId, slot, 'renderer readiness timed out');+ return;+ }if (!slot.visible) this.showAndFocus(ghostId, slot);}, DEFAULT_OPEN_TIMEOUT_MS);slot.openTimeout.unref?.();diff --git a/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.ts b/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.tsindex d6ea0b6df2..c693bb89a7 100644--- a/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.ts+++ b/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.ts@@ -712,18 +712,60 @@ describe('userInitiated:false', () => {expect(win.focus).not.toHaveBeenCalled();});- it('not-ready window: automated open fallback shows without focusing', () => {+ it('not-ready window: open fallback invalidates and rebuilds with bounded recovery', () => {+ const h = makeHarness();+ h.controller.open({ userInitiated: false });+ const win1 = h.windows[0];++ vi.advanceTimersByTime(5000);++ // 窗口规则 §3.1:shell 未就绪不得展示空白窗口;作废缓存并重建重开(有界恢复)。+ expect(win1.isDestroyed()).toBe(true);+ expect(h.windows).toHaveLength(2);+ expect(h.windows[1].show).not.toHaveBeenCalled();+ expect(h.windows[1].showInactive).not.toHaveBeenCalled();++ // 恢复额度耗尽:重建窗口再次超时后不再重建,也不展示。+ vi.advanceTimersByTime(5000);+ expect(h.windows).toHaveLength(2);+ expect(h.windows[1].show).not.toHaveBeenCalled();+ expect(h.windows[1].showInactive).not.toHaveBeenCalled();+ });++ it('renderer-ready but presentation-pending: open fallback shows the mounted shell', () => {const h = makeHarness();h.controller.open({ userInitiated: false });const win = h.windows[0];+ h.controller.markRendererReady(win.webContents as unknown as WebContents);vi.advanceTimersByTime(5000);+ // 仅 shell 就绪、内容未到:展示已挂载的 Loading 壳(基线允许)。expect(win.showInactive).toHaveBeenCalledTimes(1);expect(win.show).not.toHaveBeenCalled();expect(win.focus).not.toHaveBeenCalled();});+ it('late automation waiter keeps the window alive until its own deadline', async () => {+ const h = makeHarness({ detached: true });+ const first = h.controller.ensureOpenForAutomation();+ const firstSettled = first.catch(() => 'rejected');++ vi.advanceTimersByTime(5000); // 首次超时:waiter1 在场 → 顺延+ expect(h.windows[0].isDestroyed()).toBe(false);++ const second = h.controller.ensureOpenForAutomation(); // 6s:新 waiter(期限 14s),重排 fallback 到 11s+ const secondSettled = second.catch(() => 'rejected');+ vi.advanceTimersByTime(5000); // 11s fallback:新 waiter 在场 → 再次顺延+ expect(h.windows[0].isDestroyed()).toBe(false);++ vi.advanceTimersByTime(3000); // 14s:waiter 按自身期限拒绝,窗口未被提前拆掉+ await expect(secondSettled).resolves.toBe('rejected');++ vi.advanceTimersByTime(2000); // 16s:waiters 已空 → 作废回收,不无限顺延+ expect(h.windows[0].isDestroyed()).toBe(true);+ });+it('not-ready window: later user open upgrades pending show to focused', () => {const h = makeHarness();h.controller.open({ userInitiated: false });@@ -1722,13 +1764,13 @@ describe('crash recovery', () => {vi.advanceTimersByTime(10);expect(h.windows).toHaveLength(2);- // Wait for stability period- vi.advanceTimersByTime(30_000);-- // Recovery creates win2; need to open (request visibility) before second crash.+ // 恢复出的 win2 先正常就绪(基线:shell 超时未就绪的窗口会被作废回收,+ // 活下来的窗口都走健康路径);open() 会清零恢复额度并取消稳定期计时器,+ // 必须等稳定期自然过期后再崩溃,才能真实验证额度重置(greptile P2)。const win2 = h.windows[1];markReady(h.controller, win2);- h.controller.open();+ vi.advanceTimersByTime(30_000);+win2.emitWebContentsEvent('render-process-gone', {}, { reason: 'crashed' });vi.advanceTimersByTime(10);expect(h.windows).toHaveLength(3); // recovery quota reset allows third windowdiff --git a/apps/desktop/src/main/right-sidebar-window/controller.ts b/apps/desktop/src/main/right-sidebar-window/controller.tsindex d523d54e89..03e63cfc4d 100644--- a/apps/desktop/src/main/right-sidebar-window/controller.ts+++ b/apps/desktop/src/main/right-sidebar-window/controller.ts@@ -135,6 +135,7 @@ export class RsbWindowController {private visible = false;private pendingOpen = false;private pendingOpenShouldFocus = true;+ private openFallbackExtended = false;private disposed = false;private readyWaiters: Array<{resolve: () => void;@@ -730,6 +731,7 @@ export class RsbWindowController {this.visible = false;this.pendingOpen = false;this.pendingOpenShouldFocus = true;+ this.openFallbackExtended = false;this.destroyingWindow = false;this.clearPinnedSession();@@ -748,16 +750,32 @@ export class RsbWindowController {// ── 超时与恢复 ────────────────────────────────────────────────────- private scheduleOpenFallback(win: BrowserWindow): void {+ private scheduleOpenFallback(win: BrowserWindow, resetExtension = true): void {this.clearOpenTimeout();+ // 顺延是自我 re-arm,不得重置标志;外部重新打开(reload、新 open 周期)则给新一轮+ // 一次顺延机会,晚到的自动化等待器仍能等满自身期限。+ if (resetExtension) this.openFallbackExtended = false;this.openTimeout = setTimeout(() => {this.openTimeout = null;if (win !== this.winRef || win.isDestroyed() || !this.pendingOpen) return;- // renderer shell 未就绪时仍展示(loadURL 在 BrowserWindow 创建时就开始了,- // 5s 足够 Electron 完成 HTML 加载和 React 根挂载);即使只有 Loading 壳也是- // 可辨识的反馈,比永久不给用户任何反应好。- if (!this.rendererReady && !this.visible) {- this.deps.log.warn('right-sidebar open timed out before renderer-ready');+ // 窗口规则 §3.1:超时只能展示已挂载的 Loading 壳。shell(rendererReady)未就绪+ // 时展示可能是空白窗口;按资源用量窗口基线作废缓存并走有界恢复(重建重开),+ // 恢复额度耗尽才放弃。仅 shell 就绪、内容未到时仍展示 Loading 壳。+ if (!this.rendererReady) {+ // 自动化/宿主 waiter(ready 握手、宿主会话)各自有界等待并假定窗口存活:+ // 超时若有 waiter 在场则顺延一个周期再失效,避免提前拆窗把有界等待拒成+ // 'closed before ready';每次外部重新打开可重置一次,持续有 waiter 时窗口+ // 存活期仍以最长 waiter 期限为界,不会无限顺延。+ if (+ !this.openFallbackExtended+ && (this.readyWaiters.length > 0 || this.hostWaiters.length > 0)+ ) {+ this.openFallbackExtended = true;+ this.scheduleOpenFallback(win, false);+ return;+ }+ this.invalidateWindow(win, 'renderer readiness timed out');+ return;}if (!this.visible) this.showWindow(win, this.pendingOpenShouldFocus);}, DEFAULT_OPEN_TIMEOUT_MS);