Repository navigation
fix(plugins): reject backend choices without match - #809
Conversation
A client's `gateway.backends` `allow` that names none of the gateway's backends ended without a backend, which apps answer as an outage (e.g., proTES: 503), and the client couldn't learn why, as the request isn't stored. `run.route()` now refuses it with `400` (`invalid-backends`) before any plugin runs, without naming the client's items, and records them as discarded. `order` and `forbid` are unchanged. `run.route()` takes `known`, all backends of the app, so that an `allow` of a backend that the app left out of the candidates (e.g., as it can't run the request) still ends without a backend. Backends at the gateway's own URL never count as known. Closes #808 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review fixes: a URL may name a backend of a registry that is unavailable for now, so only an `allow` of identifiers alone is refused; `known` adds to the candidates instead of replacing them; the refusal carries the run (`InvalidSelection(run=)`), so that apps can store failed runs; docs say it happens before the `route` phase, not before any plugin, and that the 400 tells which identifiers exist. Refs #808 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideAPIExtend routing to accept backends the app knows but omitted from candidates, and carry the run on invalid-selection errors so callers can record refusals.
ImplementationShare backend matching between selection application and the predicate that identifies allow selections consisting only of unknown identifiers.
DocumentationExplain the refused backend-choice behavior, migration impact, app use of known backends, and updated problem type.
TestsCover refusal of unknown-only identifier selections and verify URL, known, routed-away, omitted, failed, empty-candidate, and own-URL cases.
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 #809 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 76 76
Lines 10550 10568 +18
=========================================
+ Hits 10550 10568 +18
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:
|
Linked issuesChecked at commit ec33575 #808 fix(plugins): reject backend choices without match · 5 of 6 met · 1 to check by hand
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="foca/plugins/selection.py" line_range="497" />
<code_context>
+ Whether the selection is `allow`, has no URLs, and none of its items
+ matches a known backend (as in :py:func:`apply_backend_selection`).
+ """
+ if selection.type != "allow" or any("://" in item for item in selection.backends):
+ return False
+ match = _matcher(known)
</code_context>
<issue_to_address>
**Unmatched URLs remain unrefused**
The issue asks to refuse an `allow` when none of its items matches a candidate, including a URL in another form. This guard exempts any selection containing a URL, so an unmatched URL still reaches the no-backend outcome.
</issue_to_address>
### Comment 2
<location path="foca/plugins/engine.py" line_range="1657" />
<code_context>
+ """
+ selection = self.selection.backends
+ if selection is None or not selects_unknown_only(
+ [backend for backend in known if not self.host.is_own_url(backend.url)],
+ selection,
+ ):
</code_context>
<issue_to_address>
**Matching backend is refused**
When an `allow` matches a known backend that routing removes, `selects_unknown_only` receives only backends that pass `not self.host.is_own_url(backend.url)`, so it treats the selection as unknown-only and refuses it; the tests do not cover this unchanged outcome.
Check the selection against the unfiltered known backends and add a test asserting the unchanged outcome when routing removes a matching backend.
Also at `tests/plugins/test_plugin_selection.py:386-387`.
</issue_to_address>
### Comment 3
<location path="docs/plugins.md" line_range="108-121" />
<code_context>
+ [provenance](#provenance)), never added. An `allow` of identifiers only,
</code_context>
<issue_to_address>
**Configuration guide not updated**
The change documents the behavior in `docs/plugins.md` and the migration notes, but the issue also asks for `docs/configuration/plugins.md` under Per-request choices to be updated.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: foca/plugins/selection.py:497, foca/plugins/engine.py:1657
The configuration reference (per-request choices) now says, as the issue asks, that an `allow` of only unknown identifiers is refused. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A candidate that the route phase removes isn't unknown: the selection ends without candidates, as before (review finding of Sourcery). Co-Authored-By: Claude Opus 5.5 <[email protected]>
A known backend that fails its attempt still ends with "no backend available" (503), not a refusal (review finding of Sourcery). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #808
Summary
A client's
gateway.backends{"type": "allow", ...}that can never match ended without a backend, which apps answer as an outage (proTES:503), and the client couldn't learn why, as the request isn't stored.PipelineRun.route()now refuses anallowof identifiers only, none of which names a backend of the app, withInvalidSelection(400,invalid-backends, "None of the chosen backends is known"), before theroutephase. The message names no client values; the items are recorded as discarded, and the error carries the run (InvalidSelection(run=)), so that apps can store failed runs.503.orderandforbidare unchanged.route()takesknown: backends that the app left out of the candidates (e.g., proTES's TES instances that can't run the task), so that choosing them still ends without a backend, which the app can explain. Backends at the gateway's own URL never count.selection.selects_unknown_only()shares the matcher withapply_backend_selection().docs/plugins.md(per-request choices, using the engine in apps, problem types) and a section indocs/migration-0.23.md. The400reveals which identifiers exist, also of backends that routing would keep from a caller; documented as accepted, as the service info usually lists them.Follow-up for proTES (its FOCA 0.23 bump): pass
known=(the TES instances left out as ineligible) inTaskRuns.create_task(), and update its pinning how-to (protes#508 / protes#509) andtest_pin_to_unknown_tes_instancefor identifiers (400).Verification
pytest tests/pluginswithout MongoDB: 886 passed, 1 skipped; the MongoDB store tests need a server (they run in CI).tests/plugins/test_plugin_selection.py: refusal after arequest-phase plugin with norouteplugin run, error carries the run, provenance; URL and mixed items not refused;knownadds to candidates; no backends at all; own URL;selects_unknown_onlyparametrized. Coverage ofselection.pyanderrors.py: 100%.ruff check,ruff format --check,mypy,ast-grep scan,mkdocs build --strict: clean. semgrep runs in the push hook.Declined review findings
run_route()can't passknown(low): plugin authors test plugins, not the app's refusal; can follow if needed.run: AnyinInvalidSelection(low): as in its sibling errors; typing them all needs aTYPE_CHECKINGimport across the module, a separate change.route()and_refuse_unknown_selection()(low): kept so that the helper is correct on its own.allowwith an unmatched URL isn't refused (high): deliberate and documented; a URL may name a discovered backend of a registry that is unavailable for now, which must stay "no backend available", as the issue asks for transient cases.test_route_allow_of_own_url_is_unknown); the gateway never uses such a backend, so it is unknown, not removed by routing.Sourcery's third finding (docs/configuration/plugins.md) is fixed in 73d8927 (docs only); its threads are answered and resolved.
🤖 Generated with Claude Code
Summary by Sourcery
Reject client backend selections that can never match a gateway backend while preserving transient availability behavior and giving applications enough context to explain valid-but-unavailable choices.
Bug Fixes:
allowselections containing only unknown identifiers with a clear400 invalid-backendserror instead of allowing them to fall through as unavailable backends.order,forbid, and known backends that routing later removes.Enhancements:
Documentation:
knownrouting argument, and the resulting migration requirements.Tests: