You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by as...@apache.org on 2026/08/24 17:37:57 UTC

(maka) 01/02: fix(side-chat): preserve admission on unknown stop

This is an automated email from the ASF dual-hosted git repository.

Astro-Han pushed a commit to branch fix/side-conversation-event-ownership
in repository https://gitbox.apache.org/repos/asf/maka.git

commit 16442cc9eef5f900fecf0722f9ad5c41c49a6b64
Author: AstroHan <le...@outlook.com>
AuthorDate: Tue Aug 25 01:24:37 2026 +0800

    fix(side-chat): preserve admission on unknown stop
    
    Generated-by: Codex
---
 .../main/__tests__/quote-companion-retry.test.ts   | 48 ++++++++++++++++++++++
 .../workbar/tools/side-chat/use-quote-companion.ts | 33 +++++++++------
 2 files changed, 68 insertions(+), 13 deletions(-)

diff --git a/apps/desktop/src/main/__tests__/quote-companion-retry.test.ts b/apps/desktop/src/main/__tests__/quote-companion-retry.test.ts
index 699be67a7..f364e5598 100644
--- a/apps/desktop/src/main/__tests__/quote-companion-retry.test.ts
+++ b/apps/desktop/src/main/__tests__/quote-companion-retry.test.ts
@@ -461,6 +461,54 @@ test('clears a queued Side Conversation send when Host stop cancels the admissio
   assert.equal(container.firstElementChild?.getAttribute('data-live-turn-id'), '');
 });
 
+test('keeps a Side Conversation admission when Host stop outcome is unknown', async () => {
+  let send: ((text: string) => Promise<boolean>) | undefined;
+  let stop: (() => Promise<void>) | undefined;
+  const pendingSend = deferred<{ ok: true; turnId: string }>();
+  const { container } = await renderProbe(
+    {
+      subscribeEvents: (_sessionId, _handler, onSeeded) => {
+        onSeeded?.();
+        return () => undefined;
+      },
+      send: async () => pendingSend.promise,
+      stop: async () => {
+        throw new Error('Host stop result is unknown');
+      },
+    },
+    {
+      ownership: true,
+      onSend: (value) => (send = value),
+      onStop: (value) => (stop = value),
+    },
+  );
+  assert.ok(send);
+  assert.ok(stop);
+
+  let sendResult: Promise<boolean> | undefined;
+  await act(async () => {
+    sendResult = send?.('keep this admission');
+    await Promise.resolve();
+  });
+  let stopResult: Promise<void> | undefined;
+  await act(async () => {
+    stopResult = stop?.();
+    await stopResult;
+    await Promise.resolve();
+  });
+
+  assert.equal(container.firstElementChild?.getAttribute('data-processing'), 'true');
+  await act(async () => {
+    pendingSend.resolve({ ok: true, turnId: 'admitted-after-unknown-stop' });
+    assert.equal(await sendResult, true);
+    await Promise.resolve();
+  });
+  assert.equal(
+    container.firstElementChild?.getAttribute('data-live-turn-id'),
+    'admitted-after-unknown-stop',
+  );
+});
+
 test('releases a queued Side Conversation admission from the Host queue retract', async () => {
   let eventHandler: ((event: SessionEvent) => void) | undefined;
   let send: ((text: string) => Promise<boolean>) | undefined;
diff --git a/apps/desktop/src/renderer/features/workbar/tools/side-chat/use-quote-companion.ts b/apps/desktop/src/renderer/features/workbar/tools/side-chat/use-quote-companion.ts
index b58f093ea..d40c36d78 100644
--- a/apps/desktop/src/renderer/features/workbar/tools/side-chat/use-quote-companion.ts
+++ b/apps/desktop/src/renderer/features/workbar/tools/side-chat/use-quote-companion.ts
@@ -67,7 +67,7 @@ type PendingAdmission = {
   restoreTurnId: string | null;
   restoreLiveTurn: LiveTurnProjection | undefined;
   cancelled: boolean;
-  stopPromise?: Promise<void>;
+  stopPromise?: Promise<'confirmed' | 'unknown'>;
 };
 
 function admissionEventForMessage(
@@ -706,19 +706,26 @@ export function useQuoteCompanion(input: UseQuoteCompanionInput): UseQuoteCompan
       setTurnInFlight(false);
     }
     if (admission) {
-      const stopPromise = sideChat.stop(id).catch(() => {
-        if (pendingAdmissionRef.current === admission) {
-          admission.cancelled = false;
-          admission.stopPromise = undefined;
-          activeTurnIdRef.current = admission.restoreTurnId;
-          setLiveTurn(admission.restoreLiveTurn);
-          setTurnInFlight(true);
-        }
-        stopRequestedRef.current = false;
-      });
+      const stopPromise = sideChat.stop(id).then(
+        () => 'confirmed' as const,
+        () => {
+          // A rejected Stop tells us nothing about whether the Host stopped
+          // the Turn. Keep the admission alive so a late Host outcome can
+          // still bind its own Turn; the user can retry Stop after this.
+          if (pendingAdmissionRef.current === admission) {
+            admission.cancelled = false;
+            admission.stopPromise = undefined;
+            activeTurnIdRef.current = admission.restoreTurnId;
+            setLiveTurn(admission.restoreLiveTurn);
+            setTurnInFlight(true);
+          }
+          stopRequestedRef.current = false;
+          return 'unknown' as const;
+        },
+      );
       admission.stopPromise = stopPromise;
-      await stopPromise;
-      if (pendingAdmissionRef.current === admission) {
+      const outcome = await stopPromise;
+      if (outcome === 'confirmed' && pendingAdmissionRef.current === admission) {
         abandonAdmission(id, admission);
       }
       return;


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