Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
feat(queue): notify coordinator of route work shortages [N2]
Corey Olson6c0694c1c123
diff --git a/src/health.js b/src/health.jsindex c7ad44a1..913a1684 100644--- a/src/health.js+++ b/src/health.js@@ -34,6 +34,7 @@ import { staleRowDecisions } from './row-decision-state.js';import { localReleaseRank } from './release-queue.js';import { workQueue } from './queue.js';import { trunkRef } from './trusted-policy.js';+import { routeWorkShortages } from './route-capacity.js';/** Each threshold's pullboard.json key under "health" and its default. */export const HEALTH_DEFAULTS = Object.freeze({ stuck: '1h', holds: '1d', release: '1d' });@@ -289,7 +290,8 @@ function queueFaults(board, { items, at, retired = [], gone = new Set() }) {const awaitsReview = items.some((item) => item.item_status === 'submitted' && item.item_built_by === row.id);const recent = !gone.has(row.path) && (lease || at - last < QUEUE_ACTIVE_MS);const pulled = Math.max(...[row.created, row.pulled_at].filter(Boolean).map((value) => Date.parse(value)));- return { ...row, last, recent, idle: recent && !lease && !awaitsReview && at - pulled >= QUEUE_ACTIVE_MS };+ const idle = recent && !lease && !awaitsReview && at - pulled >= QUEUE_ACTIVE_MS;+ return { ...row, last, recent, idle, idleSince: idle ? new Date(pulled + QUEUE_ACTIVE_MS).toISOString() : null };});const active = agents.filter((agent) => agent.recent);retired.push(...agents.filter((agent) => !agent.recent).map((agent) => ({ agent: agent.id, lane: agent.lane, since: new Date(agent.last).toISOString() })));@@ -300,6 +302,17 @@ function queueFaults(board, { items, at, retired = [], gone = new Set() }) {const now = at;const findings = [];+ for (const shortage of routeWorkShortages(board, waiting, agents)) {+ const { route, free, idle, since } = shortage;+ findings.push(finding('ROUTE_WORK_SHORTAGE', null, {+ subject: `${route} route`, key: `ROUTE_WORK_SHORTAGE:route:${route}:free:${free}:idle:${idle}`, since, now,+ title: 'needs more free work',+ why: `${free} free items can be taken by ${idle} idle seats at the ${route} route`,+ next: `split more items for the ${route} route so its idle agents have work they can take`,+ owner: { role: 'coordinator', who: COORDINATOR }, detail: { route, free, idle },+ }));+ }+for (const route of ROUTES) {const open = current.filter((entry) => entry.route === route && !lapsed(entry));if (!open.length || active.some((agent) => canTake(agent.route, route))) continue;diff --git a/src/route-capacity.js b/src/route-capacity.jsnew file mode 100644index 00000000..210e10e3--- /dev/null+++ b/src/route-capacity.js@@ -0,0 +1,32 @@+/** Compare live idle seats with compatible free work without counting a seat at multiple routes [A6,N2,B13]. */+import { ROUTES } from './route-escalation.js';+import { canTake } from './route-escalation.js';+import { firstRefusal } from './first-refusal-window.js';+import { takeoverReady } from './line-capacity.js';++/**+ * Use the queue's held/dependency/collision-filtered entries and health's existing idle projection.+ * A reserved return is free only to its original builder until the canonical takeover rule permits+ * others. Read that boundary once per item, rather than once for every possible seat/item pair.+ */+export function routeWorkShortages(board, entries, agents) {+ const restrictions = new Map();+ /** Retain exactly the same builder reservation and configured takeover condition as next. */+ function reservedFor(id) {+ if (!restrictions.has(id)) {+ const window = firstRefusal(board, id);+ restrictions.set(id, window && !takeoverReady(board, id) ? window.builder : null);+ }+ return restrictions.get(id);+ }+ return ROUTES.flatMap(route => {+ const idle = agents.filter(agent => agent.idle && agent.route === route);+ if (!idle.length) return [];+ const ids = new Set(idle.map(agent => agent.id));+ const free = new Set(entries.filter(entry => canTake(route, entry.route)+ && (reservedFor(entry.id) === null || ids.has(reservedFor(entry.id)))).map(entry => entry.id)).size;+ if (free >= idle.length) return [];+ const since = idle.reduce((earliest, agent) => agent.idleSince < earliest ? agent.idleSince : earliest, idle[0].idleSince);+ return [{ route, free, idle: idle.length, since }];+ });+}