paperclipai/paperclip · error · Error
Agent selection failed
Error message
Agent selection failed
What it means
Defensive guard in chooseAgent: after the @clack select prompt resolves, agents.find(...) by the selected id returns undefined. Because the select options are built from the same agents array, this should not happen.
Source
Thrown at cli/src/commands/client/connect.ts:230
if (!selected) return null;
return companies.find((company) => company.id === selected) ?? null;
}
async function chooseAgent(agents: Agent[], preferredAgentId: string | undefined): Promise<Agent> {
const selected = await p.select({
message: "Agent",
initialValue: preferredAgentId && agents.some((agent) => agent.id === preferredAgentId)
? preferredAgentId
: agents[0]?.id,
options: agents.map((agent) => ({
value: agent.id,
label: agent.name,
hint: agent.role,
})),
});
assertNotCancelled(selected);
const agent = agents.find((item) => item.id === selected);
if (!agent) throw new Error("Agent selection failed");
return agent;
}
function buildExports(input: {
apiBase: string;
companyId?: string;
agentId?: string;
envName: string;
token: string;
}): string {
const escaped = (value: string) => value.replace(/'/g, "'\"'\"'");
return [
`export PAPERCLIP_API_URL='${escaped(input.apiBase)}'`,
input.companyId ? `export PAPERCLIP_COMPANY_ID='${escaped(input.companyId)}'` : null,
input.agentId ? `export PAPERCLIP_AGENT_ID='${escaped(input.agentId)}'` : null,
`export ${input.envName}='${escaped(input.token)}'`,
].filter((line): line is string => Boolean(line)).join("\n");
}View on GitHub (pinned to 67001ec6eb)
Solutions
- Re-run connect; refresh fetches the current agents list.
- Confirm no concurrent agent deletion is happening in the target company.
Defensive patterns
Strategy: validation
Validate before calling
const agent = agents.find((a) => a.id === selected);
if (!agent) throw new Error('Agent selection failed'); Type guard
const isAgent = (v: unknown): v is Agent => !!v && typeof v === 'object' && typeof (v as any).id === 'string';
Prevention
- Avoid concurrent agent deletion during interactive connect.
- Re-run connect if the agents list may have changed.
When it happens
Trigger: Only if the agents array is mutated between building the select options and the find call (race with concurrent agent deletion), or a future refactor breaks the option/value pairing.
Common situations: Another operator deletes the agent while you are at the prompt; profile.agentId pointed at an id that vanished.
Related errors
- Company is required for agent profiles
- `paperclipai connect` is interactive. For scripts, pass --ap
- Failed to create board token
- Company '${company.name}' has no agents to connect.
- Failed to create agent token
AI-assisted analysis of paperclipai/paperclip@67001ec6eb (2026-08-12).
Data as JSON: /api/errors/5b309d81cdeec5f0.
Report an issue: GitHub.