feat(FN-4785): complete Step 2 — batch sanitize agent task link lookups
Fusion-Task-Id: FN-4785 Fusion-Task-Lineage: be241ee7-9df0-433c-a00b-997bcd558862
This commit is contained in:
committed by
gsxdsm
parent
3dfa162f03
commit
7aeb7583f4
@@ -3072,23 +3072,29 @@ export function createApiRoutes(store: TaskStore, options?: ServerOptions): Rout
|
||||
agents: Array<import("@fusion/core").Agent>,
|
||||
scopedStore: TaskStore,
|
||||
): Promise<Array<import("@fusion/core").Agent>> {
|
||||
// Batch lookup all unique taskIds to minimize individual store calls
|
||||
// Batch lookup all unique taskIds to avoid per-task detail hydration.
|
||||
const taskIds = [...new Set(agents.map((a) => a.taskId).filter((id): id is string => id !== undefined))];
|
||||
const taskStatusMap = new Map<string, string>();
|
||||
|
||||
// Parallel fetch all linked tasks
|
||||
await Promise.all(
|
||||
taskIds.map(async (taskId) => {
|
||||
try {
|
||||
const task = await scopedStore.getTask(taskId);
|
||||
if (task) {
|
||||
taskStatusMap.set(taskId, task.column);
|
||||
}
|
||||
} catch {
|
||||
// Task lookup failed — treat as non-terminal (preserve taskId)
|
||||
}
|
||||
}),
|
||||
);
|
||||
let taskStatusMap = new Map<string, string>();
|
||||
try {
|
||||
if (typeof (scopedStore as TaskStore & { getTaskColumns?: unknown }).getTaskColumns === "function") {
|
||||
taskStatusMap = await scopedStore.getTaskColumns(taskIds);
|
||||
} else {
|
||||
await Promise.all(
|
||||
taskIds.map(async (taskId) => {
|
||||
try {
|
||||
const task = await scopedStore.getTask(taskId);
|
||||
if (task) taskStatusMap.set(taskId, task.column);
|
||||
} catch {
|
||||
// Per-task lookup failed — treat as non-terminal.
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
// Lookup failed — treat all linked tasks as non-terminal (preserve taskId)
|
||||
taskStatusMap = new Map<string, string>();
|
||||
}
|
||||
|
||||
return agents.map((agent) => {
|
||||
if (!agent.taskId) return agent;
|
||||
|
||||
Reference in New Issue
Block a user