ref(seer): Migrate remaining seer calls to urllib3 connection pools#109263
ref(seer): Migrate remaining seer calls to urllib3 connection pools#109263
Conversation
Replace requests.post with make_signed_seer_api_request in: - supergroups.py: Supergroup embeddings - trace_summary.py: Trace summarization - tasks/seer.py & tasks/seer_explorer_index.py: Background tasks - api/endpoints/seer_models.py: Seer models API Update corresponding tests with new mocking patterns. This completes the migration from requests to urllib3 connection pools across all Seer integration code. Co-Authored-By: Claude <noreply@anthropic.com>
Migrate all remaining `requests.post` + `sign_with_seer_secret` calls to `make_signed_seer_api_request` with urllib3 connection pools, and replace bare `Exception` raises with `SeerApiError` across all cherry-picked files. Migrated callers: - explorer_context_engine_tasks (requests.post → connection pool) - uptime/seer_assertions (requests.post → connection pool) - seer/services/test_generation/impl (requests.post → connection pool) SeerApiError cleanup: - seer_models, supergroups, trace_summary, seer tasks, seer_explorer_index After this change, no external `requests.post` or `sign_with_seer_secret` calls remain outside of `make_signed_seer_api_request`. Co-Authored-By: Claude <noreply@anthropic.com>
Address Warden feedback: - test_generation/impl.py: Handle response.data being None when decoding error response body, matching the pattern used in similar_issues.py and store_data.py - uptime/seer_assertions.py: Catch urllib3 exceptions (MaxRetryError, TimeoutError) in addition to SeerApiError for network failures, preserving the graceful fallback behavior from the requests era Co-Authored-By: Claude <noreply@anthropic.com>
- seer_models.py: Simplify `except (Exception, json.JSONDecodeError)` to `except Exception:` since JSONDecodeError is a subclass. Remove unused json import. - test_seer_models.py: Replace `requests.get` mocks with `make_signed_seer_api_request` mocks (requests import was removed). - test_seer.py: Replace `@responses.activate` with `make_signed_seer_api_request` mocks (responses library doesn't intercept urllib3). Co-Authored-By: Claude <noreply@anthropic.com>
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.
| except TimeoutError: | ||
| logger.warning("Timeout when fetching models from Seer") | ||
| raise SeerTimeoutError() | ||
| except (requests.exceptions.RequestException, json.JSONDecodeError): |
There was a problem hiding this comment.
Catching wrong TimeoutError type; urllib3 timeouts uncaught
High Severity
The except TimeoutError clause catches Python's built-in TimeoutError, but make_signed_seer_api_request uses urllib3 which raises urllib3.exceptions.TimeoutError — a completely separate class that does not inherit from the built-in TimeoutError. As a result, urllib3 timeout errors will never be caught here and will instead fall through to except Exception, returning a 502 SeerConnectionError instead of the intended 504 SeerTimeoutError. Notably, uptime/seer_assertions.py in this same PR correctly imports and catches urllib3.exceptions.TimeoutError as Urllib3TimeoutError.


Migrate all remaining
requests.post+sign_with_seer_secretcalls tomake_signed_seer_api_requestwith urllib3 connection pools, completing the migration started in #109205, #109224, and #109254.Migrated callers (requests.post → connection pool):
tasks/explorer_context_engine_tasks.pyuptime/seer_assertions.pyseer/services/test_generation/impl.py(also adds signing that was previously missing)SeerApiError cleanup (bare Exception → SeerApiError):
api/endpoints/seer_models.pyseer/supergroups.pyseer/trace_summary.pytasks/seer.pytasks/seer_explorer_index.pyAfter this change, no external
requests.postorsign_with_seer_secretcalls remain outside ofmake_signed_seer_api_request. The only remainingsign_with_seer_secretusage is the internal definition and call withinsigned_seer_api.pyitself.Note:
explorer_service_map_utils.pyhas a_send_to_seerstub with a TODO comment — it doesn't make any actual requests yet.