mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 22:49:00 +01:00
fix(connections): answer AWS setup refusals with 422 instead of 502 (#22581)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Connections let agents use outside services. The AWS connection gets short-lived AWS credentials for each connection. > - When AWS refuses the customer's role, key or sign-in policy, the health check maps the failure to HTTP 502. > - The error handler reports every 5xx response as a server crash. So a customer's AWS trust setup error goes to Sentry as a Paperclip fault. > - This pull request answers these AWS setup refusals with 422. An AWS outage (`aws_unavailable`) stays a 502. > - The benefit is that Sentry shows only real server faults, and the customer still sees the same message that tells them what to fix. ## Linked Issues or Issue Description **What happened?** A staging health check for an AWS role connection failed because AWS did not accept the role (`aws_role_access_denied`). `healthFailureHttpStatus` returned 502. The error handler then sent "AWS refused this connection's role. Check that the role exists and trusts this connection." to Sentry as a crash. **Expected behavior** A refusal that the customer must fix in their own AWS account is a client-side setup error. The server must answer with a 4xx status and must not report a crash. **Steps to reproduce** 1. Connect AWS with the role method. 2. Make the role stop trusting the connection. 3. Run a connection health check. The response is 502 and Sentry gets an error event. No public GitHub issue exists. Related: #22195 (AWS connector), #22233 (AWS role setup). I found no duplicate open PR. ## What Changed - `healthFailureHttpStatus` returns 422 for AWS configuration failure codes (`aws_*` except `aws_unavailable`). `sanitizeHttpFailure` and the status mapping now use one shared helper for this code set. - The AWS connector integration test now checks that a role refusal answers 422 with code `aws_role_access_denied`. - New unit test `failures.test.ts` checks every AWS setup code maps to 422, and that `aws_unavailable` stays 502. ## Verification - `cd server && npx vitest run src/services/tool-access/catalog/failures.test.ts src/__tests__/aws-mcp-connector.test.ts` passes (9 tests). - Without the fix, the same run fails 2 tests (`expected 502 to be 422`), so the tests prove the regression. - `npx vitest run src/services/connectors/aws` passes (14 tests). - The UI AWS setup screen reads the `aws_*` code, not the HTTP status, so its copy does not change. ## Risks - Low risk. Only the HTTP status of AWS setup failures changes, from 502 to 422. The response body, code, health status and message do not change. AWS outages still answer 502. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code execution in Claude Code. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: paperclipbugbot <356415228+paperclipbugbot@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
3 files changed
+30
-1
No files matched your search
@@ -316,6 +316,7 @@ describe("AWS connector with minted credentials", () => {
|
||||
const [row] = await db.select().from(toolConnections).where(eq(toolConnections.id, connected.connectionId));
|
||||
expect(row!.healthMessage ?? JSON.stringify(health)).toContain("AWS refused this connection's role");
|
||||
expect(row!.healthMessage ?? "").not.toContain("123456789012");
|
||||
expect(health).toMatchObject({ status: 422, details: { code: "aws_role_access_denied" } });
|
||||
|
||||
// The instance's address changes: Paperclip stops with a clear message instead of a role refusal from AWS.
|
||||
vi.stubEnv("PAPERCLIP_PUBLIC_URL", "https://renamed.paperclip.app");
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { HttpError } from "../../../errors.js";
|
||||
import { healthFailureHttpStatus, sanitizeHttpFailure } from "./failures.js";
|
||||
|
||||
function awsFailure(code: string, status: number) {
|
||||
return sanitizeHttpFailure(new HttpError(status, "AWS message", { code }));
|
||||
}
|
||||
|
||||
describe("healthFailureHttpStatus", () => {
|
||||
it("answers AWS refusals of the customer's own setup with 422, so they are not reported as server crashes", () => {
|
||||
for (const code of ["aws_role_access_denied", "aws_access_key_invalid", "aws_mcp_signin_denied", "aws_issuer_changed", "aws_identity_unavailable", "aws_mcp_settings_invalid"]) {
|
||||
const failure = awsFailure(code, 403);
|
||||
expect(failure).toMatchObject({ status: "error", code });
|
||||
expect(healthFailureHttpStatus(failure)).toBe(422);
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps an AWS outage as a gateway failure", () => {
|
||||
const failure = awsFailure("aws_unavailable", 503);
|
||||
expect(failure).toMatchObject({ status: "degraded", code: "aws_unavailable" });
|
||||
expect(healthFailureHttpStatus(failure)).toBe(502);
|
||||
});
|
||||
});
|
||||
@@ -43,9 +43,14 @@ export function healthFailureHttpStatus(failure: {
|
||||
if (failure.code === "tool_connection_transport_unsupported") return 422;
|
||||
if (failure.code === "cognee_access_unverified" || failure.code === "memory_api_key_rejected") return 422;
|
||||
if (failure.code.endsWith("_endpoint_rejected")) return 422;
|
||||
if (isAwsConfigurationFailureCode(failure.code)) return 422;
|
||||
return 502;
|
||||
}
|
||||
|
||||
function isAwsConfigurationFailureCode(code: string): boolean {
|
||||
return code.startsWith("aws_") && code !== "aws_unavailable";
|
||||
}
|
||||
|
||||
export function unsupportedToolConnectionTransport() {
|
||||
return unprocessable(
|
||||
"This connection has no supported tool integration. Add a supported account or MCP connection from Connectors.",
|
||||
@@ -106,7 +111,7 @@ export function sanitizeHttpFailure(error: unknown): {
|
||||
code: "oauth_reauthorization_required",
|
||||
};
|
||||
}
|
||||
if (typeof code === "string" && code.startsWith("aws_") && code !== "aws_unavailable") {
|
||||
if (typeof code === "string" && isAwsConfigurationFailureCode(code)) {
|
||||
return { status: "error", message: error.message, code };
|
||||
}
|
||||
if (code === "aws_unavailable") return { status: "degraded", message: error.message, code };
|
||||
|
||||
Reference in new issue
Block a user