Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(feishu): reject inactive companion notification routes
Chrisb5553d99598d
diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/collabSendOutcome.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/collabSendOutcome.test.tsindex f3970a1971..76b327f872 100644--- a/apps/desktop/src/main/mcp-integrations/__tests__/collabSendOutcome.test.ts+++ b/apps/desktop/src/main/mcp-integrations/__tests__/collabSendOutcome.test.ts@@ -234,6 +234,8 @@ describe('collab send outcome semantics', () => {commitVolatileAppSession('cloud', 'feishu-test-owner');await client.exec('CREATE TABLE sessions (id TEXT PRIMARY KEY, source TEXT)');await client.exec('CREATE TABLE bot_session_links (session_id TEXT, bot_id TEXT, role TEXT)');+ await client.exec('CREATE TABLE bot_profiles (id TEXT PRIMARY KEY, status TEXT)');+ await client.exec("INSERT INTO bot_profiles VALUES ('bot-feishu', 'active')");await client.exec("INSERT INTO sessions VALUES ('background-receipt', 'bot')");await client.exec("INSERT INTO bot_session_links VALUES ('background-receipt', 'bot-feishu', 'canonical')");setCurrentDbClient(client, 'feishu-test-owner');@@ -280,6 +282,23 @@ describe('collab send outcome semantics', () => {}}+ // A paused profile may still have a live tool call and connected transport.+ // The persisted pause must block both sends even though its link survives.+ await client.exec("UPDATE bot_profiles SET status = 'paused' WHERE id = 'bot-feishu'");+ try {+ await expect(feishu.getOwnerOpenId(session)).rejects.toThrow('Companion is not active');+ expect(await feishu.sendMessage(owner!, 'paused', session.sessionId, session))+ .toMatchObject({ ok: false, reason: 'SEND_FAIL' });+ expect(await feishu.sendFile(owner!, '/tmp/report.txt', 'report.txt', session))+ .toMatchObject({ ok: false, reason: 'SEND_FAIL' });+ expect(mockState.companionFeishu.sendMarkdownText).not.toHaveBeenCalled();+ expect(mockState.companionFeishu.sendFile).not.toHaveBeenCalled();+ expect(mockState.personalFeishu.sendMarkdownText).not.toHaveBeenCalled();+ expect(mockState.personalFeishu.sendFile).not.toHaveBeenCalled();+ } finally {+ await client.exec("UPDATE bot_profiles SET status = 'active' WHERE id = 'bot-feishu'");+ }+// Same-account archive removes canonical membership without changing the// DB snapshot. An app-scoped recipient must not cross to personal credentials.await client.exec("UPDATE bot_session_links SET role = 'history' WHERE session_id = 'background-receipt'");diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/feishuTransportRouting.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/feishuTransportRouting.test.tsindex 5b18d5beb2..0b101a33f3 100644--- a/apps/desktop/src/main/mcp-integrations/__tests__/feishuTransportRouting.test.ts+++ b/apps/desktop/src/main/mcp-integrations/__tests__/feishuTransportRouting.test.ts@@ -26,6 +26,8 @@ beforeAll(async () => {client = await createDbClient({ transport: 'worker-thread', useInlineWorker: true });await client.exec('CREATE TABLE sessions (id TEXT PRIMARY KEY, source TEXT)');await client.exec('CREATE TABLE bot_session_links (session_id TEXT, bot_id TEXT, role TEXT)');+ await client.exec('CREATE TABLE bot_profiles (id TEXT PRIMARY KEY, status TEXT)');+ await client.exec("INSERT INTO bot_profiles VALUES ('bot-a', 'active')");await client.exec("INSERT INTO sessions VALUES ('canonical', 'bot'), ('desktop', 'desktop'), ('late', 'bot')");await client.exec("INSERT INTO bot_session_links VALUES ('canonical', 'bot-a', 'canonical')");});@@ -65,6 +67,21 @@ describe('Feishu transport with worker database', () => {await expect(resolve({ sessionId: 'canonical' })).rejects.toThrow('Companion Feishu connection unavailable');});+ // PR #6443: pause persists profile status before closing live sessions; a+ // failed close leaves tools callable. Unit tier, unchanged canonical link/DB.+ it('rejects a paused companion without selecting either transport, and permits resume', async () => {+ await client.exec("UPDATE bot_profiles SET status = 'paused' WHERE id = 'bot-a'");+ getCompanionTransport.mockClear();+ try {+ await expect(resolve({ sessionId: 'canonical' })).rejects.toThrow('Companion is not active');+ await expect(resolve({ sessionId: 'canonical' }, 'ou_companion')).rejects.toThrow('Companion is not active');+ expect(getCompanionTransport).not.toHaveBeenCalled();+ } finally {+ await client.exec("UPDATE bot_profiles SET status = 'active' WHERE id = 'bot-a'");+ }+ expect((await resolve({ sessionId: 'canonical' })).im).toBe(companion);+ });+// PR #6443: canonical membership can disappear between recipient lookup and// dispatch. Unit tier; keep the real worker DB and mutate only the link role.it('rejects a companion recipient after its canonical association disappears', async () => {diff --git a/apps/desktop/src/main/mcp-integrations/feishuTransportRouting.ts b/apps/desktop/src/main/mcp-integrations/feishuTransportRouting.tsindex 3ac423539b..1b552860fa 100644--- a/apps/desktop/src/main/mcp-integrations/feishuTransportRouting.ts+++ b/apps/desktop/src/main/mcp-integrations/feishuTransportRouting.ts@@ -3,7 +3,7 @@ import type { FeishuBotHostSession } from '@cindy/mcps';import { activeOwnerScopeKey, isAppSessionBoundaryPending } from '../appSessionState.js';import { getCurrentDbClientSnapshot, type CurrentDbClientSnapshot } from '../localDb/client/current.js';-import { botSessionLinks, sessions } from '../localDb/schema.js';+import { botProfiles, botSessionLinks, sessions } from '../localDb/schema.js';import type { FeishuToolTransport } from '../im/shared/channelToolScope.js';type Caller = FeishuBotHostSession | undefined;@@ -50,9 +50,10 @@ export function createFeishuTransportResolver(deps: {snapshot = getCurrentDbClientSnapshot();if (!snapshot) throw new Error('DbClient not ready');const row = await snapshot.client.drizzle- .select({ botId: botSessionLinks.botId })+ .select({ botId: botSessionLinks.botId, profileStatus: botProfiles.status }).from(botSessionLinks).innerJoin(sessions, eq(sessions.id, botSessionLinks.sessionId))+ .leftJoin(botProfiles, eq(botProfiles.id, botSessionLinks.botId)).where(and(eq(botSessionLinks.sessionId, session.sessionId),eq(sessions.source, 'bot'),@@ -62,6 +63,9 @@ export function createFeishuTransportResolver(deps: {.get();assertCurrent();if (!row?.botId) return personalTransport();+ // Keep canonical identity even if its profile is missing/inactive, so pause+ // cannot turn into a personal-bot fallback while a tool call is still alive.+ if (row.profileStatus !== 'active') throw new Error('Companion is not active');const im = deps.getCompanionTransport(row.botId, ownerOpenId);if (!im) throw new Error('Companion Feishu connection unavailable');return { im, assertCurrent };diff --git a/docs/dev-rules/im-turn-flow.md b/docs/dev-rules/im-turn-flow.mdindex 08f52b0c97..aa37186400 100644--- a/docs/dev-rules/im-turn-flow.md+++ b/docs/dev-rules/im-turn-flow.md@@ -63,9 +63,10 @@ Telegram / Slack / X)是同一件事的两套实现:把渠道里的一条消**飞书主人通知的无租约路径**:`send_message_to_user` / `send_file_to_user` 在伙伴 canonical主任务的后台回报、心跳或桌面轮次中可主动通知主人。无飞书逐轮作用域时,宿主异步查询当前账号的-`bot_session_links`(`role='canonical'`,关联 `sessions.source='bot'`),选择该伙伴已连接且已绑定-主人的飞书连接;发送时校验连接的 owner 与已解析收件人一致。已识别伙伴但没有匹配的可用连接、-数据库查询失败、账号边界处于 pending 或 owner 代次变化,均拒绝发送,不回落个人 bot;查询前后+`bot_session_links`(`role='canonical'`,关联 `sessions.source='bot'`),确认伙伴 Profile 为 `active`,+选择该伙伴已连接且已绑定主人的飞书连接;发送时校验连接的 owner 与已解析收件人一致。+已识别伙伴但没有匹配的可用连接、伙伴 Profile 非 active 或缺失、数据库查询失败、账号边界处于 pending+或 owner 代次变化,均拒绝发送,不回落个人 bot;查询前后及实际调用发送前都复核账号边界、owner 代次与所用 DB 快照。没有 canonical 伙伴归属的普通任务仍保留设置页个人 bot 的主人通知能力。使用个人 bot 发送时,已解析收件人必须匹配它当前的主人或宿主任务记录的显式 `feishuChatId`;两阶段之间 canonical 关联消失时,不将伙伴的收件人交给个人diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.mdindex 68adf935e3..8d11c49e9f 100644--- a/docs/product-rules/cindy-bots-runtime.md+++ b/docs/product-rules/cindy-bots-runtime.md@@ -341,8 +341,9 @@ Mobile 使用电脑端已连接的模型目录;目录为空时保持创建禁provider `isEnabled`,Codex 走 `buildSessionMcpConfig` 逐线程 `enabled`,Pi 走 `capabilityGated`;Codex /Pi 的共享 bridge 在空 ctx 阶段必须先注册该 server,否则永远挂不上)。桌面轮次没有作用域租约,**轮次内原生 API** fail closed;飞书 `send_message_to_user` / `send_file_to_user` 的主人通知是例外:- canonical 主任务的桌面或后台轮次可由宿主查询当前账号的伙伴归属,经该伙伴已连接、已认主的飞书- 连接发送给主人,不生成租约、不扩大原生 API 权限。伙伴连接不可用、账号边界 pending 或 owner+ canonical 主任务的桌面或后台轮次可由宿主查询当前账号的伙伴归属,仅在伙伴 Profile 为 `active`+ 时经其已连接、已认主的飞书连接发送给主人,不生成租约、不扩大原生 API 权限。+ 伙伴连接不可用、账号边界 pending 或 owner代次变化时拒绝发送,不回落个人 bot;完整路由与检查边界见[`im-turn-flow.md` §2](../dev-rules/im-turn-flow.md#2-状态清单)(含实现及回归链接)。绑定或解绑渠道后主任务的工具面在下一次会话启动时更新。