Include archived argument broke GLQL - Advanced Search integration
Summary
GLQL queries fall back to PostgreSQL instead of using Elasticsearch (Advanced Search), causing timeouts on large namespaces. This is caused by the include_archived
parameter (introduced in GitLab 18.5) not being added to the Advanced Finder's CONTROL_KEYS
array.
Steps to reproduce
- Ensure Elasticsearch is enabled and configured for Advanced Search
- Enable the feature flag:
Feature.enable(:glql_es_integration)
- Run any GLQL query against a large namespace (e.g.,
gitlab-org
):
query: group = "gitlab-org" and label = "type::bug"
fields: title, createdAt
title: Bug reports
- Observe that the query times out or takes significantly longer than expected
What is the current bug behavior?
All GLQL queries fall back to PostgreSQL instead of using Elasticsearch, even when:
- Elasticsearch is enabled (
Gitlab::CurrentSettings.elasticsearch_search? == true
) - The namespace has Advanced Search enabled
- The feature flag
glql_es_integration
is enabled - All query parameters are supported by the Advanced Finder
The fallback happens because allowed_main_filters?
validation fails due to the presence of :include_archived
in the params, which is not in the ALLOWED_ES_FILTERS
or CONTROL_KEYS
arrays.
What is the expected correct behavior?
GLQL queries should use Elasticsearch (Advanced Search) when:
- Elasticsearch is enabled
- The namespace has Advanced Search enabled
- The feature flag is enabled
- All query parameters are supported
The :include_archived
parameter should be treated as a control key (like :sort
, :include_ancestors
, etc.) and not cause the validation to fail.
Relevant logs and/or screenshots
Debug output showing the validation failure:
{
:params => "{:label_name=>[\"bug\"], :sort=>:created_desc, :include_ancestors=>false, :include_descendants=>true, :exclude_projects=>false, :exclude_group_work_items=>false, :include_archived=>false}",
:allowed_request_source => true,
:url_param_enabled => true,
:use_elasticsearch => true,
:elasticsearch_enabled_for_namespace => true,
:elasticsearch_fields_supported => false, # ← Fails here
:allowed_main_filters => false, # ← Because of include_archived
:allowed_not_filters => true,
:allowed_or_filters => true,
:allowed_sort => true
}
The validation logic in allowed_main_filters?
:
# ee/lib/ee/search/advanced_finders/work_items_finder.rb:418-422
def allowed_main_filters?
filter_keys = params.keys - CONTROL_KEYS
(filter_keys - ALLOWED_ES_FILTERS).empty?
end
# With current CONTROL_KEYS:
filter_keys = [:label_name, :include_archived] - [:sort, :include_ancestors, :include_descendants, :exclude_projects, :exclude_group_work_items]
# => [:label_name, :include_archived]
([:label_name, :include_archived] - ALLOWED_ES_FILTERS).empty?
# => false (because :include_archived is not in ALLOWED_ES_FILTERS)
Possible fixes
Add :include_archived
to the CONTROL_KEYS
array in ee/lib/ee/search/advanced_finders/work_items_finder.rb
:
CONTROL_KEYS = [
:sort, :include_ancestors, :include_descendants, :exclude_projects, :exclude_group_work_items, :include_archived
].freeze
This is the correct approach because:
-
:include_archived
is a control parameter that affects which projects are queried, similar to other control keys - The Advanced Finder already handles archived projects through the PostgreSQL finder it delegates to
- The parameter was added to
Namespaces::WorkItemsResolver
withdefault_value: false
in commit48bad4f755b2
(Oct 1, 2025), which means it's automatically included in every query
Root cause timeline:
-
Oct 1, 2025: Commit
48bad4f755b2
addedinclude_archived
parameter toNamespaces::WorkItemsResolver
withdefault_value: false
for GitLab 18.5 !207030 (merged) - GraphQL automatically adds
:include_archived => false
to every work items query due to the default value - The Advanced Finder's
CONTROL_KEYS
was not updated to account for this new parameter - This broke all GLQL queries using Advanced Search
Related files:
-
ee/lib/ee/search/advanced_finders/work_items_finder.rb:54-56
- CONTROL_KEYS definition -
ee/lib/ee/search/advanced_finders/work_items_finder.rb:418-422
- allowed_main_filters? validation -
app/graphql/resolvers/namespaces/work_items_resolver.rb:41-44
- include_archived argument definition -
app/graphql/resolvers/work_items_resolver.rb:50-59
- choose_finder method