Issue #3586378: Remove max_items context limit and rely on token budget.
Description
Removes the Max context items to inject (max_items) setting and all
selection logic that depended on it. The token budget (max_tokens) is now
the primary module-wide limit on how much context reaches an agent prompt.
max_global_items is unchanged and still caps the Global group only.
Code changes
- Remove
max_itemsfromai_context.settingsschema/defaults, General settings, and per-agent Advanced overrides. - Remove
maxItemsfromAiContextRequest,AiContextRequestParamsData, andAiContextRequestFactory. - Update
AiContextSelectorso merge/scoring/auto-include paths no longer slice by item count; token truncation at render time remains the ceiling. - Remove
AiContextLimitsConstraint(global cap vs total item cap). - Remove
max_itemsfrom theGetRelevantAiContextItemsfunction-call plugin. - Remove
getMaxItems()fromAiContextSelectionItemsSelectedEvent. - Add
ai_context_update_10015()to strip obsoletemax_itemsfrom active config on existing sites. - Strip legacy
max_itemsduring config import so older exports validate.
Documentation
- Update limit and selection docs (
context_selection.md,agent_configuration.md,scopes.md, developer docs). - Branch also includes context-selection documentation added on this branch (from #3586365).
Breaking API changes (documented)
max_itemsremoved from settings and agent configuration.AiContextRequestno longer acceptsmaxItems.AiContextSelectionItemsSelectedEvent::getMaxItems()removed.GetRelevantAiContextItemsno longer accepts amax_itemsparameter.AiContextLimitsConstraintand related validation removed.
Closes #3586378
Testing instructions
-
Run
drush updatedband confirm update10015removesmax_itemsfromai_context.settingsand any agent overrides. -
Open Configuration → AI → Context Control Center → General settings (
/admin/config/ai/context/settings/general) and confirm Max context items to inject is no longer shown. Save the form with no errors. -
Open a per-agent edit form under Agent configuration and confirm the Max context items to inject override is gone; Max global context items and Max tokens still work.
-
Configure an agent with subscriptions that would previously exceed
max_itemsbut stay withinmax_tokens. Confirm additional matching context is selected and rendered until the token budget applies. -
Export config from a site that previously had
max_items, re-import on a checkout of this branch, and confirm import succeeds (legacy key stripped). -
From the module directory, run
./lint.sh. -
Run targeted PHPUnit (example):
ddev exec bash -c 'SIMPLETEST_DB=sqlite://localhost/tmp.sqlite \ /var/www/html/vendor/bin/phpunit --configuration /var/www/html/phpunit.xml \ web/modules/contrib/ai_context/tests/src/Unit/AiContextLimitResolverTest.php \ web/modules/contrib/ai_context/tests/src/Kernel/AiContextSettingsConfigValidationTest.php \ web/modules/contrib/ai_context/tests/src/Kernel/AiContextAgentConfigValidationTest.php \ web/modules/contrib/ai_context/tests/src/Kernel/AiContextRequestFactoryTest.php \ web/modules/contrib/ai_context/tests/src/Kernel/AiContextSelectorAlgorithmTest.php \ web/modules/contrib/ai_context/tests/src/Kernel/AiContextSelectorEventsTest.php \ web/modules/contrib/ai_context/tests/src/Kernel/AiContextSettingsConfigImportValidationTest.php \ web/modules/contrib/ai_context/tests/src/Kernel/AiContextAgentsConfigImportValidationTest.php'
Post-merge
- Existing sites: run
drush updatedbonce after deploy. - No manual config edits required beyond the update hook.
Checklist
- I have updated the MR title to use format:
Issue #1234: My issue title. - I have updated the MR description to include:
Closes #1234 - I have performed a self-review of my own code
- I have added or updated tests, or explained in the description why this change is not covered by tests
- I have updated documentation for any new or changed functionality
- I have written testing instructions and verified them locally
- I have noted any required post-merge steps (config imports, cache rebuilds, manual changes)
- This MR contains no breaking API or hook changes, or they are explicitly documented in the description
AI Compliance
Note
Check the one that best describes your usage, or leave all unchecked if AI was not significantly used.
-
AI Assisted Code
Mainly written by a human; AI used for autocomplete or partial generation under full human supervision. -
AI Generated Code
Mainly generated by AI, reviewed and approved by a human before this MR was created. -
Vibe Coded
Generated by AI and only functionally reviewed before this MR was created.