Repository navigation
fix: apply revocations when services can't load - #683
Conversation
RegistryCache read GET /verifications, then GET /services, and threw away what it had read if the second failed: the previous list stayed for up to max_stale, including backends no longer verified. Apply the verifications as soon as they are read, to the cached backends: only those verified with the same URL and API type, of an accepted version, stay. This also covers threads served while the services are read. It isn't a good read: its time and max_stale still count from the last one, and nothing is added. If the verifications themselves can't be read, nothing changes. Closes #673 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorter sentences, and what happens to services with the same URL. Test that case, and that a revocation keeps the time of the read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe cache now applies valid registry verifications immediately to cached backends, dropping and warning on revocations even when the subsequent services request fails, while preserving freshness semantics and the existing selection API; documentation and comprehensive regression tests cover the new behavior. Sequence diagram for applying registry revocations during refreshsequenceDiagram
participant Cache as RegistryCache
participant Registry
participant Verifications as VerificationParser
participant Services as ServiceSelector
Cache->>Registry: fetch_json(/verifications)
Registry-->>Cache: verification response
Cache->>Verifications: _verifications(response)
Verifications-->>Cache: verified services
Cache->>Cache: _drop_unverified(verified)
alt services read succeeds
Cache->>Registry: fetch_json(/services)
Registry-->>Cache: services response
Cache->>Services: _select(services, verified, entry, api, previous)
Services-->>Cache: selected backends
Cache->>Cache: store good read
else services read fails
Cache->>Cache: keep only still-verified cached backends
Cache-->>Cache: retain last good read timestamp
end
Flow diagram for cached backend verification decisionsflowchart TD
A[Read verifications] --> B{Verification response is a list?}
B -- No --> C[Keep entire last good backend list]
B -- Yes --> D[Apply verification to cached backends]
D --> E{Same URL, API type, and accepted version?}
E -- Yes --> F[Keep cached backend]
E -- No --> G[Drop backend and log warning]
D --> H{Services read succeeds?}
H -- Yes --> I[Select and add services]
H -- No --> J[Keep reduced cache]
J --> K[Preserve last good read freshness and stale limits]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #683 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 60 60
Lines 7790 7807 +17
=========================================
+ Hits 7790 7807 +17
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:
|
CodeQL takes a bare URL in a containment check for URL sanitization. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/plugins/test_plugin_backends.py" line_range="710" />
<code_context>
+ cache = two_backends
+
+ def fetch(url: str, timeout: float, **options: Any) -> Any:
+ return document
+
+ monkeypatch.setattr(discovery, "fetch_json", fetch)
</code_context>
<issue_to_address>
**Malformed verifications evade the test**
When the implementation accepts an invalid verification response and then rejects the same invalid document as the services response, `test_invalid_verifications_keep_backends` uses the same `document` for every URL, so if invalid verifications are mistakenly accepted, the `/services` read also returns that invalid document and independently fails; the cache still stays unchanged. Its `len(cache.urls()) == 2` assertion also allows the wrong two URLs, so the test passes despite broken handling of invalid verifications.
Return a valid services list for `/services` while returning the parameterized document only for `/verifications`, and assert the exact cached URLs.
Also at `tests/plugins/test_plugin_backends.py:714`.
</issue_to_address>Linked issues
#673 fix: apply revocations when services can't load · 1 of 1 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Apply successfully read verifications to cached backends, removing those no longer verified even when /services cannot be read. | ✅ Met | The cache drops backends that fail the URL, API type, or accepted-version check immediately after parsing verifications, before fetching /services. |
Sourcery assessment
Needs a human reviewer. 1 finding to address first, and if the URL or API comparison mistakenly rejects a still-valid verification, the cached backend is removed and requests may lose that backend while the services endpoint is unavailable. Reverting the code does not restore the in-memory cache entry; it is repairable by a successful services read, and otherwise bounded by the stale-cache period.
Blocking findings: tests/plugins/test_plugin_backends.py:710
Answer only GET /verifications with the invalid document, and compare the exact URLs, so that accepting it can't go unnoticed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sourcery withdrew this approval because the latest commits introduced blocking findings.
Summary
RegistryCachereadsGET /verifications, thenGET /services. If the second read failed, the verifications just read were thrown away and the whole previous list stayed for up tomax_stale.Verifications now apply to the cached backends as soon as they are read, also for threads served while the services are read. A cached backend stays only if its service is still verified with the same URL and API type, of an accepted version; backends dropped this way are logged as a warning.
The rest of the cache's behaviour stays:
read_atandmax_stalestill count from the last good one, and nothing is added.GET /verificationsitself fails or isn't a list, the whole last good list stays.select_serviceskeeps its signature (it now wraps_select, so that verifications are parsed, and malformed items logged, once per read).docs/plugins.mdand the docstring offoca.plugins.backendsare updated. Filters or pagination of the registry's/servicesare not part of this, see the note on the issue.Closes #673
Verification
ruff check,ruff format --check,mypy,ast-grep scan,ast-grep test --skip-snapshot-tests,semgrep scan --config .semgrep(mise's 1.181.0, not the pinned version),mkdocs build --strict.tests/plugins/test_plugin_backends.py: 60 passed, 100% offoca/plugins/backends, plus ruff, mypy and the docs build.devat 19a6c82, containers, real verification andDELETEof a verification,GET /servicesfailing on FOCA's side): both backends stay while nothing is revoked, one after the revocation. Saved ascheck_revocation.pynext to the check of fix: read serviceId in backend discovery #665 in the work folder (projects/foca-665-cr-check/;CHECK=check_revocation.py run.sh ...).tests/integration_*), chart tests; left to CI.dev.Declined review findings
no longer verified, thenRegistry service not used): harmless, and they say different things.keeping N backendscounts the reduced list after a drop: accurate for what is kept.GET /services: the backend is dropped until the next good read. Kept on purpose, as it fails closed, and a verification says nothing about the other service's environment; documented and tested.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Apply registry verifications immediately to cached backends so revoked services are not used when service discovery is unavailable.
Bug Fixes:
Enhancements:
Documentation:
Tests: