Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): recheck shadow status after model restoration
Chrisbf72c64d0f34
diff --cc apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.tsindex 4606f2770f,ca5fb023b9..629cef76f7--- a/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.ts@@@ -243,60 -237,6 +243,82 @@@ function botTaskDispatchHarnessreturn { ...loadBotTaskDispatch(scope), bootstrapped, sentTo, sendOptions, readAutoReviewHistory };}+// #6895 review: the cloud-room dispatcher bypassed the ordinary send transaction.+// Execute that production closure with the real restore scope (unit behavior in+// this existing guard fixture); assert the route used to send, not call strings.+describe('companion internal delivery after automation', () => {+ // #6895: rejected input must not bootstrap the old primary or consume its restore.+ it.each(['already-shadowed', 'shadowed-while-waiting'] as const)('preserves automation state when %s', async (timing) => {+ let shadowed = timing === 'already-shadowed';+ let baseline: string | null = 'saved-pi-route';+ const restore = vi.fn(async () => { baseline = null; });+ const reconcile = vi.fn(async () => undefined);+ const dbChain = { from: () => dbChain, where: () => dbChain,+ limit: async () => [{ role: 'canonical', botId: 'companion' }] };+ const h = botTaskDispatchHarness({ child: { permissionMode: 'auto', planModeEnabled: false } }, {}, {+ getDbClient: () => ({ drizzle: { select: () => dbChain } }),+ isShadowedCompanionCanonical, isCompanionShadowed: () => shadowed,+ scheduledModelScope: { restore }, reconcileBotModelRoute: reconcile,+ waitForSendToSessionLock: async () => { shadowed = true; },+ });+ expect(await h.dispatchBotSessionMessage({ targetSessionId: 'child', message: 'Late cloud input' }))+ .toMatchObject({ ok: false, errorCode: 'AGENT_NOT_READY' });+ expect(baseline).toBe('saved-pi-route');+ expect(restore).not.toHaveBeenCalled();+ expect(h.bootstrapped).toEqual([]);+ expect(h.sentTo).toEqual([]);+ if (timing === 'already-shadowed') expect(reconcile).not.toHaveBeenCalled();+ });+++ // #6895: hand-over may finish while restore awaits, before a turn exists.++ // Exercise both consumers of the post-restore routing decision, without timers.++ it.each(['live', 'queued'] as const)('rejects %s delivery when demoted during restoration', async (path) => {++ let shadowed = false;++ const dbChain = { from: () => dbChain, where: () => dbChain,++ limit: async () => [{ role: 'canonical', botId: 'companion' }] };++ const enqueue = vi.fn(async () => undefined);++ const h = botTaskDispatchHarness({ child: { permissionMode: 'auto', planModeEnabled: false } }, {++ child: { id: 'child', agentKind: 'pi', isTurnRunning: () => false, getStatus: () => 'active' },++ }, {++ getDbClient: () => ({ drizzle: { select: () => dbChain } }),++ isShadowedCompanionCanonical, isCompanionShadowed: () => shadowed,++ scheduledModelScope: { restore: async () => { shadowed = true; } },++ inputCoordinator: { ensureQueueRestored: async () => undefined, shouldQueueNewTurn: () => path === 'queued' },++ enqueueSendToSessionMessage: enqueue,++ });++ expect(await h.dispatchBotSessionMessage({ targetSessionId: 'child', message: 'Arrived during hand-over' }))++ .toMatchObject({ ok: false, errorCode: 'AGENT_NOT_READY' });++ expect(h.sentTo).toEqual([]);++ expect(enqueue).not.toHaveBeenCalled();++ });+++ it.each(['live', 'resumed'] as const)('restores before %s dispatch reads its model', async (path) => {+ const saved = { agentKind: 'pi' as const, model: 'saved-model', providerId: 'fixture-provider', effort: null, fastMode: false };+ let current = { ...saved, agentKind: 'codex' as 'codex' | 'pi', model: 'temporary-model' };+ let baseline: string | null = JSON.stringify({ ...saved, scopeId: 'automation' });+ const live: Record<string, object> = {};+ const makeLive = () => ({ id: 'child', ...current, isTurnRunning: () => false, getStatus: () => 'active' });+ if (path === 'live') live.child = makeLive();+ let dispatchedModel: string | undefined;+ const scope = createScheduledModelScope({+ createId: () => 'unused', read: async () => ({ profile: current, baseline }),+ write: async (_id, value) => { baseline = value ? JSON.stringify(value) : null; },+ isBusy: () => false,+ apply: async (_id, route) => { current = { ...current, ...route } as typeof current; if (path === 'live') live.child = makeLive(); },+ });+ const h = botTaskDispatchHarness({ child: { permissionMode: 'auto', planModeEnabled: false } }, live, {+ scheduledModelScope: scope,+ maker: { getSession: (id: string) => live[id], getSessionMeta: async () => ({ id: 'child', ...current, workDir: '/tmp/fixture/child' }) },+ bootstrapSession: async (opts: Record<string, unknown>) => ({ session: { id: 'child', model: opts.model } }),+ sendUserMessageWithAwaitedGitBaseline: async (session: { model: string }) => { dispatchedModel = session.model; return { accepted: true }; },+ });+ const result = await h.dispatchBotSessionMessage({ targetSessionId: 'child', message: 'Next owner message', clientId: 'cloud-room:next' });+ expect(result.ok).toBe(true);+ expect(dispatchedModel).toBe('saved-model');+ expect(baseline).toBeNull();+ });+});+// PR #6514: source receipts must not promote a prior owner's deployment permission.// Existing cold-start tests omitted the receipt. Execute the actual production dispatch closure// for both idle branches; guard tier because register.ts has no separately exported entry.diff --cc apps/desktop/src/main/maker-ipc/register.tsindex 1ce77c9261,250b8862f0..59a50adfb6--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@@ -11870,6 -11933,6 +11945,10 @@@ export function registerMakerIpc(maker// 失败时 shouldQueueNewTurn 仍返回 true(未恢复即入队),消息不丢。lockStage = 'queue-restore';await inputCoordinator.ensureQueueRestored(targetSessionId).catch(() => undefined);++ // Hand-over can finish while restoration/reconciliation awaits, before any++ // turn is running. Recheck before either queue admission or idle dispatch.++ const shadowedAfterRestore = await rejectShadowedCompanion(targetSessionId);++ if (shadowedAfterRestore) return shadowedAfterRestore;// Private messages and authorization continuations use the durable coordinator, including an idle// recipient. This preserves input provenance and one recovery/dispatch path.// Pending selections also need the canonical send transaction: it consumes the intent,