Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(sentry): drop expected stale tool-approval conflicts (#16384)

cursor[bot]8c4db7ba716c
diff --git a/web/src/utils/api.clienttest.ts b/web/src/utils/api.clienttest.ts
index 47b71e26d7..17e3a6d3a7 100644
--- a/web/src/utils/api.clienttest.ts
+++ b/web/src/utils/api.clienttest.ts
@@ -3,6 +3,7 @@
import { TRPCClientError } from "@trpc/client";
import { vi } from "vitest";
import {
+ EXPECTED_TRPC_CONFLICT_PATHS,
EXPECTED_TRPC_ERROR_CODES,
captureBuildId,
fetchWithParseErrorStatus,
@@ -453,6 +454,43 @@ describe("isExpectedTrpcClientError", () => {
).toBe(false);
});
+ it("treats a stale in-app-agent tool approval as expected", () => {
+ // decideToolApproval throws CONFLICT only when the parent run is no
+ // longer AWAITING_APPROVAL (already decided, expired, or cancelled).
+ // The UI toasts "Reload the conversation." — product working as designed.
+ const error = trpcServerError({
+ code: "CONFLICT",
+ httpStatus: 409,
+ path: "inAppAgent.decideToolApproval",
+ message: "This approval is no longer pending. Reload the conversation.",
+ });
+
+ expect(isExpectedTrpcClientError(error)).toBe(true);
+ });
+
+ it("does not treat CONFLICT on other procedures as expected", () => {
+ // Negative fixture: duplicate-name / unique-constraint CONFLICTs must
+ // still reach Sentry. Widening the allowlist would hide those.
+ expect(
+ isExpectedTrpcClientError(
+ trpcServerError({
+ code: "CONFLICT",
+ httpStatus: 409,
+ path: "prompts.create",
+ }),
+ ),
+ ).toBe(false);
+ expect(
+ isExpectedTrpcClientError(
+ trpcServerError({
+ code: "CONFLICT",
+ httpStatus: 409,
+ path: "inAppAgent.startRun",
+ }),
+ ),
+ ).toBe(false);
+ });
+
it("suppresses Zod input validation (empty/too-short fields) as expected user input", () => {
expect(
isExpectedTrpcClientError(
@@ -626,6 +664,25 @@ describe("reportTrpcErrorWithoutToast", () => {
warnSpy.mockRestore();
});
+ it("suppresses a stale in-app-agent tool approval (breadcrumb, no capture)", () => {
+ reportTrpcErrorWithoutToast(
+ trpcServerError({
+ code: "CONFLICT",
+ httpStatus: 409,
+ path: EXPECTED_TRPC_CONFLICT_PATHS[0],
+ message: "This approval is no longer pending. Reload the conversation.",
+ }),
+ "in-app-agent",
+ );
+
+ expect(captureExceptionMock).not.toHaveBeenCalled();
+ expect(addBreadcrumbMock).toHaveBeenCalledTimes(1);
+ expect(addBreadcrumbMock.mock.calls[0]![0].data).toMatchObject({
+ code: "CONFLICT",
+ path: "inAppAgent.decideToolApproval",
+ });
+ });
+
it("suppresses expected codes (breadcrumb, no capture) — same policy as the seam", () => {
// The organizations.delete FORBIDDEN advice: previously console.error'd by
// the component (one Sentry event per retry), now classified as expected.
@@ -664,6 +721,25 @@ describe("reportTrpcErrorWithoutToast", () => {
// Negative fixture: real errors MUST still be captured, with the
// procedure/code fingerprint and tags.
+ it("captures CONFLICT on procedures outside the allowlist", () => {
+ reportTrpcErrorWithoutToast(
+ trpcServerError({
+ code: "CONFLICT",
+ httpStatus: 409,
+ path: "prompts.create",
+ }),
+ "prompts",
+ );
+
+ expect(captureExceptionMock).toHaveBeenCalledTimes(1);
+ const [, options] = captureExceptionMock.mock.calls[0]!;
+ expect(options.tags).toMatchObject({
+ area: "trpc",
+ "trpc.code": "CONFLICT",
+ "trpc.path": "prompts.create",
+ });
+ });
+
it("captures a real (5xx) tRPC error with fingerprint and tags", () => {
const error = trpcServerError({
code: "INTERNAL_SERVER_ERROR",
diff --git a/web/src/utils/api.ts b/web/src/utils/api.ts
index c33ff3bee4..3ed4aef588 100644
--- a/web/src/utils/api.ts
+++ b/web/src/utils/api.ts
@@ -128,10 +128,13 @@ export const isNetworkConnectivityError = (error: unknown): boolean => {
*
* Deliberately narrow: only these codes on an actual `TRPCClientError`, plus
* Zod input validation (`BAD_REQUEST` whose message is a Zod 4 issue list or
- * whose `data.zodError` is populated). Empty/too-short fields are the product
- * working as designed — the toast is the UX; Sentry must not log them.
- * A 5xx (`INTERNAL_SERVER_ERROR`), a non-Zod `BAD_REQUEST`, an unrecognized
- * code, or any non-tRPC error is not expected and keeps flowing to Sentry.
+ * whose `data.zodError` is populated), plus CONFLICT on
+ * {@link EXPECTED_TRPC_CONFLICT_PATHS}. Empty/too-short fields and stale
+ * in-app-agent approvals are the product working as designed — the toast is
+ * the UX; Sentry must not log them.
+ * A 5xx (`INTERNAL_SERVER_ERROR`), a non-Zod `BAD_REQUEST`, a CONFLICT
+ * outside the allowlist, an unrecognized code, or any non-tRPC error is not
+ * expected and keeps flowing to Sentry.
*/
export const EXPECTED_TRPC_ERROR_CODES = [
"NOT_FOUND",
@@ -140,6 +143,20 @@ export const EXPECTED_TRPC_ERROR_CODES = [
"UNPROCESSABLE_CONTENT",
] as const;
+/**
+ * CONFLICT is usually a uniqueness / concurrency failure we still want
+ * (duplicate names, unique-constraint races). These procedures throw 409
+ * only as an optimistic-concurrency / stale-UI race the product already
+ * toasts — expected user-facing state, not a regression.
+ *
+ * `inAppAgent.decideToolApproval` is the only current member: every CONFLICT
+ * it throws means the parent run is no longer AWAITING_APPROVAL (already
+ * decided, expired, or cancelled). The UI already tells the user to reload.
+ */
+export const EXPECTED_TRPC_CONFLICT_PATHS = [
+ "inAppAgent.decideToolApproval",
+] as const;
+
const getTrpcErrorData = (
error: unknown,
): { code?: unknown; path?: unknown } | undefined =>
@@ -180,7 +197,7 @@ export const getTrpcErrorFingerprint = (error: unknown): string[] => [
/**
* True when `error` is a TRPCClientError whose code is an EXPECTED, user-facing
* state that should not be captured to Sentry.
- * See {@link EXPECTED_TRPC_ERROR_CODES}.
+ * See {@link EXPECTED_TRPC_ERROR_CODES} and {@link EXPECTED_TRPC_CONFLICT_PATHS}.
*/
export const isExpectedTrpcClientError = (error: unknown): boolean => {
const code = getTrpcErrorCode(error);
@@ -190,6 +207,14 @@ export const isExpectedTrpcClientError = (error: unknown): boolean => {
) {
return true;
}
+ const path = getTrpcErrorPath(error);
+ if (
+ code === "CONFLICT" &&
+ path !== undefined &&
+ (EXPECTED_TRPC_CONFLICT_PATHS as readonly string[]).includes(path)
+ ) {
+ return true;
+ }
return isTrpcZodValidationError(error);
};