[Bug]: Mini App 弹出为独立窗口后,先关闭 MiniMax Code 会留下一个无法关闭的假死窗口

Đang mở
#633 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
electron, typescript
Lĩnh vực
backend, desktop

Hướng nghiên cứu

The report identifies miniapp-detached-window.js, embedded-browser-manager.js, miniapp-host.js, and quit-coordinator.js in the packaged desktop build, while noting that the desktop source is not public in this repository. Start by checking whether those source files or related tests exist here, then trace detached window ownership, page cleanup, and quit handling. Done means detached Mini App windows close or remain usable when the main window hides or the app exits.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

desktop
Product or interface

Desktop app

Version

3.1.19.232

Platform

Windows

OS version and architecture

Windows 11 x64 (build 26300, UBR 9818)

Issue area

UI / UX

Desktop log upload ID (optional)

No response

Steps to reproduce

背景

Mini App 可以从 File Panel 弹出(detach)成一个独立顶层窗口。这是 Host UI 的官方操作,弹出前会弹确认框询问「是否把页面移到独立窗口」,并非包自身的行为。

前置条件

一个在 miniapp.json 中声明了 surface.window 的 Mini App(此处只声明尺寸,不含 frame:false / transparent / alwaysOnTop / skipTaskbar 等必须依赖原生窗口的特性):

{
  "surface": {
    "path": "/dashboard",
    "window": { "width": 1280, "height": 820, "minWidth": 880, "minHeight": 560, "resizable": true }
  }
}

步骤

  1. 在桌面端打开该 Mini App,它出现在 File Panel 中。
  2. 把面板里的 Mini App 最大化 / 弹出成独立窗口(即 detach)。
  3. 不要关闭这个弹出窗口,保持它开着。
  4. 关闭 MiniMax Code:点主窗口的关闭按钮(Windows 上为隐藏到托盘),或托盘菜单 → 退出。
  5. 观察那个弹出窗口。
Expected and actual behavior

期望

弹出窗口应随应用一起关闭。应用退出后,屏幕上不应残留任何 Mini App 窗口;即便残留,也应仍可被用户关闭。

实际

弹出窗口留在屏幕上,并且:

  • 画面完全静止,不再刷新;
  • 点击、拖拽均无响应;
  • 点窗口标题栏的关闭按钮没有反应 —— 该窗口无法被关闭,只能结束整个进程才能收场。

从用户视角看,就是「MiniMax Code 已经关了,但 Mini App 变成一块冻住的画面」。

触发条件(两个都需满足)

  • Mini App 已处于 detached(独立窗口)状态;
  • 主窗口被关闭/隐藏,或应用退出,且该弹出窗口没有被用户先关掉。

成因分析

以下引用均取自已安装版本的打包产物 resources/app.asar → dist/main/。桌面端源码未在本仓库公开,因此这里是对打包产物的引用,行号对应 3.1.19.232。

1) 弹出窗口刻意不设 parent,生命周期与主窗口解耦

dist/main/modules/browser/miniapp-detached-window.js:51-88

    const window = (host.createWindow
        ? (options) => host.createWindow(tab, options)
        : host.detachedWindowFactory)({
        ...
        // Intentionally not `parent: host`: a child NSWindow on macOS cannot be
        // minimized independently of its parent (Electron #39578 / #26031). The
        // pop-out is its own top-level window with independent visibility, including
        // when the main window is hidden to the tray or moves between fullscreen Spaces.

2) 弹出窗口的 close 被主动拦截,只有应用进入退出流程时才放行

dist/main/modules/browser/miniapp-detached-window.js:229-234

        close: (event) => {
            if (tab.detachedWindow !== window || host.isAppQuitting())
                return;
            event.preventDefault();
            requestAttach(host, tab);
        },

host.isAppQuitting() 即 windowManager.isAppQuitting()(embedded-browser-manager.js:344),而 appQuitting 只在退出协调器里被置真(dist/main/lifecycle/quit-coordinator.js:145)。因此在非退出路径下,无论用户还是系统都无法关掉这个窗口。

3) 页面的 Host 通道绑定在主窗口的渲染进程上

