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:41 UTC

(maka) 11/27: fix(cli): keep host projection transient until canonical

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 b43f765a9ee67be9d9adb45d34d2cba8d9cc73ad
Author: AstroHan <le...@outlook.com>
AuthorDate: Wed Aug 26 05:50:18 2026 +0800

    fix(cli): keep host projection transient until canonical
    
    Generated-by: Codex
---
 packages/cli/src/__tests__/pi-transcript.test.ts | 28 +++++++++++++++++++--
 packages/cli/src/__tests__/pi-tui-runner.test.ts | 31 ++++++++++++++++++++++++
 packages/cli/src/pi-transcript.ts                | 12 ++++++++-
 packages/cli/src/pi-tui-runner.ts                |  9 +++----
 4 files changed, 71 insertions(+), 9 deletions(-)

diff --git a/packages/cli/src/__tests__/pi-transcript.test.ts b/packages/cli/src/__tests__/pi-transcript.test.ts
index a5c21880e..d9080e3c4 100644
--- a/packages/cli/src/__tests__/pi-transcript.test.ts
+++ b/packages/cli/src/__tests__/pi-transcript.test.ts
@@ -630,6 +630,30 @@ describe('Maka Pi TUI transcript', () => {
     assert.deepEqual(state.entries, [{ kind: 'user', messageId: 'message-1', text: 'send now' }]);
   });
 
+  test('keeps a projected in-flight steering echo transient until durable reconciliation', () => {
+    const state = createMakaPiTranscriptState();
+    appendUserPrompt(state, 'send now', 'message-1', true);
+
+    applyMakaSessionEventToTranscript(
+      state,
+      event({
+        type: 'steering_message',
+        messageId: 'message-1',
+        content: { text: 'send now' },
+      }),
+    );
+    applyMakaSessionEventToTranscript(
+      state,
+      event({
+        type: 'message_admission',
+        messageId: 'message-1',
+        outcome: 'retracted',
+      }),
+    );
+
+    assert.deepEqual(state.entries, []);
+  });
+
   test('removes only the transient row named by a retracted admission', () => {
     const state = createMakaPiTranscriptState();
     appendUserPrompt(state, 'keep this', 'message-kept', true);
@@ -649,7 +673,7 @@ describe('Maka Pi TUI transcript', () => {
     ]);
   });
 
-  test('reconciles a live steering event into its transient message position', () => {
+  test('updates a projected steering echo in its transient message position', () => {
     const state = createMakaPiTranscriptState();
     appendUserPrompt(state, 'send now', 'message-1', true);
     state.entries.push({ kind: 'notice', level: 'error', text: 'later row' });
@@ -664,7 +688,7 @@ describe('Maka Pi TUI transcript', () => {
     );
 
     assert.deepEqual(state.entries, [
-      { kind: 'user', messageId: 'message-1', text: 'canonical text' },
+      { kind: 'user', messageId: 'message-1', text: 'canonical text', transient: true },
       { kind: 'notice', level: 'error', text: 'later row' },
     ]);
   });
diff --git a/packages/cli/src/__tests__/pi-tui-runner.test.ts b/packages/cli/src/__tests__/pi-tui-runner.test.ts
index 8e8662364..a411cb398 100644
--- a/packages/cli/src/__tests__/pi-tui-runner.test.ts
+++ b/packages/cli/src/__tests__/pi-tui-runner.test.ts
@@ -2666,6 +2666,31 @@ describe('Maka Pi TUI runner', () => {
     await run;
   });
 
+  test('removes a one-shot Swarm transient when turn admission fails', async () => {
+    const terminal = new FakeTerminal();
+    const driver = new FailingOrchestrationDriver();
+    const run = runMakaPiTui({
+      title: 'Maka',
+      driver,
+      cwd: '/repo',
+      model: 'deepseek-v4-flash',
+      connectionSlug: 'deepseek',
+      permissionMode: 'ask',
+      terminal,
+    });
+
+    terminal.input('/swarm inspect the projection');
+    terminal.input('\r');
+    await waitFor(() => plainTerminalOutput(terminal.screenOutput()).includes('admission failed'));
+    assert.equal(
+      plainTerminalOutput(terminal.screenOutput()).includes('inspect the projection'),
+      false,
+    );
+
+    exitMaka(terminal);
+    await run;
+  });
+
   test('inspects a historical Agent Graph run without starting a turn', async () => {
     const terminal = new FakeTerminal();
     const driver = new SlashCommandDriver();
@@ -7057,6 +7082,12 @@ class SteeringTurnDriver implements MakaSessionDriver {
   }
 }
 
+class FailingOrchestrationDriver extends SteeringTurnDriver {
+  override preparePrompt(): Promise<MakaPreparedSessionTurn> {
+    return Promise.reject(new Error('admission failed'));
+  }
+}
+
 class SlowStopDriver implements MakaSessionDriver {
   stopCalls = 0;
   readonly prompts: string[] = [];
diff --git a/packages/cli/src/pi-transcript.ts b/packages/cli/src/pi-transcript.ts
index 67a5e6249..a6117344f 100644
--- a/packages/cli/src/pi-transcript.ts
+++ b/packages/cli/src/pi-transcript.ts
@@ -792,7 +792,17 @@ export function applyMakaSessionEventToTranscript(
 
     case 'steering_message':
       // A user interjection injected mid-turn; render it in place as a user turn.
-      appendUserPrompt(state, event.content.displayText ?? event.content.text, event.messageId);
+      appendUserPrompt(
+        state,
+        event.content.displayText ?? event.content.text,
+        event.messageId,
+        state.entries.some(
+          (entry) =>
+            entry.kind === 'user' &&
+            entry.messageId === event.messageId &&
+            entry.transient === true,
+        ),
+      );
       break;
 
     case 'message_admission':
diff --git a/packages/cli/src/pi-tui-runner.ts b/packages/cli/src/pi-tui-runner.ts
index 4afb5a2f7..4e6f0a897 100644
--- a/packages/cli/src/pi-tui-runner.ts
+++ b/packages/cli/src/pi-tui-runner.ts
@@ -1163,6 +1163,7 @@ export async function runMakaPiTui(input: MakaPiTuiInput): Promise<void> {
 
     let permissionAlerted = false;
     let optimisticUserEntry: (typeof state.entries)[number] | undefined;
+    let turnPrepared = false;
     const finishTurnUi = () => {
       if (!ownsTurnUi) {
         editor.disableSubmit = false;
@@ -1201,6 +1202,7 @@ export async function runMakaPiTui(input: MakaPiTuiInput): Promise<void> {
         // switch resolved (preparePrompt was in flight), and the abandoned
         // Turn's metadata must not overwrite the adopted Session's view.
         if (superseded()) return;
+        turnPrepared = true;
         if (authoritativeAttachedTurn) {
           adoptSessionMetadata(authoritativeAttachedTurn.summary);
           replaceTranscript(authoritativeAttachedTurn.messages, {
@@ -1273,12 +1275,7 @@ export async function runMakaPiTui(input: MakaPiTuiInput): Promise<void> {
         // here as "ended without completion" — never report that against the
         // adopted Session.
         if (superseded()) return;
-        if (
-          request.kind === 'external' &&
-          request.turnOrchestration === undefined &&
-          input.driver.submitMessage &&
-          optimisticUserEntry?.kind === 'user'
-        ) {
+        if (request.kind === 'external' && !turnPrepared && optimisticUserEntry?.kind === 'user') {
           removeTransientUserMessage(optimisticUserEntry.messageId);
           optimisticUserEntry = undefined;
         }


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