Fix IndexConnection.UpsertRecords swallowing errors#139
Conversation
…cords method, check res.StatusCode directly
…or 201 not 200. update TestIntegratedInference integration test to properly target the integrated index for upsert rather than the shared serverless index - errors were being swallowed silently before on this
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: New IndexConnection never closed, leaking gRPC connection
- Added a deferred
idxConn.Close()(guarded by a nil check) inTestIntegratedInferenceso the gRPC connection created byClient.Indexis always released.
- Added a deferred
Or push these changes by commenting:
@cursor push 1608f65801
Preview (1608f65801)
diff --git a/pinecone/index_connection_test.go b/pinecone/index_connection_test.go
--- a/pinecone/index_connection_test.go
+++ b/pinecone/index_connection_test.go
@@ -597,6 +597,11 @@
idxConn, err := ts.client.Index(NewIndexConnParams{Host: index.Host, Namespace: ts.namespaces[0]})
assert.NoError(ts.T(), err)
assert.NotNil(ts.T(), idxConn)
+ if idxConn != nil {
+ defer func() {
+ assert.NoError(ts.T(), idxConn.Close())
+ }()
+ }
err = idxConn.UpsertRecords(ctx, records)
assert.NoError(ts.T(), err)There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
… remove MatchTerms from integration test since we're not using the appropriate model to call it here
…is actually ready to receive requests
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer res.Body.Close() |
There was a problem hiding this comment.
We were missing closing the response body properly in a few places, so I cleaned that up.
| } | ||
| defer res.Body.Close() | ||
|
|
||
| if res.StatusCode != http.StatusCreated { |
There was a problem hiding this comment.
This was the source of the original bug involving UpsertRecords swallowing server errors completely.
| } | ||
| defer res.Body.Close() | ||
|
|
||
| if res.StatusCode != http.StatusOK { |
There was a problem hiding this comment.
SearchRecords, DescribeImport, and ListImports were also missing proper evaluation of the res.StatusCode so that's now been filled in.
These should all be 200s, you can the implementation in pinecone-db here:
- https://github.com/pinecone-io/pinecone-db/blob/main/pc-bulk-import/src/bulk_api_server.rs#L199
- https://github.com/pinecone-io/pinecone-db/blob/main/pc-bulk-import/src/bulk_api_server.rs#L278
In both cases we return Ok(Response::new(...)), which should default to 200 in tonic.

Problem
The
IndexConnection.UpsertRecordsmethod is currently swallowing errors. For example, if you're trying to callUpsertRecordson a non-integrated index, the resulting 400 error is swallowed, and never surfaced to the user.Solution
IndexConnection.UpsertRecordsmethod, checkres.StatusCodedirectly to validate upsert response.Type of Change
Test Plan
CI - unit & integration testing
The integration test that began failing with this error after making this change validates the approach. Previously, this test was running UpsertRecords against a non-integrated index, and failing silently with a successful test:
I've also built
go-pineconelocally and validated the behavior runningUpsertRecordsagainst an integrated and non-integrated index.UpsertRecordsagainst a non-integrated indexBefore
Invalid upsert against a non-integrated index
After
Invalid upsert against a non-integrated index
Valid upsert against an integrated index (
res.StatusCode == http.StatusCreated)The error'ing is the correct behavior here, and we properly surface the API errors when the status isn't successful.
Note
Medium Risk
Behavior changes in
UpsertRecords(and some other data-plane calls) now correctly return errors for non-success HTTP responses, which may break consumers that previously relied on silent success; scope is otherwise small and well-targeted.Overview
Fixes
IndexConnection.UpsertRecordsto stop swallowing server-side failures by checking the HTTP status (201 Created) and returninghandleErrorResponseBody(...)when the API responds with an error; the upsert request error is also wrapped with%w.Improves HTTP resource/error handling across related calls by adding missing
defer ...Body.Close()and explicit non-200 status checks (notablySearchRecords,DescribeImport,ListImports,Client.ListBackups, andAdminClient.APIKey.List).Updates the integrated inference integration test to wait for index readiness before data-plane calls and to create/close an
IndexConnectionfrom the newly created index host, ensuring failures are actually surfaced.Written by Cursor Bugbot for commit 1ee2602. This will update automatically on new commits. Configure here.