Limit child items added per request and per user

What does this MR do and why?

Adding child items to a work item or epic does work for every child inside a single transaction, and there is currently no limit on how many children one request can add or how often a user can add them. This MR adds two limits, both behind the work_item_hierarchy_add_children_limits feature flag (disabled by default):

  • Per-request cap: a request can add at most 50 child items. Larger requests are rejected with No more than 50 child items can be added at the same time.
  • Per-user rate limit: 300 child items per minute per user, shared across every path that adds children. Each child in a request counts toward the limit, so one request with 50 children uses 50 of the 300. The limit is a beta application setting, work_item_hierarchy_add_children_limit (default 300), following https://gitlab.com/groups/gitlab-org/-/work_items/24176#note_4152547896.

Both checks live in WorkItems::Callbacks::Hierarchy#update_work_item_children, so they cover every path that adds children:

  • workItemHierarchyAddChildrenItems GraphQL mutation
  • childrenIds in the workItemUpdate GraphQL mutation
  • /add_child quick action
  • REST API: assign an issue to an epic, and assign a child epic

The two GraphQL childrenIds arguments also check the cap in prepare, so oversized requests fail before the children are loaded.

The limits are not in WorkItems::ParentLinks::CreateService because importers and sync paths call it directly and should not be limited.

When throttled, the epic page shows a generic 429 alert rather than the rate limit message. Improving that is a frontend follow-up on the rollout issue.

Values chosen from 14 days of GitLab.com logs, details in the confidential issue.

References

How to set up and validate locally

  1. Enable the feature flag in the Rails console:

    Feature.enable(:work_item_hierarchy_add_children_limits)
  2. In GraphiQL, call workItemHierarchyAddChildrenItems with more than 50 childrenIds. The mutation returns the per-request cap error.

  3. Lower the rate limit through the application settings API:

    curl --request PUT --header "PRIVATE-TOKEN: <admin token>" \
      "http://gdk.test:3000/api/v4/application/settings?work_item_hierarchy_add_children_limit=2"
  4. Add two child items to an epic in one request (UI, /add_child, or workItemHierarchyAddChildrenItems). The request succeeds.

  5. Add one more child item within the minute (UI, /add_child, or REST). The request is rate limited, because each child item counts toward the limit.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Matt D'Angelo

Merge request reports

Loading
Loading