feat(seer): Record prompt version on night shift deliveries - #123407
Merged
Conversation
deliver_feature_result now accepts an optional Seer-reported prompt_version string. The night shift handler records it on the shard's extras (every delivery, errors included, since failed runs write no result rows) and denormalized onto each verdict row so quality and error rates can be grouped by prompt version. Other feature handlers accept the kwarg and ignore it.
trevor-e
marked this pull request as ready for review
September 2, 2026 13:57
Comment on lines
+75
to
+82
| if prompt_version or error: | ||
| extras = {**(shard.extras or {})} | ||
| if prompt_version: | ||
| extras["prompt_version"] = prompt_version | ||
| if error: | ||
| extras["error_type"] = SeerNightShiftRunErrorType.SHARD_DELIVERY_FAILED.value | ||
| extras["error_message"] = error | ||
| shard.update(extras=extras) |
Contributor
There was a problem hiding this comment.
Bug: A stale read of shard.extras between two update() calls can cause the prompt_version to be lost when clearing a pre-existing error message on a shard.
Severity: MEDIUM
Suggested Fix
Refresh the shard object from the database after the first update() call by calling shard.refresh_from_db(). This will ensure that the in-memory shard.extras is up-to-date before the logic that decides whether to perform the second update, preventing the stale data from overwriting the prompt_version.
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/night_shift/delivery.py#L75-L82
Potential issue: The function `deliver_night_shift_result` can perform two separate
`shard.update()` calls on the `extras` field. The first update, which may add a
`prompt_version`, modifies the database directly but does not refresh the in-memory
`shard` object. If the shard had a pre-existing error, a second update is triggered to
clear it. This second update reads the stale `shard.extras` from the in-memory object,
which lacks the new `prompt_version`. It then writes a modified version back to the
database, overwriting the `extras` field and silently deleting the `prompt_version` that
was just added. This occurs during retry scenarios where a failed delivery is followed
by a successful one.
Did we get this right? 👍 / 👎 to inform future reviews.
Member
Author
There was a problem hiding this comment.
My clanker doesn't think this is an issue with Sentry's version of BaseModel.
jshchnz
approved these changes
Sep 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Night shift triage results can now be attributed to the prompt revision that produced them.
deliver_feature_resultaccepts an optional Seer-reportedprompt_versionstring, and the night shift handler records it in the shard'sextras— on every delivery, errors included, since failed runs write no result rows — and denormalized onto eachSeerNightShiftRunResultrow, so verdict quality and error rates can be grouped by prompt version without a join. The smart_assignment and autofix handlers accept the kwarg and ignore it for now.This ships ahead of the Seer-side change, which will add a
PROMPT_VERSIONconstant to the night shift feature and pass it on result push. Deploy order matters: Seer must not send the kwarg until this is deployed, as the RPC dispatch would reject the unknown argument and lose the delivered result. Older Seer versions simply omit it and nothing is recorded.