Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(provider-group): 手动接手时重置限额续跑次数
Dash07fb2b7f1e48
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 dfa42e3490..ac5db438da 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@@ -11,6 +11,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { admitTaskAction, bindTaskActionInput, taskActionInputGuard } from '../taskActionAuthorization.js';import { AgentInputCoordinator } from '../agent-input-coordinator.js';import { ProviderGroupUsageLimitError } from '../../provider-group/failurePolicy.js';+import { UsageLimitAutoResume, USAGE_LIMIT_MAX_CONSECUTIVE_RESUMES } from '../usageLimitAutoResume.js';import { MCP_APP_MESSAGE_CLIENT_PREFIX, MCP_APP_MESSAGE_GUARD } from '../../mcp-apps/message.js';import { hasAcceptedUserTaskInput } from '../pluginTaskInput.js';import { runSchedulerQueuedPreparation } from '../schedulerQueuedPreparation.js';@@ -1411,6 +1412,7 @@ function createHarness(opts?: {const persistQueueSnapshot =vi.fn<NonNullable<AgentInputCoordinatorDeps['persistQueueSnapshot']>>();const onUiRetry = vi.fn<NonNullable<AgentInputCoordinatorDeps['onUiRetry']>>(() => {});+ const onUserAction = vi.fn<NonNullable<AgentInputCoordinatorDeps['onUserAction']>>(() => {});const onAutomaticEnqueue = vi.fn<NonNullable<AgentInputCoordinatorDeps['onAutomaticEnqueue']>>(() => {});@@ -1440,6 +1442,7 @@ function createHarness(opts?: {steerToAgent,abortSession,onUiRetry,+ onUserAction,onAutomaticEnqueue,onUserEnqueue,previewQueuedUserTurn,@@ -1541,6 +1544,7 @@ function createHarness(opts?: {emitProjection,projections,onUiRetry,+ onUserAction,onAutomaticEnqueue,onUserEnqueue,previewQueuedUserTurn,@@ -14223,6 +14227,64 @@ describe('usage-limit wait (ordinary tasks)', () => {sessionTotal: 0,};+ // Unit regression (#6611): existing cap tests called noteUserAction directly,+ // missing the real queue-head Retry/Continue/new-input entrances before persistence.+ // Drive both production owners with injected timers: three failed auto attempts,+ // then a human action must start a fresh budget without reopening a channel turn.+ it.each(['retry', 'continue', 'new-input'] as const)('starts a fresh quota episode on queue-head %s before persistence', async action => {+ const h = createHarness();+ const sid = 'quota-manual-episode';+ const timers: Array<() => void> = [];+ const attempts: number[] = [];+ const guard = new UsageLimitAutoResume({+ now: () => 1_000_000,+ random: () => 0,+ setTimer: fn => { timers.push(fn); return fn; },+ clearTimer: () => {},+ isEligible: async () => true,+ resolveResetAt: async () => 5_000_000,+ arm: (id, token, at) => h.coordinator.armUsageLimitWait(id, token, at),+ isCurrent: (id, token) => h.coordinator.isUsageLimitWaitCurrent(id, token),+ cancel: (id, token) => { h.coordinator.cancelUsageLimitWait(id, token); },+ continueSession: (id, token, info) => {+ attempts.push(info.attempt);+ return h.coordinator.continueAfterUsageLimitReset(id, token, info);+ },+ log: () => {},+ });+ h.onUserAction.mockImplementation(id => guard.noteUserAction(id));+ h.onUsageLimitedTurnError.mockImplementation((id, signals, _item, token) => guard.onTurnError(id, signals, token));+ h.sendToAgent.mockRejectedValue(new ProviderGroupUsageLimitError({ resetAtMs: 5_000_000 }));+ try {+ h.coordinator.enqueue(sid, makeItem('original', 'original task'));+ await flush();+ for (let i = 0; i < USAGE_LIMIT_MAX_CONSECUTIVE_RESUMES; i++) {+ expect(timers).toHaveLength(1);+ timers.shift()!();+ await flush();+ await flush();+ }+ expect(attempts).toEqual([1, 2, 3]);+ expect(timers).toHaveLength(0);+ expect(h.coordinator.getProjection(sid).usageLimitWait).toBeNull();+ expect(h.onUserMessagePersisted).not.toHaveBeenCalled();+ if (action === 'retry') await h.coordinator.retryLastError(sid);+ else h.coordinator.enqueue(sid, makeItem('next', action === 'continue' ? CONTINUE_AFTER_ERROR_PROMPT : 'new task'));+ await flush();+ expect(timers).toHaveLength(1);+ expect(h.coordinator.getProjection(sid).usageLimitWait).not.toBeNull();+ expect(h.onUiRetry).not.toHaveBeenCalled();+ timers.shift()!();+ await flush();+ await flush();+ expect(attempts).toEqual([1, 2, 3, 1]);+ expect(h.sendToAgent.mock.calls.at(-1)?.[3].persistUserMessage?.clientId)+ .toBe(action === 'new-input' ? 'next' : 'original');+ } finally {+ guard.dispose();+ }+ });+// Unit regression: group selection rejects before persistence. Existing tests covered only// running turns; the original queued message must be sent once, or retained after cancellation.it.each([false, true])('waits after a group quota rejection before dispatch (cancel=%s)', async (cancel) => {diff --git a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.tsindex d9363f7510..0a0f468528 100644--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts@@ -604,6 +604,8 @@ export interface AgentInputCoordinatorDeps {source: 'manual' | 'auto',attemptToken?: number,) => void;+ /** 真人输入/重试更新活跃时间时同步通知;不依赖消息落库,也不认领渠道续跑。 */+ onUserAction?: (sessionId: string) => void;/*** 用户/上游用一条**新**消息接管了这个会话(enqueue 或 steer 回落为普通 turn)。*@@ -6371,6 +6373,8 @@ export class AgentInputCoordinator {}private touchUserSend(sessionId: string, atMs?: number): void {+ // 真人接手在派发/落库失败时也成立;限额预算与渠道 turn 的认领分别通知。+ this.deps.onUserAction?.(sessionId);void touchUserSendInDb(sessionId, atMs).catch((err) => {log.warn('touchUserSend failed', { sessionId, error: errorMessage(err) });});diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex d3fd14f1ec..06107bed0a 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -18735,6 +18735,8 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)}},noteSessionClearBoundary,+ // 复用真人活跃边界:队首 Retry / Continue 和新输入尚未落库时也开始新限额周期。+ onUserAction: (sessionId) => usageLimitAutoResume.noteUserAction(sessionId),// 失败 turn 重试 → hook 侧把这一轮接回渠道那条已收口的消息。source 区分// 人工与自动续跑:只有真人接手才作废 scheduler waiter,自动路径不能取消自己。onUiRetry: (sessionId, clientId, source, attemptToken) => {@@ -18751,7 +18753,6 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)// persistence/vendor await, so a failed manual retry still starts a fresh episode.silentStopAutoResumeGuard.noteUserSend(sessionId);interruptedTurnAutoResumeGuard.noteUserSend(sessionId);- usageLimitAutoResume.noteUserAction(sessionId);providerGroupService?.noteUserAction(sessionId);}publishUiContinuation(sessionId, clientId);