diff --git a/apps/desktop/src/main/localDb/client/tx/types.ts b/apps/desktop/src/main/localDb/client/tx/types.ts
index dfc1c34bc33..b1fc647c34f 100644
--- a/apps/desktop/src/main/localDb/client/tx/types.ts
+++ b/apps/desktop/src/main/localDb/client/tx/types.ts
@@ -683,6 +683,8 @@ export interface BotsUpdateProfileArgs {
inactiveCindyIds?: string[];
/** A saved model choice supersedes automation restores in the same commit. */
clearScheduledModelBaseline?: boolean;
+ /** A selected plugin primary cannot be applied to an active local canonical Lead. */
+ rejectPluginPrimaryForLocalLead?: boolean;
/** Explicit settings changes also update the permanent chat in this transaction. */
canonicalPermissionMode?: 'ask' | 'auto' | 'bypassPermissions';
displayName?: string;
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
index 1b2426b458d..56aaad4f5cc 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
@@ -5724,6 +5724,45 @@ describe('Teammate model selection shares profile persistence and route reconcil
id: JSON.stringify(['pi', 'xd', model.id]), model };
}
+ // #12276, DB tier. Use the settings IPC with a built-in canonical session
+ // and an ACP primary. Before the fix the save advanced the profile version,
+ // even though the ordinary session switch could never apply it to the Lead.
+ it('rejects a plugin primary for a local canonical Lead and accepts a built-in recovery', async () => {
+ const { sessionId } = await setupModelControl();
+ const getProfile = () => invoke('local-db:bots:get', 'bot-1');
+ const save = (modelChainOverride: BotModelRoute[]) =>
+ invoke('local-db:bots:update', { id: 'bot-1', capabilities: { modelChainOverride } });
+ const setLead = (role: 'lead' | null) =>
+ h.sqlite!.prepare('UPDATE sessions SET orca_role = ? WHERE id = ?').run(role, sessionId);
+ const plugin: BotModelRoute = {
+ harness: 'acp', providerId: 'acp-plugin:fixture:echo', model: 'default', effort: '', fastMode: false,
+ };
+ const before = await getProfile();
+ const [builtIn] = before.capabilities.modelChain as BotModelRoute[];
+ if (!builtIn || builtIn.harness === 'acp') throw new Error('Expected a built-in fixture route');
+ setLead('lead');
+ h.requestRuntimeRefresh.mockClear();
+ await expect(save([plugin, builtIn])).rejects.toThrow('BOT_LEAD_PLUGIN_ENGINE_UNSUPPORTED');
+ const rejected = await getProfile();
+ expect(rejected.currentVersion).toBe(before.currentVersion);
+ expect(rejected.capabilities.modelChain).toEqual(before.capabilities.modelChain);
+ expect(h.requestRuntimeRefresh).not.toHaveBeenCalled();
+
+ await expect(save([builtIn, plugin])).resolves.toMatchObject({
+ capabilities: { modelChain: [builtIn, plugin] },
+ });
+ setLead(null);
+ await expect(save([plugin, builtIn])).resolves.toMatchObject({
+ capabilities: { modelChain: [plugin, builtIn] },
+ });
+ // Simulate a profile saved by an older build while the actual session kept its built-in route.
+ setLead('lead');
+ await expect(save([builtIn])).resolves.toMatchObject({
+ canonicalSessionId: sessionId,
+ capabilities: { modelChain: [builtIn] },
+ });
+ });
+
// #7177, DB tier: an explicit same-value tool selection must reach the
// acceptance transaction; a plain metadata edit must retain the old scope.
it('reaccepts the same model through the teammate tool without treating a rename as recovery', async () => {
diff --git a/apps/desktop/src/main/localDb/ipc/bots.ts b/apps/desktop/src/main/localDb/ipc/bots.ts
index 2eda8b3b0a0..fe51cb60c90 100644
--- a/apps/desktop/src/main/localDb/ipc/bots.ts
+++ b/apps/desktop/src/main/localDb/ipc/bots.ts
@@ -2219,6 +2219,7 @@ export async function updateBotProfile(raw: unknown, expectedVersion?: number,
// Compare the same representation so unrelated edits do not validate stale routes.
const modelSelectionChanged = botProfileModelSelectionChanged(normalizeBotModelCapabilitiesOrThrow(previous), normalizedNextConfig);
const acceptsModelSelection = modelSelectionChanged || acceptsSavedModel;
+ let pluginPrimarySelected = false;
if (acceptsModelSelection) {
const primary = (await readEffectiveBotModelChain(normalizedNextConfig))[0];
owner.assertCurrent();
@@ -2226,6 +2227,7 @@ export async function updateBotProfile(raw: unknown, expectedVersion?: number,
throwIpcError('INVALID_PARAMS', 'Model route unavailable');
}
owner.assertCurrent();
+ pluginPrimarySelected = primary.harness === 'acp';
}
const nextIdentitySource =
body.identitySource !== undefined
@@ -2258,6 +2260,7 @@ export async function updateBotProfile(raw: unknown, expectedVersion?: number,
await client.tx('bots.updateProfile', {
id,
...(acceptsModelSelection ? { clearScheduledModelBaseline: true } : {}),
+ ...(pluginPrimarySelected ? { rejectPluginPrimaryForLocalLead: true } : {}),
...(changesPermissions ? { canonicalPermissionMode: botSessionPermissionMode(normalizedNextConfig) } : {}),
...(restored?.allowSameName === true ? { allowDuplicateName: true } : {}),
...(restored?.templateId === 'cindy' ? { inactiveCindyIds: inactiveCompanionCopyIds(companionHomes.snapshot()) } : {}),
diff --git a/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts b/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts
index 66f5d4aaaa8..ae0a9ab7f5d 100644
--- a/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts
+++ b/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts
@@ -13,7 +13,8 @@ import { batchAutoReviewProjection, readAutoReviewProjectionTransaction } from '
import { CLOSE_SHARED_TASKS_FOR_SESSION_SQL } from '../../sharedTaskClosureSql.js';
import { IDLE_ARCHIVE_GUARD_SQL } from '../../../task-management/eligibility.js';
import { assertSessionDeleteTarget, COMMITTED_SIDE_CHAT_WORKER_SQL, ORCA_WORKER_LINK_TEAM_SQL, SIDE_CHAT_CLOSE_TARGET_SQL } from '../../sessionDeleteTarget.js';
-import { botProfileModelSelectionChanged } from '../../../../shared/botModelChain.js';
+import { BOT_LEAD_PLUGIN_ENGINE_UNSUPPORTED, botProfileModelSelectionChanged } from '../../../../shared/botModelChain.js';
+import { throwIpcError } from '../../../utils/ipcValidate.js';
import { dbToMakerAgentKind } from '../../../../shared/agentKindConversion.js';
import { parseScheduledModelBaseline } from '../../../../shared/scheduledModelBaseline.js';
import { normalizeBotName } from '../../../../shared/botCreation.js';
@@ -401,6 +402,7 @@ function botsUpdateProfile(db: Database.Database, args: unknown): { currentVersi
const expectedVersion = expectNumber(p.expectedCurrentVersion, 'expectedCurrentVersion');
const now = expectNumber(p.now, 'now');
const allowDuplicateName = expectOptionalFlag(p.allowDuplicateName, 'allowDuplicateName');
+ const rejectPluginPrimaryForLocalLead = expectOptionalFlag(p.rejectPluginPrimaryForLocalLead, 'rejectPluginPrimaryForLocalLead');
const inactive = inactiveCindyIds(p.inactiveCindyIds);
const avatarRef = p.botAvatarRef === undefined
? null
@@ -424,6 +426,17 @@ function botsUpdateProfile(db: Database.Database, args: unknown): { currentVersi
if (current.currentVersion !== expectedVersion) {
throw Object.assign(new Error('Bot Profile 已被另一处更新,请刷新后重试'), { code: 'PRECONDITION_FAILED' });
}
+ // Check the authoritative link and current role in the same commit as the choice.
+ if (rejectPluginPrimaryForLocalLead && db.prepare(`
+ SELECT 1 FROM bot_session_links l JOIN sessions s ON s.id = l.session_id
+ WHERE l.bot_id = ? AND l.role = 'canonical' AND l.archived_at IS NULL
+ AND s.source = 'bot' AND s.status = 'active' AND s.orca_role = 'lead'
+ AND s.remote_host_id IS NULL AND s.orca_remote_lead IS NULL
+ LIMIT 1
+ `).get(id)) {
+ throwIpcError('UNSUPPORTED_CAPABILITY',
+ `${BOT_LEAD_PLUGIN_ENGINE_UNSUPPORTED}: Choose a built-in engine for this companion chat while it leads a collaboration.`);
+ }
if (p.expectedAvatar !== undefined && current.avatar !== expectString(p.expectedAvatar, 'expectedAvatar')) {
throw Object.assign(new Error('Buddy avatar changed during update'), { code: 'PRECONDITION_FAILED' });
}
diff --git a/apps/desktop/src/renderer/features/bots/BotSettingsSaveStatus.tsx b/apps/desktop/src/renderer/features/bots/BotSettingsSaveStatus.tsx
index ea5dff9a512..369fbffb75a 100644
--- a/apps/desktop/src/renderer/features/bots/BotSettingsSaveStatus.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotSettingsSaveStatus.tsx
@@ -1,6 +1,7 @@
import { Check } from 'lucide-react';
import { Spinner } from '@/components/ui/spinner';
import { useBotTranslation } from './botPronounContext';
+import { BOT_LEAD_PLUGIN_ENGINE_ERROR_KEY } from './botSettingsAutosave';
import type { BotSettingsAutosaveController } from './useBotSettingsAutosave';
/** Shared settings header feedback; only a confirmed receipt becomes saved. */
@@ -23,7 +24,7 @@ export function BotSettingsSaveStatus({ autosave, modelPage, sourceTooLong }: {
if (autosave.status === 'error') return (
{t(autosave.errorKey ?? 'bots.profileSaveFailed')}
- {!sourceTooLong &&