Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(teammates): deliver a queued task message when the final re-check fails
Dashccc4c4f827ef
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 e27b82ce65..164972a0bf 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@@ -120,31 +120,48 @@ describe('task action dispatch authorization', () => {expect(h.coordinator.getProjection(sid)).toMatchObject({ error: null, pendingQueue: [] });});- // Review on #7969: a failed check (group transport, database not ready) is not a- // revocation. The message must stay as a retryable queue head, not be destroyed.- it('keeps the message as a retryable queue head when the delivery check itself fails', async () => {- const h = createHarness(), sid = 'task-action-check-failed';+ // Reviews on #7969: a check that merely failed (group transport, database not ready) is not+ // a revocation. The guard runs three times per dispatch: the drain pre-check, then in the send+ // transaction before and after the row is persisted. While the message can still be retried it+ // stays a queue head; once persisted a task action cannot be retried (its guard is bound to the+ // clientId), so it is delivered on the strength of the earlier successful checks.+ it.each([+ { failsAt: 'the pre-check', failingCall: 1, delivered: false },+ { failsAt: 'the re-check before persistence', failingCall: 2, delivered: false },+ { failsAt: 'the re-check after persistence', failingCall: 3, delivered: true },+ ])('a delivery check failing at $failsAt delivers=$delivered', async ({ failingCall, delivered }) => {+ const h = createHarness(), sid = `task-action-check-failed-${failingCall}`;+ const dispatched = vi.fn();h.sendToAgent.mockImplementation(async (_id, _message, _opts, sendOpts) => {await sendOpts[MCP_APP_MESSAGE_GUARD]?.();+ await sendOpts.persistUserMessage?.onPersisted?.();+ await sendOpts[MCP_APP_MESSAGE_GUARD]?.();+ dispatched();return sendSuccess();});await h.coordinator.ensureQueueRestored(sid);h.setRunning(true);+ let calls = 0;const queued = makeItem('automatic', 'Continue');bindTaskActionInput(sid, queued, async () => {- throw Object.assign(new Error('verification unavailable'), { code: 'GROUP_AUTHORIZATION_UNAVAILABLE' });+ if (++calls === failingCall)+ throw Object.assign(new Error('verification unavailable'), { code: 'GROUP_AUTHORIZATION_UNAVAILABLE' });});h.coordinator.enqueue(sid, queued);await flush();h.setRunning(false);h.coordinator.wakeSession(sid, 'idle');- await flush();- expect(h.sendToAgent).not.toHaveBeenCalled();+ if (delivered) {+ await vi.waitFor(() => expect(dispatched).toHaveBeenCalledOnce());+ await flush();+ expect(h.onUndispatchedUserTurn).not.toHaveBeenCalled();+ expect(h.coordinator.getProjection(sid)).toMatchObject({ error: null, pendingQueue: [] });+ } else {+ await vi.waitFor(() => expect(h.coordinator.getProjection(sid).recovery).toEqual({ kind: 'queue-head', clientId: 'automatic' }));+ expect(dispatched).not.toHaveBeenCalled();+ expect(h.coordinator.getProjection(sid).pendingQueue).toHaveLength(1);+ }expect(h.onDiscardedQueuedMessage).not.toHaveBeenCalled();- expect(h.coordinator.getProjection(sid)).toMatchObject({- recovery: { kind: 'queue-head', clientId: 'automatic' },- pendingQueue: [expect.objectContaining({ clientId: 'automatic' })],- });});});diff --git a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.tsindex f641ab1b83..b4ad57f69b 100644--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts@@ -5164,9 +5164,18 @@ export class AgentInputCoordinator {try {await taskActionGuard?.();} catch (error) {- // Only a proven revocation discards; a failed check keeps the message retryable.- if (isTaskActionRevoked(error)) appMessageGuardRejected = true;- throw error;+ if (isTaskActionRevoked(error)) {+ appMessageGuardRejected = true;+ throw error;+ }+ // A failed check is not a revocation. Before the row is persisted the ordinary+ // failure path keeps the message as a retryable queue head. Afterwards a task action+ // cannot be retried (its guard is bound to this clientId) and the pre-check already+ // passed: deliver rather than leave a failed reply behind.+ if (!active.persisted) throw error;+ log.warn('task action re-check failed after the row was persisted; delivering on the earlier check', {+ sessionId, clientId: head.clientId, reason: errorMessage(error),+ });}} } : {}),...(head.supersedesUserClientId ? { retryUserClientId: head.supersedesUserClientId } : {}),diff --git a/docs/product-rules/teammate-authority.md b/docs/product-rules/teammate-authority.mdindex f63a9538a5..dba2809826 100644--- a/docs/product-rules/teammate-authority.md+++ b/docs/product-rules/teammate-authority.md@@ -52,7 +52,9 @@清空或删除、伙伴被暂停或归档、委派执行代次或 Orca 团队变化、群授权失效时才不再投递;这类消息在落库前移出队列,不在接收任务里留下失败回复。清空以协调器的内存边界和数据库 `cleared_at` 中较新者为准(`/clear` 先改内存、后写库,写库可能失败);重启后晚加载的旧边界不算新的清空。校验本身失败- (群授权传输中断、数据库未就绪等)不算撤权:消息保留为可重试的队首,不被销毁。实现见+ (群授权传输中断、数据库未就绪等)不算撤权,不销毁消息:消息落库前失败(派发前预检、事务内第一次+ 复核)时保留为可重试的队首;落库之后(派发前最后一次复核)才失败时,排队的任务消息无法重试(守卫+ 绑定了 clientId),而前面的校验刚刚通过,所以照常派发,不留失败回复。实现见`taskActionHost.ts` 的 `assertDeliveryCurrent`、`taskActionAuthorization.ts` 的 `isTaskActionRevoked`与 `agent-input-coordinator.ts` 的派发前复核;回归见 `taskActionAuthorization.test.ts` 与`agent-input-coordinator.test.ts`。