You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by wy...@apache.org on 2026/10/20 02:28:31 UTC

(maka) 04/04: refactor(assistant): reuse interaction checks and trim Host scenarios

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

M4n5ter pushed a commit to branch fix/assistant-bot-model-sync
in repository https://gitbox.apache.org/repos/asf/maka.git

commit 5ec2d347db27e416bebed51a6fa27ce6c9a0efa2
Author: M4n5ter <m4...@gmail.com>
AuthorDate: Tue Oct 20 10:23:39 2026 +0800

    refactor(assistant): reuse interaction checks and trim Host scenarios
    
    Use the interaction coordinator as the pending-request authority and restore the unrelated Plugin Agent resume order. Remove unnecessary model discovery from the Host fixture and combine restart routing with current provider failure reporting.
    
    Generated-by: OpenAI Codex
---
 .../src/__tests__/execution-composition.test.ts    | 46 +++++-----------------
 .../src/server/execution-composition.ts            | 10 ++---
 2 files changed, 13 insertions(+), 43 deletions(-)

diff --git a/packages/runtime-host/src/__tests__/execution-composition.test.ts b/packages/runtime-host/src/__tests__/execution-composition.test.ts
index bbcf9f5f80..51100f85b3 100644
--- a/packages/runtime-host/src/__tests__/execution-composition.test.ts
+++ b/packages/runtime-host/src/__tests__/execution-composition.test.ts
@@ -399,7 +399,6 @@ test('assistant Bot synchronizes fresh wakes through recovery and restart and re
           const result = await bound.followup(id, message, initiator, options);
           if (!oldWakeId) {
             oldWakeId = options!.messageId;
-            await oldStarted.promise;
             await loseAdmissionResponse.promise;
             // Admission committed, but the controller must recover its durable wake.
             throw Error('Bot wake admission response lost');
@@ -445,19 +444,6 @@ test('assistant Bot synchronizes fresh wakes through recovery and restart and re
     assert.equal(created.kind, 'committed');
     if (created.kind !== 'committed') throw Error('Replacement connection was not committed');
     const replacement = created.snapshot.connections.find((entry) => entry.slug === 'replacement')!;
-    const fetch = await policy.operations.beginModelFetch(replacement.connectionId);
-    assert.equal(fetch.kind, 'ready');
-    if (fetch.kind !== 'ready') throw Error('Replacement model fetch did not start');
-    assert.equal(
-      (
-        await policy.operations.completeModelFetch(fetch.ticket, {
-          models: [{ id: 'replacement-model' }],
-          source: 'fetched',
-          fetchedAt: Date.now(),
-        })
-      ).kind,
-      'committed',
-    );
     const executions: { sessionId: string; connectionId?: string; model: string }[] = [];
     let failWake = false;
     const primaryBackendFactory: BackendFactory = (context) =>
@@ -582,6 +568,7 @@ test('assistant Bot synchronizes fresh wakes through recovery and restart and re
         { timeoutMs: 7000, pollMs: 5 },
       );
       await composition.close();
+      failWake = true;
       ({ composition, manager } = await createCapturedExecutionComposition(owner, {
         primaryBackendFactory,
       }));
@@ -589,9 +576,11 @@ test('assistant Bot synchronizes fresh wakes through recovery and restart and re
       await assistant.receiveUser(chat.id, 'after-restart', { text: '继续' });
       await pollFor(
         async () =>
-          executions.length === 3 &&
-          ((await assistant.call('assistant.status', { includeMemory: false })) as any).bot
-            .sleeping,
+          (await readLedgerMessages(stores.runtimeEventStore, chat.id)).some(
+            (message) =>
+              message.type === 'assistant' &&
+              message.text.includes('Deterministic network failure'),
+          ),
         { timeoutMs: 7000, pollMs: 5 },
       );
       const after = await stores.sessionStore.readHeaderSnapshot(workerId);
@@ -604,26 +593,11 @@ test('assistant Bot synchronizes fresh wakes through recovery and restart and re
         ).length,
         3,
       );
-      failWake = true;
-      await assistant.receiveUser(chat.id, 'provider-failure', { text: '再试一次' });
-      await pollFor(
-        async () =>
-          (await readLedgerMessages(stores.runtimeEventStore, chat.id)).some(
-            (message) =>
-              message.type === 'assistant' &&
-              message.text.includes('Deterministic network failure'),
-          ),
-        { timeoutMs: 7000, pollMs: 5 },
-      );
-      assert.deepEqual(executions.slice(2), [selectedRoute, selectedRoute]);
+      assert.deepEqual(executions.slice(2), [selectedRoute]);
       const visible = await readLedgerMessages(stores.runtimeEventStore, chat.id);
-      assert.deepEqual(
-        visible
-          .filter((row) => row.type === 'assistant')
-          .slice(0, 2)
-          .map((row) => row.text),
-        ['已用新模型处理原消息', '已用新模型处理原消息'],
-      );
+      const replies = visible.filter((row) => row.type === 'assistant');
+      assert.equal(replies.length, 2);
+      assert.equal(replies[0].text, '已用新模型处理原消息');
     } finally {
       loseAdmissionResponse.resolve();
       failOldExecution.resolve();
diff --git a/packages/runtime-host/src/server/execution-composition.ts b/packages/runtime-host/src/server/execution-composition.ts
index 8e6a147c37..d1a69d5efe 100644
--- a/packages/runtime-host/src/server/execution-composition.ts
+++ b/packages/runtime-host/src/server/execution-composition.ts
@@ -455,11 +455,7 @@ export async function createExecutionRuntimeHostComposition(
       join(context.owner.controlDirectory, 'personal-assistant'),
       {
         prepareBotWake: async (ownerId, workerId) => {
-          const [pending, boundaries] = await Promise.all([
-            stores.interactionStore.listPending({ sessionId: workerId }),
-            stores.sessionStore.listPendingSandboxBoundaryRequests(workerId),
-          ]);
-          if (pending.length || boundaries.length) return 'deferred';
+          if (await interactions.hasPendingSession(workerId)) return 'deferred';
           return sessionCatalog.synchronizeAssistantBotModel(ownerId, workerId);
         },
         stopSessions: async () => {
@@ -2280,12 +2276,12 @@ export async function createExecutionRuntimeHostComposition(
         });
       },
       resume: async (options, initiator) => {
+        if (options.prompt)
+          await submitAgentMessage(options.sessionId, options.prompt, 'next_turn', initiator);
         const session = (await visibleAgentSessions(initiator)).find(
           (item) => item.id === options.sessionId,
         );
         if (!session) throw new Error('Agent was not found');
-        if (options.prompt)
-          await submitAgentMessage(options.sessionId, options.prompt, 'next_turn', initiator);
         return describeAgent(session);
       },
       get: async (id, initiator) => {


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