You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by "liuxiaocs7 (via GitHub)" <gi...@apache.org> on 2026/09/13 11:06:05 UTC

[PR] fix(desktop): stop canceled history searches and clear stale loading [maka]

liuxiaocs7 opened a new pull request, #5256:
URL: https://github.com/apache/maka/pull/5256

   ## Summary
   
   Closing Desktop history search or replacing a query currently leaves the old transcript scan running. An unresolved old request also keeps Astryx's palette transition busy, so reopening retains a stale input/spinner or completed newer results keep spinning.
   
   Cancel by request ID across the palette, preload Host discovery/fan-out, and Desktop IPC. Settle the canceled UI promise immediately, close its search-owned transcript handle, and stop later pages/sessions. Cancel on dismissal and renderer teardown. An already dispatched page may finish. Search stays with its owning Host candidate so reconnect cannot replay abandoned work; an interrupted search can be retried with the next query.
   
   Fixes #5255
   
   ## Verification
   
   - Passed: `npm run lint`, `npm run format:check`, `npm run build`, `npm run typecheck`, `npx knip --workspace apps/desktop`, and `npx knip --workspace packages/ui`.
   - Passed after rebuilding: Desktop's full `test:dist` suite (**2,594 tests**), UI's full `test:dist` suite (**442 tests**), and the existing Runtime Host regression `close stops transcript pagination after the in-flight page`.
   - The new real-component regression failed before the fix (`reopening must not wait for the dismissed request`). The reconnect regression also failed before the IPC adjustment (two transcript opens instead of one). Coverage includes rapid replacement, dismissal/reopening, unmount, multi-Host fan-out, renderer isolation, and late replies.
   - Chromium evidence below mounts the real `SearchModal` with the Desktop theme and synthetic deferred responses. In both comparisons the abandoned request remains unresolved: before = one loading indicator, after = zero. No private conversations are included. The installed Desktop app and full cross-workspace `npm test` were not run.
   
   | Scenario | Before | After |
   | --- | --- | --- |
   | Close and reopen with an old query pending | ![Stale input and spinner](https://raw.githubusercontent.com/liuxiaocs7/maka/5ab1749ad0f7420d5b73dee6c25922f7fd8e11b8/docs/images/pr/desktop-search-cancellation/before-reopen.png) | ![Empty input and no spinner](https://raw.githubusercontent.com/liuxiaocs7/maka/5ab1749ad0f7420d5b73dee6c25922f7fd8e11b8/docs/images/pr/desktop-search-cancellation/after-reopen.png) |
   | Newest result completes while an older query remains pending | ![Result with stale spinner](https://raw.githubusercontent.com/liuxiaocs7/maka/5ab1749ad0f7420d5b73dee6c25922f7fd8e11b8/docs/images/pr/desktop-search-cancellation/before-latest-result.png) | ![Result without spinner](https://raw.githubusercontent.com/liuxiaocs7/maka/5ab1749ad0f7420d5b73dee6c25922f7fd8e11b8/docs/images/pr/desktop-search-cancellation/after-latest-result.png) |
   
   ## AI use
   
   Select exactly one:
   
   - [ ] No generative tool made a substantive contribution
   - [x] Generative tooling made a substantive contribution
   
   Tool(s) and scope: Codex diagnosed and implemented the fix, wrote regression tests, ran verification, captured synthetic UI evidence, and prepared/submitted this contribution on behalf of @liuxiaocs7. The commit includes `Generated-by: Codex`.
   
   ## Checklist
   
   - [x] Tests cover the change and fail without it
   - [x] Lint, format, typecheck and the affected suites pass locally
   
   Does this PR entail a change in behavior?
   
   - [x] Yes — described under Summary above
   - [ ] No
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): stop canceled history searches and clear stale loading [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han merged PR #5256:
URL: https://github.com/apache/maka/pull/5256


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): stop canceled history searches and clear stale loading [maka]

Posted by "liuxiaocs7 (via GitHub)" <gi...@apache.org>.
liuxiaocs7 commented on code in PR #5256:
URL: https://github.com/apache/maka/pull/5256#discussion_r4000263557


##########
apps/desktop/src/main/runtime-host-search-ipc-main.ts:
##########
@@ -38,25 +38,74 @@ interface RuntimeHostSearchIpcDeps {
 export function registerRuntimeHostSearchIpc(
   deps: RuntimeHostSearchIpcDeps,
 ): void {
-  handleReconnectableRead(deps.ipcMain, 'search:thread', async (_event, request: unknown) => {
-    const result = await runThreadSearch(request, {
-      listSessions: async () =>
-        (await deps.client.listSessions()).map(toDesktopHostSessionSummary),
-      readMessages: (sessionId) =>
-        readWithFallback(async () => {
-          const session = await deps.client.openSession(sessionId);
-          try {
-            return await session.loadTranscript();
-          } finally {
-            await session.close();
-          }
-        }, null),
-      getPrivacyContext: async () => ({
-        incognitoActive: (await deps.client.queryRuntimePolicy()).policy.privacy
-          .incognitoActive,
-      }),
-    });
-    return result.ok ? result.results.map(projectDesktopSearchResult) : result;
+  const pending = new WeakMap<WebContents, Map<string, AbortController>>();
+  // A search belongs to this candidate and its cancellation registry. Replaying
+  // it on a replacement would revive work the renderer has already abandoned.
+  deps.ipcMain.handle('search:thread', async (event, request: unknown, requestId?: unknown) => {
+    if (requestId !== undefined && (typeof requestId !== 'string' || !requestId || requestId.length > 128)) {
+      return { ok: false, reason: 'invalid_query', message: 'Invalid search request identity.' };
+    }
+    const controller = new AbortController();
+    const release = () => {
+      event.sender?.removeListener('destroyed', abort);
+      if (typeof requestId === 'string') {
+        const requests = pending.get(event.sender);
+        if (requests?.get(requestId) === controller) requests.delete(requestId);
+      }
+    };
+    const abort = () => controller.abort();
+    if (typeof requestId === 'string') {
+      let requests = pending.get(event.sender);
+      if (!requests) {
+        requests = new Map();
+        pending.set(event.sender, requests);
+      }
+      requests.get(requestId)?.abort();
+      requests.set(requestId, controller);
+    }
+    controller.signal.addEventListener('abort', release, { once: true });
+    event.sender?.once('destroyed', abort);

Review Comment:
   Confirmed, thanks. Fixed in 0872f80f8a: the existing abort/release pair now subscribes to and removes both `render-process-gone` and `destroyed`.
   
   Both new crash regressions fail before the fix and pass afterward. They cover a crash while `openSession` is pending, immediate transcript closure during an in-flight read, stopping subsequent sessions, and a successful new search on the same WebContents while the abandoned reply is still pending. The tests also check late replies, exactly-once closure, and listener cleanup.
   
   Validation: 31 related tests passed, along with build, typecheck, lint, format, and knip checks. The [CI test check](https://github.com/apache/maka/actions/runs/34769689608) also passed for this commit.
   
   Posted by Codex on behalf of @liuxiaocs7.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(desktop): stop canceled history searches and clear stale loading [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on code in PR #5256:
URL: https://github.com/apache/maka/pull/5256#discussion_r4000100982


##########
apps/desktop/src/main/runtime-host-search-ipc-main.ts:
##########
@@ -38,25 +38,74 @@ interface RuntimeHostSearchIpcDeps {
 export function registerRuntimeHostSearchIpc(
   deps: RuntimeHostSearchIpcDeps,
 ): void {
-  handleReconnectableRead(deps.ipcMain, 'search:thread', async (_event, request: unknown) => {
-    const result = await runThreadSearch(request, {
-      listSessions: async () =>
-        (await deps.client.listSessions()).map(toDesktopHostSessionSummary),
-      readMessages: (sessionId) =>
-        readWithFallback(async () => {
-          const session = await deps.client.openSession(sessionId);
-          try {
-            return await session.loadTranscript();
-          } finally {
-            await session.close();
-          }
-        }, null),
-      getPrivacyContext: async () => ({
-        incognitoActive: (await deps.client.queryRuntimePolicy()).policy.privacy
-          .incognitoActive,
-      }),
-    });
-    return result.ok ? result.results.map(projectDesktopSearchResult) : result;
+  const pending = new WeakMap<WebContents, Map<string, AbortController>>();
+  // A search belongs to this candidate and its cancellation registry. Replaying
+  // it on a replacement would revive work the renderer has already abandoned.
+  deps.ipcMain.handle('search:thread', async (event, request: unknown, requestId?: unknown) => {
+    if (requestId !== undefined && (typeof requestId !== 'string' || !requestId || requestId.length > 128)) {
+      return { ok: false, reason: 'invalid_query', message: 'Invalid search request identity.' };
+    }
+    const controller = new AbortController();
+    const release = () => {
+      event.sender?.removeListener('destroyed', abort);
+      if (typeof requestId === 'string') {
+        const requests = pending.get(event.sender);
+        if (requests?.get(requestId) === controller) requests.delete(requestId);
+      }
+    };
+    const abort = () => controller.abort();
+    if (typeof requestId === 'string') {
+      let requests = pending.get(event.sender);
+      if (!requests) {
+        requests = new Map();
+        pending.set(event.sender, requests);
+      }
+      requests.get(requestId)?.abort();
+      requests.set(requestId, controller);
+    }
+    controller.signal.addEventListener('abort', release, { once: true });
+    event.sender?.once('destroyed', abort);

Review Comment:
   [P2] Cancel searches when the renderer process is lost
   
   Could the same abort/release pair also subscribe to and remove render-process-gone? Desktop crash recovery reloads the existing WebContents, so destroyed does not fire, and a crashed renderer cannot run the React cleanup that sends cancel IPC. The abandoned search can therefore continue scanning up to 200 sessions. Replacing destroyed with render-process-gone in the existing teardown test returns normal results rather than aborted; a real Electron probe also confirms that an invoke handler continues after renderer crash while sender.isDestroyed() is false. The adjacent session-copy owner already handles both events, so the same bounded cleanup pattern should fit here.
   
   <details><summary>中文</summary>
   
   Renderer 崩溃后会复用 WebContents,因此 destroyed 不触发,React cleanup 也无法发送取消。旧搜索会继续后台扫描。请让现有 abort/release 同时监听并解除 render-process-gone 和 destroyed,并补崩溃回归。
   
   </details>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org