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): 容量不足时优先切换组内电脑
guyongacf93333a353
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 8830e369aa..9480dda8d8 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@@ -14776,6 +14776,73 @@ describe('provider group computer switch hold', () => {sessionTotal: 0,};+ // Unit regression through onTurnEvent: an overload and a switch candidate used+ // to spend the generic retry budget instead of handing off (including a guest's+ // short-lived switch offer). Existing hold cases only used non-resumable limits.+ // Cover both a settled user row and an error arriving before that row persists.+ it.each([false, true])('prioritizes a group switch over overload retry (pending persist: %s)', async pendingPersist => {+ const sid = `group-overload-${pendingPersist}`;+ const candidate = vi.fn<NonNullable<AgentInputCoordinatorDeps['providerGroupSwitchCandidate']>>(+ () => 'overload',+ );+ const h = createHarness({ providerGroupSwitchCandidate: candidate });+ h.setResumableTurnErrorTakeover({ attempt: 1, maxAttempts: 5, sessionTotal: 1 });+ h.setResumableTurnErrorCandidate(isInterruptedTurnError);+ const persisted = deferred<Record<string, never>>();+ if (pendingPersist) mocks.createMessage.mockImplementationOnce(() => persisted.promise);+ h.coordinator.enqueue(sid, makeItem('q-capacity', 'finish the task'));+ await flush();+ h.setRunning(false);+ h.coordinator.onTurnEvent(sid, 'error', 'Selected model is at capacity. Please try a different model.', {+ reason: 'upstream-overload',+ codexErrorInfo: 'serverOverloaded',+ });+ if (pendingPersist) {+ expect(h.coordinator.isAutoResumeDeferred(sid)).toBe(true);+ expect(h.onUsageLimitedTurnError).not.toHaveBeenCalled();+ persisted.resolve({});+ }+ await flush();++ expect(h.coordinator.getProjection(sid)).toMatchObject({+ error: null,+ autoResumePending: { groupSwitchPending: { cause: 'overload' } },+ recovery: { kind: 'active-turn' },+ });+ expect(h.coordinator.isAutoResumePending(sid)).toBe(false);+ expect(h.onResumableTurnError).not.toHaveBeenCalled();+ expect(h.onUsageLimitedTurnError).toHaveBeenCalledExactlyOnceWith(+ sid,+ expect.objectContaining({ reason: 'upstream-overload', codexErrorInfo: 'serverOverloaded' }),+ expect.objectContaining({ clientId: 'q-capacity' }),+ expect.any(Number),+ );+ if (pendingPersist) {+ expect(h.onResumableTurnErrorDiscarded).toHaveBeenCalledExactlyOnceWith(sid, {+ surfaceError: true,+ owner: expect.objectContaining({ clientId: 'q-capacity' }),+ providerGroupSwitchHoldId: h.coordinator.getProviderGroupSwitchHoldId(sid),+ });+ }+ expect(h.projections.every(projection => projection.error === null)).toBe(true);+ expect(h.sendToAgent).toHaveBeenCalledTimes(1);+ });++ it.each([null, 'unavailable'] as const)('keeps generic recovery when the switch cause is %s', async cause => {+ const h = createHarness({ providerGroupSwitchCandidate: () => cause });+ const takeover = { attempt: 1, maxAttempts: 5, sessionTotal: 1 };+ h.setResumableTurnErrorTakeover(takeover);+ h.coordinator.enqueue('group-recovery', makeItem('q-recovery', 'finish the task'));+ await flush();+ h.setRunning(false);+ h.coordinator.onTurnEvent('group-recovery', 'error', 'retryable upstream failure', {+ reason: cause === null ? 'upstream-overload' : 'remote-agent-lost',+ });+ expect(h.coordinator.getProjection('group-recovery')).toMatchObject({ error: null, autoResumePending: takeover });+ expect(h.coordinator.isAutoResumePending('group-recovery')).toBe(true);+ expect(h.onUsageLimitedTurnError).not.toHaveBeenCalled();+ });+async function failWhileSwitching(sid: string, cause: 'usage-limit' | 'unavailable' | null = 'usage-limit') {const candidate = vi.fn<NonNullable<AgentInputCoordinatorDeps['providerGroupSwitchCandidate']>>(() => cause,diff --git a/apps/desktop/src/main/maker-ipc/__tests__/autoResumeBookkeeping.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/autoResumeBookkeeping.test.tsindex ce362b435c..fe85872e16 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/autoResumeBookkeeping.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/autoResumeBookkeeping.test.ts@@ -486,6 +486,35 @@ describe('退避排期:必可撤销、必只认自己那次', () => {expect(h.persisted).toEqual([{ sessionId: 's1', detail: { message: 'deferred error' } }]);});+ // Unit regression: a capacity terminal before the user row persists changes+ // owner from generic recovery to the group. Existing flush coverage surfaced+ // the error and finalized the Worker before handoff; transfer must do neither.+ it('transfers the deferred error and Worker terminal exactly once to group recovery', () => {+ const h = createHarness();+ const owner = { generation: 3, clientId: 'capacity-turn' };+ const detail = { reason: 'upstream-overload', message: 'model at capacity' };+ const orcaTerminal = createOrcaTerminal();+ h.book.stashSuppressedError('s1', detail, null, owner);+ h.book.stashOrcaSuppressedTerminal('s1', orcaTerminal);+ expect(h.book.takeDeferredError('s1', { ...owner, generation: 4 })).toBeNull();+ expect(h.book.takeDeferredError('s1', owner)).toEqual({ detail, orcaTerminal });+ expect(h.book.takeDeferredError('s1', owner)).toBeNull();+ h.book.teardown('s1');+ expect(h.persisted).toEqual([]);+ expect(h.surfaced).toEqual([]);+ expect(h.orcaFinalized).toEqual([]);+ });++ it('does not transfer a deferred error that a retry attempt already owns', () => {+ const h = createHarness();+ const owner = { generation: 3, clientId: 'capacity-turn' };+ h.book.stashSuppressedError('s1', { message: 'model at capacity' }, null, owner);+ h.book.beginAttempt('s1', 9);+ expect(h.book.takeDeferredError('s1', owner)).toBeNull();+ expect(h.book.surfaceSuppressedError('s1', { attemptToken: 9 })).toBe(true);+ expect(h.persisted).toEqual([{ sessionId: 's1', detail: { message: 'model at capacity' } }]);+ });+it('释放 suppressed error 后回收无其它 owner 的 current attempt', () => {const h = createHarness();h.book.beginAttempt('s1', 11);diff --git a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.tsindex e89373a69d..62abc2f14a 100644--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts@@ -443,6 +443,7 @@ export interface AgentInputCoordinatorDeps {* (docs/product-rules/provider-groups.md §6.1)。返回换电脑的原因时,这次错误照常成为当前状态* (重试入口、限额等待候选都绑定它),只是先不呈现:投影里不带 error,改带「正在换一台电脑继续」,* 直到 host 调 `releaseProviderGroupSwitchHold`,或续跑 / 用户接手换掉了这次错误。+ * 过载时先问这个判定:能换电脑就跳过通用同机自动续跑,及时消费受邀者的切换凭证。*/providerGroupSwitchCandidate?: (sessionId: string,@@ -468,7 +469,12 @@ export interface AgentInputCoordinatorDeps {*/onResumableTurnErrorDiscarded?: (sessionId: string,- options: { surfaceError: boolean; owner: SuppressedTurnErrorOwner },+ options: {+ surfaceError: boolean;+ owner: SuppressedTurnErrorOwner;+ /** 自愈候选改由供应商组接管:把暂存的失败交给这次登记,继续先不呈现。 */+ providerGroupSwitchHoldId?: number;+ },) => void;/** 在 vendor dispatch 前读取用户选中的本地/在线会话引用。 */resolveSessionReferences?: (@@ -6500,6 +6506,9 @@ export class AgentInputCoordinator {signals?: Omit<InterruptedTurnErrorSignals, 'message'>,): AutoResumeInfo | null {if (!this.deps.onResumableTurnError) return null;+ // 容量错误已经走到终态:组能接管时直接交接,不再叠加主进程的同机重试。+ // 其他中断仍先走自愈(如断线后在原电脑恢复);不能交给组的输入也保持原有处理。+ if (this.getProviderGroupSwitchCandidate(sessionId, item, message, signals) === 'overload') return null;try {return (this.deps.onResumableTurnError(sessionId, { ...(signals ?? {}), message }, item) ?? null@@ -6661,7 +6670,11 @@ export class AgentInputCoordinator {/** 被按住的 error 没能走到决策 → 通知 host 补落 error 行(不变量 I2)。 */private notifyResumableTurnErrorDiscarded(sessionId: string,- options: { surfaceError: boolean; owner: SuppressedTurnErrorOwner },+ options: {+ surfaceError: boolean;+ owner: SuppressedTurnErrorOwner;+ providerGroupSwitchHoldId?: number;+ },): void {try {this.deps.onResumableTurnErrorDiscarded?.(sessionId, options);@@ -6719,14 +6732,8 @@ export class AgentInputCoordinator {signals?: Omit<InterruptedTurnErrorSignals, 'message'>,): void {state.providerGroupSwitchHold = null;- const candidate = this.deps.providerGroupSwitchCandidate;- if (!candidate || !this.willNotifyUsageLimitedTurnError(state, item)) return;- let cause: AutoResumeAgentSwitchCause | null = null;- try {- cause = candidate(sessionId, { ...(signals ?? {}), message }, item);- } catch (err) {- log.warn('providerGroupSwitchCandidate failed', { sessionId, error: errorMessage(err) });- }+ if (!this.willNotifyUsageLimitedTurnError(state, item)) return;+ const cause = this.getProviderGroupSwitchCandidate(sessionId, item, message, signals);if (!cause) return;state.providerGroupSwitchHold = {id: ++this.providerGroupSwitchHoldSeq,@@ -6736,6 +6743,22 @@ export class AgentInputCoordinator {};}+ /** 只查询可由组接管的输入;判定不可用时保留通用重试与错误呈现。 */+ private getProviderGroupSwitchCandidate(+ sessionId: string,+ item: AgentInputQueuedMessage,+ message?: string,+ signals?: Omit<InterruptedTurnErrorSignals, 'message'>,+ ): AutoResumeAgentSwitchCause | null {+ if (!this.deps.onUsageLimitedTurnError || isSchedulerOriginItem(item) || item.sharedTaskAuthor) return null;+ try {+ return this.deps.providerGroupSwitchCandidate?.(sessionId, { ...(signals ?? {}), message }, item) ?? null;+ } catch (err) {+ log.warn('providerGroupSwitchCandidate failed', { sessionId, error: errorMessage(err) });+ return null;+ }+ }+/*** 换电脑这一趟先等原电脑恢复(那台连不上):进行中行改为「重新连接中 attempt/maxAttempts」;传 null 回到* 「正在换一台电脑继续」。只认仍有效的那次登记;返回是否更新了。@@ -7248,10 +7271,18 @@ export class AgentInputCoordinator {} else {state.error = terminalEvent.message ?? state.error;setErrorProjectionSignals(state, terminalEvent.signals);+ // 先登记换电脑,再移交候选期暂存的错误;否则 host 会先放出错误卡与 Worker 失败回报。+ if (outcome === 'kept' && active.item && terminalEvent.supersededByUser !== true) {+ this.holdForProviderGroupSwitch(+ sessionId, state, active.item, terminalEvent.message, terminalEvent.signals,+ );+ }if (deferredPersistSuppressed) {+ const holdId = this.getProviderGroupSwitchHoldId(sessionId);this.notifyResumableTurnErrorDiscarded(sessionId, {surfaceError: terminalEvent.supersededByUser !== true,owner: { generation: active.generation, clientId: active.item!.clientId },+ ...(holdId !== null ? { providerGroupSwitchHoldId: holdId } : {}),});}if (schedulerItem) {@@ -7267,17 +7298,6 @@ export class AgentInputCoordinator {outcome === 'kept' &&active.item &&terminalEvent.supersededByUser !== true;- // 与 onTurnEvent 的 persisted 分支对称。这条时序下横幅在持久化期间已经出现过、error 行也已落库,- // 这里至少让换电脑期间不再挂着横幅。- if (notifyUsageLimited) {- this.holdForProviderGroupSwitch(- sessionId,- state,- active.item!,- terminalEvent.message,- terminalEvent.signals,- );- }this.emit(sessionId);if (notifyUsageLimited) {this.notifyUsageLimitedTurnError(diff --git a/apps/desktop/src/main/maker-ipc/autoResumeBookkeeping.ts b/apps/desktop/src/main/maker-ipc/autoResumeBookkeeping.tsindex 482d59a47d..19f97d8221 100644--- a/apps/desktop/src/main/maker-ipc/autoResumeBookkeeping.ts+++ b/apps/desktop/src/main/maker-ipc/autoResumeBookkeeping.ts@@ -454,6 +454,18 @@ export class AutoResumeBookkeeping {return this.suppressedErrors.has(sessionId);}+ /** 供应商组接管尚未排期的候选错误:交出同一轮的详情与 Worker 终态,不落库、不提前回报失败。 */+ takeDeferredError(+ sessionId: string,+ owner: SuppressedTurnErrorOwner,+ ): { detail: SuppressedTurnError; orcaTerminal: OrcaSuppressedTerminal | null } | null {+ const entry = this.suppressedErrors.get(sessionId);+ if (!entry || entry.attemptToken !== null || !sameSuppressedTurnErrorOwner(entry.deferredOwner, owner)) return null;+ this.suppressedErrors.delete(sessionId);+ this.suppressedErrorClients.delete(sessionId);+ return { detail: entry.detail, orcaTerminal: entry.orcaTerminal };+ }+/** Product terminal error(非 continuation)记下随后那条同一代 unclaimed done。 */noteFailedTurnCompletionTail(sessionId: string, generation: number): void {this.failedTurnCompletionTails.set(sessionId, generation);diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex f078453d79..12f71f32af 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -18576,8 +18576,18 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)},onResumableTurnErrorDiscarded: (sessionId: string,- options: { surfaceError: boolean; owner: SuppressedTurnErrorOwner },+ options: { surfaceError: boolean; owner: SuppressedTurnErrorOwner; providerGroupSwitchHoldId?: number },) => {+ if (options.providerGroupSwitchHoldId !== undefined) {+ const deferred = autoResumeBookkeeping.takeDeferredError(sessionId, options.owner);+ if (deferred) {+ providerGroupHeldErrors.stash(sessionId, options.providerGroupSwitchHoldId, deferred.detail);+ if (deferred.orcaTerminal) {+ providerGroupHeldWorkerTerminals.stash(sessionId, options.providerGroupSwitchHoldId, deferred.orcaTerminal);+ }+ }+ return;+ }if (options.surfaceError) {autoResumeBookkeeping.surfaceSuppressedError(sessionId, { deferredOwner: options.owner });} else {diff --git a/apps/desktop/src/main/provider-group/__tests__/service.test.ts b/apps/desktop/src/main/provider-group/__tests__/service.test.tsindex de10fb0c75..fc42765e47 100644--- a/apps/desktop/src/main/provider-group/__tests__/service.test.ts+++ b/apps/desktop/src/main/provider-group/__tests__/service.test.ts@@ -11,6 +11,7 @@ import type { ProviderGroupConfig, ProviderGroupMember } from '../../../shared/pimport type { ClaudeSubscriptionUsageSnapshot } from '../../../shared/claudeSubscriptionUsage';import type { ProviderGroupBinding, ProviderGroupRef } from '../bindings';import type { ProviderGroupDirectory, ResolvedMemberState, ResolvedProviderGroupMember } from '../directory';+import { PROVIDER_GROUP_FAILURE_COOLDOWN_MS } from '../cooling';import { createProviderGroupGuestSwitch, PROVIDER_GROUP_SWITCH_OFFER_TTL_MS } from '../guestSwitch';import { createProviderGroupRouter, PROVIDER_GROUP_DEFAULT_COOLDOWN_MS } from '../router';import { providerGroupCodexUsageSnapshot, type ProviderGroupCodexUsageSnapshot } from '../usage';@@ -44,6 +45,13 @@ function member(kind: ProviderGroupMember['kind'], agentDeviceId: string | null,}const LEASE = { recovery: 'lease' };+// Runtime handoff regression: overload must cool the failing member and consume+// a guest's offer just like limits. Earlier service coverage only sent limits;+// the coordinator regression covers which recovery owner receives this error.+const SWITCH_FAILURES = [+ { cause: 'usage-limit', signals: { sdkError: 'rate_limit' } },+ { cause: 'overload', signals: { reason: 'upstream-overload', codexErrorInfo: 'serverOverloaded' } },+] as const;const LOCAL = member('local', null, 'anthropic');const MINI = member('device', 'mini', 'anthropic-1a2b3c4d');const STUDIO = member('share', 'share:s1', 'anthropic');@@ -434,10 +442,10 @@ describe('nextAfterStartFailure', () => {});describe('onTurnError (automatic switch)', () => {- it('hands the task to the next computer and continues the turn with an activity row', async () => {+ it.each(SWITCH_FAILURES)('hands off, cools the member and continues after $cause', async ({ cause, signals }) => {const h = harness();h.bindings.set('s1', { providerId: 'anthropic', memberKey: 'local', at: 1 });- h.service.onTurnError('s1', { sdkError: 'rate_limit' }, 7);+ h.service.onTurnError('s1', signals, 7);await flush();expect(h.deps.leaseRecovery).toHaveBeenCalledWith('s1', 7);expect(h.deps.switchAgentLocation).toHaveBeenCalledWith('s1', {@@ -450,12 +458,16 @@ describe('onTurnError (automatic switch)', () => {// 交接后用新令牌续跑(旧会话关闭撤销了原来的等待)。expect(h.deps.rearmContinue).toHaveBeenCalledWith('s1', LEASE, expect.any(Number));expect(h.deps.continueSession).toHaveBeenCalledWith('s1', 99, expect.objectContaining({- agentSwitch: { from: 'local-name', to: `${MINI.key}-name`, cause: 'usage-limit' },+ agentSwitch: { from: 'local-name', to: `${MINI.key}-name`, cause },}));expect(h.deps.fallback).not.toHaveBeenCalled();- // 撞到用量上限的那台进入冷却,新任务不会分到它。- expect(h.router.coolingUntil('anthropic', 'local', MODEL)).toBe(1_000_000 + PROVIDER_GROUP_DEFAULT_COOLDOWN_MS);- expect(h.router.coolingUntil('anthropic', 'local', 'claude-sonnet-5')).toBeNull();+ // 限额按模型冷却,过载按账号短暂冷却;其他任务不会立即回到这台。+ expect(h.router.coolingUntil('anthropic', 'local', MODEL)).toBe(+ 1_000_000 + (cause === 'overload' ? PROVIDER_GROUP_FAILURE_COOLDOWN_MS : PROVIDER_GROUP_DEFAULT_COOLDOWN_MS),+ );+ expect(h.router.coolingUntil('anthropic', 'local', 'claude-sonnet-5')).toBe(+ cause === 'overload' ? 1_000_000 + PROVIDER_GROUP_FAILURE_COOLDOWN_MS : null,+ );});it('switches back to this computer with its provider when a remote member fails', async () => {@@ -1292,10 +1304,11 @@ describe('onTurnError for a shared user (the sharer’s group picks the computerreturn { ...h, service, guestSwitch, tick: (ms: number) => { clock += ms; } };}- it('hands off and reopens with the token when the group computer asks to switch', async () => {+ it.each(SWITCH_FAILURES)('hands off and reopens with the token after $cause', async ({ cause, signals }) => {const h = guestHarness();h.guestSwitch.offer('s1', 'token-aaaaaaaaaaaaaaaa');- h.service.onTurnError('s1', { sdkError: 'rate_limit' }, 7);+ expect(h.service.mayHandleTurnError('s1', signals)).toBe(true);+ h.service.onTurnError('s1', signals, 7);await flush();// 位置仍是同一个分享:强制重新交接。expect(h.deps.switchAgentLocation).toHaveBeenCalledWith('s1', {@@ -1307,7 +1320,7 @@ describe('onTurnError for a shared user (the sharer’s group picks the computer// 交接时重新打开带上凭证(这里交接是假的,凭证仍在等打开)。expect(h.guestSwitch.takeForOpen('s1')).toBe('token-aaaaaaaaaaaaaaaa');expect(h.deps.continueSession).toHaveBeenCalledWith('s1', 99, expect.objectContaining({- groupSwitch: { cause: 'usage-limit' },+ groupSwitch: { cause },}));const info = (h.deps.continueSession.mock.calls[0] as unknown[])[2] as Record<string, unknown>;expect(info).not.toHaveProperty('agentSwitch');@@ -1413,38 +1426,38 @@ describe('onTurnError for a shared user (the sharer’s group picks the computerdescribe('no error while switching (mayHandleTurnError + hooks)', () => {const LIMIT = { sdkError: 'rate_limit' };- it('predicts a switch only for bound tasks in a group that can still move them', () => {+ it.each(SWITCH_FAILURES)('predicts a switch only for a group that can move after $cause', ({ signals }) => {const h = harness();// 没归组、也没有分享者的凭证:照常先报错。- expect(h.service.mayHandleTurnError('s1', LIMIT)).toBe(false);+ expect(h.service.mayHandleTurnError('s1', signals)).toBe(false);h.bindings.set('s1', { providerId: 'anthropic', memberKey: 'local', at: 1 });- expect(h.service.mayHandleTurnError('s1', LIMIT)).toBe(true);+ expect(h.service.mayHandleTurnError('s1', signals)).toBe(true);// 换到哪台都一样的失败不换。expect(h.service.mayHandleTurnError('s1', { message: 'prompt is too long', sdkError: 'invalid_request' })).toBe(false);const off = harness({ autoSwitch: false });off.bindings.set('s1', { providerId: 'anthropic', memberKey: 'local', at: 1 });- expect(off.service.mayHandleTurnError('s1', LIMIT)).toBe(false);+ expect(off.service.mayHandleTurnError('s1', signals)).toBe(false);// 组里只剩这一台电脑:换不了。const alone = harness({ members: [LOCAL] });alone.bindings.set('s1', { providerId: 'anthropic', memberKey: 'local', at: 1 });- expect(alone.service.mayHandleTurnError('s1', LIMIT)).toBe(false);+ expect(alone.service.mayHandleTurnError('s1', signals)).toBe(false);});- it('predicts a switch for a shared task only with a fresh token from the group computer', () => {+ it.each(SWITCH_FAILURES)('requires a fresh token from the group computer after $cause', ({ signals }) => {let clock = 0;const guestSwitch = createProviderGroupGuestSwitch(() => clock);const h = harness({ row: { agentDeviceId: 'share:share-from-alice', providerId: 'alice-anthropic' } });const service = createProviderGroupService({ ...h.deps, guestSwitch });- expect(service.mayHandleTurnError('s1', LIMIT)).toBe(false);+ expect(service.mayHandleTurnError('s1', signals)).toBe(false);guestSwitch.offer('s1', 'token-aaaaaaaaaaaaaaaa');- expect(service.mayHandleTurnError('s1', LIMIT)).toBe(true);+ expect(service.mayHandleTurnError('s1', signals)).toBe(true);// 只看不取:之后的换电脑仍拿得到凭证。expect(guestSwitch.claim('s1')).toBe(true);guestSwitch.offer('s1', 'token-bbbbbbbbbbbbbbbb');clock += PROVIDER_GROUP_SWITCH_OFFER_TTL_MS + 1;- expect(service.mayHandleTurnError('s1', LIMIT)).toBe(false);+ expect(service.mayHandleTurnError('s1', signals)).toBe(false);});it('reports a successful switch and never hands back', async () => {diff --git a/docs/product-rules/provider-groups.md b/docs/product-rules/provider-groups.mdindex 98a6aa275a..50147d0cb3 100644--- a/docs/product-rules/provider-groups.md+++ b/docs/product-rules/provider-groups.md@@ -301,7 +301,8 @@已经都不能用。这些照现有方式报错。- **其余一律换**,不再只认列出来的错误:用量上限、额度或余额用完、请求频率限制;登录失效、被拒绝或被停用;那台离线、不可达、关闭了远程控制或远程调用、分享被暂停或删除、不提供这个模型、版本太旧、没装这个 Agent;Agent 启动失败、一轮中途意外退出;- 服务报错、过载或超时(偶发一次先由中断自愈在同一台重试,重试用尽才到这里,即「同一台连续失败才算」);以及其他认不出的失败+ 模型容量不足或服务过载(终态错误到达主进程时,组能接管就优先换电脑,不再叠加通用同机自动续跑;Agent 内部已有的有界重试保留);+ 服务报错或超时(偶发一次先由中断自愈在同一台重试,重试用尽才到这里,即「同一台连续失败才算」);以及其他认不出的失败(活动记录写「{原电脑} 出了问题,已换到 {新电脑} 继续」)。- **换时先不先等**:只是连接断了(连续拉不到那台、对方 Cindy 重启后会话没了)先等它恢复,恢复了留在原电脑;可能连不上(读取放弃、分享连不上、太忙)先现读一次,确实连不上才等,连得上就直接换;其余不等。见下面「连不上先等它恢复」。@@ -403,6 +404,7 @@电脑、或换到哪台都一样的失败,只转出原来的错误。- 任务所在的电脑只在持有这张凭证时才换:分享被暂停、删除、撤权是分享本身的问题,没有凭证,不会触发换电脑。凭证只用于紧随其后的那次错误(2 分钟内);用户亲自接手(发消息、重试、换模型)即作废。+ 容量或过载错误已有有效凭证时立即交接,不先走通用同机自动续跑,避免凭证在反复重试中失效。- 换法与组所在电脑自己的任务相同:任务的位置仍是同一个分享,强制交接(全量交接 + 全新原生会话,分隔条写「Agent 已改到另一台电脑上运行」,不写电脑名称),重新打开时带回凭证,组所在电脑据此避开这一轮换下来的电脑;然后按额度重置后自动继续的路径续跑这一轮,活动记录写「已自动换一台电脑继续」。交接没成时交回原有的