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:
workItemHierarchyAddChildrenItemsGraphQL mutationchildrenIdsin theworkItemUpdateGraphQL mutation/add_childquick 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
- Feature flag rollout issue: #636961
- https://gitlab.com/gitlab-org/gitlab/-/work_items/637489
How to set up and validate locally
-
Enable the feature flag in the Rails console:
Feature.enable(:work_item_hierarchy_add_children_limits) -
In GraphiQL, call
workItemHierarchyAddChildrenItemswith more than 50childrenIds. The mutation returns the per-request cap error. -
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" -
Add two child items to an epic in one request (UI,
/add_child, orworkItemHierarchyAddChildrenItems). The request succeeds. -
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.