Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(companion): drop the welcome an unfinished meeting queued when a take-over replaces the copy

nanaa3f6e47a2355
diff --git a/apps/desktop/src/main/companion-cloud/host.ts b/apps/desktop/src/main/companion-cloud/host.ts
index f638f47066..db8cbd1f3a 100644
--- a/apps/desktop/src/main/companion-cloud/host.ts
+++ b/apps/desktop/src/main/companion-cloud/host.ts
@@ -166,6 +166,7 @@ type MaterializeLocal = Omit<CompanionMaterializeHost, 'latestRows'>;
function createMaterializer(input: {
ensureCanonicalSession: (botId: string) => Promise<string>;
+ discardInvitationWelcome?: (sessionId: string) => Promise<void>;
rebuildContext: (sessionId: string) => Promise<'rebuilt' | 'busy'>;
selfDeviceId?: () => string | null;
}): MaterializeLocal {
@@ -217,6 +218,15 @@ function createMaterializer(input: {
fence.assertCurrent();
if (image) await setBotProfileAvatar(id, image);
}
+ // The meeting record is gone, so no new greeting can be queued; one an unfinished meeting
+ // already queued (even one restored from the crash snapshot) must not go out on the owner's
+ // first message. Not tied to the record, so a retry that finds it already gone still clears it.
+ if (input.discardInvitationWelcome) {
+ const [row] = await getDbClient().drizzle.select({ sessionId: botProfiles.canonicalSessionId })
+ .from(botProfiles).where(eq(botProfiles.id, id)).limit(1);
+ fence.assertCurrent();
+ if (row?.sessionId) await input.discardInvitationWelcome(row.sessionId);
+ }
},
applyCapabilities: async (botId, value, fence) => {
// Only the same provider + model that this computer can use is kept (no credential travels);
@@ -363,6 +373,8 @@ async function companionSessionIds(botId: string): Promise<string[]> {
export function createCompanionCloudHost(input: {
deliverToCanonical: CompanionCloudHost['deliverToCanonical'];
ensureCanonicalSession: (botId: string) => Promise<string>;
+ /** Remove the greeting request an unfinished meeting queued in this task (cloud-companions.md §6). */
+ discardInvitationWelcome?: (sessionId: string) => Promise<void>;
rebuildContext: (sessionId: string) => Promise<'rebuilt' | 'busy'>;
/** A turn is running (or queued) in this Session. */
isTurnActive?: (sessionId: string) => boolean;
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
index 459939145b..803de96600 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
@@ -33,6 +33,7 @@ import {
isInterruptedTurnError,
} from '../interruptedTurnAutoResume.js';
import { createQueuedDispatchReceipts } from '../queuedDispatchReceipts.js';
+import { discardQueuedInvitationWelcomes } from '../queuedInvitationWelcome.js';
import { createOrcaInterAgentDispatcher } from '../orcaInterAgentDispatcher.js';
import {
createOrcaTeamService,
@@ -622,6 +623,39 @@ describe('queued welcome dispatch receipts', () => {
});
});
+// #7095: a companion taken over from the cloud drops its unfinished meeting; the greeting request that
+// meeting queued (restored from the crash snapshot) must not go out on the owner's next message.
+describe('discarding the welcome an unfinished meeting queued', () => {
+ const welcome = () => makeItem('welcome', `${UI_ACTION_TRIGGER_PREFIX}Say hello.`, { toolsDisabled: true });
+ const sent = (h: ReturnType<typeof createHarness>) => h.sendToAgent.mock.calls.map(call => String((call[1] as { content?: unknown })?.content));
+
+ it('removes a restored welcome but keeps the owner\'s own queued messages', async () => {
+ const h = createHarness();
+ h.setLoadQueueSnapshot(async () => [welcome(), makeItem('mine', 'my own question'), makeItem('trigger', `${UI_ACTION_TRIGGER_PREFIX}continue`)]);
+ await expect(discardQueuedInvitationWelcomes(h.coordinator, 'welcome-session')).resolves.toBe(1);
+ expect(h.coordinator.getQueueControlSnapshot('welcome-session').pendingQueue.map(item => item.clientId)).toEqual(['mine', 'trigger']);
+ h.coordinator.enqueue('welcome-session', makeItem('typed', 'next'), { resumeRestorePausedQueue: true });
+ await flush();
+ expect(sent(h).join('\n')).not.toContain('Say hello');
+ expect(sent(h)).toEqual(['my own question']);
+ });
+
+ it('leaves the welcome in place when it is not discarded (the bug this prevents)', async () => {
+ const h = createHarness();
+ h.setLoadQueueSnapshot(async () => [welcome()]);
+ await h.coordinator.ensureQueueRestored('welcome-session');
+ h.coordinator.enqueue('welcome-session', makeItem('typed', 'next'), { resumeRestorePausedQueue: true });
+ await flush();
+ expect(sent(h).join('\n')).toContain('Say hello');
+ });
+
+ it('fails when the queue cannot be read, so the take-over retries', async () => {
+ const h = createHarness();
+ h.setLoadQueueSnapshot(async () => { throw new Error('snapshot unreadable'); });
+ await expect(discardQueuedInvitationWelcomes(h.coordinator, 'welcome-session')).rejects.toThrow('INVITATION_QUEUE_UNAVAILABLE');
+ });
+});
+
describe('AgentInputCoordinator Orca priority queue transactions', () => {
const orcaItem = (clientId: string, text: string) =>
makeItem(clientId, text, {
diff --git a/apps/desktop/src/main/maker-ipc/queuedInvitationWelcome.ts b/apps/desktop/src/main/maker-ipc/queuedInvitationWelcome.ts
new file mode 100644
index 0000000000..2e77f30f5e
--- /dev/null
+++ b/apps/desktop/src/main/maker-ipc/queuedInvitationWelcome.ts
@@ -0,0 +1,24 @@
+import { UI_ACTION_TRIGGER_PREFIX } from '../../shared/interruptedTurn.js';
+import type { AgentInputQueuedMessage } from '../../shared/agentInputQueue.js';
+import type { AgentInputCoordinator } from './agent-input-coordinator.js';
+
+/** The hidden greeting request the invitation queues: text-only, marked as a host UI trigger. */
+function isQueuedInvitationWelcome(item: Pick<AgentInputQueuedMessage, 'text' | 'toolsDisabled'>): boolean {
+ return item.toolsDisabled === true && item.text.startsWith(UI_ACTION_TRIGGER_PREFIX);
+}
+
+/**
+ * Drop the greeting request an unfinished meeting left in a task's queue (also one restored from
+ * the crash snapshot, which would otherwise be released by the owner's next input). Everything
+ * else queued there stays. Fails when the queue cannot be read, so the caller retries.
+ */
+export async function discardQueuedInvitationWelcomes(
+ queue: Pick<AgentInputCoordinator, 'ensureQueueRestored' | 'isQueueRestored' | 'getQueueControlSnapshot' | 'remove'>,
+ sessionId: string,
+): Promise<number> {
+ await queue.ensureQueueRestored(sessionId).catch(() => undefined);
+ if (!queue.isQueueRestored(sessionId)) throw new Error('INVITATION_QUEUE_UNAVAILABLE');
+ const welcomes = queue.getQueueControlSnapshot(sessionId).pendingQueue.filter(isQueuedInvitationWelcome);
+ for (const item of welcomes) queue.remove(sessionId, item.clientId);
+ return welcomes.length;
+}
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index bd3eae1e67..20c1579ac6 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -125,6 +125,7 @@ import { configureAppDefaultModelSelection, inspectAppDefaultModel } from './app
import type { BuiltinApiKeyBridgeDeps } from '../secrets/builtinApiKeyBridge.js';
import { setBotInvitationWelcomeDispatch } from './botInvitation.js';
import { createQueuedDispatchReceipts } from './queuedDispatchReceipts.js';
+import { discardQueuedInvitationWelcomes } from './queuedInvitationWelcome.js';
import type { TurnUsageContext } from './turnUsageContext.js';
import { retainProviderPresentationAfterAuthChange } from '../maker-host/provider-presentation-store.js';
import { registerPluginListHandler } from './pluginListHandler.js';
@@ -13074,6 +13075,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
if (!ensured.ok) throw new Error(ensured.errorCode);
return ensured.sessionId;
},
+ discardInvitationWelcome: async (sessionId) => { await discardQueuedInvitationWelcomes(inputCoordinator, sessionId); },
// Cloud history was added: rebuild like a restart, but never interrupt a turn.
rebuildContext: async (sessionId) => {
if (companionTurnActive(sessionId)) return 'busy';
diff --git a/docs/product-rules/cloud-companions.md b/docs/product-rules/cloud-companions.md
index 57e130724d..7fe3a71305 100644
--- a/docs/product-rules/cloud-companions.md
+++ b/docs/product-rules/cloud-companions.md
@@ -206,7 +206,7 @@
不会把已删除的内容带回云端。资料上传只给本机曾上传或曾接管写入过的键写墓碑,服务器上仅存在的键(含本机未能写入的
记忆)从不被墓碑。云端既没有值也没有墓碑、只存在于这台电脑的记忆 / 技能(例如第二台电脑 Cindy 自己积累的)接管后保留,
并作为新内容上传、合入伙伴(Dash 2026-10-13 确认:合并,不按云端删除)。
-- 接管已有的本机副本时,副本上没走完的「见面」(新电脑首次启动播种默认伙伴并开始见面,随后因伙伴在另一台电脑运行而被降级,见面停在中途)随云端资料一并结束:接管写资料时由主进程把这条见面记录清掉(`updateBotProfile` 的 `RestoredBotOrigin.replacesUnfinishedMeeting`,只有接管这条受信任路径传入,渲染层与模型请求体不能带;已经走完的见面记录保持不动),不再拦住资料写入和建主任务,也不会在接管后重新生成欢迎消息、头像或人设(正在跑或启动时恢复的见面在下一次保存时以 `INVITATION_REPLACED` 结束,且降级副本拒绝一切发送)。普通编辑资料时「伙伴正在准备见面」的保护不变。
+- 接管已有的本机副本时,副本上没走完的「见面」(新电脑首次启动播种默认伙伴并开始见面,随后因伙伴在另一台电脑运行而被降级,见面停在中途)随云端资料一并结束:接管写资料时由主进程把这条见面记录清掉(`updateBotProfile` 的 `RestoredBotOrigin.replacesUnfinishedMeeting`,只有接管这条受信任路径传入,渲染层与模型请求体不能带;已经走完的见面记录保持不动),不再拦住资料写入和建主任务,也不会在接管后重新生成欢迎消息、头像或人设(正在跑或启动时恢复的见面在下一次保存时以 `INVITATION_REPLACED` 结束,且降级副本拒绝一切发送)。见面已经排进主任务队列、被降级拒绝而留下的打招呼请求(含启动时从崩溃快照恢复的暂停队列里的那条),同样在资料写入之后由 main 侧清掉(`discardInvitationWelcome` → `queuedInvitationWelcome.ts`,只认「仅文本 + 界面触发前缀」的这种队列项,主人自己排的消息和其它队列项保留;读不到队列则这次接管失败、稍后重试)。否则接管成功后主人发的第一条消息会把它放行,冒出一条欢迎和问候。普通编辑资料时「伙伴正在准备见面」的保护不变。
- 技能按 `SKILL.md` 原文(含 Cindy 不认识的原生 frontmatter)上传与恢复,停用状态一并恢复(整个技能目录在启用 / 停用之间移动),换电脑后技能语义不变。
- 接管后对话镜像从本机最后一条自有消息(不含导入的云端历史)之后开始,本机接管前的旧对话不上传到房间。
- 资料上传遇到版本冲突时先确认本机仍是主力电脑(否则停止并重新读取),再按服务器当前值最多重写一次;读本机资料(SOUL / USER / 自定义提示词)、