Skip to content

Conversation

@JoshFerge
Copy link
Member

@JoshFerge JoshFerge commented Jan 24, 2026

Summary

When branch_name is an empty string, the Cursor API returns an error:

"Git ref (branch/tag) cannot be an empty string"

This fix converts empty/falsy branch_name to None, which gets excluded from the JSON payload via exclude_none=True, allowing Cursor to automatically resolve to the repository's default branch.

Root Cause Analysis

The issue occurs when:

  1. A repo is configured in Seer preferences (with branch_name left blank, expecting default branch to be used)
  2. The Sentry GitHub app is NOT installed on the repo (or lacks read permissions)
  3. Seer's update_repo_access_and_properties() cannot resolve the default branch because the repo is not readable
  4. branch_name stays empty
  5. Cursor API receives "ref": "" and rejects it

Note: When the Sentry GitHub app HAS read access, Seer correctly resolves branch_name to the default branch during autofix run creation.

Why This Fix Helps

This is a workaround for cases where:

  • User has the Cursor GitHub app installed (so Cursor can access the repo)
  • But forgot to install the Sentry GitHub app (so Seer can't resolve the default branch)
Scenario Without fix With fix
Sentry app has access ✅ Works ✅ Works
Sentry app NO access, Cursor HAS access ❌ Fails (ref: "") ✅ Works (Cursor resolves default)
Neither app has access ❌ Fails ❌ Still fails

The proper fix is ensuring users install the Sentry GitHub app on their repos. A companion PR adds logging in Seer to help identify when this happens: https://github.com/getsentry/seer/pull/4619

Verified with Cursor API

# Empty string → Error
curl ... --data '{"source": {"repository": "...", "ref": ""}}'
# {"error": "Invalid creation request parameters", "details": [{"message": "Git ref (branch/tag) cannot be an empty string"}]}

# Omitted → Success (resolves to default branch)
curl ... --data '{"source": {"repository": "..."}}'
# {"source": {"ref": "main"}, ...}  ✓

Test plan

  • Added tests for empty string and None branch_name cases
  • Verified existing tests still pass
  • Manually tested against Cursor API

When `branch_name` is an empty string, the Cursor API returns an error:
"Git ref (branch/tag) cannot be an empty string"

This affects ~50% of Seer project preferences where users intentionally
leave branch_name blank, expecting Seer to use the repo's default branch.

The fix converts empty/falsy `branch_name` to `None`, which gets excluded
from the JSON payload via `exclude_none=True`, allowing Cursor to
automatically resolve to the repository's default branch.

Fixes: Seer fails when invoking Cursor agent with empty source.ref
@linear
Copy link

linear bot commented Jan 24, 2026

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 24, 2026
@JoshFerge
Copy link
Member Author

@sentry review
bugbot review

@JoshFerge
Copy link
Member Author

bugbot review

@JoshFerge
Copy link
Member Author

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

Copy link
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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@JoshFerge JoshFerge marked this pull request as ready for review January 27, 2026 18:08
@JoshFerge JoshFerge requested review from a team as code owners January 27, 2026 18:08
@JoshFerge JoshFerge merged commit 25eb1b5 into master Jan 27, 2026
68 checks passed
@JoshFerge JoshFerge deleted the jferg/fix-cursor-empty-branch-ref branch January 27, 2026 18:14
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants