mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-21 00:05:49 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Agents escalate work up the org chart (`reports_to`), and operators pause agents — notably, instance imports pause every agent by default > - A paused manager does not invalidate the chain (subordinates stay invokable), so nothing surfaces when an operator unpauses workers but leaves their manager paused > - Escalations then dead-letter silently: agent-created issues assigned to the paused manager sit in a queue nothing will ever run > - This pull request computes paused ancestors in the existing org-chain health model and surfaces a non-blocking warning on the agent read models and detail page > - The benefit is that the operator learns their escalation paths are dead before work vanishes into them ## Linked Issues or Issue Description Fixes #10647 (companion to #10648, which refuses agent-initiated assignment to paused agents at write time — this PR makes the standing hazard visible) ## What Changed - `AgentOrgChainHealth` gains two additive, optional fields: `pausedAncestors` (paused agents in the `reports_to` chain) and `escalationWarning` (human-readable, only set when the agent itself can work — a paused/terminated agent's escalation path is moot). Chain validity, invokability, and assignability are byte-identical. - No server route changes needed: the fields flow through every existing agent read model (list, detail, org chart) since they ride the same `getAgentWorkEligibility` computation. - Agent detail page shows an amber "Escalation path is paused" banner (same visual language as the invalid-chain banner, but non-blocking) with the warning text naming the paused manager and the two remedies. ## Verification - `pnpm vitest run packages/shared/src/agent-eligibility.test.ts` — 5 new cases: paused direct manager warns; paused grandparent through a healthy manager warns; the agent itself paused → no warning (but ancestors still reported); fully active chain → no warning, empty list; terminated ancestor keeps the invalid-chain classification without double-counting as paused. - Full `@paperclipai/shared` suite (392 tests) and `agent-eligibility-routes` (54) unchanged. - `tsc --noEmit` in shared, server, and ui. ## Risks - Low. Purely additive fields plus one UI banner; no behavior gates on the new data. ## Model Used Claude Fable 5 (`claude-fable-5`, Anthropic) via Claude Code — extended thinking, agentic tool use. No other models involved. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge
225 lines
9.9 KiB
TypeScript
225 lines
9.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
getAgentOrgChainHealth,
|
|
getAgentWorkEligibility,
|
|
isAgentAssignableToWork,
|
|
isAgentInvokable,
|
|
type AgentEligibilityAgent,
|
|
} from "./agent-eligibility.js";
|
|
|
|
const companyId = "company-1";
|
|
|
|
function agent(overrides: Partial<AgentEligibilityAgent> = {}): AgentEligibilityAgent {
|
|
return {
|
|
id: "agent-1",
|
|
companyId,
|
|
name: "Coder",
|
|
status: "active",
|
|
reportsTo: "manager-1",
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("agent work eligibility", () => {
|
|
it("allows healthy active agents to accept work and be invoked", () => {
|
|
const agents = [
|
|
agent(),
|
|
agent({ id: "manager-1", name: "CTO", status: "active", reportsTo: null }),
|
|
];
|
|
|
|
expect(isAgentAssignableToWork({ agent: agents[0]!, agents })).toBe(true);
|
|
expect(isAgentInvokable({ agent: agents[0]!, agents })).toBe(true);
|
|
expect(getAgentWorkEligibility({ agent: agents[0]!, agents })).toMatchObject({
|
|
assignable: true,
|
|
invokable: true,
|
|
assignabilityReason: "eligible",
|
|
invokabilityReason: "eligible",
|
|
orgChainHealth: { status: "healthy" },
|
|
});
|
|
});
|
|
|
|
it("blocks terminated and pending approval agents from assignment and invocation", () => {
|
|
const manager = agent({ id: "manager-1", name: "CTO", status: "active", reportsTo: null });
|
|
|
|
for (const status of ["terminated", "pending_approval"]) {
|
|
const target = agent({ status });
|
|
const eligibility = getAgentWorkEligibility({ agent: target, agents: [target, manager] });
|
|
|
|
expect(eligibility.assignable).toBe(false);
|
|
expect(eligibility.invokable).toBe(false);
|
|
expect(eligibility.assignabilityReason).toBe(status);
|
|
expect(eligibility.invokabilityReason).toBe(status);
|
|
}
|
|
});
|
|
|
|
it("allows paused agents to keep assignments but blocks invocation", () => {
|
|
const target = agent({ status: "paused" });
|
|
const manager = agent({ id: "manager-1", name: "CTO", status: "active", reportsTo: null });
|
|
|
|
expect(getAgentWorkEligibility({ agent: target, agents: [target, manager] })).toMatchObject({
|
|
assignable: true,
|
|
invokable: false,
|
|
assignabilityReason: "eligible",
|
|
invokabilityReason: "paused",
|
|
});
|
|
});
|
|
|
|
it("reports unknown lifecycle statuses explicitly", () => {
|
|
const target = agent({ status: "sabbatical" });
|
|
const manager = agent({ id: "manager-1", name: "CTO", status: "active", reportsTo: null });
|
|
|
|
expect(getAgentWorkEligibility({ agent: target, agents: [target, manager] })).toMatchObject({
|
|
assignable: false,
|
|
invokable: false,
|
|
assignabilityReason: "unknown_status",
|
|
invokabilityReason: "unknown_status",
|
|
orgChainHealth: { status: "healthy" },
|
|
});
|
|
});
|
|
|
|
it("blocks active descendants of terminated ancestors and reports repair details", () => {
|
|
const target = agent({ id: "qa-2", name: "QA 2", status: "active", reportsTo: "cto-2" });
|
|
const terminatedManager = agent({
|
|
id: "cto-2",
|
|
name: "CTO 2",
|
|
status: "terminated",
|
|
reportsTo: "ceo-2",
|
|
});
|
|
const terminatedRoot = agent({
|
|
id: "ceo-2",
|
|
name: "CEO 2",
|
|
status: "terminated",
|
|
reportsTo: null,
|
|
});
|
|
const agents = [target, terminatedManager, terminatedRoot];
|
|
|
|
const health = getAgentOrgChainHealth({ agent: target, agents });
|
|
expect(health.status).toBe("invalid_org_chain");
|
|
expect(health.reason).toBe("terminated_ancestor");
|
|
expect(health.fullChain).toEqual([
|
|
expect.objectContaining({ id: "qa-2", name: "QA 2", relation: "self", depth: 0 }),
|
|
expect.objectContaining({ id: "cto-2", name: "CTO 2", status: "terminated", relation: "ancestor", depth: 1 }),
|
|
expect.objectContaining({ id: "ceo-2", name: "CEO 2", status: "terminated", relation: "ancestor", depth: 2 }),
|
|
]);
|
|
expect(health.firstInvalidAncestor).toEqual({ id: "cto-2", name: "CTO 2", status: "terminated" });
|
|
expect(health.invalidAncestors).toEqual([
|
|
{ id: "cto-2", name: "CTO 2", status: "terminated" },
|
|
{ id: "ceo-2", name: "CEO 2", status: "terminated" },
|
|
]);
|
|
expect(health.repairGuidance).toContain("QA 2 reports through terminated ancestor CTO 2");
|
|
|
|
const eligibility = getAgentWorkEligibility({ agent: target, agents });
|
|
expect(eligibility.assignable).toBe(false);
|
|
expect(eligibility.invokable).toBe(false);
|
|
expect(eligibility.assignabilityReason).toBe("invalid_org_chain");
|
|
expect(eligibility.invokabilityReason).toBe("invalid_org_chain");
|
|
});
|
|
|
|
it("blocks agents whose manager is missing from the company org", () => {
|
|
const target = agent({ id: "qa-3", name: "QA 3", status: "active", reportsTo: "missing-manager" });
|
|
|
|
const health = getAgentOrgChainHealth({ agent: target, agents: [target] });
|
|
expect(health.status).toBe("invalid_org_chain");
|
|
expect(health.reason).toBe("missing_manager");
|
|
expect(health.fullChain).toEqual([
|
|
expect.objectContaining({ id: "qa-3", relation: "self", depth: 0 }),
|
|
expect.objectContaining({ id: "missing-manager", status: "missing", relation: "ancestor", depth: 1 }),
|
|
]);
|
|
expect(health.repairGuidance).toContain("QA 3 reports to missing manager missing-manager");
|
|
|
|
const eligibility = getAgentWorkEligibility({ agent: target, agents: [target] });
|
|
expect(eligibility.assignable).toBe(false);
|
|
expect(eligibility.invokable).toBe(false);
|
|
expect(eligibility.assignabilityReason).toBe("invalid_org_chain");
|
|
expect(eligibility.invokabilityReason).toBe("invalid_org_chain");
|
|
});
|
|
|
|
it("blocks agents with reporting cycles", () => {
|
|
const target = agent({ id: "qa-4", name: "QA 4", status: "active", reportsTo: "cto-4" });
|
|
const manager = agent({ id: "cto-4", name: "CTO 4", status: "active", reportsTo: "qa-4" });
|
|
const agents = [target, manager];
|
|
|
|
const health = getAgentOrgChainHealth({ agent: target, agents });
|
|
expect(health.status).toBe("invalid_org_chain");
|
|
expect(health.reason).toBe("cycle");
|
|
expect(health.fullChain).toEqual([
|
|
expect.objectContaining({ id: "qa-4", relation: "self", depth: 0 }),
|
|
expect.objectContaining({ id: "cto-4", relation: "ancestor", depth: 1 }),
|
|
expect.objectContaining({ id: "qa-4", status: "cycle", relation: "ancestor", depth: 2 }),
|
|
]);
|
|
expect(health.repairGuidance).toContain("QA 4 has a cycle in its reporting chain");
|
|
|
|
const eligibility = getAgentWorkEligibility({ agent: target, agents });
|
|
expect(eligibility.assignable).toBe(false);
|
|
expect(eligibility.invokable).toBe(false);
|
|
expect(eligibility.assignabilityReason).toBe("invalid_org_chain");
|
|
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([]);
|
|
});
|
|
});
|