Repository navigation
feat(slack): Reply to @-mentions when Seer runs out of credits - #130440
alexsohn1126 wants to merge 7 commits into
Conversation
40899d5 to
fa1ae81
Compare
Sentry Snapshot Testing
|
c62ef58 to
93db726
Compare
93db726 to
c90d978
Compare
e18a83b to
7bc8ef8
Compare
|
bugbot review |
3d425d4 to
27944c5
Compare
|
bugbot review |
| title: str | None = None | ||
| description: str | None = None | ||
| integration_id: str | None = None | ||
| idempotency_key: str | None = Field(default=None, exclude=True) |
There was a problem hiding this comment.
this allows us to give each PR push attempt its own unique key, so we can send "out of credits" message again if the PR push fails, and user @ mentions again to do a PR push.
|
bugbot review |
540ee18 to
6360888
Compare
| key | ||
| for pr in _get_repo_pr_states(state) | ||
| if _is_pr_out_of_credits(pr) | ||
| and (key := f"pr_out_of_credits:{pr.repo_name}:{pr.idempotency_key}") not in replies |
There was a problem hiding this comment.
🤖 Reply-cache docstring doesn't list the new out-of-credits keys
The docstring on SlackSeerAgentReplyCache in cache.py (lines 68–72, outside this diff) lists every reply key: the answer's block id, approval:<input id>, approval_dm:<input id>, and error. It describes itself as the only record of what was posted. This PR adds out_of_credits:<turn's first block id> and pr_out_of_credits:<repo>:<push key>. Add them to that list so the next person changing dedupe logic sees every key kind in one place.
Written by an AI agent and included in this review by its author.
| _send_out_of_credits_message( | ||
| entrypoint=entrypoint, | ||
| organization=organization, | ||
| thread_ts=thread_ts or ts, |
There was a problem hiding this comment.
I'm not sure if this is true or not
🤖 Top-level @-mentions likely never see the ephemeral out-of-credits reply
For a top-level @-mention, thread_ts is None. The ephemeral therefore goes out with thread_ts=ts, into a thread on the user's own message that has no replies yet. Slack's chat.postEphemeral docs say ephemeral messages in threads only show if the thread is already active. This path returns before anything public is posted, so that thread never becomes active. The person who mentioned @sentry would see the "is thinking..." status clear and nothing else. That's case 1 in the description, and probably the most common one.
The halt paths a few lines up already handle this with thread_ts if thread_ts else "" and the comment "In a thread, show the prompt in the thread; top-level, show in the channel". Doing the same here posts the notice in the channel for top-level mentions:
| thread_ts=thread_ts or ts, | |
| thread_ts=thread_ts if thread_ts else "", |
(_send_out_of_credits_message's docstring says "in the thread", so it would need a small tweak too.)
TASK_KWARGS always sets thread_ts, so the new tests only cover mentions inside a thread. Add a case with thread_ts=None that asserts the ephemeral is sent with thread_ts="". If you've already seen this render for a top-level mention, ignore this comment.
Written by an AI agent and included in this review by its author.
| assert second_data.missing_scope_settings_url is None | ||
|
|
||
| @patch("sentry.seer.entrypoints.slack.entrypoint.send_thread_update", return_value="1.1") | ||
| def test_on_agent_update_out_of_credits_replies_once(self, mock_send: MagicMock) -> None: |
There was a problem hiding this comment.
🤖 Two new on_agent_update tests only repeat what later tests already catch
Two of the seven new tests don't catch any bug the others miss:
test_on_agent_update_out_of_credits_replies_once(this one). It catches two bugs: the run-levelOUT_OF_CREDITSbranch being removed, or itskey in repliescheck being dropped. Both bugs also failtest_on_agent_update_run_and_pr_out_of_credits_share_one_noticeandtest_on_agent_update_out_of_credits_notice_once_per_turn. Both of those refresh twice and assert a singleSeerAgentOutOfCredits.test_on_agent_update_pr_out_of_credits_posts_notice_once(line 1349).test_on_agent_update_pr_out_of_credits_notice_per_push_attemptalready asserts[SeerAgentResponse, SeerAgentOutOfCredits]on the first refresh, and asserts no repeat when the same state is refreshed again. The extrasummaryandrepo_pr_stateschecks on the answer are covered by the existing PR-status tests.
Deleting both keeps the same coverage with less to maintain.
Written by an AI agent and included in this review by its author.
6360888 to
a5f33c0
Compare
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.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a5f33c0. Configure here.
Slack posts the agent out-of-credits notification when a mention is stopped by the credit check, when an agent chat turn stops for credits, and when a PR push fails for credits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a push runs out of credits Seer marks every remaining repo with the same error, so each repo posted its own copy of the org-level notice. The run-level notice used a different key, so a turn where a PR failed and the run then stopped got it from both paths. Share one notice across all PRs that newly failed, and key the run and PR paths on the turn so a turn gets at most one. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The out-of-credits notice for a failed PR was deduplicated on the repo, PR number and commit SHA. A push that fails leaves the number and SHA as they were (both unset when the PR never landed), so a retry in a later turn of the same thread looked like the failure already reported and got no notice. Key the notice on the push's idempotency key instead, which Seer sets per attempt. A failure left in the run state from an earlier turn still stays silent. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The out-of-credits notification now has a copy per reader. These replies don't pass who is reading yet, so they use the member copy. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…essage The pre-check reply is private to the person who mentioned Seer, so use their billing access directly. The replies posted when a run or a PR push fails use the Slack user stored with the run. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
a5f33c0 to
13ec451
Compare

This PR replies to the thread when
@sentryis mentioned and the organization does not have enough seer credits for the operation.There are multiple ways that a Seer Agent will fail.
out-of-crediterrorIn all cases, we send a message like this:
And for PR creation, this would be shown (along with the standard message we send)
Fixes CW-2325