Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix: restore archived model selection before direct send
Dash3e3fb4c2c785
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaModelSelectionIntent.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaModelSelectionIntent.test.tsindex 525fb6f2df..083f1a59ee 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaModelSelectionIntent.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaModelSelectionIntent.test.ts@@ -12,7 +12,19 @@ const branches: string[] = [];const confirmationChecks: string[] = [];let applySelectionAdapter = '';let piWindowOverride = '';+let directSendAdapter = '';+let archivedAdmission = '';+let terminalGuard = '';function visit(node: ts.Node) {+ if (ts.isBinaryExpression(node) && node.left.getText(source) === 'pendingAgentSwitchApplyHolder') {+ directSendAdapter = node.right.getText(source);+ }+ if (ts.isVariableDeclaration(node) && node.name.getText(source) === 'canStageArchivedSelection') {+ archivedAdmission = node.initializer!.getText(source);+ }+ if (ts.isIfStatement(node) && node.expression.getText(source) === "runtimeStatus.status !== 'active' && !canStageArchivedSelection") {+ terminalGuard = node.getText(source);+ }if (ts.isPropertyAssignment(node)) {if (node.name.getText(source) === 'confirmedTargetPressure' && node.initializer.getText(source).includes('runtimeStatus.orcaRole')) {confirmationChecks.push(node.initializer.getText(source));@@ -37,6 +49,61 @@ const orcaIdentities = [];describe('Orca model-only picker intent admission', () => {+ // PR #6403 P1: the composer already restores archived tasks, but Goal's+ // direct-send lease did not. Execute the real lease, send boundary and model+ // admission together; earlier picker tests stop before this boundary (unit).+ it.each(['archived', 'restore-failed', 'cancelled'] as const)('handles archived direct-send selection: %s', async mode => {+ const compile = (expression: string, bindings: Record<string, unknown>) => {+ const js = ts.transpileModule(`return ${expression};`, { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText;+ return new Function(...Object.keys(bindings), js)(...Object.values(bindings));+ };+ const row = { status: 'archived' };+ const pending = createPendingAgentSwitchRegistry();+ pending.set('s1', { sameAgentSelection: true, targetAgentKind: 'codex', model: 'new', providerId: 'provider' });+ const applied = vi.fn(() => ({ deferred: false }));+ const throwIpcError = (code: string, message: string) => { throw new Error(`[${code}] ${message}`); };+ const admission = compile(`(internalOptions) => {+ const canStageArchivedSelection = ${archivedAdmission};+ ${terminalGuard}+ return applied();+ }`, { runtimeStatus: row, applied, throwIpcError });+ const selectSameAgentModel = compile(applySelectionAdapter, { throwIpcError,+ applySessionRuntimeSelection: (_id: string, _model: string, _provider: unknown, _axes: unknown, opts: unknown) => admission(opts),+ });+ const release = vi.fn();+ const acquire = vi.fn(async () => release);+ const restore = vi.fn(async () => {+ if (mode === 'restore-failed') throw new Error('restore failed');+ row.status = 'active';+ });+ const deps = { pendingSwitches: pending, getLiveSession: () => ({ isTurnRunning: () => false }),+ selectSameAgentModel, log: { info: vi.fn(), warn: vi.fn() } } as unknown as MakerSessionAgentSwitchHandlerDeps;+ const directSend = compile(directSendAdapter, {+ agentSwitchPending: pending, restoreArchivedSessionForSend: restore,+ acquireSendToSessionLock: acquire, reconcileBotModelRoute: vi.fn(),+ applyPendingAgentSwitchIfIdle, agentSwitchDeps: deps, contextOverflowRolloverHolder: null,+ });+ const controller = new AbortController();+ if (mode === 'cancelled') controller.abort();+ if (mode === 'archived') {+ const lease = await directSend('s1', controller.signal);+ expect(row.status).toBe('active');+ expect(applied).toHaveBeenCalledOnce();+ expect(pending.get('s1')).toBeUndefined();+ expect(restore.mock.invocationCallOrder[0]).toBeLessThan(acquire.mock.invocationCallOrder[0]);+ expect(release).not.toHaveBeenCalled();+ lease.release();+ expect(release).toHaveBeenCalledOnce();+ } else {+ await expect(directSend('s1', controller.signal)).rejects.toThrow(mode === 'restore-failed' ? 'restore failed' : /abort/i);+ expect(row.status).toBe('archived');+ expect(applied).not.toHaveBeenCalled();+ expect(pending.get('s1')).toBeDefined();+ if (mode === 'cancelled') expect(restore).not.toHaveBeenCalled();+ else expect(acquire).not.toHaveBeenCalled();+ }+ });+it.each(['lead', 'worker'] as const)('stages %s model and axes on both execution locations until send', async orcaRole => {expect(branches).toHaveLength(2);for (const branch of branches) {diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex af33cbf749..c009f3b005 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -10433,6 +10433,12 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)log,});pendingAgentSwitchApplyHolder = async (sessionId, signal, selection, beforeApply) => {+ // Match composer sends: restore before applying a user's staged model.+ // The restore owns the same route lock, so run it before acquiring the+ // direct-send lease (which is deliberately held until the caller sends).+ if (!signal?.aborted && agentSwitchPending.get(sessionId)?.sameAgentSelection) {+ await restoreArchivedSessionForSend(sessionId);+ }let stage = 'direct-send:acquire';let deferPendingApply = false;const release = await acquireSendToSessionLock(sessionId, undefined, () => stage);@@ -20654,7 +20660,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)}// 归档/删除写入与本 handler 共用 session route lock。归档后仍允许用户// 暂存下一次发送的选择,但不得应用 runtime 或允许自动更新重建 override。- // 删除任务始终拒绝;先选后归档时仍由归档 cleanup 清除旧意图。+ // 删除任务始终拒绝;暂存意图留到发送前先恢复任务再应用。const [runtimeStatus] = await getDbClient().drizzle.select({status: sessions.status,diff --git a/docs/dev-rules/model-catalog-runtime.md b/docs/dev-rules/model-catalog-runtime.mdindex 70cb3e9702..3a2480fd6a 100644--- a/docs/dev-rules/model-catalog-runtime.md+++ b/docs/dev-rules/model-catalog-runtime.md@@ -50,11 +50,12 @@ thread 配置,同时设置窗口和 90% 自动压缩预算,保留原生 5%### 归档任务的模型设置归档任务允许用户调整模型、推理强度与 Fast,不要求先恢复,也不因设置变化恢复任务。-模型选择沿用活动任务的暂存意图,下一次发送先恢复任务再应用;暂存意图仍只在被控端+模型选择沿用活动任务的暂存意图,下一次发送(含 Goal 直发)先经普通任务恢复入口恢复+任务再应用;受管任务的恢复限制保持不变。暂存意图仍只在被控端内存中保留,不新增跨进程恢复。已有模型意图时,推理强度与 Fast 更新该意图;否则只保存任务字段,不重建归档时清掉的 runtime 状态。自动模型变更与已删除任务仍拒绝。本机桌面、设备互联与手机共用此处理,见 `maker-ipc/register.ts` 和-`sessionRuntimeControlWiring.test.ts` 的归档生命周期回归。+`sessionRuntimeControlWiring.test.ts` 与 `orcaModelSelectionIntent.test.ts` 的归档生命周期回归。### 默认型号与预览版的选择