Repository navigation
refactor!: upgrade to FOCA 0.15 - #219
Conversation
proTES required `foca>=0.12.1` without an upper bound, so fresh installs got FOCA 0.15, with which the app did not start; only the 2022 base image kept the image working. - Require `foca>=0.15.0,<0.16`, `connexion>=2.15.1,<3` and `py-tes>=1.1` (supports `ignore_error`, #176); drop the `pymongo` pin and move `pytest-ordering`, `celery-types` and the type stubs to the dev requirements (plus `setuptools` for linting `setup.py` on Python 3.12). - Build the image on `elixircloud/foca:0.15.0-py3.12`, pinned by digest; install as root, as the FOCA image runs as UID 1000. The API directory no longer needs to be writable (FOCA does not write specs). - CI: lint on Python 3.10 and 3.12, and run the new unit tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Follow FOCA's migration guides for 0.14 and 0.15: - Config: no removed options (`validation_methods`, `validation_checks`, `environment`, `use_reloader`, the old exception members), `server.debug: False`, a 1 MiB request body limit (`max_content_length`), problem details sent as `application/json` (GA4GH), a literal task ID charset, and fully qualified controller modules. No trusted token issuers yet: FOCA requires an `audience` with issuers, and authentication stays disabled until #212. - Service info: served by FOCA from `service_info` (version of the installed package), instead of the app's controller and its `service_info` collection. - The middleware management API is no longer registered: its controller module does not exist (#194). - Code: pydantic 2 (`ConfigDict`, `RootModel`, `model_dump(mode= "json")`, executors and commands default to empty lists), `foca.get_config()`, a typed `get_custom_config()`, and `foca.get_collection()` in the Celery task, which no longer uses FOCA's private client factory or a hard-coded database name (`MONGO_DBNAME` applies). The worker validates the custom config. - Specs: the GA4GH service info schemas are local, so the app starts without fetching them. - `ignore_error` of executors is relayed in both directions (#176). - Forwards: the recursive `tesNextTes` schema made startup hang with jsonschema 4 (#173). As suggested there, `logs[].metadata.forwarded_to` is a list of `tesForward` objects (`id`, `url`, `forward_time` in RFC 3339), in the order of forwarding; proTES appends its own forward and cancels tasks at the last one. Tests (in `tests/`, run in CI) cover startup, config, service info, problem details, the body limit, task relay with a fake backend, the Celery task and the models. BREAKING CHANGE: errors are problem details (`title`, `status`, `detail`) instead of `message` and `code`; the service info is configured in `service_info.service` and no longer stored; configs must apply FOCA 0.15's changes; the middleware management API is not served; `logs[].metadata.forwarded_to` is a list of forwards instead of a nested `tesNextTes` object. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Current PyMongo releases refuse to connect to MongoDB 3.6 (#171); MongoDB 8.0 does not start on Linux kernels 6.19 to 7.0.13 (SERVER-121912). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review findings on the FOCA 0.15 migration: - py-tes returns output sizes as integers, which pydantic 2 no longer converts to strings, so the Celery task failed for every finished task with outputs; the converter converts them (sizes may be missing). - Tasks stored by earlier versions, and tasks of other instances running them, have forwards nested as `tesNextTes` objects; they are read as lists, so such tasks can still be canceled and tracked. `forward_time` is optional for these. - Remove the unused `TaskRuns.foca_config`, and name #212 wherever the config says when authentication is enabled. - Tests: split the endpoint tests, cancel at the last of several forwards, outputs of tracked tasks, missing documents. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tasks stored by earlier versions were served with forwards nested as `tesNextTes` objects, against the new spec; GET and list responses now flatten them. Task updates no longer store `null` for unset fields (e.g., `forward_time` of such forwards, missing output sizes). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThis breaking-change PR upgrades proTES to FOCA 0.15 and Python 3.12-era dependencies, refactors configuration, Pydantic models, database access, service-info routing, and error handling, modernizes forwarding and backend conversion behavior, rebuilds the container with a compiled dependency stage, and adds cross-version unit and integration coverage. Sequence diagram for task forwarding and progress trackingsequenceDiagram
participant Client
participant API as proTES API
participant Backend as TES backend
participant Mongo as MongoDB
participant Worker as Celery worker
Client->>API: CreateTask
API->>Backend: create_task
Backend-->>API: remote task ID
API->>Mongo: model_dump and store forwarded_to
API-->>Client: task ID
Worker->>Backend: get_task
Backend-->>Worker: task state and outputs
Worker->>Mongo: upsert_fields_in_root_object
Client->>API: GetTask or CancelTask
API->>Mongo: get_collection
API->>Backend: cancel_task using last forwarded ID
Backend-->>API: cancellation result
API-->>Client: task response
Flow diagram for FOCA service-info and API configurationflowchart TD
Config[service_info.service in config.yaml]
Specs[additions.openapi.yaml]
FOCA[FOCA service-info controller]
Endpoint[GET /service-info]
Version[Installed pro-tes package version]
Config --> FOCA
Version --> FOCA
Specs --> Endpoint
FOCA --> Endpoint
Endpoint --> Response[GA4GH Service response]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
`ip2geotools` requires `typed-ast`, which has no wheels for Python 3.12, and the FOCA image has no compiler, so the image build failed. Wheels are now built in a build stage with gcc and installed from there, so the final image has no build tools. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Hey - I've found 3 issues
Fixed security issues:
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pro_tes/tasks/track_task_progress.py" line_range="112-113" />
<code_context>
# updating the database
- db_client.upsert_fields_in_root_object(root="task", **document.task.dict())
+ db_client.upsert_fields_in_root_object(
+ root="task", **document.task.model_dump(mode="json", exclude_none=True)
+ )
</code_context>
<issue_to_address>
**Successful cancellation is overwritten**
When a cancel request reads a cancelable state and its backend cancellation succeeds after the tracker reads a terminal response but before the tracker’s final MongoDB write, the tracker writes its previously fetched task state and full task snapshot after the cancel handler sets the state to `CANCELED`, replacing that update with the stale remote state. The caller sees the task as completed or running despite the successful cancellation.
Make the final update conditional on the current state or update only fields that cannot overwrite a concurrent cancellation.
</issue_to_address>
### Comment 2
<location path="pro_tes/ga4gh/tes/models.py" line_range="260" />
<code_context>
- size_bytes: str = Field(
- ...,
+ # required by the specs, but py-tes may return none
+ size_bytes: Optional[str] = Field(
+ default=None,
description=(
</code_context>
<issue_to_address>
**Output logs omit required sizes**
When a backend returns an output log whose `size_bytes` is missing, `convert_output_file_logs` preserves a missing backend size as `None`, and the task update serializes with `exclude_none=True`, so the stored output log lacks `size_bytes` and GET responses violate the TES schema; clients receive malformed task data.
Ensure output logs remain schema-valid when the backend omits a size, or explicitly change the API schema and response contract to allow its omission.
Also at `pro_tes/utils/models.py:242-244`, `pro_tes/tasks/track_task_progress.py:112`.
</issue_to_address>
### Comment 3
<location path="tests/test_models.py" line_range="110" />
<code_context>
+ remote_task_id="task-1",
+ )
+ assert document.task.logs is not None
+ for log, previous in zip(document.task.logs, [[earlier], []]):
+ assert log.metadata is not None
+ assert log.metadata.forwarded_to is not None
</code_context>
<issue_to_address>
**Dropped logs pass the test**
When `_update_task_metadata` returns an empty `logs` list, `test_forward_logged` line 110 iterates with `zip`, so if `_update_task_metadata` drops all logs, the loop runs zero times and never checks that any forward was appended.
Assert that the returned logs contain the expected two entries before checking their forwards.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 3 findings to address first, and changing the Compose MongoDB image from 3.6 to 7.0 affects existing persisted database volumes; MongoDB requires supported upgrade steps, so an existing deployment may fail to start or become inaccessible. Reverting the image may not be enough if the database upgrade has progressed, so verify the upgrade path and backups before deploying.
Blocking findings: pro_tes/tasks/track_task_progress.py:113, pro_tes/ga4gh/tes/models.py:260, tests/test_models.py:110
- CI: read-only token permissions by default (CodeQL). - Test that forwards are logged for every task log (Sourcery). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Upgrades proTES to FOCA 0.15, following FOCA's migration guides for 0.14 and 0.15.
foca>=0.12.1had no upper bound, so fresh installs already got FOCA 0.15, with which proTES did not start (removed config options, pydantic 2) and CI was bound to fail; only the 2022 base image kept the image working.foca>=0.15.0,<0.16,connexion>=2.15.1,<3,py-tes>=1.1; nopymongopin; test and typing packages moved to the dev requirements.elixircloud/foca:0.15.0-py3.12, pinned by digest; installs as root, runs as UID 1000 (FOCA image). Dependency wheels are built in a build stage with gcc, asip2geotoolsrequirestyped-ast, which has no wheels for Python 3.12; the final image has no build tools.server.debug: False(S7); request bodies limited to 1 MiB (max_content_length, S9); problem details (title,status,detail) sent asapplication/json(GA4GH); literal task ID charset; fully qualified controller module (pro_tes.ga4gh.tes.server).foca.api.service_info) fromservice_info.service, with the version of the installed package; the app's controller, itsservice_infocollection andcustom.service_infoare gone. The values are unchanged for now; neutral defaults follow in fix: use neutral service-info defaults #205.ConfigDict,RootModel,model_dump(mode="json"), fixed defaults ofTesExecutor.commandandTesTask.executors, B5);foca.get_config()and a typedget_custom_config();foca.get_collection()in the Celery task instead of FOCA's removed private client factory and the hard-coded databasetaskStore(B6;MONGO_DBNAMEapplies now); the worker validates the custom config too.logs[].metadata.forwarded_tois a non-recursive list oftesForward(id,url,forward_timein RFC 3339), in the order of forwarding; proTES appends its forward and cancels tasks at the last one. Forwards nested by earlier versions (stored tasks, or other instances running them) are read and served as lists (withoutforward_time), so such tasks can still be canceled and tracked.size_bytesas integers, which pydantic 2 rejects for the string field; the converter converts them (found in review: the Celery task failed for every finished task with outputs).ignore_errorof executors is relayed to backends and kept when converting backend tasks.additions.openapi.yaml(renamed fromadditional_logs.yaml), so startup no longer fetches them from GitHub (needed to test without network; as in cloud-registry#93).tests/(app startup and config, service info, problem details, body limit, task create/list/get/cancel with a fake backend, the Celery task with and withoutMONGO_DBNAME, models and forwarding log); CI lints on Python 3.10 and 3.12 and runs them. The tests intests/unitTeststay uncollectable until test: add app test harness and fix the tests #207.Deviation from the issue:
security.auth.issuersstays empty instead of listing LS Login, because FOCA 0.15 refuses issuers without anaudience, and authentication is still disabled (disable_auth: True). LS Login and the audience come with #212.Closes #203, closes #171, closes #173, closes #176. Supersedes #172 (to be closed after merge).
Upgrade notes (breaking changes)
{"title", "status", "detail"},application/json) instead of{"message", "code"}.service_info.service(FOCA) instead ofcustom.service_info, and is no longer stored in MongoDB; theservice_infocollection can be dropped.logs[].metadata.forwarded_tois a list of{id, url, forward_time}instead of a nestedtesNextTesobject; tasks stored with the old shape are served as lists (withoutforward_time).exceptions.mapping, novalidation_methods,validation_checks,environment,use_reloader); withMONGO_DBNAMEset, the Celery worker now uses that database too.413)./protes/v1/middlewares) is not served.PROTES_DATA_DIR/db(default../data/pro_tes/db) or upgrade it one major version at a time.How it was verified
pytest tests --ignore=tests/unitTest --ignore=tests/test_integration: 20 passed on Python 3.10 and 3.12 (fresh venvs fromrequirements*.txt, without network).flake8 pro_tes/ setup.py,pylint pro_tes/ setup.py(10.00/10),mypy pro_tes/: clean on Python 3.10 and 3.12.docker runisn't available here).Run tests); the first run failed on the image build (typed-ast), fixed by the build stage.Declined review findings
Reviewed by the adversarial and quality reviewer subagents (two adversarial rounds); fixed: output sizes, nested forwards (cancel, tracking, responses),
nullfields in updates, deadTaskRuns.foca_config, inconsistent issue references, split endpoint tests, cancel at the last of several forwards, missing-document test. Declined:register_mongodb.MongoClientat conftest import time (quality, medium): needed becausepro_tes.celery_workercreates its app on import; the comment says so, and test: add app test harness and fix the tests #207 reworks the harness.test_config,test_forwarded_to_not_recursive; quality, low): kept as guards for the security settings (S7, S9) and against reintroducing the recursive schema (fix: infinite loop with jsonschema>3.2.0 #173).test_service_info_not_stored(quality, low): acceptable for now; test: add app test harness and fix the tests #207.create_task(adversarial, low): the nested-forwards case is fixed by the validator; other robustness of the relay is fix: task listing, timestamps and relay bugs #208.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Upgrade proTES to FOCA 0.15 with compatible configuration, containerization, task handling, and validation coverage.
New Features:
Bug Fixes:
Enhancements:
Build:
CI:
Documentation:
Tests: