diff --git a/services/core/internal/api/errors.go b/services/core/internal/api/errors.go index 3b4b6c0b2..af339ab6d 100644 --- a/services/core/internal/api/errors.go +++ b/services/core/internal/api/errors.go @@ -98,8 +98,13 @@ func writeOperationError(w http.ResponseWriter, r *http.Request, err error) { const invalidInputMessage = "Invalid resource identifier or request limits." // writeInternalError reports an unmapped failure. Driver errors can include -// submitted values, so the raw error is never logged. +// submitted values, so the raw error is never logged. Once the client has gone, +// the failure is its ended request context: nothing is reported, and the request +// log records the request as aborted. func writeInternalError(w http.ResponseWriter, r *http.Request) { + if r.Context().Err() != nil { + return + } log.Ctx(r.Context()).Error("oac-core persistence operation failed") writeError(w, http.StatusInternalServerError, "internal_error", "The operation could not be completed.") } diff --git a/services/core/internal/api/errors_agents.go b/services/core/internal/api/errors_agents.go index f8577c622..728c9e481 100644 --- a/services/core/internal/api/errors_agents.go +++ b/services/core/internal/api/errors_agents.go @@ -4,7 +4,6 @@ import ( "errors" "net/http" - "github.com/MiniMax-AI/OpenAgentCore/internal/obs/log" "github.com/MiniMax-AI/OpenAgentCore/services/core/internal/agents" ) @@ -19,7 +18,6 @@ func writeAgentsError(w http.ResponseWriter, r *http.Request, err error) { case errors.Is(err, agents.ErrInvalidInput): writeError(w, http.StatusBadRequest, "invalid_request", "Invalid resource identifier or request limits.") default: - log.Ctx(r.Context()).Error("oac-core persistence operation failed") - writeError(w, http.StatusInternalServerError, "internal_error", "The operation could not be completed.") + writeInternalError(w, r) } } diff --git a/services/core/internal/api/errors_files.go b/services/core/internal/api/errors_files.go index 0b8d1ab9b..f5de3795c 100644 --- a/services/core/internal/api/errors_files.go +++ b/services/core/internal/api/errors_files.go @@ -5,7 +5,6 @@ import ( "net/http" "strings" - "github.com/MiniMax-AI/OpenAgentCore/internal/obs/log" "github.com/MiniMax-AI/OpenAgentCore/services/core/internal/files" ) @@ -28,8 +27,6 @@ func writeFilesError(w http.ResponseWriter, r *http.Request, err error, notFound case errors.Is(err, files.ErrInvalidInput): writeError(w, http.StatusBadRequest, "invalid_request", "Invalid resource identifier or request limits.") default: - // Storage failures can include submitted values; do not log the error. - log.Ctx(r.Context()).Error("oac-core persistence operation failed") - writeError(w, http.StatusInternalServerError, "internal_error", "The operation could not be completed.") + writeInternalError(w, r) } } diff --git a/services/core/internal/api/errors_test.go b/services/core/internal/api/errors_test.go index 6295a799d..521a2d5f6 100644 --- a/services/core/internal/api/errors_test.go +++ b/services/core/internal/api/errors_test.go @@ -1,6 +1,7 @@ package api import ( + "context" "encoding/json" "errors" "fmt" @@ -197,3 +198,14 @@ func TestSharedPersistenceErrors(t *testing.T) { } } } + +// A client that has gone gets no error report: its ended context is the failure. +func TestInternalErrorAfterClientAbort(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + cancel() + response := httptest.NewRecorder() + writeAgentsError(response, httptest.NewRequest(http.MethodGet, "/v1/agents", nil).WithContext(ctx), context.Canceled) + if response.Body.Len() != 0 { + t.Fatal(response.Body) + } +}