Skip to content

ref(issues): Replay derived features from action history - #126621

Merged
cvxluo merged 1 commit into
masterfrom
cvxluo/replay-derived-features-from-action-history
Oct 8, 2026
Merged

cvxluo merged 1 commit into
masterfrom
cvxluo/replay-derived-features-from-action-history

Conversation

@cvxluo

@cvxluo cvxluo commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Sometimes we'll really want fresh data for derived data, and don't want to wait for automatic regeneration to fix these problems. Add replay_feature_from_log that replays the GAL for a selected feature without persisting it, and use it in assignment summarization decisions.

@cvxluo
cvxluo added this pull request to stack #126622 October 6, 2026 18:41
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 6, 2026
Base automatically changed from cvxluo/generate-summaries-on-first-assignment to master October 6, 2026 18:43
@cvxluo
cvxluo force-pushed the cvxluo/replay-derived-features-from-action-history branch from 1a3a167 to 3c04688 Compare October 6, 2026 18:43
@cvxluo
cvxluo marked this pull request as ready for review October 6, 2026 21:11
@cvxluo
cvxluo requested review from a team as code owners October 6, 2026 21:11
@cvxluo
cvxluo force-pushed the cvxluo/replay-derived-features-from-action-history branch from 3c04688 to 7e187d3 Compare October 6, 2026 21:12
@cvxluo
cvxluo requested a review from a team October 6, 2026 21:15
"""The relevant action history is too large to replay inline."""


def replay_feature_from_log[T](

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i did decide to avoid writing an opportunistic promotion feature, since it's not really what i want in the case of assignment summaries (just not high volume enough to be relevant imo). this one is just a scoped feature replay instead

@kcons
kcons self-requested a review October 7, 2026 20:03

@kcons kcons left a comment

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.

cool.

"""Replay a feature's action history. This does not update stored derived data."""
selected = Pipeline(resolve((feature,), pipeline.aggregators))
query = GroupActionLogEntry.objects.filter(group_id=group_id).order_by("date_added", "id")
if not any(agg.scope is Scope.ALL for agg in selected.aggregators):

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.

kinda want to have a scope() method on Pipeline just like

def scope(self) -> EffectiveScope:
       result = set[int]()
       for _, _, _, scope in self._steps:
           if scope is Scope.ALL:
               return Scope.ALL
           result.update(scope)
        return frozenset(result)

and then perhaps a

# maybe on the manager or queryset?
def scope_filter(q: QuerySet[GroupActionLogEntry], scope: EffectiveScope):
       if scope is Scope.ALL:
           return q
       return q.filter(type__in=(scope))

so "filter this query by the pipeline scope" is trivial. We could generalize the existing GroupActionLogEntryManager methods to use it.

Not needed in this PR, just pondering what would make this PR less awkward to write. Pipeline scopes and being able to use that to query more efficiently is part of the design, but it's not really part of the API so it's not terribly discoverable.

Comment thread src/sentry/issues/derived/replay.py Outdated
*,
history_limit: int = 2000,
) -> T:
"""Replay a feature's action history. This does not update stored derived data."""

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.

Need to document the limit.

history_limit: int = 2000,
) -> T:
"""Replay a feature's action history. This does not update stored derived data."""
selected = Pipeline(resolve((feature,), pipeline.aggregators))

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.

I initially imagined we may want to try to grab a subset of the Pipeline rather than pay the cost of resolve again, but in retrospect that's a little silly.

Comment thread src/sentry/issues/derived/replay.py Outdated
raise FeatureHistoryLimitExceeded(
f"History for {feature.name!r} exceeds {history_limit} entries"
)
if not entries:

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.

This isn't even worth checking. run without entries or an initial state reduces to basically putting initial_value() in a dict and returning it.

In my original comment I had this fast-path because it'd avoid Pipeline construction altogether for cases that land on the default value, which may not be a meaningful optimization, but does risk only having the validation logic run once you have a meaningful history, which seems less ideal for ensuring correctness, so I think what we have here is good.

@cvxluo
cvxluo force-pushed the cvxluo/replay-derived-features-from-action-history branch from 7e187d3 to af898ff Compare October 8, 2026 20:22

@cursor cursor Bot left a comment

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.

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.

Reviewed by Cursor Bugbot for commit af898ff. Configure here.

@cvxluo
cvxluo force-pushed the cvxluo/replay-derived-features-from-action-history branch from af898ff to 647763e Compare October 8, 2026 20:32
Resolve only the aggregators needed for the requested feature and its dependencies.
Filter action history using their declared scopes and cap inline replay at 2,000
relevant entries, without persisting derived state. Skip the assignment summary
when the limit is exceeded while allowing assignment to proceed.

Co-authored-by: Codex <codex@openai.com>
@cvxluo
cvxluo force-pushed the cvxluo/replay-derived-features-from-action-history branch from 647763e to e41947f Compare October 8, 2026 20:38
@cvxluo
cvxluo merged commit 1ab3624 into master Oct 8, 2026
73 checks passed
@cvxluo
cvxluo deleted the cvxluo/replay-derived-features-from-action-history branch October 8, 2026 22:34
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.

2 participants