{"record":{"id":"43a98a2cc6499cf0","repo":"paperclipai/paperclip","slug":"anthropic-pinned-agent-version-identity-does-not-m","errorCode":null,"errorMessage":"Anthropic pinned Agent version identity does not match the selected Agent","messagePattern":"Anthropic pinned Agent version identity does not match the selected Agent","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/src/commands/managed-agent.ts","lineNumber":355,"sourceCode":"  const environmentId = String(environment.id ?? \"\");\n  if (!agentId || !environmentId) {\n    throw new Error(\"Anthropic did not return usable Agent and Environment identities\");\n  }\n\n  const versions = await listAll(\n    validated.anthropicApiKey,\n    `/v1/agents/${encodeURIComponent(agentId)}/versions`,\n  );\n  const version = normalizedOptions.agentVersion\n    ?? String(agent.version ?? versions.at(-1)?.version ?? \"\");\n  const pinnedAgent = version\n    ? versions.find((entry) => String(entry.version) === version)\n    : undefined;\n  if (!version || !pinnedAgent) {\n    throw new Error(\"Anthropic did not return a usable pinned Agent version\");\n  }\n  if (String(pinnedAgent.id ?? \"\") !== agentId) {\n    throw new Error(\"Anthropic pinned Agent version identity does not match the selected Agent\");\n  }\n  assertSafeManagedAgent(pinnedAgent);\n  assertManagedAgentModel(pinnedAgent, normalizedOptions.model);\n\n  const qualification = {\n    probedAt: new Date().toISOString(),\n    betaVersion: CLAUDE_MANAGED_BETA_VERSION,\n    environmentPolicy: \"limited_no_hosts_no_packages\",\n    agentCapabilities: \"no_tools_no_mcp_no_skills_no_multiagent\",\n  };\n  const profile = {\n    profileKey: normalizedOptions.profileKey,\n    displayName: normalizedOptions.displayName,\n    anthropicAgentId: agentId,\n    agentVersion: version,\n    environmentId,\n    defaultModel: normalizedOptions.model,\n    defaultMaxListCostUsd: validated.defaultMaxListCostUsd,","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/paperclipai/paperclip/blob/5716fe907e596ce73501408fc6efdb19fb61edf2/cli/src/commands/managed-agent.ts#L337-L373","documentation":"After selecting the pinned version entry, setupManagedAgent verifies that the matched version record's `id` equals the resolved agentId. A mismatch means the versions endpoint returned an entry belonging to a different agent (identity drift between listing and detail), and setup refuses to attach credentials to the wrong resource.","triggerScenarios":"versions.find(...) returned an entry whose pinnedAgent.id differs from the resolved agent.id — typically caused by a concurrent agent recreation between the two calls, a caching proxy serving versions of another agent, or an API returning non-filtered version listings.","commonSituations":"Agent deleted and recreated mid-setup (ID changed while versions were fetched); misconfigured gateway cache keyed incorrectly; race between two concurrent setup runs using the same profile.","solutions":["Re-run setup; a transient race usually resolves once the agent identity is stable.","Avoid deleting/recreating the agent while a setup or probe run is in flight.","Bypass any caching proxy or verify cache keys when calling api.anthropic.com.","Pass an explicit agentId so the detail fetch and version listing refer to the same resource."],"exampleFix":"// before: deleting and recreating the agent during setup races the version fetch\n// after: serialize operations — only recreate the agent when no setup is running\nawait setupManagedAgent(options); // then recreate\n// or pass a stable explicit agentId so both calls hit the same resource","handlingStrategy":"retry","validationCode":"// detect identity drift before attaching credentials\nconst versions = await listAll(key, `/v1/agents/${agentId}/versions`);\nconst pinned = versions.find(v => String(v.version) === version);\nif (pinned && String(pinned.id) !== agentId) {\n  console.warn(\"Version identity drift detected — agent changed mid-setup; rerun.\");\n}","typeGuard":"function versionBelongsToAgent(v: { id?: unknown }, agentId: string): boolean {\n  return typeof v.id === \"string\" && v.id === agentId;\n}","tryCatchPattern":"try {\n  await setupManagedAgent(options);\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"pinned Agent version identity does not match\")) {\n    await sleep(1000);               // let identity settle after any recreate\n    await setupManagedAgent(options); // single bounded retry\n  } else throw e;\n}","preventionTips":["Never delete/recreate the agent concurrently with setup or probe runs.","Serialize setup runs per profile with a lock.","Bypass or correctly key caches on the API path.","Pass an explicit agentId so detail and version calls reference one resource."],"tags":["anthropic","agent","identity-mismatch","race-condition"],"backgroundTag":"identity-mismatch","analyzedSha":"5716fe907e596ce73501408fc6efdb19fb61edf2","analyzedAt":"2026-09-02T18:44:00.616Z","contentChangedAt":"2026-09-02T18:44:00.616Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}