mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-03 22:00:34 +08:00
fix(provider-group): 「全部停止」同时作废进行中的换电脑
「全部停止」(stopSessionBackgroundTasksHandler) 只撤自动续跑簿记并关闭会话, 不经过输入协调器的 Stop:错误与重试入口仍在,供应商组的句柄仍有效;也不作废 供应商组这一趟(review PRRT_kwDOTgdRUs6reh5c)。结果是: - 检查期间(句柄已提前取得)停止:继续换电脑并续跑——本 PR 上一提交引入; - 等原电脑恢复期间停止:同样继续——main 上已存在,这里一并修复。 只在 register 的「全部停止」注册处,于 resetAutomaticRecoveryForExplicitStop 之后 调 providerGroupService?.noteUserAction,落实 provider-groups.md §6.1「用户停止不换」。 不改 resetAutomaticRecoveryForExplicitStop 本身与其他停止入口;对不归组的任务近乎 no-op,分享来的供应商上未用掉的「需要换一台」凭证随之作废(与 §6.1 一致)。 回归经真实 registerStopSessionBackgroundTasksHandler 与 register 里 noteSessionReset 的接线原文覆盖检查期间、等 B 期间两种停止,并断言共用的显式停止清理不碰供应商组。 Signed-off-by: ficowang <fico@xd.com>
This commit is contained in:
@@ -5987,7 +5987,12 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
|
||||
closeSession: (sessionId) => maker.closeSession(sessionId),
|
||||
clearBackgroundActivity: clearClaudeSessionBackgroundActivity,
|
||||
// 「全部停止」是会话级止损:已排期的自动续跑必须撤掉,别在用户喊停后又补发一条。
|
||||
noteSessionReset: resetAutomaticRecoveryForExplicitStop,
|
||||
// 它不经过输入协调器的 Stop(错误与重试入口仍在):供应商组进行中的换电脑也要作废,
|
||||
// 用户停止不换(provider-groups.md §6.1,#5880)。
|
||||
noteSessionReset: (sessionId) => {
|
||||
resetAutomaticRecoveryForExplicitStop(sessionId);
|
||||
providerGroupService?.noteUserAction(sessionId);
|
||||
},
|
||||
notifyGoalStop: pauseGoalBeforeExplicitStop,
|
||||
});
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
*/
|
||||
import type { SessionStatus } from '@cindy/maker-core';
|
||||
import type { ProviderView } from '@cindy/model-providers';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { ScriptTarget, transpileModule } from 'typescript';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { CONTINUE_AFTER_ERROR_PROMPT } from '../../../shared/interruptedTurn';
|
||||
@@ -14,6 +16,8 @@ import type { ProviderGroupConfig, ProviderGroupMember } from '../../../shared/p
|
||||
import { AgentInputCoordinator, type AgentInputCoordinatorDeps } from '../../maker-ipc/agent-input-coordinator';
|
||||
import { shouldPreserveWaitingContinuationOnlyAutoResume } from '../../maker-ipc/interruptedTurnAutoResume';
|
||||
import { createSessionBindingLifecycle, runSessionCloseCleanup } from '../../maker-ipc/sessionBindingLifecycle';
|
||||
import type { IpcHandler } from '../../maker-ipc/ipcHandlerRegistry';
|
||||
import { registerStopSessionBackgroundTasksHandler } from '../../maker-ipc/stopSessionBackgroundTasksHandler';
|
||||
import type { ProviderGroupBinding } from '../bindings';
|
||||
import type { ProviderGroupDirectory, ResolvedMemberState, ResolvedProviderGroupMember } from '../directory';
|
||||
import { createProviderGroupRouter } from '../router';
|
||||
@@ -78,6 +82,32 @@ function item(clientId: string, text: string): AgentInputQueuedMessage {
|
||||
} as AgentInputQueuedMessage;
|
||||
}
|
||||
|
||||
/** register.ts 里「全部停止」注册处的 noteSessionReset(生产接线原文)。 */
|
||||
const REGISTER_SOURCE = readFileSync(new URL('../../maker-ipc/register.ts', import.meta.url), 'utf8').replace(/\r\n/g, '\n');
|
||||
function stopAllRegistration(): string {
|
||||
const start = REGISTER_SOURCE.indexOf('registerStopSessionBackgroundTasksHandler(createElectronIpcHandlerRegistry(), {');
|
||||
const end = REGISTER_SOURCE.indexOf('\n });', start);
|
||||
expect(start).toBeGreaterThan(0);
|
||||
expect(end).toBeGreaterThan(start);
|
||||
return REGISTER_SOURCE.slice(start, end);
|
||||
}
|
||||
function productionStopAllNoteSessionReset(bindings: {
|
||||
resetAutomaticRecoveryForExplicitStop: (sessionId: string) => void;
|
||||
providerGroupService: { noteUserAction(sessionId: string): void } | null;
|
||||
}): (sessionId: string) => void {
|
||||
const registration = stopAllRegistration();
|
||||
const start = registration.indexOf(' noteSessionReset:');
|
||||
const end = registration.indexOf('\n notifyGoalStop:', start);
|
||||
expect(start).toBeGreaterThan(0);
|
||||
expect(end).toBeGreaterThan(start);
|
||||
const expression = registration.slice(start + ' noteSessionReset:'.length, end).trim().replace(/,$/, '');
|
||||
const compiled = transpileModule(`return (${expression});`, { compilerOptions: { target: ScriptTarget.ES2022 } }).outputText;
|
||||
return new Function('resetAutomaticRecoveryForExplicitStop', 'providerGroupService', compiled)(
|
||||
bindings.resetAutomaticRecoveryForExplicitStop,
|
||||
bindings.providerGroupService,
|
||||
) as (sessionId: string) => void;
|
||||
}
|
||||
|
||||
async function flush() {
|
||||
for (let i = 0; i < 200; i++) await Promise.resolve();
|
||||
}
|
||||
@@ -90,7 +120,7 @@ function gate() {
|
||||
|
||||
interface FakeSession {
|
||||
id: string;
|
||||
closeReason: 'unexpected' | 'agent-switch';
|
||||
closeReason: 'unexpected' | 'agent-switch' | 'requested';
|
||||
listeners: Set<(status: SessionStatus) => void>;
|
||||
onStatusChange(listener: (status: SessionStatus) => void): () => void;
|
||||
setInteractionListener(listener: unknown): void;
|
||||
@@ -309,11 +339,27 @@ function setup(options: { bComesBack?: boolean } = {}) {
|
||||
}
|
||||
|
||||
const markTried = vi.spyOn(router, 'markTried');
|
||||
// 「全部停止」的真实 IPC handler 与 register 里的 noteSessionReset 接线原文;resetAutomaticRecoveryForExplicitStop
|
||||
// (撤中断自愈 / silent-stop / 退避簿记,不碰输入协调器与供应商组)用 spy 代替,closeSession 接 maker.closeSession(requested)。
|
||||
const noteSessionReset = vi.fn((_sessionId: string) => {});
|
||||
let stopAllHandler: IpcHandler | null = null;
|
||||
registerStopSessionBackgroundTasksHandler({ handle: (_channel, handler) => { stopAllHandler = handler; } }, {
|
||||
closeSession: async () => closeSession(live, 'requested'),
|
||||
clearBackgroundActivity: () => {},
|
||||
noteSessionReset: productionStopAllNoteSessionReset({
|
||||
resetAutomaticRecoveryForExplicitStop: noteSessionReset,
|
||||
providerGroupService: service,
|
||||
}),
|
||||
notifyGoalStop: () => {},
|
||||
});
|
||||
return {
|
||||
coordinator,
|
||||
service,
|
||||
router,
|
||||
markTried,
|
||||
noteSessionReset,
|
||||
/** 用户点「全部停止」。 */
|
||||
stopAll: () => stopAllHandler!({}, SID),
|
||||
deps,
|
||||
hooks,
|
||||
row,
|
||||
@@ -486,4 +532,47 @@ describe('provider group failover vs. the terminal-error drain close (#5880)', (
|
||||
expectNothingDoneFor(h);
|
||||
expect(h.sendToAgent).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
// 「全部停止」(stopSessionBackgroundTasksHandler) 只关闭会话、撤自动续跑簿记,不走协调器的 Stop:
|
||||
// 换电脑这一趟也必须停下,不换、不续跑、不交回(provider-groups.md §6.1「用户停止」)。
|
||||
function expectStoppedByStopAll(h: ReturnType<typeof setup>) {
|
||||
expect(h.noteSessionReset).toHaveBeenCalledWith(SID);
|
||||
expect(h.closeContexts.at(-1)).toEqual({ closeReason: 'requested', preserveAutoResumeIntent: false });
|
||||
expect(h.deps.switchAgentLocation).not.toHaveBeenCalled();
|
||||
expect(h.deps.continueSession).not.toHaveBeenCalled();
|
||||
expect(h.deps.fallback).not.toHaveBeenCalled();
|
||||
expect(h.sendToAgent).toHaveBeenCalledTimes(1);
|
||||
}
|
||||
|
||||
it('stop all while the checks are pending stops the switch', async () => {
|
||||
const h = setup();
|
||||
h.pauseNextReadSessionRow();
|
||||
await h.failOnB();
|
||||
await flush();
|
||||
await h.stopAll();
|
||||
await h.releaseAndSettle();
|
||||
expectStoppedByStopAll(h);
|
||||
});
|
||||
|
||||
it('stop all while waiting for B to come back stops the switch', async () => {
|
||||
const h = setup();
|
||||
h.pauseNextProbe();
|
||||
await h.failOnB();
|
||||
await flush();
|
||||
expect(h.leaseResults).toEqual([expect.any(Object)]);
|
||||
await h.stopAll();
|
||||
await h.releaseAndSettle();
|
||||
expectStoppedByStopAll(h);
|
||||
});
|
||||
|
||||
it('register wires stop all to the provider group without changing the shared explicit-stop reset', () => {
|
||||
const registration = stopAllRegistration();
|
||||
expect(registration).toContain('resetAutomaticRecoveryForExplicitStop(sessionId);');
|
||||
expect(registration).toContain('providerGroupService?.noteUserAction(sessionId);');
|
||||
// 只接在「全部停止」:其他停止入口共用的 resetAutomaticRecoveryForExplicitStop 本身不碰供应商组。
|
||||
const start = REGISTER_SOURCE.indexOf('function resetAutomaticRecoveryForExplicitStop(');
|
||||
const end = REGISTER_SOURCE.indexOf('\n}\n', start);
|
||||
expect(start).toBeGreaterThan(0);
|
||||
expect(REGISTER_SOURCE.slice(start, end)).not.toContain('providerGroupService');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user