Skip to content

refactor!: run task plugins with FOCA #321

Closed
5 of 5 issues completed
Closed

Description

@uniqueg

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

  1. Dependency: foca>=0.18.0,<0.19 (and the base image, by hand as
    usual).
  2. Engine: the controller of POST /tasks (server.CreateTask, the
    only place that reads the request) builds the inbound request and
    principal with foca.plugins.adapter and passes them, with the task
    and the request path, to TaskRuns.create_task(), which stays free
    of Flask (ast-grep rule framework-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
    by run = host.start(...), run.request() and run.route(...):
    • validate: TesTask (pydantic) and py-tes tes.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).
  3. Routing and forwarding: the candidates are
    foca.plugins.backends.expand(custom.tes.backends, api="tes", public_url=…); the forward loop runs over run.attempts(candidates):
    • the forward phase replaces _relayed_task();
    • TesClient sends each OutboundRequest (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 with SYSTEM_ERROR; success →
      attempt.succeeded();
    • ForwardTimeout (total forward_timeout) and NoBackendAvailable
      → 503, task discarded as today.
  4. Backend list (breaking): custom.tes.backends, FOCA P10's typed
    entries (ga4gh-tes, ga4gh-service-registry), replacing
    custom.tes.service_list and custom.tes.discovery. proTES's own
    discovery (pro_tes/ga4gh/tes/discovery.py), check_public_host and
    is_public_address are 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)).
  5. Config (breaking): top-level plugins section in config.yaml,
    default pipeline = foca.routing.ordered (FOCA P6). The old keys
    custom.middlewares, custom.tes.service_list and
    custom.tes.discovery stop the app with a hint that lists the
    mapping (design section 16; middlewares by FOCA P1, the other two by
    proTES's config model).
  6. 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.
  7. Tags: the stored task keeps the client's tags (including
    gateway.pipeline and gateway.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.
  8. 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, the tes_urls handling.
  9. Errors: FOCA's problem types (PipelineFailed 500,
    PipelineRejected 4xx, NoBackendAvailable/ForwardTimeout 503,
    LoopDetected 508) in exceptions.mapping, next to proTES's.
  10. Chart and Compose: tes.backends values (camelCase, typed
    entries) and plugins values (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) and docker-compose.yaml.
  11. Docs: docs/middlewares.md becomes docs/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).
  12. 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 /tasks runs the configured pipeline through foca.plugins;
    failed alternatives leave no trace (engine), plugins see no
    credentials of backends and no Authorization/Cookie headers.
  • Default routing is ordered failover over custom.tes.backends
    (registry entries shuffled); 5xx and read timeouts stop; the total
    forward budget gives 503.
  • 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.py and exceptions.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

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.

Sub-issues

Sub-issues

5 of 5 Issues completed
Loading 5 sub-issues

Activity

  1. added
    priority: high
    status: blocked
    type flag: breaking change
    type: maintenance
    type: security
    workload: weeks
    on Oct 24, 2026
  2. added
    status: in progress
    and removed
    status: blocked
    on Oct 28, 2026
  3. uniqueg commented on Oct 31, 2026

    @uniqueg
    MemberAuthor

    All sub-issues are closed (#331, #332, #333 via #346, #334 via #349, #335 via #348), so this is done.

  4. removed
    status: in progress
    on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: hightype flag: breaking changetype: maintenancetype: securityworkload: weeks

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions