Files
fusion/packages/engine/src/node-routing-policy.ts
Fusion 7cb9d20125 feat(FN-2951): enforce unavailable-node scheduling and improve active agents panel
- Enforce unavailable-node routing policy in the scheduler and wire policy integration through engine startup
- Expand scheduler and node-routing policy test coverage for unavailable-node handling and policy integration behavior
- Hoist the Active Agents panel above the main agents list and display next-heartbeat ETA details
- Fix Active Agents panel UI issues by resolving stuck "Connecting..." cards and adding spacing adjustments
- Add changesets covering Active Agents panel hoist/heartbeat ETA and connecting-state fixes

Fusion-Task-Id: FN-2951
2026-04-29 14:36:50 -07:00

43 lines
1.3 KiB
TypeScript

import type { NodeStatus, UnavailableNodePolicy } from "@fusion/core";
import type { EffectiveNode } from "./effective-node.js";
export type PolicyDecision =
| { allowed: true; fallbackToLocal: false }
| { allowed: true; fallbackToLocal: true; reason: string }
| { allowed: false; reason: string };
const UNHEALTHY_STATUSES: ReadonlySet<NodeStatus> = new Set(["offline", "error", "connecting"]);
export function applyUnavailableNodePolicy(params: {
effectiveNode: EffectiveNode;
nodeHealth: NodeStatus | undefined;
policy: UnavailableNodePolicy | undefined;
}): PolicyDecision {
const { effectiveNode, nodeHealth, policy } = params;
if (effectiveNode.source === "local") {
return { allowed: true, fallbackToLocal: false };
}
if (nodeHealth === "online" || nodeHealth === undefined) {
return { allowed: true, fallbackToLocal: false };
}
if (!effectiveNode.nodeId || !UNHEALTHY_STATUSES.has(nodeHealth)) {
return { allowed: true, fallbackToLocal: false };
}
if (policy === "fallback-local") {
return {
allowed: true,
fallbackToLocal: true,
reason: `Node ${effectiveNode.nodeId} is ${nodeHealth}; falling back to local per policy`,
};
}
return {
allowed: false,
reason: `Node ${effectiveNode.nodeId} is ${nodeHealth}; policy is block`,
};
}