Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 恢复轻量索引中较旧运行的任务归属
Dashfc2d4cdd843d
diff --git a/apps/mobile/src/__tests__/scheduleIndex.test.ts b/apps/mobile/src/__tests__/scheduleIndex.test.tsindex 8d095156d9..58b3fed62e 100644--- a/apps/mobile/src/__tests__/scheduleIndex.test.ts+++ b/apps/mobile/src/__tests__/scheduleIndex.test.ts@@ -35,6 +35,42 @@ function makerWithSchedules(}describe('scheduleIndex', () => {+ it.each([false, true])('restores older running ownership from the same snapshot (lightweight=%s)', async (lightweight) => {+ const schedules = [{ id: 'sched', name: 'run', status: 'active', targetSessionId: 'task' }];+ const row = { scheduleId: 'sched', scheduleName: 'run', scheduleStatus: 'active', readAt: 1 };+ const snapshot = {+ runs: [+ { ...row, runId: 'new', sessionId: 'task', status: 'success', firedAt: 20 },+ { ...row, runId: 'old', status: 'running', firedAt: 10 },+ { ...row, runId: 'unbound', status: 'running', firedAt: 5 },+ { ...row, runId: 'historical', status: 'failed', firedAt: 3 },+ ],+ inflightPolicies: [+ { runId: 'old', sessionId: 'task', silenced: false },+ { runId: 'historical', sessionId: 'must-not-restore', silenced: false },+ ],+ };+ const listRuns = vi.fn();+ const maker = { schedule: { list: async () => schedules, listSidebarIndexRuns: async () => snapshot, listRuns } } as unknown as Pick<MobileMakerTransport, 'schedule'>;+ const index = lightweight+ ? await loadLightweightSessionScheduleIndex('device', vi.fn().mockResolvedValue(snapshot))+ : await loadSessionScheduleIndex(maker);+ expect(index.get('task')).toMatchObject({ running: true, latestRunAt: 20, unreadCount: 0 });+ expect(index.has('must-not-restore')).toBe(false);+ expect(index.size).toBe(1);+ expect(listRuns).not.toHaveBeenCalled();+ // A policy can disappear as a run settles; never invent a missing binding.+ snapshot.inflightPolicies = [];+ const withoutPolicies = await loadSessionScheduleIndex(maker);+ expect(withoutPolicies.get('task')?.running).toBe(false);+ // Explicit row ownership wins, even when policy metadata disagrees.+ snapshot.runs[1] = { ...snapshot.runs[1], sessionId: 'task' };+ snapshot.inflightPolicies = [{ runId: 'old', sessionId: 'other', silenced: false }];+ expect((await loadSessionScheduleIndex(maker)).get('task')?.running).toBe(true);+ // Rebinding remains authoritative over both stored and recovered ownership.+ schedules[0].targetSessionId = 'rebound';+ expect((await loadSessionScheduleIndex(maker)).has('task')).toBe(false);+ });it.each([false, true])('lets joined visible consumers take over a blurred initiator (visible=%s)', async (visible) => {vi.useFakeTimers();resetScheduleIndexThrottleForTesting();diff --git a/apps/mobile/src/session/scheduleIndex.ts b/apps/mobile/src/session/scheduleIndex.tsindex d55481ecfe..46ab709096 100644--- a/apps/mobile/src/session/scheduleIndex.ts+++ b/apps/mobile/src/session/scheduleIndex.ts@@ -370,12 +370,22 @@ export const resetScheduleIndexThrottleForTesting = clearSessionScheduleIndexCac/** Existing lightweight host query; never starts the schedule list + per-run scan. */export async function loadLightweightSessionScheduleIndex(deviceId: string, invoke: RemoteInvoke): Promise<Map<string, RemoteSessionScheduleInfo>> {- const raw = await invoke<{ runs?: unknown[] }>(deviceId, 'maker:schedule:list-sidebar-index-runs', []);+ const raw = await invoke<LightweightScheduleSnapshot>(deviceId, 'maker:schedule:list-sidebar-index-runs', []);return buildLightweightSessionScheduleIndex(raw);}-function buildLightweightSessionScheduleIndex(raw: { runs?: unknown[] }, authoritativeSchedules?: ReturnType<typeof normalizeScheduleList>): Map<string, RemoteSessionScheduleInfo> {+type LightweightScheduleSnapshot = { runs?: unknown[]; inflightPolicies?: unknown[] };++function buildLightweightSessionScheduleIndex(raw: LightweightScheduleSnapshot, authoritativeSchedules?: ReturnType<typeof normalizeScheduleList>): Map<string, RemoteSessionScheduleInfo> {if (!raw || !Array.isArray(raw.runs)) throw new Error('Invalid schedule index');+ const inflightSessions = new Map<string, string>();+ for (const value of raw.inflightPolicies ?? []) {+ if (!value || typeof value !== 'object') continue;+ const policy = value as Record<string, unknown>;+ if (typeof policy.runId === 'string' && typeof policy.sessionId === 'string') {+ inflightSessions.set(policy.runId, policy.sessionId);+ }+ }const schedules = new Map<string, import('@/scheduler/types').RemoteSchedule>();const runs = new Map<string, RemoteScheduleRun[]>();for (const value of raw.runs) {@@ -383,7 +393,10 @@ function buildLightweightSessionScheduleIndex(raw: { runs?: unknown[] }, authoriconst row = value as Record<string, unknown>;if (typeof row.scheduleId !== 'string' || typeof row.runId !== 'string' || typeof row.scheduleName !== 'string') throw new Error('Invalid schedule index row');const schedule = normalizeScheduleList([{ id: row.scheduleId, name: row.scheduleName, status: row.scheduleStatus }])[0];- const run = normalizeScheduleRuns([{ ...row, id: row.runId }])[0];+ // The host omits older running rows' binding to preserve latest ownership.+ // Restore only that missing input; the shared builder still owns binding and recency rules.+ const sessionId = row.sessionId || (row.status === 'running' ? inflightSessions.get(row.runId) : undefined);+ const run = normalizeScheduleRuns([{ ...row, id: row.runId, sessionId }])[0];if (!schedule || !run) throw new Error('Invalid schedule index row');schedules.set(schedule.id, schedule);runs.set(schedule.id, [...(runs.get(schedule.id) ?? []), run]);