Skip to content

feat(inner_api): add endpoint to invalidate plugin model providers cache - #39468

Merged
wylswz merged 3 commits into
mainfrom
fix/esq1-190-invalidate-model-providers
Jul 27, 2026
Merged

wylswz merged 3 commits into
mainfrom
fix/esq1-190-invalidate-model-providers

Conversation

@GareArc

@GareArc GareArc commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds POST /inner/api/enterprise/workspace/plugin-model-providers/invalidate, which drops the cached model provider list for a batch of tenants.

The handler delegates to the existing PluginService.invalidate_plugin_model_providers_cache, so Dify keeps sole ownership of the cache key layout and the generation counter — no new invalidation logic is introduced.

Why

Dify caches a tenant's model providers under plugin_model_providers:tenant_id:<t>:generation:<n> for 24h, and only invalidates it from its own plugin lifecycle code and task-polling endpoints.

Dify Enterprise installs plugins into a workspace by calling the plugin daemon directly, which bypasses those paths entirely. Dify never learns the cache is stale, so a plugin assigned from the enterprise admin console does not show up in the workspace's model provider list. If the tenant had no providers when the list was first cached, an empty list is served for the full TTL.

This endpoint gives enterprise a supported way to say "this tenant changed" without reaching into Dify's Redis keys.

Testing

Unit tests cover payload validation (including rejection of unknown fields), one invalidation per tenant in order, and the empty-list and missing-payload no-ops.

Enterprise installs plugins into a workspace by talking to the plugin
daemon directly, so Dify never learns that a tenant's cached model
provider list is stale and serves it for the full 24h TTL.

Expose the existing PluginService.invalidate_plugin_model_providers_cache
over the inner API so enterprise can drop the cache for the tenants it
just changed. Batching is left to the caller.
@github-actions

github-actions Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 55.11% 55.10% -0.01%
Strict coverage 54.61% 54.60% -0.01%
Typed symbols 35,785 35,788 +3
Untyped symbols 29,412 29,426 +14
Modules 3073 3075 +2

@codecov

codecov Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.93%. Comparing base (e4e99d1) to head (d68b3cf).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #39468      +/-   ##
==========================================
- Coverage   86.10%   85.93%   -0.18%     
==========================================
  Files        5073     5031      -42     
  Lines      286857   281256    -5601     
  Branches    57225    55249    -1976     
==========================================
- Hits       247006   241689    -5317     
+ Misses      35115    34831     -284     
  Partials     4736     4736              
Flag Coverage Δ
api 86.32% <100.00%> (+<0.01%) ⬆️

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

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GareArc
GareArc marked this pull request as ready for review July 24, 2026 00:36
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 24, 2026
@GareArc
GareArc requested a review from wylswz July 24, 2026 09:47
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 27, 2026
@wylswz
wylswz added this pull request to the merge queue Jul 27, 2026
Merged via the queue into main with commit b6099d0 Jul 27, 2026
40 checks passed
@wylswz
wylswz deleted the fix/esq1-190-invalidate-model-providers branch July 27, 2026 04:50
GareArc added a commit that referenced this pull request Jul 27, 2026
…iders cache (#39468)"

This reverts commit b6099d0.

The endpoint existed so an external installer could drop a tenant's provider
cache after installing plugins behind this service's back. Disabling the
cache outright removes the need: there is nothing to invalidate, and the
endpoint has no caller.

PluginService.invalidate_plugin_model_providers_cache stays. It predates the
endpoint and is still called from this service's own plugin lifecycle paths.
GareArc added a commit that referenced this pull request Jul 27, 2026
…iders cache (#39468)"

This reverts commit b6099d0.

The endpoint existed so an external installer could drop a tenant's provider
cache after installing plugins behind this service's back. Disabling the
cache outright removes the need: there is nothing to invalidate, and the
endpoint has no caller.

PluginService.invalidate_plugin_model_providers_cache stays. It predates the
endpoint and is still called from this service's own plugin lifecycle paths.
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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants