Skip to content

feat(plugin): cache plugin model providers by tenant#36449

Merged
WH-2099 merged 5 commits into
mainfrom
laipz8200/plugin-model-provider-cache
May 23, 2026
Merged

feat(plugin): cache plugin model providers by tenant#36449
WH-2099 merged 5 commits into
mainfrom
laipz8200/plugin-model-provider-cache

Conversation

@laipz8200
Copy link
Copy Markdown
Member

Summary

Fixes #36448.

  • Move PluginService into core.plugin so plugin lifecycle changes and provider discovery share one cache owner.
  • Add a tenant-scoped TTL cache for plugin model provider discovery.
  • Invalidate plugin model provider cache when a tenant installs, uninstalls, or upgrades plugins.
  • Inject PluginService into PluginModelRuntime and remove the per-runtime provider cache.
  • Remove the legacy services.plugin.plugin_service module and update imports to core.plugin.plugin_service.

Screenshots

N/A, backend-only change.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 20, 2026

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 44.92% 44.96% +0.04%
Strict coverage 44.44% 44.48% +0.04%
Typed symbols 23,134 23,177 +43
Untyped symbols 28,677 28,682 +5
Modules 2610 2610 0

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 93.07692% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.11%. Comparing base (2a0c098) to head (5d50696).

Files with missing lines Patch % Lines
api/core/plugin/plugin_service.py 93.26% 3 Missing and 4 partials ⚠️
api/services/plugin/plugin_migration.py 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #36449      +/-   ##
==========================================
+ Coverage   86.06%   86.11%   +0.04%     
==========================================
  Files        4483     4483              
  Lines      214838   214909      +71     
  Branches    39891    39897       +6     
==========================================
+ Hits       184911   185060     +149     
+ Misses      26554    26457      -97     
- Partials     3373     3392      +19     
Flag Coverage Δ
api 85.75% <93.07%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@laipz8200 laipz8200 marked this pull request as ready for review May 20, 2026 12:06
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 20, 2026
laipz8200 added 4 commits May 23, 2026 03:03
Move PluginService into core.plugin and make it own tenant-scoped plugin model provider cache reads, writes, and invalidation.

Inject PluginService into PluginModelRuntime and remove the request-scoped provider cache so install, uninstall, and upgrade flows share the same cache owner.
Delete services.plugin.plugin_service and update remaining tests to import and patch core.plugin.plugin_service directly.

This completes the move of PluginService ownership into core.plugin without retaining the compatibility module.
Increase the default provider cache TTL to one day and document the setting in API and Docker environment examples.
Add unit coverage for tenant-scoped plugin model provider cache reads, invalidation, Redis failure handling, lifecycle cache invalidation, and deleted-tools plugin service resolution.
@WH-2099 WH-2099 force-pushed the laipz8200/plugin-model-provider-cache branch from e37be5b to 43ed1dc Compare May 22, 2026 19:06
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 23, 2026
@WH-2099 WH-2099 self-assigned this May 23, 2026
@WH-2099 WH-2099 enabled auto-merge May 23, 2026 09:01
@WH-2099 WH-2099 added this pull request to the merge queue May 23, 2026
Merged via the queue into main with commit 8d99326 May 23, 2026
33 checks passed
@WH-2099 WH-2099 deleted the laipz8200/plugin-model-provider-cache branch May 23, 2026 09:25
ryuta-kobayashi-ug added a commit to ryuta-kobayashi-ug/dify that referenced this pull request May 24, 2026
The PluginModelRuntime.invoke_llm() now forwards app_id to the plugin
client. Update the existing assert_called_once_with checks in
test_model_runtime_adapter.py (added by langgenius#36449 on main) to include
app_id=None for parity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache plugin model provider discovery across runs with tenant-scoped invalidation

2 participants