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/26 16:14:40 UTC

(maka) 10/27: fix(desktop): reconcile transient messages from host proof

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

Astro-Han pushed a commit to branch fix/canonical-message-projection
in repository https://gitbox.apache.org/repos/asf/maka.git

commit 2ef7ab9136c60ac5f2462c6d3901a3d19687800b
Author: AstroHan <le...@outlook.com>
AuthorDate: Wed Aug 26 05:50:11 2026 +0800

    fix(desktop): reconcile transient messages from host proof
    
    Generated-by: Codex
---
 .../main/__tests__/app-shell-stop-action.test.ts   | 59 ++++++++++++++++
 .../main/__tests__/message-queue-ui-state.test.ts  | 18 +++--
 ...runtime-host-session-execution-ipc-main.test.ts | 80 +++++++++++++++++++---
 .../runtime-host-session-execution-ipc-main.ts     | 10 ++-
 apps/desktop/src/preload/bridge-contract.d.ts      |  1 +
 .../src/renderer/app-shell-session-events.ts       |  6 ++
 apps/desktop/src/renderer/app-shell-stop-action.ts |  9 ++-
 apps/desktop/src/renderer/app-shell.tsx            |  4 +-
 .../platform/desktop/create-workbar-services.ts    |  8 ++-
 .../renderer/use-app-shell-session-workspace.ts    |  5 --
 10 files changed, 175 insertions(+), 25 deletions(-)

diff --git a/apps/desktop/src/main/__tests__/app-shell-stop-action.test.ts b/apps/desktop/src/main/__tests__/app-shell-stop-action.test.ts
new file mode 100644
index 000000000..e86ed76f1
--- /dev/null
+++ b/apps/desktop/src/main/__tests__/app-shell-stop-action.test.ts
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { createAppShellStopAction } from '../../renderer/app-shell-stop-action.js';
+
+test('removes exactly the transient messages the Host retracts while stopping', async () => {
+  const removed: Array<{ sessionId: string; messageId: string }> = [];
+  const target = globalThis as unknown as { window?: unknown };
+  const previousWindow = target.window;
+  target.window = {
+    maka: {
+      sessions: {
+        stop: async () => ({
+          kind: 'interrupted',
+          retractedMessageIds: ['message-1', 'message-2'],
+        }),
+      },
+    },
+  };
+  try {
+    const stop = createAppShellStopAction({
+      uiLocale: 'en',
+      activeIdRef: { current: 'session-1' },
+      addPendingSessionAction: () => true,
+      clearPendingSessionAction: () => undefined,
+      setStopPendingBySession: () => undefined,
+      stopPendingRef: { current: new Set<string>() },
+      removeTransientMessage: (sessionId, messageId) => removed.push({ sessionId, messageId }),
+      toastApi: { error() {} },
+    });
+
+    await stop();
+
+    assert.deepEqual(removed, [
+      { sessionId: 'session-1', messageId: 'message-1' },
+      { sessionId: 'session-1', messageId: 'message-2' },
+    ]);
+  } finally {
+    target.window = previousWindow;
+  }
+});
diff --git a/apps/desktop/src/main/__tests__/message-queue-ui-state.test.ts b/apps/desktop/src/main/__tests__/message-queue-ui-state.test.ts
index 9d1a466c6..134ecb1dc 100644
--- a/apps/desktop/src/main/__tests__/message-queue-ui-state.test.ts
+++ b/apps/desktop/src/main/__tests__/message-queue-ui-state.test.ts
@@ -111,27 +111,37 @@ test('queue_update events drive the independent desktop queue projection', () =>
     },
   ]);
 
+  handlers.handleEvent('session-1', {
+    type: 'steering_message',
+    id: 'steering-message-delivering',
+    turnId: 'turn-1',
+    messageId: 'message-delivering',
+    ts: 2,
+    content: { text: 'already delivering' },
+  });
+  assert.deepEqual(removedTransientMessageIds, ['message-delivering']);
+
   handlers.handleEvent('session-1', {
     type: 'queue_update',
     id: 'queue-2',
     turnId: 'turn-1',
-    ts: 2,
+    ts: 3,
     queueRevision: 4,
     steering: [],
     followup: [],
   });
   assert.equal(controller.getState().messageQueueBySession['session-1'], undefined);
