Conversation
| 404: RESPONSE_NOT_FOUND, | ||
| }, | ||
| ) | ||
| @track_alert_endpoint_execution("GET", "sentry-api-0-project-rule-group-history-index") |
There was a problem hiding this comment.
Bug: The @track_alert_endpoint_execution decorator resets the _legacy_models_used context variable prematurely, causing metrics to always incorrectly report that legacy models were not used.
Severity: MEDIUM
Suggested Fix
Modify the @track_alert_endpoint_execution decorator to read the value of the _legacy_models_used context variable before resetting it. The value should be captured after the endpoint handler runs but before the context variable is reset, ensuring the correct state is recorded in the metric.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/sentry/rules/history/endpoints/project_rule_group_history.py#L82
Potential issue: The `@track_alert_endpoint_execution` decorator introduces a timing bug
related to the `_legacy_models_used` context variable. The decorator's wrapper function
immediately resets this variable to `False` by calling `_legacy_models_used.set(False)`
before the actual endpoint handler is executed. The value is correctly set to `True` in
the `convert_args` method, which runs before the decorator's wrapper. However, because
the reset happens before the handler runs and the value is read, the decorator always
captures `False`. This results in the `alert_endpoint.executed` metric consistently and
incorrectly reporting `legacy_models: false`, defeating the purpose of the legacy model
usage tracking.
Did we get this right? 👍 / 👎 to inform future reviews.
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.
Reviewed by Cursor Bugbot for commit eb94516. Configure here.
|
|
||
| return args, kwargs | ||
|
|
||
| report_used_legacy_models() |
There was a problem hiding this comment.
ContextVar reset in decorator nullifies convert_args tracking
High Severity
report_used_legacy_models() in convert_args sets _legacy_models_used to True, but convert_args runs before the endpoint handler method. The track_alert_endpoint_execution decorator on the handler resets the ContextVar to False at the start of its wrapper. This means the legacy-model flag is always wiped before the decorator reads it, so legacy_models will always be reported as false — defeating the entire purpose of this tracking improvement. The same issue applies to the newly decorated rule history/stats endpoints, where the pre-existing report_used_legacy_models() in WorkflowEngineRuleEndpoint.convert_args is similarly reset.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit eb94516. Configure here.
|
ah right, I forgot about that. |


Our metric for tracking legacy model API use have a few holes, but I think this should close the biggest ones.