Skip to content

Prevent code generation setting bypasses#111294

Merged
geoffg-sentry merged 12 commits into
masterfrom
fix-code-gen-bypass
Mar 31, 2026
Merged

Prevent code generation setting bypasses#111294
geoffg-sentry merged 12 commits into
masterfrom
fix-code-gen-bypass

Conversation

@geoffg-sentry
Copy link
Copy Markdown
Contributor

It's the second time we have a bypass of this organization setting which allowed for code gen, new branches, and new PRs. Fixing this upstream in chokepoints rather than in all the endpoints since RPC callbacks, on-complete hooks, and slack flows lacked enforcement too.

Added check to:

  • coding_agent.py launch_coding_agents_for_run()
  • autofix_agent.py trigger_coding_agent_handoff()
  • autofix.py update_autofix()
  • SeerExplorerClient.push_changes()
  • group_autofix_update.py & organization_seer_explorer_update.py to inspect payload_type and request.data type to 403 when appropriate

Plus a bunch of tests

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 23, 2026

Backend Test Failures

Failures on e6d2312 in this run:

tests/sentry/seer/autofix/test_autofix.py::UpdateAutofixTest::test_update_autofix_blocks_coding_payloads_when_disabledlog
/opt/hostedtoolcache/Python/3.13.1/x64/lib/python3.13/unittest/mock.py:1424: in patched
    return func(*newargs, **newkeywargs)
E   TypeError: UpdateAutofixTest.test_update_autofix_blocks_coding_payloads_when_disabled() missing 1 required positional argument: 'payload_type'
tests/sentry/seer/endpoints/test_group_autofix_update.py::TestGroupAutofixUpdate::test_coding_payload_blocked_when_coding_disabledlog
/opt/hostedtoolcache/Python/3.13.1/x64/lib/python3.13/unittest/mock.py:1424: in patched
    return func(*newargs, **newkeywargs)
E   TypeError: TestGroupAutofixUpdate.test_coding_payload_blocked_when_coding_disabled() missing 1 required positional argument: 'payload_type'

Comment thread src/sentry/seer/autofix/autofix.py Outdated
Copy link
Copy Markdown
Contributor

@sentry-warden sentry-warden Bot left a comment

Choose a reason for hiding this comment

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

TypeError when request.data is a list due to unvalidated dict unpacking (src/sentry/seer/endpoints/organization_seer_explorer_update.py:52)

Line 52 correctly handles non-dict request.data by checking isinstance(request.data, dict) before calling .get(), but line 66 uses **request.data without ensuring request.data is a dict. If a client sends a JSON array (e.g., [{"type": "create_pr"}]) instead of a JSON object, the dict unpacking will raise TypeError: 'list' object is not a mapping, causing a 500 error.

Identified by Warden sentry-backend-bugs

@geoffg-sentry geoffg-sentry marked this pull request as ready for review March 23, 2026 16:10
@geoffg-sentry geoffg-sentry requested review from a team as code owners March 23, 2026 16:10
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.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Missing create_branch in autofix coding payload guard
    • Updated CODING_UPDATE_PAYLOAD_TYPES in update_autofix() to include create_branch, aligning the chokepoint guard with endpoint-level coding payload checks.

Create PR

Or push these changes by commenting:

@cursor push 0b1222bfcf
Preview (0b1222bfcf)
diff --git a/src/sentry/seer/autofix/autofix.py b/src/sentry/seer/autofix/autofix.py
--- a/src/sentry/seer/autofix/autofix.py
+++ b/src/sentry/seer/autofix/autofix.py
@@ -823,7 +823,7 @@
     )
 
 
-CODING_UPDATE_PAYLOAD_TYPES = frozenset({"select_solution", "create_pr"})
+CODING_UPDATE_PAYLOAD_TYPES = frozenset({"select_solution", "create_branch", "create_pr"})
 
 
 def update_autofix(

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Comment thread src/sentry/seer/autofix/autofix.py Outdated
Comment thread src/sentry/seer/endpoints/organization_seer_explorer_update.py
Comment thread src/sentry/seer/autofix/autofix.py Outdated
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.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Unused constant added with no consumers
    • Confirmed the constant had no references and removed AUTOFIX_AUTOMATION_OCCURRENCE_THRESHOLD from the constants module.

Create PR

Or push these changes by commenting:

@cursor push 1ab3d81c95
Preview (1ab3d81c95)
diff --git a/src/sentry/seer/autofix/constants.py b/src/sentry/seer/autofix/constants.py
--- a/src/sentry/seer/autofix/constants.py
+++ b/src/sentry/seer/autofix/constants.py
@@ -2,11 +2,7 @@
 
 CODING_PAYLOAD_TYPES = frozenset({"select_solution", "create_branch", "create_pr"})
 
-# An issue group must have >= this number of occurrences in order to be
-# a target for 'workflow' autofix.
-AUTOFIX_AUTOMATION_OCCURRENCE_THRESHOLD = 10
 
-
 class FixabilityScoreThresholds(enum.Enum):
     SUPER_HIGH = 0.76
     HIGH = 0.66

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Comment thread src/sentry/seer/autofix/constants.py
# Conflicts:
#	src/sentry/seer/autofix/constants.py
#	tests/sentry/seer/autofix/test_autofix_agent.py
@github-actions
Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on 01052dd in this run:

tests/sentry/seer/autofix/test_autofix_agent.py::TestTriggerCodingAgentHandoff::test_raises_permission_denied_when_coding_disabledlog
tests/sentry/seer/autofix/test_autofix_agent.py:807: in test_raises_permission_denied_when_coding_disabled
    trigger_coding_agent_handoff(
E   TypeError: trigger_coding_agent_handoff() missing 1 required positional argument: 'referrer'

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.

Fix All in Cursor

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

Comment thread src/sentry/seer/explorer/client.py
@github-actions
Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on 54873ee in this run:

tests/sentry/seer/autofix/test_autofix_agent.py::TestTriggerCodingAgentHandoff::test_raises_permission_denied_when_coding_disabledlog
tests/sentry/seer/autofix/test_autofix_agent.py:807: in test_raises_permission_denied_when_coding_disabled
    trigger_coding_agent_handoff(
E   TypeError: trigger_coding_agent_handoff() missing 1 required positional argument: 'referrer'

Comment thread src/sentry/seer/endpoints/group_ai_autofix.py Fixed
@github-actions
Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on ffb9319 in this run:

tests/sentry/seer/endpoints/test_group_ai_autofix.py::GroupAutofixEndpointExplorerRoutingTest::test_open_pr_permission_errorlog
tests/sentry/seer/endpoints/test_group_ai_autofix.py:1079: in test_open_pr_permission_error
    assert response.status_code == 404, f"Failed for {flag}: {response.data}"
E   AssertionError: Failed for organizations:seer-explorer: {'detail': ErrorDetail(string='Seer permission error: Unknown run id for group', code='permission_denied')}
E   assert 403 == 404
E    +  where 403 = <Response status_code=403, "application/json">.status_code

# Conflicts:
#	tests/sentry/seer/autofix/test_autofix_agent.py
@geoffg-sentry geoffg-sentry merged commit 7c22ba9 into master Mar 31, 2026
67 checks passed
@geoffg-sentry geoffg-sentry deleted the fix-code-gen-bypass branch March 31, 2026 15:34
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 16, 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