From 82a70d8a1678c73363784c77c362f90116f898ff Mon Sep 17 00:00:00 2001 From: iliya Date: Sat, 21 Mar 2026 14:27:13 +0200 Subject: [PATCH] refactor: improve task notification logic for unblocked tasks - Simplified the logic for determining pending blockers in the notifyUnblockedOwners function. - Replaced filter method with a for loop for better clarity and performance. - Updated notification message to accurately reflect the status of pending blockers. --- agent-teams-controller/src/internal/tasks.js | 32 ++++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/agent-teams-controller/src/internal/tasks.js b/agent-teams-controller/src/internal/tasks.js index e302ff09..6c29a319 100644 --- a/agent-teams-controller/src/internal/tasks.js +++ b/agent-teams-controller/src/internal/tasks.js @@ -244,34 +244,26 @@ function notifyUnblockedOwners(context, completedTask) { if (!normalizeActorName(blockedTask.owner)) continue; const allBlockerIds = Array.isArray(blockedTask.blockedBy) ? blockedTask.blockedBy : []; - const pendingBlockers = allBlockerIds.filter((id) => { - if (id === completedTask.id) return false; + const pendingBlockerTasks = []; + for (const id of allBlockerIds) { + if (id === completedTask.id) continue; try { const t = taskStore.readTask(context.paths, id, { includeDeleted: true }); - return t.status !== 'completed' && t.status !== 'deleted'; - } catch { return false; } - }); - - const allResolved = pendingBlockers.length === 0; - const blockedLabel = `#${blockedTask.displayId || blockedTask.id}`; - - let pendingList = ''; - if (!allResolved) { - const refs = pendingBlockers.map((id) => { - try { - const t = taskStore.readTask(context.paths, id, { includeDeleted: true }); - return `#${t.displayId || t.id}`; - } catch { return `#${id.slice(0, 8)}`; } - }); - pendingList = refs.join(', '); + if (t.status !== 'completed' && t.status !== 'deleted') { + pendingBlockerTasks.push(t); + } + } catch { /* missing task = not blocking */ } } + const allResolved = pendingBlockerTasks.length === 0; + const blockedLabel = `#${blockedTask.displayId || blockedTask.id}`; + const lines = [ `**Dependency resolved** — task ${completedLabel} _${completedTask.subject}_ completed.`, ``, allResolved ? `All blockers for ${blockedLabel} are resolved — this task is ready to start.` - : `${allBlockerIds.length - pendingBlockers.length} of ${allBlockerIds.length} blockers resolved. Still waiting on: ${pendingList}.`, + : `${allBlockerIds.length - pendingBlockerTasks.length} of ${allBlockerIds.length} blockers resolved. Still waiting on: ${pendingBlockerTasks.map((t) => `#${t.displayId || t.id}`).join(', ')}.`, ]; if (allResolved) { @@ -299,7 +291,7 @@ function notifyUnblockedOwners(context, completedTask) { function completeTask(context, taskId, actor) { const task = setTaskStatus(context, taskId, 'completed', actor); try { - notifyUnblockedOwners(context, task, actor); + notifyUnblockedOwners(context, task); } catch { // Best-effort: task completion succeeded, notification failure is non-fatal }