Keep the knowledge graph when one schedule fails to load

One failing per-schedule request no longer blanks the whole graph, and
the graph shows the engine's own error instead of always saying the
engine cannot be reached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Iqbal
2026-10-29 10:19:56 +07:00
parent 278c66897a
commit adbcfcc7ba
3 changed files with 33 additions and 5 deletions

View File

@@ -172,14 +172,24 @@ async function sourcesOf({ agent, rule }: Schedule): Promise<FoundSource[]> {
}))
}
// One schedule the engine cannot answer for (e.g. an archived agent) leaves its results out
// instead of failing them all; only when every schedule fails is that an error.
export function keepSettled<T>(results: PromiseSettledResult<T[]>[]): T[] {
const kept = results.flatMap(r => (r.status === 'fulfilled' ? r.value : []))
const failed = results.filter(r => r.status === 'rejected')
if (failed.length) console.warn(`${failed.length} of ${results.length} schedules could not be loaded`, failed.map(r => r.reason))
if (results.length && failed.length === results.length) throw failed[0].reason
return kept
}
export async function listResults(): Promise<{ materials: Material[]; sources: FoundSource[] }> {
const schedules = await expressAgents({ archived: true })
const [materials, sources] = await Promise.all([
Promise.all(schedules.filter(s => s.rule.type === 'content').map(materialsOf)),
Promise.all(schedules.filter(s => s.rule.type === 'research').map(sourcesOf)),
Promise.allSettled(schedules.filter(s => s.rule.type === 'content').map(materialsOf)),
Promise.allSettled(schedules.filter(s => s.rule.type === 'research').map(sourcesOf)),
])
const newest = <T extends { createdAt: string }>(a: T, b: T) => b.createdAt.localeCompare(a.createdAt)
return { materials: materials.flat().sort(newest), sources: sources.flat().sort(newest) }
return { materials: keepSettled(materials).sort(newest), sources: keepSettled(sources).sort(newest) }
}
const draftContent = (m: Material, id: number) =>