dist/main/modules/browser/embedded-browser-manager.js:862-874

        const miniApp = tab.miniApp;
        const ownerWindow = miniApp.ownerWindow;
        try {
            const owner = ownerWindow && !ownerWindow.isDestroyed() ? ownerWindow.webContents : null;
            const ownerFrame = owner && !owner.isDestroyed() ? owner.mainFrame : null;
            if (!owner || !ownerFrame || ownerFrame.detached)
                return null;

owner 是「打开该 Mini App 的那个窗口」(即主窗口)。主窗口的 renderer 一消失,所有 Mini App 页面的订阅立刻以 host_unavailable 结束 —— 像素还在,但页面再也收不到任何东西:

dist/main/modules/browser/miniapp-host.js:395-410

    endOwner(host, expected) {
        ...
        for (const page of this.pages.values())
            if (page.source.owner === host) {
                for (const subscription of [...page.subscriptions.values()])
                    this.endSubscription(page, subscription, 'host_unavailable');
                page.navigationRevision = -1;
            }

owner 的文档结束(did-navigate / destroyed / render-process-gone)由 embedded-browser-manager.js:4917-4932 监听。

4) 弹出窗口可以比它自己的页面活得久 —— 这是既有设计

dist/main/modules/browser/embedded-browser-manager.js:1206-1244

        // A minimized or hidden pop-out outlives its page; only the page is destroyed.
        const keptWindow = (0, miniapp_detached_window_1.releaseDetachedWindow)(tab);
        try {
            this.destroyTab(tab, 'miniapp-sleep', { preserveLogicalTab: true });
        }
        ...
        if (keptWindow)
            this.keepSleepingMiniAppWindow(record, keptWindow);

窗口被交给睡眠记录继续保留,页面被销毁。保留窗口的 close 同样被拦截(miniapp-detached-window.js:196-201),所以它既不会自己消失,也关不掉。

5) 应用级退出清理覆盖不到弹出窗口

dist/main/lifecycle/application-bootstrap-production.js:297-307

                destroyAll: () => {
                    for (const window of electron_1.BrowserWindow.getAllWindows()) {
                        try {
                            if (!window.isDestroyed())
                                window.destroy();
                        }
                        catch (error) {
                            logLifecycleError('Failed to destroy a window during update shutdown', error);
                        }
                    }
                },

且弹出窗口从未登记进窗口管理器(dist/main/windows/manager.js:15:ALL_WINDOW_TYPES = ['onboarding', 'login', 'archon']),因此 destroyWindowsExcept() / destroyWindowByType() 同样够不到它。

建议修复方案

  1. 页面被销毁时,窗口不应比它活得久:sleepMiniAppTab() 销毁页面时应同时关闭弹出窗口;若产品需要保留窗口位置以便页面恢复,应把边界持久化后在页面销毁时关窗,重开时按记忆重建。
  2. 保留态弹出窗口不应无条件拦截用户发起的关闭。
  3. 退出流程中显式关闭全部 Mini App 弹出窗口(两种后端都要),并在关闭 BaseWindow 前释放其子 WebContentsView.webContents。
  4. detach 之后,页面的 Host owner 应改为弹出窗口本身,而不是主窗口 —— 否则主窗口一关闭,弹出的页面立刻失去交互能力。
  5. 让运行时知道页面当前处于「独立窗口」形态:MiniAppPresenter 契约目前只有 open / close(packages/local-runtime-v2/src/application/session/process-local-application-contract.ts:46-55),无法表达这一点,因此记忆协调器可能去 sleep 一个用户正看着的页面。

用户侧临时规避

  • 退出 MiniMax Code 前先关闭 Mini App 的弹出窗口 —— 它的 close 会把页面搬回 File Panel,而不是留下孤儿窗口;
  • 已卡死时:托盘图标 → 退出,或从任务管理器结束进程;不要直接杀进程,那是最快制造孤儿窗口的方式。
Redacted error summary
[2026-11-23 21:04:34.149] [info] [EmbeddedBrowserLifecycle] hidden
  {"rendererBackend":"webview","guestGeneration":1,"event":"hidden","tabId":1,
   "pageHost":"127.0.0.1:65242","webContentsId":3,"aliveMs":1622,"hiddenMs":0,
   "operationCount":0,"reason":null}

[2026-11-23 21:04:35.805] [info] [EmbeddedBrowserLifecycle] webview-host-ready
  {"hostWebContentsId":4,"isMainHost":false,"lostTabIds":[]}

[2026-11-23 21:04:35.812] [info] [EmbeddedBrowserLifecycle] web-contents-destroyed
  {"event":"web-contents-destroyed","tabId":1,"webContentsId":3,
   "rendererPid":33048,"expected":true}

[2026-11-23 21:04:35.931] [info] [EmbeddedBrowserLifecycle] guest-rebuild
  {"tabId":1,"rendererBackend":"webview","guestGeneration":2,"committed":true,
   "recovered":true,"durationMs":180}

[2026-11-29 13:10:32.658] [info] [ArchonChat] close: hiding window to tray
[2026-11-29 13:10:35.607] [info] [ArchonChat] close: hiding window to tray
[2026-11-29 13:10:54.494] [info] [MainMemory] heap_used_mb=46.1 heap_limit_mb=4096.0 rss_mb=174.2

第一组日志显示 detach 时页面被重建到了另一个窗口(hostWebContentsId:4,isMainHost:false),主窗口里的旧 guest 被销毁。第二组日志显示「关闭 MiniMax Code」在 Windows 上是隐藏到托盘,进程在 19 秒后仍然存活。

Screenshots

No response

Before submitting
  • I have searched existing issues.
  • I have included my version and removed sensitive information.
Ngôn ngữ chính
TypeScript
Star
2.3k
Fork
315
Merge trung bình
3 giờ 54 phút
Pull request đã merge (30 ngày)
9

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của MiniMax-AI/minimax-code

Tất cả issue của MiniMax-AI/minimax-code

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.