Repository navigation
Closed
10 / 1010 of 10 issues completedLabels
priority: highHigh prioritytype flag: breaking changeProposed change breaks current APItype flag: metaGeneric issue that will spawn more specific issuestype: featureNew feature or requestworkload: weeksLikely takes weeks to resolve
Milestone
Description
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 /pluginslists 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 monorepofoca-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):
- Prep, no new FOCA needed: fix: undo changes of failed middlewares #313 (fallbacks see no changes
of failed alternatives), fix: keep the backend order in middlewares #314 (backend order kept),
refactor!: pass tasks to middlewares, not requests #315 (tasks, not requests, for middlewares; Flask-free task
processing), refactor: remove the middleware management API #316 (management API spec and collection
removed). - refactor!: run task plugins with FOCA #321
refactor!: run task plugins with FOCA(engine, backend
list, config; breaking). - feat: select plugins and backends per task #218
feat: select plugins and backends per task. - feat: serve task provenance #322
feat: serve task provenance(tags,forwarded_to
deprecated). - docs: add a derived-image recipe for plugins #323
docs: add a derived-image recipe for plugins. - feat!: stop serving forwarded_to #324
feat!: stop serving forwarded_to(next minor after T3).
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
Collapse Sub-issuesSub-issues
Loading 10 sub-issues
Metadata
Metadata
Assignees
Labels
priority: highHigh prioritytype flag: breaking changeProposed change breaks current APItype flag: metaGeneric issue that will spawn more specific issuestype: featureNew feature or requestworkload: weeksLikely takes weeks to resolve
Activity
keshxvdayal commentedon Jan 22, 2026
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:
refactor!: upgrade to FOCA 0.15 (#219)
[-]Dynamic Middleware Management API Implementation[/-][+]feat!: run task plugins with FOCA[/+]uniqueg commentedon Nov 2, 2026
All sub-issues are closed, and dev runs task plugins with FOCA (no middleware code left). Closing for v1.0.0-rc1.