From 2d4dd039fd95f3fc85088420f092211f6178348e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 20 May 2026 20:30:51 +0000 Subject: [PATCH] fix: log underlying errors when agent chat endpoint returns HTTP 500 When GET /api/v1/agents/canvases/{canvas_id}/chat returns codes.Internal, the underlying error was either swallowed or logged with limited context. The grpc error sanitizer then only forwarded the sanitized message to logs, and Sentry only saw 'HTTP 500 ...' messages with no payload, making it impossible to diagnose the root cause from a Sentry issue alone. Capture the actual error with organization_id/user_id/canvas_id fields before wrapping it in a status.Error, so the next 500 from this endpoint has the context needed to investigate (DB error in FindCanvas, upstream provider failure on session provisioning, or invalid JWT identifiers). Refs: Sentry issue 7495744767 Co-authored-by: Aleksandar Mitrovic --- pkg/grpc/actions/agents/common.go | 11 +++++++++++ pkg/grpc/actions/agents/get_canvas_agent_chat.go | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/grpc/actions/agents/common.go b/pkg/grpc/actions/agents/common.go index 10515d7a10..2347354b90 100644 --- a/pkg/grpc/actions/agents/common.go +++ b/pkg/grpc/actions/agents/common.go @@ -6,6 +6,7 @@ import ( "errors" "github.com/google/uuid" + log "github.com/sirupsen/logrus" agentservice "github.com/superplanehq/superplane/pkg/agents" "github.com/superplanehq/superplane/pkg/models" pb "github.com/superplanehq/superplane/pkg/protos/agents" @@ -38,10 +39,16 @@ func agentModeFromProto(mode pb.AgentMode) string { func parseOrgUser(orgID, userID string) (org, user uuid.UUID, err error) { org, err = uuid.Parse(orgID) if err != nil { + log.WithError(err). + WithField("organization_id", orgID). + Error("agent request received an invalid organization id") return uuid.Nil, uuid.Nil, status.Error(codes.Internal, "invalid organization") } user, err = uuid.Parse(userID) if err != nil { + log.WithError(err). + WithField("user_id", userID). + Error("agent request received an invalid user id") return uuid.Nil, uuid.Nil, status.Error(codes.Internal, "invalid user") } return org, user, nil @@ -52,6 +59,10 @@ func ensureCanvas(orgID, canvasID uuid.UUID) error { if errors.Is(err, gorm.ErrRecordNotFound) { return status.Error(codes.NotFound, "canvas not found") } + log.WithError(err). + WithField("organization_id", orgID.String()). + WithField("canvas_id", canvasID.String()). + Error("failed to load canvas for agent request") return status.Error(codes.Internal, "failed to load canvas") } return nil diff --git a/pkg/grpc/actions/agents/get_canvas_agent_chat.go b/pkg/grpc/actions/agents/get_canvas_agent_chat.go index 77230c053c..b14cc99ae3 100644 --- a/pkg/grpc/actions/agents/get_canvas_agent_chat.go +++ b/pkg/grpc/actions/agents/get_canvas_agent_chat.go @@ -30,7 +30,11 @@ func GetCanvasAgentChat(ctx context.Context, svc AgentsService, orgID, userID st if errors.Is(err, agents.ErrSessionForbidden) { return nil, status.Error(codes.PermissionDenied, "agent chat is not allowed") } - log.WithError(err).WithField("canvas_id", canvas).Error("failed to ensure agent chat") + log.WithError(err). + WithField("canvas_id", canvas.String()). + WithField("organization_id", org.String()). + WithField("user_id", user.String()). + Error("failed to ensure agent chat") return nil, status.Error(codes.Internal, "failed to load agent chat") } return &pb.GetCanvasAgentChatResponse{Chat: serializeChat(session)}, nil