Repository navigation
Description
Problem
proTES runs its "middlewares" with its own engine
(pro_tes/middleware/): classes imported by dotted path from
custom.middlewares, rebuilt for every request, no time bound, no
provenance, and the routing result travels inside the task body
(tes_urls). Backends come from two places (custom.tes.service_list
and one registry in custom.tes.discovery). The default stack sends the
hosts of every task to third-party geolocation services (DB-IP,
Nominatim). FOCA 0.18.0 ships the shared gateway plugin engine
(foca.plugins, ) that proTES, proWES and later gateways
use, with typed backend lists and a default failover router.
Proposal
- Dependency:
foca>=0.18.0,<0.19(and the base image, by hand as
usual). - Engine: the controller of
POST /tasks(server.CreateTask, the
only place that reads the request) builds the inbound request and
principal withfoca.plugins.adapterand passes them, with the task
and the request path, toTaskRuns.create_task(), which stays free
of Flask (ast-grep ruleframework-free-tasks, from refactor!: pass tasks to middlewares, not requests #315).
TaskRuns._apply_middlewares()(the seam of refactor!: pass tasks to middlewares, not requests #315) is replaced
byrun = host.start(...),run.request()andrun.route(...):validate:TesTask(pydantic) and py-testes.Task;sanitize:_handle_url_credentials(mode="strip")and
_check_inline_content()(as today after the middlewares);- order of the security checks unchanged: owner, URL credentials,
inline limit,task_original, then the plugins (design 4.1, P2).
- Routing and forwarding: the candidates are
foca.plugins.backends.expand(custom.tes.backends, api="tes", public_url=…); the forward loop runs overrun.attempts(candidates):- the forward phase replaces
_relayed_task(); TesClientsends eachOutboundRequest(path, query, headers incl.
Via, JSON payload) and attaches the backend's credentials after
the plugins; exceptions map as today: not accepted
(requests.RequestException,BackendAuthError, unknown backend)
→attempt.failed(), next;BackendOutcomeUnknown(5xx, read
timeout) →attempt.unknown(), stop withSYSTEM_ERROR; success →
attempt.succeeded();ForwardTimeout(totalforward_timeout) andNoBackendAvailable
→503, task discarded as today.
- the forward phase replaces
- Backend list (breaking):
custom.tes.backends, FOCA P10's typed
entries (ga4gh-tes,ga4gh-service-registry), replacing
custom.tes.service_listandcustom.tes.discovery. proTES's own
discovery (pro_tes/ga4gh/tes/discovery.py),check_public_hostand
is_public_addressare deleted in favour of FOCA's (P5, P10).
get_backend(url)(used by the Celery tracker and cancel) looks
backends up in the same list. Kept in proTES:
custom.tes.client_credentials,custom.tes.timeout,
custom.tes.url_schemes(if P10 doesn't cover it, see the list of what proTES needs from FOCA (tracked in feat: add gateway plugin engine foca#485)). - Config (breaking): top-level
pluginssection inconfig.yaml,
default pipeline =foca.routing.ordered(FOCA P6). The old keys
custom.middlewares,custom.tes.service_listand
custom.tes.discoverystop the app with a hint that lists the
mapping (design section 16;middlewaresby FOCA P1, the other two by
proTES's config model). - Provenance:
run.provenance()stored in the task document
(provenance, prospective part at creation, retrospective part with
the backend update); failed pipelines stored only if
plugins.provenance.record_failed(FOCA P3, default off). Serving it
is T3. - Tags: the stored task keeps the client's tags (including
gateway.pipelineandgateway.backends); the relayed task has no
gateway.*key (strip_for_forwarding, FOCA P11); other client
gateway.*keys →400(FOCA P2). Server-written tags are T3. - Deleted:
pro_tes/middleware/,pro_tes/plugins/middlewares/
(random and distance routing move to the monorepo:
generic.routing.random, ;tes.routing.distance, , which
absorbs perf: store geolocations of TES instances #130),MiddlewareException,InvalidMiddleware,geopy
and its mypy override, thetes_urlshandling. - Errors: FOCA's problem types (
PipelineFailed500,
PipelineRejected4xx,NoBackendAvailable/ForwardTimeout503,
LoopDetected508) inexceptions.mapping, next to proTES's. - Chart and Compose:
tes.backendsvalues (camelCase, typed
entries) andpluginsvalues (plugins.available,
plugins.pipeline,plugins.presets,plugins.clientPipelines,
plugins.clientBackends,plugins.tags,plugins.provenance),
rendered into the config;values.schema.json; the smoke config
(tests/smoke/config.yaml) anddocker-compose.yaml. - Docs:
docs/middlewares.mdbecomesdocs/plugins.md(operator
view: allowlist, pipelines, presets, per-task selection, provenance,
backends; author guide in FOCA's docs); configuration, API, access
control, operations pages; "Upgrading" with the mapping of section
16 and the routing change (ordered failover instead of
distance-then-random; no third-party lookups by default). - Tests: fake plugins registered as entry points by a test-only
distribution (or FOCA P7's fixture, see the list of what proTES needs from FOCA (tracked in feat: add gateway plugin engine foca#485)), so the real
allowlist path is tested; every forward outcome; old keys refused;
100% coverage.
Acceptance criteria
-
POST /tasksruns the configured pipeline throughfoca.plugins;
failed alternatives leave no trace (engine), plugins see no
credentials of backends and noAuthorization/Cookieheaders. - Default routing is ordered failover over
custom.tes.backends
(registry entries shuffled); 5xx and read timeouts stop; the total
forward budget gives503. - Old keys stop the app with the migration hint; the smoke test, the
chart tests and the docs use the new keys. -
pro_tes/has no Flask, Werkzeug or Connexion import outside
app.py,server.pyandexceptions.py(ast-grep), so the move
to FOCA 1.0 (Connexion 3, no Flask) changes only the controller
glue. - Release notes: breaking changes (backend list, plugin config,
routing default, custom middlewares → FOCA plugins), with the
mapping.
Surviving the Connexion 3 migration
Everything below the controllers gets plain data: the task (body),
the request path, and the neutral InboundRequest/Principal that
foca.plugins.adapter builds. When FOCA 1.0.0-rc1 replaces the adapter,
proTES changes server.py only.
Dependencies
- Blocked by the FOCA v0.18.0 release (; P1, P2, P3, P5,
P6, P10, P11). - Blocked by fix: undo changes of failed middlewares #313, fix: keep the backend order in middlewares #314, refactor!: pass tasks to middlewares, not requests #315, refactor: remove the middleware management API #316 (prep
work; merged before). - Blocks: T2 (feat: select plugins and backends per task #218), T3, T4.
- Related: feat: pass user identity to TES backends #254 (user identity for backends: becomes a forward-phase
plugin), perf: store geolocations of TES instances #130 (moves to ), Middleware for Crypt4GH Support #170 (crypt4gh: left out for now).
Open questions
- The release with T1 removes distance and random routing from proTES.
Safe choice: don't release proTES with T1 until and are
published, so operators can keep the old behaviour; or release
anyway and document the gap (pre-1.0)? - See the list of what proTES needs from FOCA (tracked in feat: add gateway plugin engine foca#485) for what T1 needs from FOCA beyond the FOCA drafts.
Activity
uniqueg commentedon Oct 31, 2026
All sub-issues are closed (#331, #332, #333 via #346, #334 via #349, #335 via #348), so this is done.