Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bot-autonomy): 归属读到之前不补「上一轮被打断」的任务,留给之后的扫描
Chris8d012b0dc13c
diff --git a/apps/desktop/src/main/bot-autonomy/__tests__/taskWatch.test.ts b/apps/desktop/src/main/bot-autonomy/__tests__/taskWatch.test.tsindex 1c36dcce09..2651de18ea 100644--- a/apps/desktop/src/main/bot-autonomy/__tests__/taskWatch.test.ts+++ b/apps/desktop/src/main/bot-autonomy/__tests__/taskWatch.test.ts@@ -9,7 +9,7 @@* - 最小失败输入:伙伴主任务(canonical)出现在活动里;启动时灵动岛残留「完成」;主人点停止后灵动岛条目消失* 被当成做完;同一条挂起交互在重启后得到新的事件 id;远程 list-active 连续失败;远程任务两次轮询之间从权限请求* A 换到 B,仍显示 A;本机任务在同一相位里从请求 A 换到 B,沿用 A 的等待时刻;读任务元数据失败一次后,- * 这批任务被丢掉,之后再无活动就永远不进表;启动兜底读失败一次后再不重试;伙伴刚开的任务在上次归属读取+ * 这批任务被丢掉,之后再无活动就永远不进表;启动兜底读失败一次后再不重试;启动时归属读失败,上一轮被打断的任务按空归属判给总调度;伙伴刚开的任务在上次归属读取* 几秒内出现,被当成「没人开」落到总调度。* - tier:unit(全部 IO 经注入的内存 fake,时间由 now() 推进,无真实等待)。*/@@ -55,6 +55,7 @@ function harness(options: {const onChange = vi.fn();let metaReadFailures = 0;let interruptedReadFailures = 0;+ let ownershipReadFailures = 0;const creators = new Map(Object.entries(options.creators ?? {}));const invokeRemote = vi.fn(options.invokeRemote ?? (async () => { throw new Error('offline'); }));const watch = new TaskWatch({@@ -77,11 +78,17 @@ function harness(options: {}return [...metas.values()].filter((m) => m.interrupted);},- readOwnership: async () => ({+ readOwnership: async () => {+ if (ownershipReadFailures > 0) {+ ownershipReadFailures -= 1;+ throw Object.assign(new Error('busy'), { code: 'SQLITE_BUSY' });+ }+ return {bots: new Map([['sched', { status: 'active', allowSchedulerFollow: false }], ['a', { status: 'active', allowSchedulerFollow: false }]]),creatorBySession: new Map(creators),responsibleByBot: new Map(),- }),+ };+ },readSchedulerOverride: () => ({ customized: true, schedulerBotId: 'sched' }),listRemoteDevices: async () => options.devices ?? null,invokeRemote,@@ -92,6 +99,7 @@ function harness(options: {advance: (ms: number) => { now += ms; },failMetaReads: (count: number) => { metaReadFailures = count; },failInterruptedReads: (count: number) => { interruptedReadFailures = count; },+ failOwnershipReads: (count: number) => { ownershipReadFailures = count; },creators,now: () => now,};@@ -215,6 +223,16 @@ describe('TaskWatch ownership and startup retries', () => {expect(h.watch.get('crashed')).toMatchObject({ phase: 'errored', phaseSince: 5_000, followerBotId: 'sched' });});+ it('does not add interrupted tasks with an empty ownership table; it waits until ownership loads', async () => {+ const h = harness({ metas: [meta('crashed', { interrupted: true, activeTurnStartedAt: 5_000 })], creators: { crashed: 'a' } });+ h.failOwnershipReads(1);+ await h.watch.start();+ expect(h.watch.get('crashed')).toBeUndefined();+ h.advance(10 * 60_000);+ await h.watch.sweep();+ expect(h.watch.get('crashed')).toMatchObject({ phase: 'errored', creatorBotId: 'a', followerBotId: 'a' });+ });+it('re-reads ownership before judging a newly seen task unowned, even right after the last read', async () => {const h = harness({ metas: [meta('fresh')] });await h.watch.start();diff --git a/apps/desktop/src/main/bot-autonomy/taskWatch.ts b/apps/desktop/src/main/bot-autonomy/taskWatch.tsindex 4e91d50850..705e2fa8ef 100644--- a/apps/desktop/src/main/bot-autonomy/taskWatch.ts+++ b/apps/desktop/src/main/bot-autonomy/taskWatch.ts@@ -223,7 +223,8 @@ export class TaskWatch {this.local.set(snapshot.sessionId, { ...this.factsFor(snapshot.sessionId), activity: snapshot });this.pending.add(snapshot.sessionId);}- await this.seedInterrupted();+ // 归属没读到时不补「上一轮被打断」的任务:空归属会把它判成没人开、先落到总调度;留给读到归属后的扫描。+ if (this.ownershipLoaded) await this.seedInterrupted();await this.flush();}@@ -543,8 +544,8 @@ export class TaskWatch {const now = this.deps.now();if (now - this.ownershipAt >= OWNERSHIP_REFRESH_MS) await this.refreshOwnership();await this.refreshLocalMeta();- // 启动兜底读失败(如数据库一时忙):按扫描节奏重试,读成功一次后不再读。- if (!this.interruptedSeeded && !this.stopped) await this.seedInterrupted();+ // 启动兜底读失败(如数据库一时忙)或启动时归属还没读到:按扫描节奏重试,读成功一次后不再读。+ if (!this.interruptedSeeded && this.ownershipLoaded && !this.stopped) await this.seedInterrupted();// 上次读元数据失败留下的 pending:按扫描节奏重试一次,不形成重试风暴。if (this.pending.size && this.ownershipLoaded && !this.stopped) this.scheduleFlush();for (const [id, row] of this.rows) {