fix(api): keep provider refresh waiters single-flight#38226
Conversation
Pyrefly Type Coverage
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #38226 +/- ##
==========================================
- Coverage 85.27% 85.27% -0.01%
==========================================
Files 4982 4982
Lines 263256 263230 -26
Branches 50022 50014 -8
==========================================
- Hits 224504 224480 -24
- Misses 34366 34367 +1
+ Partials 4386 4383 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I feel that we should not make this an infinite wait. A good idea would be introduce a hard timeout that once exceeded, fail the whole process. |
There was a problem hiding this comment.
Pull request overview
This PR refines the plugin provider-list refresh coordination in PluginService so concurrent cache-miss waiters remain single-flight across Redis lock TTL boundaries (treating lock TTL as a lease rather than a waiter deadline), while still preserving the “fallback to direct daemon discovery” behavior when Redis cache/lock coordination fails.
Changes:
- Replaces the prior “wait with deadline” approach with a loop that keeps re-checking the current generation cache and retrying lock acquisition until cache is filled or the caller becomes refresh owner.
- Tightens typing around Redis locks via a small internal
Protocoland updates the lock acquisition/release helpers accordingly. - Updates and extends unit tests to cover (a) continuing to wait past lock TTL and (b) restarting the lock/cache path after generation changes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| api/core/plugin/plugin_service.py | Reworks provider-cache coordination to keep waiters single-flight across lock TTL and generation changes. |
| api/tests/unit_tests/services/plugin/test_plugin_service.py | Updates and adds tests validating the new wait/lock/generation behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-07-02 04:15:00.682688556 +0000
+++ /tmp/pyrefly_pr.txt 2026-07-02 04:14:52.046710658 +0000
@@ -4619,8 +4619,6 @@
--> tests/unit_tests/core/plugin/test_backwards_invocation_app.py:417:74
ERROR Argument `SimpleNamespace` is not assignable to parameter `tenant` with type `Tenant` in function `core.plugin.backwards_invocation.model.PluginModelBackwardsInvocation.invoke_summary` [bad-argument-type]
--> tests/unit_tests/core/plugin/test_backwards_invocation_model.py:54:72
-ERROR Generator function should return `Generator` [bad-return]
- --> tests/unit_tests/core/plugin/test_model_runtime_adapter.py:72:51
ERROR Class member `_BadString.__str__` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
--> tests/unit_tests/core/plugin/test_plugin_entities.py:238:17
ERROR Argument `TestPluginDaemonEntities.test_credential_type_helpers._FakeCredential` is not assignable to parameter `self` with type `CredentialType` in function `core.plugin.entities.plugin_daemon.CredentialType.get_name` [bad-argument-type]
@@ -6827,8 +6825,6 @@
--> tests/unit_tests/services/plugin/test_oauth_service.py:68:34
ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
--> tests/unit_tests/services/plugin/test_oauth_service.py:95:9
-ERROR Generator function should return `Generator` [bad-return]
- --> tests/unit_tests/services/plugin/test_plugin_service.py:18:51
ERROR Class member `DummyRetrieval.get_pipeline_templates` overrides parent class `PipelineTemplateRetrievalBase` in an inconsistent manner [bad-override]
--> tests/unit_tests/services/rag_pipeline/pipeline_template/test_pipeline_template_base.py:5:9
ERROR Class member `DummyRetrieval.get_pipeline_templates` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
|
067986f to
ed0265f
Compare
08feeaa to
a885793
Compare
a885793 to
3f2e02d
Compare
404588f to
b57853c
Compare
(cherry picked from commit 7fb797c)
Summary
This is a follow-up to #37388 for the provider-list refresh path tracked under #34264.
The previous single-flight lock prevented ordinary cache-miss stampedes, but waiters could still fall through to the plugin daemon after the lock TTL deadline.
That made the Redis lock TTL act as both a crashed-owner lease and a waiter deadline.
This PR makes the coordination contract explicit:
CI Stability
This PR also fixes #38277.
test_inspect_skill_maps_invalid_archives_to_service_errorsgenerated ZIP bytes during pytest collection.Because
zipfile.writestr(name, payload)stores the current timestamp in ZIP entry metadata, xdist workers could collect different parametrized node ids and fail before running tests.The ZIP fixture now uses a fixed entry timestamp, and the parametrized cases have stable ids.
Tests
Refs #34264
Fixes #38277