diff --git a/packages/shared/src/agent-eligibility.test.ts b/packages/shared/src/agent-eligibility.test.ts index fba9d41d89..ee85624d2e 100644 --- a/packages/shared/src/agent-eligibility.test.ts +++ b/packages/shared/src/agent-eligibility.test.ts @@ -156,3 +156,69 @@ describe("agent work eligibility", () => { expect(eligibility.invokabilityReason).toBe("invalid_org_chain"); }); }); + +describe("paused escalation path warning", () => { + it("warns when an active agent's manager is paused", () => { + const manager = agent({ id: "manager-1", name: "CTO", status: "paused", reportsTo: null }); + const coder = agent({ id: "agent-1", name: "Coder", status: "active", reportsTo: "manager-1" }); + const result = getAgentWorkEligibility({ agent: coder, agents: [coder, manager] }); + + expect(result.invokable).toBe(true); + expect(result.orgChainHealth.status).toBe("healthy"); + expect(result.orgChainHealth.pausedAncestors).toEqual([ + { id: "manager-1", name: "CTO", status: "paused" }, + ]); + expect(result.orgChainHealth.escalationWarning).toContain("route to paused agent CTO"); + expect(result.orgChainHealth.escalationWarning).toContain("never runs"); + }); + + it("warns about a paused grandparent through a healthy manager", () => { + const executive = agent({ id: "exec-1", name: "CEO", status: "paused", reportsTo: null }); + const manager = agent({ id: "manager-1", name: "CTO", status: "active", reportsTo: "exec-1" }); + const coder = agent({ id: "agent-1", name: "Coder", status: "active", reportsTo: "manager-1" }); + const result = getAgentWorkEligibility({ agent: coder, agents: [coder, manager, executive] }); + + expect(result.orgChainHealth.pausedAncestors).toEqual([ + { id: "exec-1", name: "CEO", status: "paused" }, + ]); + expect(result.orgChainHealth.escalationWarning).toContain("CEO"); + }); + + it("does not warn when the agent itself is paused", () => { + const manager = agent({ id: "manager-1", name: "CTO", status: "paused", reportsTo: null }); + const coder = agent({ id: "agent-1", name: "Coder", status: "paused", reportsTo: "manager-1" }); + const result = getAgentWorkEligibility({ agent: coder, agents: [coder, manager] }); + + expect(result.orgChainHealth.escalationWarning).toBeNull(); + expect(result.orgChainHealth.pausedAncestors).toEqual([ + { id: "manager-1", name: "CTO", status: "paused" }, + ]); + }); + + it("does not warn for agents with unknown statuses", () => { + const manager = agent({ id: "manager-1", name: "CTO", status: "paused", reportsTo: null }); + const coder = agent({ id: "agent-1", name: "Coder", status: "mystery", reportsTo: "manager-1" }); + const result = getAgentWorkEligibility({ agent: coder, agents: [coder, manager] }); + + expect(result.invokable).toBe(false); + expect(result.orgChainHealth.escalationWarning).toBeNull(); + }); + + it("does not warn on a fully active chain", () => { + const manager = agent({ id: "manager-1", name: "CTO", status: "active", reportsTo: null }); + const coder = agent({ id: "agent-1", name: "Coder", status: "active", reportsTo: "manager-1" }); + const result = getAgentWorkEligibility({ agent: coder, agents: [coder, manager] }); + + expect(result.orgChainHealth.escalationWarning).toBeNull(); + expect(result.orgChainHealth.pausedAncestors).toEqual([]); + }); + + it("keeps invalid-chain classification for terminated ancestors, without duplicating them as paused", () => { + const manager = agent({ id: "manager-1", name: "CTO", status: "terminated", reportsTo: null }); + const coder = agent({ id: "agent-1", name: "Coder", status: "active", reportsTo: "manager-1" }); + const result = getAgentWorkEligibility({ agent: coder, agents: [coder, manager] }); + + expect(result.orgChainHealth.status).toBe("invalid_org_chain"); + expect(result.orgChainHealth.pausedAncestors).toEqual([]); + }); +}); diff --git a/packages/shared/src/agent-eligibility.ts b/packages/shared/src/agent-eligibility.ts index ae53bb57bf..bf658da7e9 100644 --- a/packages/shared/src/agent-eligibility.ts +++ b/packages/shared/src/agent-eligibility.ts @@ -45,6 +45,15 @@ export interface AgentOrgChainHealth { firstInvalidAncestor: AgentInvalidOrgChainAncestor | null; invalidAncestors: AgentInvalidOrgChainAncestor[]; repairGuidance: string | null; + /** + * Paused ancestors of a non-paused agent. A paused manager does not make + * the chain invalid (the agent stays invokable), but escalations routed to + * it dead-letter: assigned work never runs and nothing surfaces it. This is + * a warning, not a block. + */ + pausedAncestors?: AgentInvalidOrgChainAncestor[]; + /** Human-readable warning when the escalation path routes to a paused agent. */ + escalationWarning?: string | null; } export interface AgentWorkEligibility { @@ -121,6 +130,7 @@ export function getAgentOrgChainHealth(input: { const byId = new Map(input.agents.map((agent) => [agent.id, agent])); const fullChain: AgentOrgChainEntry[] = [chainEntry(input.agent, 0, "self")]; const invalidAncestors: AgentInvalidOrgChainAncestor[] = []; + const pausedAncestors: AgentInvalidOrgChainAncestor[] = []; const seen = new Set([input.agent.id]); let current = input.agent; @@ -171,12 +181,25 @@ export function getAgentOrgChainHealth(input: { if (parent.status === "terminated") { invalidAncestors.push(invalidAncestor(parent)); } + if (parent.status === "paused") { + pausedAncestors.push({ id: parent.id, name: parent.name, status: "paused" }); + } current = parent; depth += 1; } const firstInvalidAncestor = invalidAncestors[0] ?? null; + // Only warn for agents that can themselves receive and run work: a paused, + // terminated, or unknown-status agent's escalation path is moot until it is + // invokable again. Allowlist on purpose — a denylist complement would treat + // unrecognized statuses as workable and warn misleadingly. + const agentCanWork = isAgentStatusInvokable(input.agent.status); + const firstPausedAncestor = pausedAncestors[0] ?? null; + const escalationWarning = agentCanWork && firstPausedAncestor + ? `Escalations from ${input.agent.name} route to paused agent ${firstPausedAncestor.name}. ` + + `Work assigned to a paused agent never runs; unpause ${firstPausedAncestor.name} or change who this agent reports to.` + : null; return { status: firstInvalidAncestor ? "invalid_org_chain" : "healthy", reason: firstInvalidAncestor @@ -192,6 +215,8 @@ export function getAgentOrgChainHealth(input: { repairGuidance: firstInvalidAncestor ? buildRepairGuidance(input.agent, firstInvalidAncestor) : null, + pausedAncestors, + escalationWarning, }; } diff --git a/ui/src/pages/AgentDetail.tsx b/ui/src/pages/AgentDetail.tsx index 53cc43fdc9..b4bd9138bd 100644 --- a/ui/src/pages/AgentDetail.tsx +++ b/ui/src/pages/AgentDetail.tsx @@ -1051,6 +1051,7 @@ export function AgentDetail() { } const isPendingApproval = agent.status === "pending_approval"; const hasInvalidOrgChain = agent.orgChainHealth?.status === "invalid_org_chain"; + const pausedEscalationWarning = !hasInvalidOrgChain ? agent.orgChainHealth?.escalationWarning ?? null : null; const showConfigActionBar = (activeView === "configuration" || activeView === "instructions") && (configDirty || configSaving); const showLeftAgentNotice = agentMembershipState === "left" && !dismissedLeftAgentIds.has(agent.id); const agentMembershipPending = @@ -1097,6 +1098,15 @@ export function AgentDetail() { ) : null} + {pausedEscalationWarning ? ( +
+ +
+

Escalation path is paused

+

{pausedEscalationWarning}

+
+
+ ) : null} {hasInvalidOrgChain ? (