Skip to content

feat!: run task plugins with FOCA #194

Closed
10 of 10 issues completed
Closed

Description

@keshxvdayal

proTES's task "middlewares" become task plugins, run by the gateway
plugin engine of FOCA (foca.plugins, FOCA 0.18.0,
elixir-cloud-aai/foca#485), which proWES and later gateways
share. Decided by the maintainer on 2026-10-24; design summary:

  • Names: plugin (installable unit), pipeline (ordered steps),
    step (ordered alternatives = fallbacks). "Middleware" is left to real
    HTTP middleware.
  • Phases: request (after authentication, validation, access
    control and sanitation; the output is validated and sanitised again),
    route (choose among known backends only), forward (per attempt;
    backend credentials attached after the plugins), response.
  • Semantics: each alternative works on its own copy, kept only on
    success; timeouts per alternative and per pipeline; a plugin may
    reject a task (4xx).
  • Management by config only: an allowlist of installed plugins
    (entry points, optionally pinned), a default pipeline and presets. No
    runtime management API and no code installed at runtime (so feat: Implement Controllers for Middleware Management API #197 and
    PR feat: implement middleware management controllers #199 are closed as not planned, fix(api)!: load only installed middlewares #217 as superseded).
  • Per task: clients choose a pipeline (gateway.pipeline) and
    restrict or order backends (gateway.backends) with reserved TES task
    tags, from what the operator allows (feat: select plugins and backends per task #218); GET /plugins lists it.
  • Routing: an ordered list of typed backends (custom.tes.backends:
    TES instances and service registries); the default router tries them in
    the configured order, registry entries in random order, and moves on
    only if a backend certainly did not accept the task. Distance-based
    and random routing move to the plugin monorepo foca-plugins.
  • Provenance: what was requested, resolved and executed is stored
    with each task, served to owners and admins
    (GET /tasks/{id}/provenance) and summarised in server-written
    gateway.* tags, which replace the non-compliant
    metadata.forwarded_to (deprecated for one release).
  • Framework-free: plugins and the task processing get plain data,
    never Flask objects, so they survive FOCA 1.0's move to Connexion 3
    without Flask.

Plan (sub-issues):

Not in this plan: crypt4gh (#170, left out for now), the geolocation
cache (#130, moves to the monorepo's distance plugin).

Original proposal

A dynamic middleware management system for proTES that allows runtime modification of the middleware stack without service restarts. The system provides RESTful API endpoints to list, add, remove, and reorder middlewares, with changes persisted to the database and reflected immediately in request processing.

Sub-issues

Sub-issues

10 of 10 Issues completed
Loading 10 sub-issues

Activity

  1. keshxvdayal commented on Jan 22, 2026

    @keshxvdayal
    ContributorAuthor

    Implementation Plan
    1. Backend API Endpoints (COMPLETED)

    GET /api/middlewares - List all configured middlewares with their order and metadata
    POST /api/middlewares - Add new middleware (local or from external sources like GitHub)
    DELETE /api/middlewares/ - Remove a middleware by ID
    PUT /api/middlewares/order - Reorder the middleware stack by providing ordered list of IDs

    2. Dynamic Middleware Loading (COMPLETED)
    Middleware classes are dynamically imported at runtime using importlib
    Support for loading middleware from local class paths (e.g., 'pro_tes.middleware.TaskLog')
    Support for fetching middleware code from GitHub URLs
    Validation ensures all middleware classes inherit from AbstractMiddleware
    Each middleware addition triggers immediate reload of the in-memory stack

    3. Order Field Logic (COMPLETED)
    When order field is not specified in POST request, middleware is appended to the end of the stack
    When order field is specified, middleware is inserted at that position and existing middlewares at that position or higher have their order incremented by 1
    Reordering endpoint accepts array of middleware IDs in desired order and updates all order values accordingly

    4. Fallback Groups Support (COMPLETED)
    API accepts class_path as either a string (single middleware) or list of strings (fallback group)
    Fallback groups allow multiple middlewares at the same position where first is tried, and if it fails, next is attempted
    Current implementation stores fallback groups in database and middleware_handler processes them correctly

    5. Persistence (COMPLETED)
    All middleware configurations stored in MongoDB 'middlewares' collection
    Each middleware document contains: name, class_path, order, source (local/github)
    On service startup, middleware stack is automatically loaded from database
    reload_middleware_stack() function reconstructs in-memory middleware list from database after any modification

    6. Immediate Effect (COMPLETED)
    Changes to middleware stack via API are immediately reflected in request processing
    reload_middleware_stack() is called after every add, delete, or reorder operation
    No service restart required for middleware changes to take effect

    7. Auto-Dependency Installation (IN PROGRESS)
    When fetching middleware from GitHub, detect presence of requirements.txt, pyproject.toml, or setup.py in the repository
    Parse dependency specifications from these files
    Automatically install dependencies using subprocess calls to pip
    Log installation progress and errors for debugging
    Handle edge cases: missing dependency files, installation failures, version conflicts

    8. Documentation (PENDING)
    Document all API endpoints with request/response examples in service README
    Explain order field behavior and fallback group mechanism
    Provide examples of local and external middleware addition
    Document persistence and immediate effect behavior
    Include troubleshooting section for common issues

    9. Testing and Validation (PENDING)

    Test with existing middlewares from pro_tes.middleware package
    Test with custom external middleware from GitHub repositories
    Verify persistence by restarting service and checking middleware stack
    Verify immediate effect by monitoring request logs before and after middleware changes
    Test edge cases: duplicate names, duplicate class paths, invalid middleware code, GitHub fetch failures
    Capture screenshots demonstrating each operation for PR review

    Screenshots Testing all core functionality:

    • List middlewares (GET)
    • Add middleware without order (appends)
    • Add middleware with order (inserts)
    • Fallback groups
    • Get specific middleware
    • Duplicate prevention
    • Reordering
    • Deletion
    Image Image
  2. added
    type flag: meta
    on Oct 22, 2026
  3. added a commit that references this issue on Oct 22, 2026
  4. added
    type: feature
    on Oct 24, 2026
  5. changed the title [-]Dynamic Middleware Management API Implementation[/-] [+]feat!: run task plugins with FOCA[/+] on Oct 24, 2026
  6. added
    type flag: breaking change
    priority: high
    workload: weeks
    status: in progress
    on Oct 24, 2026
  7. added this to the v1.0.0-rc1 milestone on Nov 1, 2026
  8. uniqueg commented on Nov 2, 2026

    @uniqueg
    Member

    All sub-issues are closed, and dev runs task plugins with FOCA (no middleware code left). Closing for v1.0.0-rc1.

  9. modified the milestones: v1.0.0-rc1, v0.5.0 on Nov 3, 2026
  10. removed
    status: in progress
    on Nov 3, 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 flag: metatype: featureworkload: weeks

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions