Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(provider-group): 创建会话时保留限额等待信息

Dash2d16649e8243
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.ts
index ac5db438da..5a1e9264af 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
@@ -14227,6 +14227,77 @@ describe('usage-limit wait (ordinary tasks)', () => {
sessionTotal: 0,
};
+ // Unit regression (#6611): direct send rejections missed the transaction's bootstrap
+ // wrappers. Drive the real transaction + coordinator for lazy creation and rehydrate;
+ // a verified quota error must keep its reset metadata and original queued input.
+ it.each([
+ { rehydrate: false, resetAtMs: 5_000_000 },
+ { rehydrate: true, resetAtMs: 5_000_000 },
+ { rehydrate: false, resetAtMs: null },
+ { rehydrate: true, resetAtMs: null },
+ ])('preserves bootstrap quota through the send transaction (%j)', async ({ rehydrate, resetAtMs }) => {
+ const h = createHarness();
+ const sid = 'quota-bootstrap';
+ const session: MakerSendTransactionSession = {
+ id: sid, instanceId: 'runtime', agentKind: 'claude-code', workDir: '/repo',
+ remoteHostId: null, isTurnRunning: () => false,
+ send: vi.fn(async (_message, opts) => {
+ await opts?.beforeProviderStart?.();
+ await opts?.onAccepted?.();
+ opts?.onDispatching?.();
+ return { accepted: true as const };
+ }),
+ };
+ const quota = new ProviderGroupUsageLimitError({ resetAtMs });
+ const bootstrap = vi.fn(async () => ({
+ session, didInjectOrcaInstructions: false, didInjectProjectContext: false,
+ })).mockRejectedValueOnce(quota);
+ const transaction = createMakerSendTransaction({
+ getSession: () => rehydrate ? session : undefined,
+ closeSession: async () => {}, preflightBotRuntimeResources: async () => {},
+ getSessionMeta: async () => ({}), ensureRemoteReadyForSessionStart: async () => {},
+ checkWorkDirExists: async () => true, isOrcaMcpHydrated: () => !rehydrate,
+ buildCreateOptsWithStderr: x => x, synthesizeOrcaVendorOptionsFromDb: async () => rehydrate,
+ readSessionExtraDirsFromDb: async () => [], readSessionWorkingDirFromDb: async () => '/repo',
+ readWorkingDirectoryRecoveryCreateOpts: async () => ({ agentKind: 'claude-code', workingDir: '/repo', model: 'claude-opus-4-7' }),
+ withRehydrateCloseSuppressed: async (_id, fn) => fn(), bootstrapSession: bootstrap,
+ markOrcaRoleIfNeeded: async () => {}, broadcastSessionCreated: () => {},
+ prepareSendUserMessage: async (_id, message) => message as string,
+ createDbMessage: async (id, row) => { await mocks.createMessage(id, row); },
+ isSessionRunningError: () => false, log: { info: () => {}, warn: () => {} },
+ });
+ h.sendToAgent.mockImplementation(async (...args) =>
+ (await transaction.sendToAgentAccepted(...args)).outcome);
+ h.coordinator.enqueue(sid, makeItem('original', 'original task'));
+ await flush();
+ await h.sendToAgent.mock.results[0].value.catch(() => {});
+ await flush();
+ expect(bootstrap).toHaveBeenCalledOnce();
+ expect(session.send).not.toHaveBeenCalled();
+ expect(h.onUserMessagePersisted).not.toHaveBeenCalled();
+ expect(h.onUsageLimitedTurnError).toHaveBeenCalledWith(sid,
+ expect.objectContaining({ usageLimit: true, providerGroupUsageLimit: { resetAtMs } }),
+ expect.objectContaining({ clientId: 'original' }), expect.any(Number));
+ expect(h.coordinator.getProjection(sid).error).toBe(quota.message);
+ expect(h.coordinator.getProjection(sid).pendingQueue[0].clientId).toBe('original');
+ if (resetAtMs === null) {
+ expect(h.coordinator.getProjection(sid).usageLimitWait).toBeNull();
+ return;
+ }
+ const token = h.onUsageLimitedTurnError.mock.calls[0][3];
+ expect(h.coordinator.armUsageLimitWait(sid, token, resetAtMs)).toBe(true);
+ expect(await h.coordinator.continueAfterUsageLimitReset(sid, token, INFO)).toBe('resumed');
+ await flush();
+ await h.sendToAgent.mock.results[1].value;
+ await flush();
+ expect(session.send).toHaveBeenCalledOnce();
+ expect(h.onUserMessagePersisted).toHaveBeenCalledOnce();
+ expect(h.sendToAgent.mock.calls[1][3].persistUserMessage).toMatchObject({
+ clientId: 'original', autoResumeInfo: INFO,
+ });
+ expect(h.coordinator.getProjection(sid).usageLimitWait).toBeNull();
+ });
+
// 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,
diff --git a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts b/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
index e6b552ded2..1585cb3ab1 100644
--- a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
+++ b/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
@@ -28,6 +28,7 @@ import {
toDesktopSessionDispatchOutcome,
} from '../maker-host/send-outcome.js';
import { isCredentialModeSwitchBusyError } from '../maker-host/codex-credential-switch.js';
+import { ProviderGroupUsageLimitError } from '../provider-group/failurePolicy.js';
import { routinePermissionSnapshot } from '../maker-host/routinePermission.js';
import { throwIpcError } from '../utils/ipcValidate.js';
import {
@@ -889,6 +890,9 @@ export function createMakerSendTransaction(deps: MakerSendTransactionDeps): Make
});
return { kind: 'session', session };
} catch (err) {
+ // Let the input coordinator own verified group quota waits; generic host
+ // failure results would erase the structured reset time before it sees it.
+ if (err instanceof ProviderGroupUsageLimitError) throw err;
if (isCredentialModeSwitchBusyError(err)) {
// 不映射成 SESSION_RUNNING:那会命中输入协调器的静默无限重试(250ms 一次),
// 用户看到消息永远排队(2026-07-03 实报)。CREDENTIAL_SWITCH_BUSY 由协调器
@@ -970,6 +974,8 @@ export function createMakerSendTransaction(deps: MakerSendTransactionDeps): Make
});
return { kind: 'session', session: lazySess };
} catch (err) {
+ // Same boundary as rehydrate: preserve the branded error and its reset data.
+ if (err instanceof ProviderGroupUsageLimitError) throw err;
if (isCredentialModeSwitchBusyError(err)) {
// 不映射成 SESSION_RUNNING:那会命中输入协调器的静默无限重试(250ms 一次),
// 用户看到消息永远排队(2026-07-03 实报)。CREDENTIAL_SWITCH_BUSY 由协调器