Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
refactor(maker-ipc): 直接复用可导入的关闭收尾入口
guyongdb71c3f80187
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 49ee5876dd..71a05daf9a 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@@ -12,7 +12,7 @@ import { admitTaskAction, bindTaskActionInput, taskActionInputGuard } from '../timport { AgentInputCoordinator } from '../agent-input-coordinator.js';import { ProviderGroupUsageLimitError } from '../../provider-group/failurePolicy.js';import type { Session } from '@cindy/maker-core';-import { createSessionBindingLifecycle } from '../sessionBindingLifecycle.js';+import { createSessionBindingLifecycle, createSessionCloseTeardown } from '../sessionBindingLifecycle.js';import { captureProductTurnFailureOwner, createDeferredProductTurnFailureGate } from '../productTurnFailureOwner.js';import { createProviderGroupHeldRecovery, createProviderGroupHeldTurnErrors } from '../../provider-group/heldTurnErrors.js';import { createProviderGroupHeldWorkerTerminals } from '../../provider-group/heldWorkerTerminals.js';@@ -14991,7 +14991,7 @@ describe('provider group computer switch hold', () => {// #6671/r4339380528, unit: queue acceptance releases the original hold, so a// runtime close after onPersisted used to erase the product owner before the// real coordinator's onDiscarded outcome. Prior tests manually cleared the- // gate and missed the upstream waiter. Execute register's actual close adapter+ // gate and missed the upstream waiter. Import the close adapter used by register// with the real lifecycle/coordinator/controller and a paused send transaction.it.each(['failed', 'closed-failed', 'closed-dispatched'] as const)('finishes the upstream waiter after a queued group continuation: %s', async outcome => {@@ -15035,21 +15035,13 @@ describe('provider group computer switch hold', () => {const delivered = vi.fn();const terminals = createProviderGroupHeldWorkerTerminals({ deliver: delivered, ownerKey: () => 'account' });const recovery = createProviderGroupHeldRecovery({ errors, terminals, settleFailure, ownerKey: () => 'account' });- // Run the production adapter rather than duplicating its close policy.- const source = readFileSync(new URL('../register.ts', import.meta.url), 'utf8');- const start = source.indexOf(' beforeCloseTeardown: (session: WiredSession) => {');- const end = source.indexOf(' finalizeClosedSession:', start);- const adapter = transpileModule('return ({' + source.slice(start, end) + '}).beforeCloseTeardown;', {- compilerOptions: { target: ScriptTarget.ES2022 },- }).outputText;- const beforeCloseTeardown = new Function(- 'botCompactRuntimeRefreshCoordinator', 'cancelDirectAbortReconciliation',- 'pendingFailedTurnAssistantPersistId', 'deferredProductTurnFailureGate',- 'rehydrateCloseSuppression', 'agentInputCoordinatorHolder', 'hasPendingProviderGroupContinuation', adapter,- )({ clearForClosedSession: vi.fn() }, vi.fn(), new Map(), gate,- { isSuppressed: () => false }, h.coordinator,- recovery.hasPendingContinuation,- ) as (runtime: Session) => void;+ const beforeCloseTeardown = createSessionCloseTeardown<Session>({+ clearCompactRuntimeRefresh: vi.fn(), cancelDirectAbortReconciliation: vi.fn(),+ clearPendingFailedTurnPersist: vi.fn(), isRehydrateCloseSuppressed: () => false,+ getProviderGroupSwitchHoldId: id => h.coordinator.getProviderGroupSwitchHoldId(id),+ hasPendingProviderGroupContinuation: recovery.hasPendingContinuation,+ clearDeferredProductTurnFailure: (id, runtime, options) => gate.clearSession(id, runtime, options),+ });const binding = createSessionBindingLifecycle({log: { warn: vi.fn() }, restoreInteractionListener: vi.fn(), beforeReplace: vi.fn(),onBind: vi.fn(), broadcastStatus: vi.fn(), captureCloseContext: () => null,diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex 1c7063f289..0c022217d3 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -347,6 +347,7 @@ import {} from './sessionQueueControl.js';import {createSessionBindingLifecycle,+ createSessionCloseTeardown,finalizeSessionClose,runSessionCloseCleanup,} from './sessionBindingLifecycle.js';@@ -5812,19 +5813,16 @@ const sessionBindings = createSessionBindingLifecycle<WiredSession, WiredSessioncleanupRuntimeState: () => cleanupClosedSessionRuntime(session),});},- beforeCloseTeardown: (session: WiredSession) => {- botCompactRuntimeRefreshCoordinator.clearForClosedSession(session);- cancelDirectAbortReconciliation(session.id);- pendingFailedTurnAssistantPersistId.delete(session.id);- // A group recovery owns the logical failure until fallback or real dispatch.- // Keep it through the exact close/bootstrap transaction, including a failed- // bootstrap. User stop and a new dispatch still clear all deferred receipts.- deferredProductTurnFailureGate.clearSession(session.id, session, {- preserveRecovery: (rehydrateCloseSuppression.isSuppressed(session.id) &&- agentInputCoordinatorHolder?.getProviderGroupSwitchHoldId(session.id) != null) ||- hasPendingProviderGroupContinuation(session.id),- });- },+ beforeCloseTeardown: createSessionCloseTeardown<WiredSession>({+ clearCompactRuntimeRefresh: session => botCompactRuntimeRefreshCoordinator.clearForClosedSession(session),+ cancelDirectAbortReconciliation,+ clearPendingFailedTurnPersist: sessionId => { pendingFailedTurnAssistantPersistId.delete(sessionId); },+ isRehydrateCloseSuppressed: sessionId => rehydrateCloseSuppression.isSuppressed(sessionId),+ getProviderGroupSwitchHoldId: sessionId => agentInputCoordinatorHolder?.getProviderGroupSwitchHoldId(sessionId),+ hasPendingProviderGroupContinuation,+ clearDeferredProductTurnFailure: (sessionId, session, options) =>+ deferredProductTurnFailureGate.clearSession(sessionId, session, options),+ }),finalizeClosedSession: (session: WiredSession, context) => {// 关闭前固化 live 用量(见 sessionLastLiveUsage.ts):冷 Pi 切模的窗口核实// 预检用它代替可能低报的 DB 快照(Greptile P1)。diff --git a/apps/desktop/src/main/maker-ipc/sessionBindingLifecycle.ts b/apps/desktop/src/main/maker-ipc/sessionBindingLifecycle.tsindex 42fb7376fe..7efb15b207 100644--- a/apps/desktop/src/main/maker-ipc/sessionBindingLifecycle.ts+++ b/apps/desktop/src/main/maker-ipc/sessionBindingLifecycle.ts@@ -123,6 +123,35 @@ export interface SessionCloseCleanupActions {cleanupRuntimeState(): void;}+/** Shared close adapter; dependencies stay live until the actual close boundary. */+export function createSessionCloseTeardown<S extends Pick<Session, 'id'>>(deps: {+ clearCompactRuntimeRefresh(session: S): void;+ cancelDirectAbortReconciliation(sessionId: string): void;+ clearPendingFailedTurnPersist(sessionId: string): void;+ isRehydrateCloseSuppressed(sessionId: string): boolean;+ getProviderGroupSwitchHoldId(sessionId: string): number | null | undefined;+ hasPendingProviderGroupContinuation(sessionId: string): boolean;+ clearDeferredProductTurnFailure(+ sessionId: string,+ session: S,+ options: { preserveRecovery: boolean },+ ): void;+}): (session: S) => void {+ return session => {+ deps.clearCompactRuntimeRefresh(session);+ deps.cancelDirectAbortReconciliation(session.id);+ deps.clearPendingFailedTurnPersist(session.id);+ // A group recovery owns the logical failure until fallback or real dispatch.+ // Keep it through the exact close/bootstrap transaction, including a failed+ // bootstrap. User stop and a new dispatch still clear all deferred receipts.+ deps.clearDeferredProductTurnFailure(session.id, session, {+ preserveRecovery: (deps.isRehydrateCloseSuppressed(session.id) &&+ deps.getProviderGroupSwitchHoldId(session.id) != null) ||+ deps.hasPendingProviderGroupContinuation(session.id),+ });+ };+}+/** A runtime rebuild may preserve input/recovery, but never skips runtime cleanup. */export function runSessionCloseCleanup(preserveAutoResumeIntent: boolean,