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。

merge: sync main and preserve scheduled baseline revisions

Yuewei-LLba7267549950
diff --cc apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.ts
index 08b7a3b8c6,80634a92d6..2c8148d548
--- a/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.ts
@@@ -48,25 -45,34 +48,77 @@@ describe('one-run automation model pref
await scope.restore('task');
expect(h.state()).toEqual({ profile: h.original, baseline: null });
});
+ // Unit: location is part of the durable restore record, including explicit local null.
+ it.each([null, 'shared:owner'])('restores the original Agent location %j after restart', async (device) => {
+ const h = scopeFixture('high', false, device);
+ const scopeId = await h.scope.begin('task');
+ h.automate();
+ await createScheduledModelScope(h.deps).restore('task', scopeId);
+ expect(h.state()).toEqual({ profile: h.original, baseline: null });
+ });
+ // Merge regression, unit: old baselines have no location. A repeated automation
+ // must capture that missing axis before moving the task, preserving the old model.
+ it.each([null, 'shared:owner'])('upgrades a legacy baseline at %j before a location change', async (device) => {
+ const h = scopeFixture('high', false, device);
+ const { agentDeviceId: _location, ...legacy } = h.original;
+ await h.deps.write('task', { ...legacy, scopeId: 'legacy-scope' });
- expect(await h.scope.begin('task')).toBe('legacy-scope');
++ // Companion baseline writes now require the revision captured with the route.
++ const scope = createScheduledModelScope({ ...h.deps,
++ read: async () => ({ ...await h.deps.read(), profileRevision: 'A' }),
++ write: async (id, baseline, revision) => {
++ if (baseline && revision !== 'A') return false;
++ await h.deps.write(id, baseline);
++ return true;
++ },
++ });
++ expect(await scope.begin('task')).toBe('legacy-scope');
+ h.automate();
+ await createScheduledModelScope(h.deps).restore('task', 'legacy-scope');
+ expect(h.state()).toEqual({ profile: h.original, baseline: null });
+ });
++ // Merge regression, unit: a profile save can invalidate a legacy location
++ // upgrade after its read. A rejected durable write must stop the automation
++ // before it moves the task; earlier coverage only exercised successful writes.
++ it('retries a legacy location upgrade when the profile changes before writing', async () => {
++ const h = scopeFixture('high', false, 'shared:owner');
++ const { agentDeviceId: _location, ...legacy } = h.original;
++ await h.deps.write('task', { ...legacy, scopeId: 'legacy-scope' });
++ const saved = h.state().baseline;
++ const scope = createScheduledModelScope({ ...h.deps,
++ read: async () => ({ ...await h.deps.read(), profileRevision: 'A' }),
++ write: async () => false,
++ });
++ await expect(scope.begin('task')).rejects.toThrow(ScheduledModelSelectionBusyError);
++ expect(h.state()).toEqual({ profile: h.original, baseline: saved });
++ });
+ // #6895 unit regression: preparing a newly saved route may defer/fail. The
+ // stale session row must not become durable recovery state in that case.
+ it('does not capture an old baseline when preparing the saved choice fails', async () => {
+ const h = scopeFixture();
+ const prepareBaseline = vi.fn(async () => { throw new ScheduledModelSelectionBusyError('waiting'); });
+ const scope = createScheduledModelScope({ ...h.deps, prepareBaseline });
+ await expect(scope.begin('task')).rejects.toThrow(ScheduledModelSelectionBusyError);
+ expect(h.state().baseline).toBeNull();
+ await h.scope.begin('task');
+ // Existing scopes preserve the owner's original choice without switching
+ // away from the automation just to capture it again.
+ expect(await scope.begin('task')).toBe('scope-1');
+ expect(prepareBaseline).toHaveBeenCalledTimes(1);
+ });
+ // #6895 unit regression: a lane outside the save's lock snapshot can see
+ // Profile B after preparation applied A. Do not stamp A with B's revision.
+ it('retries capture when the profile changes during route preparation', async () => {
+ const h = scopeFixture();
+ let profileRevision = 'A';
+ const write = vi.fn(h.deps.write);
+ const scope = createScheduledModelScope({ ...h.deps, write,
+ read: async () => ({ ...await h.deps.read(), profileRevision }),
+ prepareBaseline: async () => { profileRevision = 'B'; },
+ });
+ await expect(scope.begin('task')).rejects.toThrow(ScheduledModelSelectionBusyError);
+ expect(write).not.toHaveBeenCalled();
+ expect(h.state().baseline).toBeNull();
+ });
// PR #6559 + #6579 integration: the persisted scope must restore an
// Ultrafast owner after automation/restart. Existing cases used booleans;
// minimal failure is baseline JSON with fastMode='ultrafast'. Unit tier.
diff --cc apps/desktop/src/main/maker-ipc/register.ts
index 740839eb83,673d6a56b8..b6069b2440
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@@ -197,7 -199,7 +199,7 @@@ import
readInputDeliveryClientIds,
} from '@cindy/device-link';
import { and, asc, desc, eq, gte, inArray, isNull, like, lt, or, sql } from 'drizzle-orm';
- import { applyScheduledModelSelection, createScheduledModelScope, resolveScheduledModelSelection, ScheduledModelSelectionBusyError, type ScheduledModelSelection, type ScheduledModelSelectionLease } from './scheduledModelSelection';
-import { applyScheduledModelSelection, createScheduledModelScope, writeScheduledModelBaselineIfProfileCurrent, ScheduledModelSelectionBusyError, type ScheduledModelSelection, type ScheduledModelSelectionLease } from './scheduledModelSelection';
++import { applyScheduledModelSelection, createScheduledModelScope, resolveScheduledModelSelection, writeScheduledModelBaselineIfProfileCurrent, ScheduledModelSelectionBusyError, type ScheduledModelSelection, type ScheduledModelSelectionLease } from './scheduledModelSelection';
import { parseScheduledModelBaseline } from '../../shared/scheduledModelBaseline';
import { recordTurnModelChange, type TurnModelIdentity } from './turnModelChange';
import { app, BrowserWindow, dialog, ipcMain, shell, type IpcMainInvokeEvent } from 'electron';
@@@ -10991,12 -11100,15 +11101,17 @@@ export function registerMakerIpc(maker
const [row] = await getDbClient().drizzle.select({
agentKind: sessions.agentKind, model: sessions.model, providerId: sessions.providerId,
effort: sessions.effort, fastMode: sessions.fastMode, baseline: sessions.scheduledModelBaseline,
+ agentDeviceId: sessions.agentDeviceId,
- status: sessions.status,
- }).from(sessions).where(eq(sessions.id, sessionId)).limit(1);
- return row?.status === 'active' ? { baseline: row.baseline, profile: {
+ status: sessions.status, botId: botProfiles.id, profileVersion: botProfiles.currentVersion,
+ }).from(sessions)
+ .leftJoin(botSessionLinks, and(eq(botSessionLinks.sessionId, sessions.id),
+ isNull(botSessionLinks.archivedAt), inArray(botSessionLinks.role, ['canonical', 'group', 'channel', 'thread'])))
+ .leftJoin(botProfiles, eq(botProfiles.id, botSessionLinks.botId))
+ .where(eq(sessions.id, sessionId)).limit(1);
+ return row?.status === 'active' ? { baseline: row.baseline,
+ profileRevision: row.botId ? JSON.stringify([row.botId, row.profileVersion]) : null, profile: {
agentKind: dbToMakerAgentKind(row.agentKind), model: row.model, providerId: row.providerId,
+ agentDeviceId: row.agentDeviceId,
effort: row.effort, fastMode: row.fastMode,
} } : null;
},
diff --cc apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts
index dda4811d19,a72d971ed1..528bc2419b
--- a/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts
+++ b/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts
@@@ -44,17 -44,25 +46,37 @@@ export function createScheduledModelSco
assertOwner(owner);
if (!row) return undefined;
const existing = parseScheduledModelBaseline(row.baseline);
- if (existing) return existing.scopeId;
+ if (existing) {
+ // Older baselines predate location overrides. Capture the current location
+ // before this automation can move it, without replacing the owner's model.
+ if (existing.agentDeviceId === undefined) {
- await deps.write(sessionId, { ...existing, agentDeviceId: row.profile.agentDeviceId ?? null });
++ const written = await deps.write(sessionId,
++ { ...existing, agentDeviceId: row.profile.agentDeviceId ?? null }, row.profileRevision);
++ if (written === false) {
++ throw new ScheduledModelSelectionBusyError('Companion profile changed during baseline upgrade');
++ }
+ }
+ return existing.scopeId;
+ }
+ const profileRevision = row.profileRevision;
+ // Settings may have committed while their asynchronous runtime refresh is
+ // still queued. Align the owner under this same send lease before capture.
+ if (deps.prepareBaseline) {
+ await deps.prepareBaseline(sessionId);
+ assertOwner(owner);
+ row = await deps.read(sessionId);
+ assertOwner(owner);
+ if (!row) return undefined;
+ }
+ if (row.profileRevision !== profileRevision) {
+ throw new ScheduledModelSelectionBusyError('Companion profile changed during baseline preparation');
+ }
const scopeId = deps.createId();
- await deps.write(sessionId, { ...row.profile, agentDeviceId: row.profile.agentDeviceId ?? null,
- effort: row.profile.effort || null, scopeId });
- const written = await deps.write(sessionId, { ...row.profile, effort: row.profile.effort || null, scopeId }, profileRevision);
++ const written = await deps.write(sessionId, { ...row.profile, agentDeviceId: row.profile.agentDeviceId ?? null,
++ effort: row.profile.effort || null, scopeId }, profileRevision);
+ if (written === false) {
+ throw new ScheduledModelSelectionBusyError('Companion profile changed during baseline capture');
+ }
return scopeId;
},
async restore(sessionId: string, expectedScopeId?: string): Promise<void> {