-  assert.deepEqual(removedTransientMessageIds, []);
+  assert.deepEqual(removedTransientMessageIds, ['message-delivering']);
 
   handlers.handleEvent('session-1', {
     type: 'message_admission',
     id: 'retracted-message-next',
     turnId: 'turn-1',
-    ts: 3,
+    ts: 4,
     messageId: 'message-next',
     outcome: 'retracted',
   });
-  assert.deepEqual(removedTransientMessageIds, ['message-next']);
+  assert.deepEqual(removedTransientMessageIds, ['message-delivering', 'message-next']);
 });
 
 test('complete events deliver the durable context compaction outcome to Desktop', () => {
diff --git a/apps/desktop/src/main/__tests__/runtime-host-session-execution-ipc-main.test.ts b/apps/desktop/src/main/__tests__/runtime-host-session-execution-ipc-main.test.ts
index 2fab214e8..4ae67b122 100644
--- a/apps/desktop/src/main/__tests__/runtime-host-session-execution-ipc-main.test.ts
+++ b/apps/desktop/src/main/__tests__/runtime-host-session-execution-ipc-main.test.ts
@@ -607,7 +607,7 @@ test("submits an ordinary composer message once under its stable message identit
   const result = await ipc.invoke("sessions:send", "session-1", {
     type: "send",
     messageId: "message-1",
-    text: "/skill:review check the projection",
+    text: "check the projection",
   });
 
   assert.deepEqual(submits, [
@@ -615,7 +615,7 @@ test("submits an ordinary composer message once under its stable message identit
       sessionId: "session-1",
       messageId: "message-1",
       content: {
-        text: "/skill:review check the projection",
+        text: "check the projection",
         inlineReferences: [],
       },
       placement: "current_turn",
@@ -632,6 +632,63 @@ test("submits an ordinary composer message once under its stable message identit
   });
 });
 
+test('keeps slash Skill sends on the exact-Turn path with their stable message identity', async () => {
+  const starts: unknown[] = [];
+  const ipc = ipcHarness();
+  registerExecutionIpc(
+    {
+      client: executionClient({
+        getSession: async () => session(),
+        submitMessage: async () => {
+          throw new Error('slash Skill send must preserve Skill invocation feedback');
+        },
+        startTurn: async (input) => {
+          starts.push(input);
+          return {
+            kind: 'started',
+            turn: {
+              sessionId: input.sessionId,
+              turnId: input.turnId,
+              runId: 'run-skill',
+              status: 'running',
+            },
+            skillInvocation: {
+              loaded: [],
+              failed: [{ request: 'missing', reason: 'not_found' }],
+              receipts: [],
+            },
+          };
+        },
+      }),
+      newId: () => 'unexpected-generated-id',
+    },
+    ipc,
+  );
+
+  const result = await ipc.invoke('sessions:send', 'session-1', {
+    type: 'send',
+    messageId: 'message-skill',
+    text: '/skill:missing inspect this',
+  });
+
+  assert.deepEqual(starts, [{
+    sessionId: 'session-1',
+    turnId: 'message-skill',
+    content: { text: '/skill:missing inspect this', inlineReferences: [] },
+  }]);
+  assert.deepEqual(result, {
+    ok: true,
+    turnId: 'message-skill',
+    attachments: [],
+    inlineReferences: [],
+    skillInvocation: {
+      loaded: [],
+      failed: [{ request: 'missing', reason: 'not_found' }],
+      receipts: [],
+    },
+  });
+});
+
 test("queues a mid-turn send as steering when the Host reports the session busy", async () => {
   const submits: unknown[] = [];
   const changes: unknown[] = [];
@@ -731,6 +788,7 @@ test("retries a dispatched normal send with its original Turn identity", async (
 
   const result = await ipc.invoke("sessions:send", "session-1", {
     type: "send",
+    messageId: 'message-1',
     text: "keep this Turn identity",
   });
 
@@ -738,18 +796,18 @@ test("retries a dispatched normal send with its original Turn identity", async (
   assert.deepEqual(starts, [
     {
       sessionId: "session-1",
-      turnId: "turn-1",
+      turnId: "message-1",
       content: { text: "keep this Turn identity", inlineReferences: [] },
     },
     {
       sessionId: "session-1",
-      turnId: "turn-1",
+      turnId: "message-1",
       content: { text: "keep this Turn identity", inlineReferences: [] },
     },
   ]);
   assert.deepEqual(result, {
     ok: true,
-    turnId: "turn-1",
+    turnId: "message-1",
     attachments: [],
     inlineReferences: [],
     skillInvocation: { loaded: [], failed: [], receipts: [] },
@@ -1270,7 +1328,13 @@ test("binds steer and stop to Host-owned queue and active Turn identities", asyn
       interrupts.push(input);
       return {
         queueRevision: 3,
-        retracted: [],
+        retracted: [{
+          entryId: 'entry-followup',
+          messageId: 'message-followup',
+          content: { text: 'Do this next' },
+          placement: 'next_turn',
+          state: 'retracted',
+        }],
         turn: {
           sessionId: input.sessionId,
           turnId: input.turnId,
@@ -1375,10 +1439,10 @@ test("binds steer and stop to Host-owned queue and active Turn identities", asyn
     expectedTurnId: "turn-unrelated",
   });
   assert.deepEqual(stopLifecycle, []);
-  await ipc.invoke("sessions:stop", "session-1", {
+  assert.deepEqual(await ipc.invoke("sessions:stop", "session-1", {
     source: "stop_button",
     expectedTurnId: "turn-1",
-  });
+  }), { kind: 'interrupted', retractedMessageIds: ['message-followup'] });
   assert.deepEqual(stopLifecycle, [
     'teardown',
     'interrupt',
diff --git a/apps/desktop/src/main/runtime-host-session-execution-ipc-main.ts b/apps/desktop/src/main/runtime-host-session-execution-ipc-main.ts
index af545cff1..dd68f8420 100644
--- a/apps/desktop/src/main/runtime-host-session-execution-ipc-main.ts
+++ b/apps/desktop/src/main/runtime-host-session-execution-ipc-main.ts
@@ -26,6 +26,7 @@ import {
 } from '@maka/runtime-host/client';
 import { SKILL_INVOCATION_TOKEN_SOURCE } from '@maka/core/skill-invocation-token';
 import { isSideConversationSession } from '@maka/core/side-conversation';
+import { parseSkillInvocationTokens } from '@maka/runtime/skill-invocation';
 import {
   type SessionChangedEvent,
   type SessionChangedReason,
@@ -263,7 +264,7 @@ export function registerRuntimeHostSessionExecutionIpc(
       if (!session)
         throw new Error(`Runtime Host Session not found: ${sessionId}`);
       const sideConversation = isSideConversationSession(session.labels);
-      const turnId = command.turnId ?? newId();
+      const turnId = command.turnId ?? command.messageId ?? newId();
       let attachments = retainedAttachmentsForSession(
         sessionId,
         command.retainedAttachments ?? [],
@@ -325,6 +326,7 @@ export function registerRuntimeHostSessionExecutionIpc(
         command.messageId !== undefined &&
         !sideConversation &&
         (command.skillIds?.length ?? 0) === 0 &&
+        parseSkillInvocationTokens(command.text).length === 0 &&
         command.turnOrchestration === undefined
       ) {
         const submitted = await submitMessageWithReconnect(deps.client, {
@@ -917,7 +919,7 @@ function createRuntimeHostSessionStop(
       }
       return;
     }
-    await deps.client.interruptTurn({
+    const interrupted = await deps.client.interruptTurn({
       sessionId,
       interruptId: newId(),
       turnId: turn.turnId,
@@ -926,6 +928,10 @@ function createRuntimeHostSessionStop(
     deps.emitSessionsChanged("turn-status-change", sessionId, {
       turnId: turn.turnId,
     });
+    return {
+      kind: 'interrupted',
+      retractedMessageIds: interrupted.retracted.map((message) => message.messageId),
+    };
   };
 }
 
diff --git a/apps/desktop/src/preload/bridge-contract.d.ts b/apps/desktop/src/preload/bridge-contract.d.ts
index 82eebd600..c804ee2d2 100644
--- a/apps/desktop/src/preload/bridge-contract.d.ts
+++ b/apps/desktop/src/preload/bridge-contract.d.ts
@@ -209,6 +209,7 @@ export type DesktopSideConversationBranchResult =
 
 export type DesktopSessionStopResult =
   | { kind: 'retracted'; messageId: string }
+  | { kind: 'interrupted'; retractedMessageIds: string[] }
   | undefined;
 
 export type DesktopReviseBeforeTurnInput = ReviseBeforeTurnInput & {
diff --git a/apps/desktop/src/renderer/app-shell-session-events.ts b/apps/desktop/src/renderer/app-shell-session-events.ts
index 211f2c40a..20d4021b3 100644
--- a/apps/desktop/src/renderer/app-shell-session-events.ts
+++ b/apps/desktop/src/renderer/app-shell-session-events.ts
@@ -328,6 +328,12 @@ export function createAppShellSessionEventHandlers(options: {
           removeTransientMessage?.(sessionId, event.messageId);
         }
         break;
+      case 'steering_message':
+        // The live Turn projection now renders this same messageId in place.
+        // Retire only the renderer-owned tail row; a later nack queue_update
+        // will project it again if the Host returns the message to the queue.
+        removeTransientMessage?.(sessionId, event.messageId);
+        break;
       case 'text_complete':
         void refreshMessages(sessionId, { requiredAssistantMessageId: event.messageId }).catch(() => false);
         break;
diff --git a/apps/desktop/src/renderer/app-shell-stop-action.ts b/apps/desktop/src/renderer/app-shell-stop-action.ts
index 81b8c34dc..ea1fa70ea 100644
--- a/apps/desktop/src/renderer/app-shell-stop-action.ts
+++ b/apps/desktop/src/renderer/app-shell-stop-action.ts
@@ -48,6 +48,7 @@ export function createAppShellStopAction(deps: {
   ) => void;
   setStopPendingBySession: BooleanRecordUpdater;
   stopPendingRef: RefBox<Set<string>>;
+  removeTransientMessage: (sessionId: string, messageId: string) => void;
   toastApi: ToastApi;
 }): () => Promise<void> {
   const {
@@ -57,6 +58,7 @@ export function createAppShellStopAction(deps: {
     clearPendingSessionAction,
     setStopPendingBySession,
     stopPendingRef,
+    removeTransientMessage,
     toastApi,
   } = deps;
 
@@ -64,7 +66,12 @@ export function createAppShellStopAction(deps: {
     const sessionId = activeIdRef.current;
     if (!sessionId || !addPendingSessionAction(sessionId, stopPendingRef, setStopPendingBySession)) return;
     try {
-      await window.maka.sessions.stop(sessionId, { source: 'stop_button' });
+      const result = await window.maka.sessions.stop(sessionId, { source: 'stop_button' });
+      if (result?.kind === 'interrupted') {
+        for (const messageId of result.retractedMessageIds) {
+          removeTransientMessage(sessionId, messageId);
+        }
+      }
     } catch (error) {
       // The Composer wires this through both the Stop button onClick
       // and the Escape key. Both invoke `onStop` without awaiting, so
diff --git a/apps/desktop/src/renderer/app-shell.tsx b/apps/desktop/src/renderer/app-shell.tsx
index d89c049ca..02bb97c18 100644
--- a/apps/desktop/src/renderer/app-shell.tsx
+++ b/apps/desktop/src/renderer/app-shell.tsx
@@ -351,7 +351,6 @@ function AppShellContent({
     setMessages,
     addTransientMessage,
     removeTransientMessage,
-    hasTransientMessages,
     transcriptRangeRef,
     messageLoadPending,
     setMessageLoadPending,
@@ -801,7 +800,7 @@ function AppShellContent({
   const activeQuestion = activeInteraction?.type === 'user_question_request' ? activeInteraction : undefined;
   const activeSession = sessions.find((session) => session.id === activeId);
   const activeMessageQueue = activeId ? messageQueueBySession[activeId] : undefined;
-  const activeMessageSubmitting = activeId ? hasTransientMessages(activeId) : false;
+  const activeMessageSubmitting = transientMessages.length > 0;
   const activeDesktopSession = activeSession;
   // The shell's reading of the active live turn: streaming/settled flags, the
   // in-flight tool signal, and the #646 turn-wait cues, all derived from the
@@ -2190,6 +2189,7 @@ function AppShellContent({
     clearPendingSessionAction,
     setStopPendingBySession,
     stopPendingRef,
+    removeTransientMessage,
     toastApi,
   });
 
diff --git a/apps/desktop/src/renderer/platform/desktop/create-workbar-services.ts b/apps/desktop/src/renderer/platform/desktop/create-workbar-services.ts
index 2cfd56a22..2c3e36db0 100644
--- a/apps/desktop/src/renderer/platform/desktop/create-workbar-services.ts
+++ b/apps/desktop/src/renderer/platform/desktop/create-workbar-services.ts
@@ -120,15 +120,17 @@ export function createDesktopWorkbarServices(
       abandonSessionCopy: (sourceSessionId, copyId) =>
         bridge.sessions.abandonSessionCopy(sourceSessionId, copyId),
       send: (sessionId, command) => bridge.sessions.send(sessionId, command),
-      stop: (sessionId, target) =>
-        bridge.sessions.stop(
+      stop: async (sessionId, target) => {
+        const result = await bridge.sessions.stop(
           sessionId,
           target?.kind === 'admission'
             ? { source: 'stop_button', expectedAdmissionId: target.messageId }
             : target?.kind === 'turn'
               ? { source: 'stop_button', expectedTurnId: target.turnId }
               : undefined,
-        ),
+        );
+        return result?.kind === 'retracted' ? result : undefined;
+      },
       steer: (sessionId, text, admissionId) => bridge.sessions.steer(sessionId, text, admissionId),
       setPermissionMode: (sessionId, mode) =>
         bridge.sessions.setPermissionMode(sessionId, mode),
diff --git a/apps/desktop/src/renderer/use-app-shell-session-workspace.ts b/apps/desktop/src/renderer/use-app-shell-session-workspace.ts
index a4486ced4..6fc56b695 100644
--- a/apps/desktop/src/renderer/use-app-shell-session-workspace.ts
+++ b/apps/desktop/src/renderer/use-app-shell-session-workspace.ts
@@ -111,10 +111,6 @@ export function useAppShellSessionWorkspace(toastApi: ToastApi) {
     }
   }
 
-  function hasTransientMessages(sessionId: string): boolean {
-    return (transientMessagesBySessionRef.current.get(sessionId)?.size ?? 0) > 0;
-  }
-
   function setActiveId(next: string | undefined): void {
     selectionRevisionRef.current += 1;
     // Clear here, not in the read effect: a layout-effect clear would wipe an
@@ -170,7 +166,6 @@ export function useAppShellSessionWorkspace(toastApi: ToastApi) {
     setMessages: setMessagesForActiveSession,
     addTransientMessage,
     removeTransientMessage,
-    hasTransientMessages,
     transcriptRangeRef,
     messageLoadPending,
     setMessageLoadPending,


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