Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 排队项冷启动按库内状态恢复计划模式
Dash5c1177857eb7
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.tsindex dec5650cf1..2487c8de74 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.ts@@ -297,3 +297,68 @@ describe('Bot Session task cold start keeps the persisted permission and Plan',expect(setPlanMode).not.toHaveBeenCalled();});});++/**+ * 排队项的冷启动(发送事务 lazy-create 前的 reconcileCreateOptsAgainstDb):伙伴委派等 Host+ * 输入入队时 createOpts.planMode 恒为 false(那一条消息按普通执行)。排队期间运行实例关闭后,+ * drain 冷启动若照搬它,会话的计划模式就与库内不一致,绑定的心跳又会被判失配。会话起档必须+ * 取库内值;本轮意图由发送事务另按原快照传给 send,不经这里。+ */+describe('queued cold start keeps the persisted Plan', () => {+ const reconcileSource = (() => {+ const start = registerSource.indexOf('async function reconcileCreateOptsAgainstDb(');+ const end = registerSource.indexOf('\n // 冷 Pi 切模核实前', start);+ expect(start).toBeGreaterThanOrEqual(0);+ expect(end).toBeGreaterThan(start);+ return ts.transpileModule(`${registerSource.slice(start, end)}\nreturn reconcileCreateOptsAgainstDb;`, {+ compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.None },+ }).outputText;+ })();++ function reconcileWithRow(row: Record<string, unknown>) {+ const chain = { from: () => chain, where: () => chain, limit: async () => [row] };+ const stubs: Record<string, unknown> = {+ getDbClient: () => ({ drizzle: { select: () => chain } }),+ sessions: {},+ eq: () => undefined,+ log: { warn: () => undefined, info: () => undefined, debug: () => undefined },+ dbToMakerAgentKind: (kind: string) => (kind === 'cc' ? 'claude-code' : kind),+ permissionModeOrAsk,+ };+ const scope = new Proxy(stubs, {+ has: (target, key) => key in target || !(key in globalThis),+ get: (target, key) => {+ if (key === Symbol.unscopables) return undefined;+ if (key in target) return target[key as string];+ throw new ReferenceError(`unstubbed dependency of the production slice: ${String(key)}`);+ },+ });+ // eslint-disable-next-line @typescript-eslint/no-implied-eval+ return new Function('scope', `with (scope) { return (function () { ${reconcileSource} })(); }`)(+ scope,+ ) as (sessionId: string, co: Record<string, unknown>) => Promise<void>;+ }++ it.each([true, false])('starts a queued Host input with the stored Plan %s', async (planModeEnabled) => {+ const reconcile = reconcileWithRow({+ agentKind: 'cc',+ model: 'claude-opus-fixture',+ sdkSessionId: 'sdk-child',+ providerId: 'fixture-provider',+ effort: 'high',+ fastMode: false,+ permissionMode: 'auto',+ planModeEnabled,+ agentDeviceId: null,+ remoteHostId: null,+ });+ // 入队时的快照:伙伴委派排队项 planMode=false,权限是旧值。+ const co: Record<string, unknown> = {+ agentKind: 'claude-code',+ permissionMode: 'bypassPermissions',+ planMode: false,+ };+ await reconcile('child', co);+ expect(co).toMatchObject({ permissionMode: 'auto', planMode: planModeEnabled });+ });+});diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex ea24bb4a61..9faad8b7fe 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -9992,6 +9992,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)effort: sessions.effort,fastMode: sessions.fastMode,permissionMode: sessions.permissionMode,+ planModeEnabled: sessions.planModeEnabled,agentDeviceId: sessions.agentDeviceId,remoteHostId: sessions.remoteHostId,})@@ -10035,6 +10036,10 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)co.effort = (row.effort ?? undefined) as CreateOpts['effort'];co.fastMode = !!row.fastMode;co.permissionMode = permissionModeOrAsk(row.permissionMode);+ // 新建会话的计划模式按落库状态起档:排队项的 createOpts.planMode 是那一条消息的+ // 计划意图(伙伴委派等 Host 输入恒为 false),本轮意图仍由发送事务按原快照传给+ // send,这里只校正冷启动的会话状态,不改本轮是否以计划执行。+ co.planMode = row.planModeEnabled === true;} catch (error) {// context.rebuild clears sdk_session_id before the next bootstrap. If the// DB truth cannot be read, continuing with caller-supplied opts coulddiff --git a/apps/desktop/src/main/scheduler-host/runner.ts b/apps/desktop/src/main/scheduler-host/runner.tsindex e122dcfae1..8c057daa77 100644--- a/apps/desktop/src/main/scheduler-host/runner.ts+++ b/apps/desktop/src/main/scheduler-host/runner.ts@@ -444,7 +444,8 @@ export class MakerScheduleRunner implements ScheduleRunner {* scheduleId → 当前这一个稳定失配(见 RoutinePermissionMismatchError.signature)连续出现的次数。* 受理时的核验只要给出别的结论(通过、切换在途、实例更换、排队后被改、revision 变化)* 或换成另一个失配,就从头计数;没走到受理核验的触发不改变计数。只在内存:重启后- * 运行实例本就重建,旧计数没有意义。+ * 运行实例本就重建,旧计数没有意义。调度在失配期间被删除时条目会留到进程结束;+ * 每条只有签名与计数,数量上限是本进程内出现过稳定失配的调度数,不另接删除通知。*/private readonly permissionMismatchStreaks = new Map<string,