{"record":{"id":"203e69da41fe1141","repo":"paperclipai/paperclip","slug":"multiple-anthropic-resourcelabel-resources-use","errorCode":null,"errorMessage":"Multiple Anthropic ${resourceLabel} resources use Paperclip profile ${profileKey}; pass an explicit resource ID","messagePattern":"Multiple Anthropic (.+?) resources use Paperclip profile (.+?); pass an explicit resource ID","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/src/commands/managed-agent.ts","lineNumber":166,"sourceCode":"    page = typeof response.next_page === \"string\" && response.next_page\n      ? response.next_page\n      : null;\n  } while (page);\n  return rows;\n}\n\nfunction resourceByProfile(\n  resources: RemoteResource[],\n  profileKey: string,\n  resourceLabel: string,\n): RemoteResource | null {\n  const matches = resources.filter(\n    (resource) =>\n      typeof resource.id === \"string\"\n      && record(resource.metadata).paperclip_profile === profileKey,\n  );\n  if (matches.length > 1) {\n    throw new Error(\n      `Multiple Anthropic ${resourceLabel} resources use Paperclip profile ${profileKey}; pass an explicit resource ID`,\n    );\n  }\n  return matches[0] ?? null;\n}\n\nexport function assertSafeManagedEnvironment(environment: Record<string, unknown>): void {\n  const config = record(environment.config);\n  const networking = record(config.networking);\n  const packages = record(config.packages);\n  const installed = Object.entries(packages)\n    .filter(([key]) => key !== \"type\")\n    .flatMap(([, value]) => (Array.isArray(value) ? value : [value]))\n    .filter((value) => value !== undefined && value !== null);\n  if (\n    environment.archived_at !== null\n    || config.type !== \"cloud\"\n    || networking.type !== \"limited\"","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/paperclipai/paperclip/blob/5716fe907e596ce73501408fc6efdb19fb61edf2/cli/src/commands/managed-agent.ts#L148-L184","documentation":"When no explicit resource id is given, `resourceByProfile` finds Anthropic Environments/Agents by matching the `paperclip_profile` metadata key against the profile key. If two or more remote resources carry the same profile key, the lookup is ambiguous, so it throws and asks you to pass an explicit resource ID. This prevents setup from mutating or adopting the wrong resource.","triggerScenarios":"Running setup twice with the same --profile-key in a way that created duplicate Environments or Agents (e.g. a first run partially failed after creating the resource but before recording it locally); manually copying an existing resource's metadata.paperclip_profile; running setup concurrently from two shells with the same profile key.","commonSituations":"Retrying setup after a network failure mid-run without knowing the first resource was created; reusing a profile key across projects; cleaning up in the Anthropic console by cloning resources and forgetting to change the metadata tag.","solutions":["Pass the explicit id flag (--environment-id / --agent-id) naming the resource you want to use","List the Anthropic resources (via API/console) and delete the duplicate, keeping one with metadata.paperclip_profile = <profileKey>","Remove the stale duplicate's paperclip_profile metadata so only one matches","Going forward, use unique profile keys per project and avoid concurrent setup runs with the same key"],"exampleFix":"// before\npaperclip managed-agent setup --profile-key acme ...\n// after (explicit id)\npaperclip managed-agent setup --profile-key acme --environment-id 5c1f... --agent-id a9b2... ...","handlingStrategy":"validation","validationCode":"// Before running setup without explicit ids, check the profile is unambiguous:\nconst resources = await listAll(key, \"/v1/environments\");\nconst matches = resources.filter(r => r.metadata?.paperclip_profile === profileKey);\nif (matches.length > 1) throw new Error(`Duplicate profile ${profileKey}: ${matches.map(r => r.id).join(\", \")}`);","typeGuard":null,"tryCatchPattern":"try {\n  await setupManagedAgent(opts);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"Multiple Anthropic\")) {\n    console.error(\"List resources, delete/archive duplicates, or pass explicit --environment-id/--agent-id\"); process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["Use a unique profile key per project/workspace","Never run managed-agent setup concurrently with the same profile key","After a failed setup run, list remote resources and clean up duplicates before retrying","Or always pass explicit --environment-id/--agent-id to remove ambiguity"],"tags":["ambiguity","deduplication","anthropic","state-conflict"],"backgroundTag":"ambiguous-resource-match","analyzedSha":"5716fe907e596ce73501408fc6efdb19fb61edf2","analyzedAt":"2026-09-02T18:44:00.616Z","contentChangedAt":"2026-09-02T18:44:00.616Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}