{"record":{"id":"4d6a21ec23594c45","repo":"paperclipai/paperclip","slug":"remote-app-returned-an-error","errorCode":null,"errorMessage":"Remote app returned an error","messagePattern":"Remote app returned an error","errorType":"http","errorClass":"HttpError","httpStatus":502,"severity":"error","filePath":"server/src/services/tool-access.ts","lineNumber":3058,"sourceCode":"    agentId: string;\n    issueId: string | null;\n    projectId: string | null;\n    routineId: string | null;\n  }) {\n    const bindings = await db.select().from(toolProfileBindings).where(eq(toolProfileBindings.companyId, input.companyId));\n    const matchingBindings = bindings.filter((binding) => {\n      if (binding.targetType === \"company\") return binding.targetId === input.companyId;\n      if (binding.targetType === \"agent\") return binding.targetId === input.agentId;\n      if (binding.targetType === \"issue\") return Boolean(input.issueId && binding.targetId === input.issueId);\n      if (binding.targetType === \"project\") return Boolean(input.projectId && binding.targetId === input.projectId);\n      if (binding.targetType === \"routine\") return Boolean(input.routineId && binding.targetId === input.routineId);\n      return false;\n    });\n    const profileIds = profileIdsInBindingOrder(narrowestScopeBindings(matchingBindings));\n    if (profileIds.length === 0) return false;\n    const profiles = await db.select().from(toolProfiles).where(and(\n      eq(toolProfiles.companyId, input.companyId),\n      inArray(toolProfiles.id, profileIds),\n    ));\n    const activeProfileIds = profiles\n      .filter((profile) => profile.status === \"active\")\n      .map((profile) => profile.id);\n    if (activeProfileIds.length === 0) return false;\n    const entries = await db.select().from(toolProfileEntries).where(and(\n      eq(toolProfileEntries.companyId, input.companyId),\n      inArray(toolProfileEntries.profileId, activeProfileIds),\n    ));\n    return activeProfileIds.some((profileId) => {\n      const profileEntries = entries.filter((entry) => entry.profileId === profileId);\n      const exactBrokerEntries = profileEntries.filter((entry) =>\n        entry.selectorType === \"tool_name\"\n        && entry.toolName === CONNECTION_TOKEN_MINT_TOOL_NAME\n        && Object.keys(asRecord(entry.conditions)).length === 0\n      );\n      if (exactBrokerEntries.some((entry) => entry.effect === \"exclude\")) return false;\n      return exactBrokerEntries.some((entry) => entry.effect === \"include\");","sourceCodeStart":3040,"sourceCodeEnd":3076,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/server/src/services/tool-access.ts#L3040-L3076","documentation":"Upstream error translation: the remote app's OAuth-protected endpoint returned an error response, which is wrapped into HttpError 502 with the discovered provider metadata persisted for debugging. The remote provider's failed response is at fault.","triggerScenarios":"Thrown at server/src/services/tool-access.ts:2914 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["The remote app returned an error during auth. Check the app's configuration and provider-side logs, then retry the connection."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}