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/30 16:15:26 UTC
(maka) branch main updated: fix(cli): refresh connection identities after /setup saves a connection (#4262)
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/maka.git
The following commit(s) were added to refs/heads/main by this push:
new 5058b29f17 fix(cli): refresh connection identities after /setup saves a connection (#4262)
5058b29f17 is described below
commit 5058b29f179f459e0d33f63bedf02a4af3335dec
Author: skblue <xi...@gmail.com>
AuthorDate: Mon Aug 31 00:15:22 2026 +0800
fix(cli): refresh connection identities after /setup saves a connection (#4262)
After /setup created a connection and /model selected it, the first prompt showed The original account was deleted even though the request succeeded.
packages/cli/src/pi-tui-runner.ts:1175 retained the startup identity snapshot while the save path at line 2199 refreshed only model choices, so adoptSessionMetadata could not recognize the new Host connection identity.
Return model choices and connection identities from one refreshed Runtime Host catalog, share their identity contract, and update both runner projections atomically after a successful save.
Verified with a failing-first TUI regression, the full pi-tui-runner test file, format, lint, CLI typecheck, and CLI build.
Generated-by: pi (gpt-5.6-sol)
---
packages/cli/src/__tests__/pi-tui-runner.test.ts | 105 ++++++++++++++++++++++-
packages/cli/src/pi-tui-contracts.ts | 12 ++-
packages/cli/src/pi-tui-runner.ts | 11 ++-
packages/cli/src/runtime-host-onboarding.ts | 17 +++-
packages/cli/src/runtime-host-tui-context.ts | 14 +--
5 files changed, 138 insertions(+), 21 deletions(-)
diff --git a/packages/cli/src/__tests__/pi-tui-runner.test.ts b/packages/cli/src/__tests__/pi-tui-runner.test.ts
index bc0524f253..b791c793bf 100644
--- a/packages/cli/src/__tests__/pi-tui-runner.test.ts
+++ b/packages/cli/src/__tests__/pi-tui-runner.test.ts
@@ -223,7 +223,7 @@ function savedOnboardingResult(
slug: 'openai',
providerType: 'openai',
},
- refresh: { kind: 'ok', modelChoices },
+ refresh: { kind: 'ok', modelChoices, connectionIdentities: [] },
};
}
@@ -7764,6 +7764,109 @@ describe('Maka Pi TUI runner', () => {
await run;
});
+ test('refreshes connection identities after setup before adopting the new model', async () => {
+ const terminal = new FakeTerminal();
+ const driver = new SlashCommandDriver();
+ driver.hostSummary = {
+ llmConnectionId: 'connection-b',
+ llmConnectionSlug: 'new-account',
+ model: 'gpt-5.5',
+ };
+ const newConnectionChoice: ModelChoice = {
+ connectionId: 'connection-b',
+ connectionSlug: 'new-account',
+ connectionName: 'New account',
+ providerType: 'openai',
+ model: 'gpt-5.5',
+ isDefaultConnection: true,
+ };
+ const saveCalls: OnboardingSaveInput[] = [];
+ const run = runMakaPiTui({
+ title: 'Maka',
+ locale: 'en',
+ driver,
+ cwd: '/repo',
+ model: 'claude-sonnet-4-5',
+ connectionId: 'connection-a',
+ connectionSlug: 'existing-account',
+ providerType: 'anthropic',
+ connectionIdentities: [
+ { connectionId: 'connection-a', connectionSlug: 'existing-account', enabled: true },
+ ],
+ modelChoices: [
+ {
+ connectionId: 'connection-a',
+ connectionSlug: 'existing-account',
+ connectionName: 'Existing account',
+ providerType: 'anthropic',
+ model: 'claude-sonnet-4-5',
+ isDefaultConnection: true,
+ },
+ ],
+ permissionMode: 'ask',
+ terminal,
+ onboarding: fakeOnboardingSurface({
+ verify: async () => ({ kind: 'ok', models: [{ id: 'gpt-5.5' }] }),
+ save: async (input) => {
+ saveCalls.push(input);
+ const refresh = {
+ kind: 'ok' as const,
+ modelChoices: [newConnectionChoice],
+ connectionIdentities: [
+ { connectionId: 'connection-a', connectionSlug: 'existing-account', enabled: true },
+ { connectionId: 'connection-b', connectionSlug: 'new-account', enabled: true },
+ ],
+ };
+ return {
+ kind: 'ok' as const,
+ connection: {
+ connectionId: 'connection-b',
+ revision: 1,
+ slug: 'new-account',
+ providerType: 'openai' as const,
+ },
+ refresh,
+ };
+ },
+ }),
+ });
+
+ await waitForTuiPaint(terminal);
+ terminal.input('/setup');
+ terminal.input('\r');
+ await waitFor(() => plainTerminalOutput(terminal.screenOutput()).includes('Set Up Provider'));
+ terminal.input('\r');
+ await waitFor(() => plainTerminalOutput(terminal.screenOutput()).includes('API key'));
+ terminal.input('sk-test');
+ terminal.input('\r');
+ await waitFor(() => plainTerminalOutput(terminal.screenOutput()).includes('3/3'));
+ terminal.input(' ');
+ terminal.input('\r');
+ await waitFor(() => saveCalls.length === 1);
+ await waitFor(() => plainTerminalOutput(terminal.screenOutput()).includes('Models enabled'));
+ terminal.input('\r');
+ await waitFor(() => !plainTerminalOutput(terminal.screenOutput()).includes('Models enabled'));
+
+ terminal.input('/model');
+ terminal.input('\r');
+ await waitFor(() => plainTerminalOutput(terminal.screenOutput()).includes('New account'));
+ terminal.input('\r');
+ await waitFor(() => driver.modelConnectionIds.length === 1);
+ assert.deepEqual(driver.modelConnectionIds, ['connection-b']);
+
+ terminal.input('hello');
+ terminal.input('\r');
+ await waitFor(() => driver.prompts.length === 1 && driver.streamPulls === 1);
+ await waitForTuiPaint(terminal);
+ assert.doesNotMatch(
+ plainTerminalOutput(terminal.screenOutput()),
+ /The original account was deleted/,
+ );
+
+ exitMaka(terminal);
+ await run;
+ });
+
test('resumes an active Host turn from its atomic transcript and continues live output', async () => {
const terminal = new FakeTerminal();
const driver = new ActiveResumeDriver();
diff --git a/packages/cli/src/pi-tui-contracts.ts b/packages/cli/src/pi-tui-contracts.ts
index 957c75ae56..26d87bedd1 100644
--- a/packages/cli/src/pi-tui-contracts.ts
+++ b/packages/cli/src/pi-tui-contracts.ts
@@ -50,6 +50,12 @@ export interface ModelChoice {
thinkingLevels?: readonly ThinkingLevel[];
}
+export type ConnectionIdentity = {
+ readonly connectionId: string;
+ readonly connectionSlug: string;
+ readonly enabled: boolean;
+};
+
export interface OnboardableProvider {
providerType: ProviderType;
label: string;
@@ -126,7 +132,11 @@ export type OnboardingSaveResult =
kind: 'ok';
connection: OnboardingSavedConnection;
refresh:
- | { kind: 'ok'; modelChoices: ModelChoice[] }
+ | {
+ kind: 'ok';
+ modelChoices: ModelChoice[];
+ connectionIdentities: readonly ConnectionIdentity[];
+ }
| { kind: 'failed'; reason: 'catalog_unavailable' };
}
| OnboardingFailure;
diff --git a/packages/cli/src/pi-tui-runner.ts b/packages/cli/src/pi-tui-runner.ts
index 3580b89432..48dfa5908d 100644
--- a/packages/cli/src/pi-tui-runner.ts
+++ b/packages/cli/src/pi-tui-runner.ts
@@ -65,6 +65,7 @@ import type { TurnOrchestration } from '@maka/core/runtime-inputs';
import type { SessionActivityLease } from '@maka/runtime/goal-turn-lifecycle';
import { listApiKeyOnboardableProviders } from './onboarding-catalog.js';
import type {
+ ConnectionIdentity,
MakaForeignSessionReader,
MakaOnboardingSurface,
MakaPiTuiTurnActivitySurface,
@@ -186,11 +187,7 @@ export interface MakaPiTuiInput {
*/
modelChoices?: readonly ModelChoice[];
connectionId?: string;
- connectionIdentities?: readonly {
- readonly connectionId: string;
- readonly connectionSlug: string;
- readonly enabled: boolean;
- }[];
+ connectionIdentities?: readonly ConnectionIdentity[];
connectionSlug: string;
providerType?: ProviderType;
permissionMode: PermissionMode;
@@ -1177,6 +1174,7 @@ export async function runMakaPiTui(input: MakaPiTuiInput): Promise<void> {
// in place after `/setup` saves so newly configured models are immediately
// available — the single source the picker and connection/model lookups read.
let modelChoices = input.modelChoices;
+ let connectionIdentities = input.connectionIdentities;
// Monotonic attempt id: each setup submit captures one, and any transition
// that abandons the in-flight attempt (back, re-pick, close) increments it so
// a late verify/save settlement cannot clobber a newer attempt.
@@ -1461,7 +1459,7 @@ export async function runMakaPiTui(input: MakaPiTuiInput): Promise<void> {
connectionSlug = summary.llmConnectionSlug;
const identityNotice = sessionConnectionIdentityNotice(
summary,
- input.connectionIdentities,
+ connectionIdentities,
input.locale ?? 'en',
);
if (announceIdentity && identityNotice && identityNotice !== connectionIdentityNotice) {
@@ -2194,6 +2192,7 @@ export async function runMakaPiTui(input: MakaPiTuiInput): Promise<void> {
// attempt must not overwrite choices refreshed by a newer save.
if (result.refresh.kind === 'ok') {
modelChoices = result.refresh.modelChoices;
+ connectionIdentities = result.refresh.connectionIdentities;
}
if (input.firstRun) {
beginClose();
diff --git a/packages/cli/src/runtime-host-onboarding.ts b/packages/cli/src/runtime-host-onboarding.ts
index 610d05c766..1774971532 100644
--- a/packages/cli/src/runtime-host-onboarding.ts
+++ b/packages/cli/src/runtime-host-onboarding.ts
@@ -25,6 +25,7 @@ import {
} from '@maka/runtime-host/client';
import { listApiKeyOnboardableProviders } from './onboarding-catalog.js';
import type {
+ ConnectionIdentity,
MakaOnboardingSurface,
ModelChoice,
OnboardingProviderEntry,
@@ -61,14 +62,14 @@ export function createRuntimeHostOnboardingSurface(
return result;
}
try {
+ const catalog = await readRuntimeHostConnectionCatalog(connection);
return {
kind: 'ok',
connection: result.connection,
refresh: {
kind: 'ok',
- modelChoices: projectRuntimeHostModelChoices(
- await readRuntimeHostConnectionCatalog(connection),
- ),
+ modelChoices: projectRuntimeHostModelChoices(catalog),
+ connectionIdentities: projectRuntimeHostConnectionIdentities(catalog),
},
};
} catch {
@@ -120,6 +121,16 @@ export function projectRuntimeHostModelChoices(catalog: ConnectionCatalogSnapsho
return choices;
}
+export function projectRuntimeHostConnectionIdentities(
+ catalog: ConnectionCatalogSnapshot,
+): ConnectionIdentity[] {
+ return catalog.connections.map((connection) => ({
+ connectionId: connection.connectionId,
+ connectionSlug: connection.slug,
+ enabled: connection.enabled,
+ }));
+}
+
export function projectProviders(catalog: ConnectionCatalogSnapshot): OnboardingProviderEntry[] {
const entries: OnboardingProviderEntry[] = [];
for (const provider of listApiKeyOnboardableProviders()) {
diff --git a/packages/cli/src/runtime-host-tui-context.ts b/packages/cli/src/runtime-host-tui-context.ts
index c31a03ee8b..1247ebc169 100644
--- a/packages/cli/src/runtime-host-tui-context.ts
+++ b/packages/cli/src/runtime-host-tui-context.ts
@@ -49,6 +49,7 @@ import {
resolveRuntimeHostCliTarget,
} from './runtime-host-cli-context.js';
import type {
+ ConnectionIdentity,
MakaPiTuiTurnActivitySurface,
ModelChoice,
SessionRecapGenerator,
@@ -59,6 +60,7 @@ import {
} from './runtime-host-session-driver.js';
import {
createRuntimeHostOnboardingSurface,
+ projectRuntimeHostConnectionIdentities,
projectRuntimeHostModelChoices,
} from './runtime-host-onboarding.js';
import {
@@ -73,11 +75,7 @@ export interface RuntimeHostTuiContext {
readonly cwd: string;
readonly connectionSlug: string;
readonly connectionId?: string;
- readonly connectionIdentities: readonly {
- readonly connectionId: string;
- readonly connectionSlug: string;
- readonly enabled: boolean;
- }[];
+ readonly connectionIdentities: readonly ConnectionIdentity[];
readonly connectionName: string;
readonly providerType?: ConnectionCatalogEntry['providerType'];
readonly model: string;
@@ -181,11 +179,7 @@ export async function createRuntimeHostTuiContext(
...(selectedTarget.connectionId === undefined
? {}
: { connectionId: selectedTarget.connectionId }),
- connectionIdentities: catalog.connections.map((entry) => ({
- connectionId: entry.connectionId,
- connectionSlug: entry.slug,
- enabled: entry.enabled,
- })),
+ connectionIdentities: projectRuntimeHostConnectionIdentities(catalog),
connectionName: selectedTarget.connection?.name ?? selectedTarget.connectionSlug,
...(selectedTarget.connection
? { providerType: selectedTarget.connection.providerType }
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org