Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(feishu): 保留未关联话题路由并丢弃失效账号派发
liugaowei2358ad45a6f3
diff --git a/apps/desktop/src/main/im/feishu/__tests__/notificationOrigin.test.ts b/apps/desktop/src/main/im/feishu/__tests__/notificationOrigin.test.tsindex ecec4ac657..2c9a2d9b81 100644--- a/apps/desktop/src/main/im/feishu/__tests__/notificationOrigin.test.ts+++ b/apps/desktop/src/main/im/feishu/__tests__/notificationOrigin.test.ts@@ -127,6 +127,25 @@ describe('Feishu notification origins', () => {}});+ it('keeps an unlinked topic on its normal route when an unrelated send times out', async () => {+ vi.useFakeTimers();+ let finish!: (value: { messageId: string; chatId: string }) => void;+ sendNotification.mockImplementationOnce(() => new Promise((resolve) => { finish = resolve; }));+ mocks.origin = null;+ const send = sendFeishuSessionNotification(im, 'other', 'other');+ try {+ const reply = resolveFeishuNotificationReply(im, event);+ const assertion = expect(reply).resolves.toBeNull();+ await vi.advanceTimersByTimeAsync(10_000);+ await assertion;+ expect(mocks.where).toHaveBeenCalledTimes(2);+ } finally {+ finish({ messageId: 'om_other', chatId: 'oc_chat' });+ await send;+ vi.useRealTimers();+ }+ });+it('rechecks a fast reply as soon as its send finishes, even while another is pending', async () => {let finishOther!: (value: { messageId: string; chatId: string }) => void;let finishTarget!: (value: { messageId: string; chatId: string }) => void;diff --git a/apps/desktop/src/main/im/feishu/notificationOrigin.ts b/apps/desktop/src/main/im/feishu/notificationOrigin.tsindex 895f4aab2e..4025e0a995 100644--- a/apps/desktop/src/main/im/feishu/notificationOrigin.ts+++ b/apps/desktop/src/main/im/feishu/notificationOrigin.ts@@ -95,14 +95,17 @@ export async function resolveFeishuNotificationReply(im: FeishuIM, event: IMMessoperation, operation.then(() => ({ operation }), () => ({ operation })),]));let timer: ReturnType<typeof setTimeout> | undefined;- const timeout = new Promise<never>((_, reject) => {- timer = setTimeout(() => reject(new Error('Notification receipt is still pending')), 10_000);+ const timeout = new Promise<null>((resolve) => {+ timer = setTimeout(() => resolve(null), 10_000);});try {while (!origin && remaining.size) {- const { operation } = await Promise.race([...remaining.values(), timeout]);- remaining.delete(operation);+ const settled = await Promise.race([...remaining.values(), timeout]);origin = await readOrigin();+ // A pending send cannot prove this root belongs to a notification.+ // After the bounded wait, preserve the unlinked topic's normal route.+ if (settled === null) break;+ remaining.delete(settled.operation);}} finally {if (timer) clearTimeout(timer);diff --git a/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts b/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.tsindex 83b4a87826..abedb798ed 100644--- a/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts+++ b/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts@@ -99,6 +99,7 @@ vi.mock('../fbotTitle', () => ({generateAndPersistFbotTitle: mocks.generateAndPersistFbotTitle,}));+import { ImAccountScopeClosedError } from '../../accountBoundary';import { createTurnRunner, type ImTurnRunner } from '../turnRunner';import type { ImCardBuilders } from '../cardBuilders';import type { ImSessionRepo, ImSessionRow } from '../sessionRepo';@@ -714,6 +715,28 @@ describe('notification replies reuse the originating session without takeover',expect(fakeRepo.createSession).not.toHaveBeenCalled();});+ it('discards queued account-closure errors without sending through the replacement account', async () => {+ origin();+ await reply('om_notification_a');+ await runner.runAgentTurn({+ notificationSessionId: 'original-session',+ revalidateNotificationReply: async () => { throw new ImAccountScopeClosedError(); },+ botContextId: 'T1', userId: 'U1', userMessageId: 'reply-stale',+ text: 'continue', attachments: [], scopeKey: 'om_notification_b',+ });+ mocks.slackIm.sendText.mockClear();+ const h = harnesses.get('original-session')!;+ h.emit({ type: 'done' } as AgentEvent);+ await vi.waitFor(() => expect(mocks.logger.error).toHaveBeenCalledWith(+ expect.stringContaining('dispatchQueuedSend threw (queued path): [IM_NOT_READY]'),+ ));+ expect(h.send).toHaveBeenCalledTimes(1);+ expect(mocks.slackIm.sendText).not.toHaveBeenCalledWith(+ 'U1', expect.anything(), expect.objectContaining({ threadTs: 'om_notification_b' }),+ );+ expect(mocks.slackIm.removeMessageReaction.mock.calls.some(([id]) => id === 'reply-stale')).toBe(false);+ });+it('stopping a queued topic never aborts the active turn from another topic', async () => {origin();await reply('om_notification_a');diff --git a/apps/desktop/src/main/im/shared/turnRunner.ts b/apps/desktop/src/main/im/shared/turnRunner.tsindex c3b5dc166e..bc7abc8db6 100644--- a/apps/desktop/src/main/im/shared/turnRunner.ts+++ b/apps/desktop/src/main/im/shared/turnRunner.ts@@ -33,6 +33,7 @@ import { createLocalImSource, type ImContextSnapshot } from '../../../shared/imMimport { createHash, randomUUID } from 'node:crypto';import path from 'node:path';+import { isImAccountScopeClosedError } from '../accountBoundary';import { bindRuntimeRecoveryNotice } from './runtimeRecoveryNotice';/**@@ -1049,7 +1050,6 @@ export function createTurnRunner(> {userId = item.turn.userId;const rowId = item.rowId;- await beginChunkedReply(item.turn);// 过程区耗时基准取真实派发时刻 — TurnState 创建时可能还要在 sendQueue 里// 等上一轮跑完, 排队等待不该计入"第 N 步 · 耗时"显示item.turn.presenter.activity.startedAt = Date.now();@@ -1066,6 +1066,7 @@ export function createTurnRunner(await item.turn.revalidateNotificationReply?.();await resolveNotificationTarget(rowId, item.turn.scopeKey);}+ await beginChunkedReply(item.turn);// deferred 切换会关闭旧 session。apply 成功后重新读取 maker 里的 live// session 并原地换绑 IM listener,确保当前这条消息发给目标引擎且队列不丢。if (deps.acquirePendingAgentSwitch) {@@ -1286,6 +1287,11 @@ export function createTurnRunner(return { kind: 'accepted', acceptedAt: acceptedAt || Date.now() };} catch (err) {if (turnChangeSetStarted) clearPendingTurnChangeSets(rowId);+ if (isImAccountScopeClosedError(err)) {+ const index = state.queue.indexOf(item.turn);+ if (index >= 0) state.queue.splice(index, 1);+ throw err;+ }const turnPolicyFailureReason = classifyTurnPermissionPolicySendFailure(err, item, state);if (turnPolicyFailureReason) {await handleSendPreDispatchFailure(state, userId, {