Skip to content

feat(autopilot): Add finish reason to prompt#107229

Merged
ArthurKnaus merged 2 commits intomasterfrom
aknaus/feat/autopilot/add-finish-reason-to-prompt
Jan 29, 2026
Merged

feat(autopilot): Add finish reason to prompt#107229
ArthurKnaus merged 2 commits intomasterfrom
aknaus/feat/autopilot/add-finish-reason-to-prompt

Conversation

@ArthurKnaus
Copy link
Copy Markdown
Member

No description provided.

@ArthurKnaus ArthurKnaus requested a review from a team January 29, 2026 13:47
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 29, 2026
Comment on lines +349 to +386
@@ -370,9 +373,17 @@ def run_missing_sdk_integration_detector_for_project(

# Output

Return a JSON array of missing integration names using exact names from the docs.
Example: `["zodErrorsIntegration"]`
If none missing: `[]`"""
Return a JSON object with:
- `missing_integrations`: Array of missing integration names using exact names from the docs
- `finish_reason`: A short snake_case string describing the outcome:
- `done`: Successfully analyzed the project (even if no integrations are missing)
- `missing_sentry_init`: Could not find Sentry initialization code (`Sentry.init` or `sentry_sdk.init`)
- `missing_dependency_file`: Could not find any dependency file for the project
- For other issues, use a descriptive snake_case reason (e.g., `docs_unavailable`)

Example success: `{{"missing_integrations": ["zodErrorsIntegration"], "finish_reason": "done"}}`
Example no missing: `{{"missing_integrations": [], "finish_reason": "done"}}`
Example no init: `{{"missing_integrations": [], "finish_reason": "missing_sentry_init"}}`"""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we use constants for the return values, so that we ensure they are consistent?

@@ -385,6 +396,7 @@ def run_missing_sdk_integration_detector_for_project(
# Extract the structured result
result = state.get_artifact("missing_integrations", MissingSdkIntegrationsResult)
missing_integrations = result.missing_integrations if result else []
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 call to state.get_artifact can raise a ValidationError if the AI response is missing the required finish_reason field. This unhandled exception causes the task to fail silently.
Severity: HIGH

Suggested Fix

Wrap the call to state.get_artifact in a try...except pydantic.ValidationError block to handle cases where the artifact data is malformed. Alternatively, make the finish_reason field in the MissingSdkIntegrationsResult model optional with a default value to prevent validation from failing.

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/autopilot/tasks.py#L387

Potential issue: The `state.get_artifact` method at line 387 uses Pydantic's `parse_obj`
to validate data against the `MissingSdkIntegrationsResult` model, which requires a
`finish_reason` field. If the AI model returns data without this field, `parse_obj`
raises a `ValidationError`. This exception is not handled locally, so the `result`
variable is never assigned. The subsequent fallback logic for a `None` result is never
reached. The entire task then fails, caught by a generic `except Exception` block that
logs a non-specific error and prevents any Sentry issues from being created for the
missing integrations.

Did we get this right? 👍 / 👎 to inform future reviews.

Return a JSON object with:
- `missing_integrations`: Array of missing integration names using exact names from the docs
- `finish_reason`: A short snake_case string describing the outcome:
- `done`: Successfully analyzed the project (even if no integrations are missing)
Copy link
Copy Markdown
Member

@shellmayr shellmayr Jan 29, 2026

Choose a reason for hiding this comment

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

'done' may indicate that the task was completed unsuccessfully as well - should we call this "success" instead?

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 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Copy link
Copy Markdown
Member

@shellmayr shellmayr left a comment

Choose a reason for hiding this comment

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

Looks good overall - left some comments 👍

@ArthurKnaus ArthurKnaus enabled auto-merge (squash) January 29, 2026 14:27
@ArthurKnaus ArthurKnaus merged commit 4453f7b into master Jan 29, 2026
66 checks passed
@ArthurKnaus ArthurKnaus deleted the aknaus/feat/autopilot/add-finish-reason-to-prompt branch January 29, 2026 14:35
@github-actions github-actions bot locked and limited conversation to collaborators Feb 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants