Skip to content

ref(aci): dual write workflow group action status #92522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

cathteng
Copy link
Member

Must merge #92478 first

Dual write WorkflowGroupActionStatus alongside ActionGroupStatus. We need a new function to do this because each action can be associated with its own set of workflows, and we want to enforce each workflow's frequency independently for each workflow+action combo. It's also difficult to query specific combinations of workflow+action statuses, so I query all the statuses for the actions+group and iterate to find the valid ones.

I renamed the old function to filter_recently_fired_actions and the new function is called filter_recently_fired_workflow_actions :)

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label May 29, 2025
Copy link

codecov bot commented May 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #92522      +/-   ##
==========================================
+ Coverage   86.61%   87.89%   +1.28%     
==========================================
  Files       10236    10236              
  Lines      586994   587131     +137     
  Branches    22806    22806              
==========================================
+ Hits       508398   516084    +7686     
+ Misses      78166    70617    -7549     
  Partials      430      430              

Comment on lines 144 to 146
all_statuses = WorkflowActionGroupStatus.objects.filter(
group=group, action_id__in=action_to_workflows_ids.keys()
)
Copy link
Member Author

@cathteng cathteng May 29, 2025

Choose a reason for hiding this comment

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

wasn't sure how to query for specific action+workflow combos without making a long query with a ton of Q()'s, so opted for iterating through a big query

Copy link
Member

Choose a reason for hiding this comment

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

any reason to not also do workflow_id__in just to ensure that results are as narrow as we can simply get them?

Then the filtering below can use [] instead of get too.

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, will update

workflow_action_statuses = WorkflowActionGroupStatus.objects.filter(
id__in=status_ids, date_updated__lt=now
)
action_ids = {status.action_id for status in workflow_action_statuses}
Copy link
Member Author

Choose a reason for hiding this comment

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

using a set will dedupe actions if multiple workflows would fire the same action. in a follow up we should know which workflow is firing it (out of all the workflows that could have done so here)

@cathteng cathteng marked this pull request as ready for review May 29, 2025 22:29
@cathteng cathteng requested a review from a team as a code owner May 29, 2025 22:29
Base automatically changed from cathy/aci/workflow-action-group-status to master May 30, 2025 16:07
@cathteng cathteng requested a review from a team as a code owner May 30, 2025 16:07
@cathteng cathteng requested a review from kcons May 30, 2025 17:04
@cathteng cathteng force-pushed the cathy/aci/dual-write-workflow-group-action-status branch from 9f0ffee to 441484a Compare May 30, 2025 17:07
Copy link
Member

@kcons kcons left a comment

Choose a reason for hiding this comment

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

Looks good, some thoughts tho.

Comment on lines 144 to 146
all_statuses = WorkflowActionGroupStatus.objects.filter(
group=group, action_id__in=action_to_workflows_ids.keys()
)
Copy link
Member

Choose a reason for hiding this comment

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

any reason to not also do workflow_id__in just to ensure that results are as narrow as we can simply get them?

Then the filtering below can use [] instead of get too.

create_workflow_fire_histories(filtered_actions, event_data)

return filtered_actions


def get_workflow_group_action_statuses(
action_to_workflows_ids: dict[int, set[int]], group: Group
) -> dict[int, list[WorkflowActionGroupStatus]]:
Copy link
Member

Choose a reason for hiding this comment

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

Docstring.. "returns them grouped by Action ID" as I'm not sure the key is obvious enough from name or type.

@@ -127,11 +130,122 @@ def filter_recently_fired_workflow_actions(
actions_without_statuses_ids = {action.id for action in actions_without_statuses}
filtered_actions = actions.filter(id__in=actions_to_include | actions_without_statuses_ids)

# dual write to WorkflowActionGroupStatus
filter_recently_fired_workflow_actions(filtered_action_groups, event_data)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe

# dual write to ... ignoring results for now until they are canonical
_ = filter_recently_fired_workflow_action(...)

just to make our discarding of the return value explicit and obviously intentional.

return actions_with_statuses


def update_workflow_action_group_statuses(
Copy link
Member

Choose a reason for hiding this comment

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

Should document what it returns.

# TODO: write this in a single spot
# create_workflow_fire_histories

return Action.objects.filter(id__in=action_ids).distinct()
Copy link
Member

Choose a reason for hiding this comment

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

aren't these guaranteed to be distinct?

Copy link
Member Author

Choose a reason for hiding this comment

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

true. thanks

@@ -94,7 +97,7 @@ def create_workflow_fire_histories(


# TODO(cathy): only reinforce workflow frequency for certain issue types
def filter_recently_fired_workflow_actions(
def filter_recently_fired_actions(
Copy link
Member

Choose a reason for hiding this comment

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

By name, this just filters what we pass in, but it also does status and history updating.
I think a docstring with "Returns actions associated with the provided DataConditionGroups, excluding those that ... whatever. Also updates ...".

I do wonder if some of the book-keeping could be separated from the filtering to simplify that.

)

# TODO: need to know the exact workflow that fired the action
return action_ids
Copy link
Member

Choose a reason for hiding this comment

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

So, action_ids are the actions not filtered out based on workflow config and previous status? Rather than constructing action_ids, I wonder if it'd be simpler to note action_ids filtered out, and return <full set of action ids> - filtered_action_ids, and leave the WAGS book-keeping as its own thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

i will look into whether this can be cleaned up a bit in a follow up, i'm also not a huge fan how i've mixed updating the statuses with figuring out which actions to fire

)

# TODO: write this in a single spot
# create_workflow_fire_histories
Copy link
Member

Choose a reason for hiding this comment

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

kinda think this should be lifted out of here instead; noting which workflows fire isn't really a job for action filtering; the higher level stuff needs to know "we have our list of workflow actions to fire". If we bump this to a higher level, this TODO doesn't need to exist and I think the correctness of it all is clearer.
That said, not a change for this PR.

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