{"record":{"id":"24816af05da58c28","repo":"paperclipai/paperclip","slug":"detail-name-already-has-an-env-var-named-key","errorCode":null,"errorMessage":"${detail.name} already has an env var named ${key}.","messagePattern":"(.+?) already has an env var named (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ui/src/pages/Secrets.tsx","lineNumber":4426,"sourceCode":"    setAccessError(null);\n  }, [referenceId]);\n\n  function invalidateAfterChange(agentId: string) {\n    queryClient.invalidateQueries({ queryKey: queryKeys.agents.list(companyId) });\n    queryClient.invalidateQueries({ queryKey: queryKeys.agents.detail(agentId) });\n    if (reference.kind === \"company\") {\n      queryClient.invalidateQueries({ queryKey: queryKeys.secrets.usage(reference.secret.id) });\n    }\n  }\n\n  const grantMutation = useMutation({\n    mutationFn: async ({ agentId, key }: { agentId: string; key: string }) => {\n      // Re-fetch right before patching so we merge into the freshest env config.\n      const detail = await agentsApi.get(agentId, companyId);\n      const adapterConfig = { ...((detail.adapterConfig ?? {}) as Record<string, unknown>) };\n      const env = { ...((adapterConfig.env ?? {}) as Record<string, unknown>) };\n      if (env[key] !== undefined) {\n        throw new Error(`${detail.name} already has an env var named ${key}.`);\n      }\n      env[key] =\n        reference.kind === \"company\"\n          ? { type: \"secret_ref\", secretId: reference.secret.id }\n          : { type: \"user_secret_ref\", key: reference.definition.key };\n      return agentsApi.update(\n        agentId,\n        { adapterConfig: { ...adapterConfig, env }, replaceAdapterConfig: true },\n        companyId,\n      );\n    },\n    onSuccess: (agent, variables) => {\n      setSelectedAgentId(\"\");\n      setEnvKey(\"\");\n      setEnvKeyDirty(false);\n      setAccessError(null);\n      invalidateAfterChange(variables.agentId);\n      pushToast({ title: \"Access granted\", body: `${agent.name} now receives ${variables.key}`, tone: \"success\" });","sourceCodeStart":4408,"sourceCodeEnd":4444,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/ui/src/pages/Secrets.tsx#L4408-L4444","documentation":"Conflict guard in the secret-grant mutation: the caller tried to grant agent access via an env-var binding, but the target agent already has an environment variable with that key, which would collide in the generated runtime environment. The offending input is the requested env var key for that agent.","triggerScenarios":"Thrown at ui/src/pages/Secrets.tsx:4426 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Choose a different env var key, or update the existing env var with that name instead."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}