Skip to content

feat(nightshift): Add endpoint to manually trigger nightshift#113803

Merged
chromy merged 4 commits intomasterfrom
chromy/2026-04-23-add-endpoint-to-trigger-nightshift
Apr 23, 2026
Merged

feat(nightshift): Add endpoint to manually trigger nightshift#113803
chromy merged 4 commits intomasterfrom
chromy/2026-04-23-add-endpoint-to-trigger-nightshift

Conversation

@chromy
Copy link
Copy Markdown
Contributor

@chromy chromy commented Apr 23, 2026

No description provided.

@chromy chromy requested a review from a team as a code owner April 23, 2026 15:23
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 23, 2026
Comment thread src/sentry/seer/endpoints/project_seer_night_shift.py Outdated
Comment thread src/sentry/seer/endpoints/project_seer_night_shift.py Outdated
@getsantry getsantry Bot requested a review from a team as a code owner April 23, 2026 15:25
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on f6c8d93 in this run:

tests/sentry/seer/endpoints/test_project_seer_night_shift.py::ProjectSeerNightShiftTest::test_triggers_tasklog
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/seer/endpoints/test_project_seer_night_shift.py:20: in test_triggers_task
    self.get_success_response(
src/sentry/testutils/cases.py:629: in get_success_response
    assert_status_code(response, status_code)
src/sentry/testutils/asserts.py:46: in assert_status_code
    assert minimum <= response.status_code < maximum, response
E   AssertionError: <Response status_code=200>
E   assert 202 <= 200
E    +  where 200 = <Response status_code=200>.status_code

Comment thread src/sentry/seer/endpoints/project_seer_night_shift.py Outdated
Convert run_night_shift_for_project into an instrumented Celery task and
have the manual trigger endpoint enqueue it via apply_async instead of
running it synchronously in the request. The endpoint now returns 202 to
reflect that the work happens in the background.

Co-Authored-By: Claude <noreply@anthropic.com>

Agent transcript: https://claudescope.sentry.dev/share/NbgWwkYbXHUsKP9fXIEeS354KlJdTM6vT4hp_VRZFho
@chromy chromy force-pushed the chromy/2026-04-23-add-endpoint-to-trigger-nightshift branch from 8959c40 to 8c905cf Compare April 23, 2026 16:18
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8c905cf. Configure here.


def post(self, request: Request, project: Project) -> Response:
if not features.has("organizations:seer-night-shift", project.organization):
raise NotFound
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual trigger bypasses org-level feature flag checks

Medium Severity

The endpoint only checks "organizations:seer-night-shift" before dispatching the task. The scheduled path in _get_eligible_orgs_from_batch enforces all three FEATURE_NAMES"organizations:seer-night-shift", "organizations:gen-ai-features", and "organizations:seat-based-seer-enabled" — plus the sentry:hide_ai_features option. The manual trigger path skips the latter two feature flags, which likely gate AI product entitlement and billing, allowing nightshift to run for orgs that aren't fully entitled.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8c905cf. Configure here.

raise NotFound

run_night_shift_for_project.apply_async(args=[project.id])
return Response(status=202)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Endpoint missing rate limiting for expensive operation

Low Severity

ProjectSeerNightShiftEndpoint lacks rate limiting, yet each POST creates a SeerNightShiftRun, consumes Seer autofix quota, and can trigger autofix runs. The sibling ProjectSeerPreferencesEndpoint in the same directory explicitly sets enforce_rate_limit = True with a RateLimitConfig. Without rate limits, repeated calls could queue many concurrent nightshift runs for the same project.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8c905cf. Configure here.

Comment on lines +24 to +28
def post(self, request: Request, project: Project) -> Response:
if not features.has("organizations:seer-night-shift", project.organization):
raise NotFound

run_night_shift_for_project.apply_async(args=[project.id])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The endpoint only checks the organizations:seer-night-shift flag, not projects:seer-night-shift. This can lead to silently failing jobs if the project-level flag is disabled.
Severity: MEDIUM

Suggested Fix

Before enqueuing the task, check if the project has the projects:seer-night-shift feature flag enabled, in addition to the existing organizations:seer-night-shift check. Return an appropriate error response if the project-level flag is not set.

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/seer/endpoints/project_seer_night_shift.py#L24-L28

Potential issue: The endpoint checks for the `organizations:seer-night-shift` feature
flag but not the project-specific `projects:seer-night-shift` flag. If the organization
flag is enabled but the project flag is not, the endpoint returns a 202 Accepted
response and enqueues a task. The task creates a `SeerNightShiftRun` database record,
but then the `_get_eligible_projects` function filters out the project due to the
missing project flag. This results in a silent failure where the user is notified of
success, but no work is performed, and a dangling database record is created.

@chromy chromy merged commit 1770ddc into master Apr 23, 2026
72 of 77 checks passed
@chromy chromy deleted the chromy/2026-04-23-add-endpoint-to-trigger-nightshift branch April 23, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants