Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(companion): make clearing a queued invitation welcome best effort
nanab708a1580850
diff --git a/apps/desktop/src/main/companion-cloud/host.ts b/apps/desktop/src/main/companion-cloud/host.tsindex db8cbd1f3a..58ee90dfba 100644--- a/apps/desktop/src/main/companion-cloud/host.ts+++ b/apps/desktop/src/main/companion-cloud/host.ts@@ -166,9 +166,11 @@ type MaterializeLocal = Omit<CompanionMaterializeHost, 'latestRows'>;function createMaterializer(input: {ensureCanonicalSession: (botId: string) => Promise<string>;- discardInvitationWelcome?: (sessionId: string) => Promise<void>;+ /** False when the task's queue could not be read. */+ discardInvitationWelcome?: (sessionId: string) => Promise<boolean>;rebuildContext: (sessionId: string) => Promise<'rebuilt' | 'busy'>;selfDeviceId?: () => string | null;+ log?: CompanionLog;}): MaterializeLocal {return {applyTodos: async (botId, items, remove, fence) => {@@ -225,7 +227,12 @@ function createMaterializer(input: {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);+ if (row?.sessionId) {+ // Best effort: an unreadable queue must not fail a take-over that otherwise works.+ const cleared = await input.discardInvitationWelcome(row.sessionId).catch(() => false);+ fence.assertCurrent();+ if (!cleared) input.log?.warn('Queued invitation welcome could not be cleared', { sessionId: row.sessionId });+ }}},applyCapabilities: async (botId, value, fence) => {@@ -373,8 +380,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>;+ /** Remove the greeting request an unfinished meeting queued in this task (cloud-companions.md §6); false when its queue is unreadable. */+ discardInvitationWelcome?: (sessionId: string) => Promise<boolean>;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.tsindex 803de96600..841bdfdf2d 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@@ -649,10 +649,11 @@ describe('discarding the welcome an unfinished meeting queued', () => {expect(sent(h).join('\n')).toContain('Say hello');});- it('fails when the queue cannot be read, so the take-over retries', async () => {+ it('does nothing and does not throw when the queue cannot be read', async () => {const h = createHarness();h.setLoadQueueSnapshot(async () => { throw new Error('snapshot unreadable'); });- await expect(discardQueuedInvitationWelcomes(h.coordinator, 'welcome-session')).rejects.toThrow('INVITATION_QUEUE_UNAVAILABLE');+ await expect(discardQueuedInvitationWelcomes(h.coordinator, 'welcome-session')).resolves.toBeNull();+ expect(h.coordinator.getQueueControlSnapshot('welcome-session').pendingQueue).toEqual([]);});});diff --git a/apps/desktop/src/main/maker-ipc/queuedInvitationWelcome.ts b/apps/desktop/src/main/maker-ipc/queuedInvitationWelcome.tsindex 2e77f30f5e..94c7ad5e4f 100644--- a/apps/desktop/src/main/maker-ipc/queuedInvitationWelcome.ts+++ b/apps/desktop/src/main/maker-ipc/queuedInvitationWelcome.ts@@ -10,14 +10,14 @@ function isQueuedInvitationWelcome(item: Pick<AgentInputQueuedMessage, 'text' |/*** 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.+ * else queued there stays. Best effort: null when the queue cannot be read (nothing is removed).*/export async function discardQueuedInvitationWelcomes(queue: Pick<AgentInputCoordinator, 'ensureQueueRestored' | 'isQueueRestored' | 'getQueueControlSnapshot' | 'remove'>,sessionId: string,-): Promise<number> {+): Promise<number | null> {await queue.ensureQueueRestored(sessionId).catch(() => undefined);- if (!queue.isQueueRestored(sessionId)) throw new Error('INVITATION_QUEUE_UNAVAILABLE');+ if (!queue.isQueueRestored(sessionId)) return null;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.tsindex 20c1579ac6..5d02d1d09e 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -13075,7 +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); },+ discardInvitationWelcome: async (sessionId) => (await discardQueuedInvitationWelcomes(inputCoordinator, sessionId)) !== null,// 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.mdindex 7fe3a71305..ff7d606dcf 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` 结束,且降级副本拒绝一切发送)。见面已经排进主任务队列、被降级拒绝而留下的打招呼请求(含启动时从崩溃快照恢复的暂停队列里的那条),同样在资料写入之后由 main 侧清掉(`discardInvitationWelcome` → `queuedInvitationWelcome.ts`,只认「仅文本 + 界面触发前缀」的这种队列项,主人自己排的消息和其它队列项保留;读不到队列则这次接管失败、稍后重试)。否则接管成功后主人发的第一条消息会把它放行,冒出一条欢迎和问候。普通编辑资料时「伙伴正在准备见面」的保护不变。+- 接管已有的本机副本时,副本上没走完的「见面」(新电脑首次启动播种默认伙伴并开始见面,随后因伙伴在另一台电脑运行而被降级,见面停在中途)随云端资料一并结束:接管写资料时由主进程把这条见面记录清掉(`updateBotProfile` 的 `RestoredBotOrigin.replacesUnfinishedMeeting`,只有接管这条受信任路径传入,渲染层与模型请求体不能带;已经走完的见面记录保持不动),不再拦住资料写入和建主任务,也不会在接管后重新生成欢迎消息、头像或人设(正在跑或启动时恢复的见面在下一次保存时以 `INVITATION_REPLACED` 结束,且降级副本拒绝一切发送)。见面已经排进主任务队列、被降级拒绝而留下的打招呼请求(含启动时从崩溃快照恢复的暂停队列里的那条),同样在资料写入之后由 main 侧清掉(`discardInvitationWelcome` → `queuedInvitationWelcome.ts`,只认「仅文本 + 界面触发前缀」的这种队列项,主人自己排的消息和其它队列项保留;读不到队列时只记一条警告日志(带任务 ID、不含正文)并继续接管,不因此让接管失败)。否则接管成功后主人发的第一条消息会把它放行,冒出一条欢迎和问候。普通编辑资料时「伙伴正在准备见面」的保护不变。- 技能按 `SKILL.md` 原文(含 Cindy 不认识的原生 frontmatter)上传与恢复,停用状态一并恢复(整个技能目录在启用 / 停用之间移动),换电脑后技能语义不变。- 接管后对话镜像从本机最后一条自有消息(不含导入的云端历史)之后开始,本机接管前的旧对话不上传到房间。- 资料上传遇到版本冲突时先确认本机仍是主力电脑(否则停止并重新读取),再按服务器当前值最多重写一次;读本机资料(SOUL / USER / 自定义提示词)、