ref(seer): remove redundant SeerViewerContext from endpoint call sites - #121021
Draft
sehr-m wants to merge 3 commits into
Draft
ref(seer): remove redundant SeerViewerContext from endpoint call sites#121021sehr-m wants to merge 3 commits into
sehr-m wants to merge 3 commits into
Conversation
Endpoints already have ViewerContext set by ViewerContextMiddleware, so explicitly constructing SeerViewerContext and threading it to Seer API functions is redundant. Remove it from ~19 endpoint files and their helpers, letting _resolve_viewer_context read from the contextvar. Task/consumer call sites keep their SeerViewerContext as a fallback until VC is hoisted at those infrastructure boundaries. Add seer_path to the chokepoint observe_viewer_context_propagation call so missing-VC warnings identify which Seer API path is affected. Add has_project_id to observation metrics for completeness tracking.
Adds a warning at the Seer RPC chokepoint when the resolved viewer context has an organization_id but no project_id, so uncovered paths are visible in logs.
The warning fires on nearly every Seer call because most endpoints are org-scoped and legitimately don't have a single project. The has_project_id metric tag in observe_viewer_context_propagation already provides passive observability — filter by seer_path to identify gaps.
Contributor
Backend Test FailuresFailures on
|
| agent_run_options["enable_streaming"] = True | ||
|
|
||
| response = make_agent_chat_request(chat_body, viewer_context=self.viewer_context) | ||
| response = make_agent_chat_request(chat_body) |
Contributor
There was a problem hiding this comment.
Background continue_run callers lose X-Viewer-Context header to Seer
Dropping viewer_context=self.viewer_context here also strips the viewer header for task/consumer callers of SeerExplorerClient.continue_run (e.g. dashboards/on_completion_hook.py, seer/autofix/autofix_agent.py, seer/entrypoints/operator.py), where the middleware contextvar is not set — contradicting the PR's claim that task call sites keep a fallback — so Seer receives those requests with no org/user attribution.
Evidence
SeerExplorerClient.continue_runnow callsmake_agent_chat_request(chat_body)with noviewer_context, and the same pattern applies tomake_agent_runs_request/make_agent_update_request(client.py:903,975)._resolve_viewer_context(None)insigned_seer_api.py:56returnsget_viewer_context(), which isNoneoutside request middleware; when resolved is None theX-Viewer-Contextheader is simply not added (make_signed_seer_api_request).continue_runis called from non-endpoint paths:dashboards/on_completion_hook.py:262(task, builds client withuser=None),seer/autofix/autofix_agent.py:485, andseer/entrypoints/operator.py:553, none of which are covered byViewerContextMiddleware.- Previously
self.viewer_context(built from the client's organization/user) was always sent, so Seer-side attribution/scoping was preserved even in background contexts; the PR body states VC is not yet hoisted at task/consumer boundaries.
Identified by Warden · security-review · 37R-U7N
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SeerViewerContextconstruction from ~19 endpoint files and their helpers —ViewerContextMiddlewarealready sets ViewerContext via contextvar, making these redundantseer_pathto the chokepointobserve_viewer_context_propagation("seer_rpc_out")call so missing-VC warnings identify which Seer API path is affectedhas_project_idto VC observation metrics for completeness trackingSeerViewerContextas a fallback until VC is hoisted at those infrastructure boundariesThis is the first step of the gradual migration discussed with Greg — endpoints are safe to migrate immediately because middleware guarantees VC. Future PRs will hoist VC at task/consumer entry points, using the chokepoint warnings to identify gaps.
Test plan
🤖 Generated with Claude Code