Skip to content

fix(api/ontologies): offload blocking filesystem IO off the event loop#3070

Open
ly-wang19 wants to merge 1 commit into
topoteretes:devfrom
ly-wang19:fix/ontology-routes-blocking-io
Open

fix(api/ontologies): offload blocking filesystem IO off the event loop#3070
ly-wang19 wants to merge 1 commit into
topoteretes:devfrom
ly-wang19:fix/ontology-routes-blocking-io

Conversation

@ly-wang19

Copy link
Copy Markdown
Contributor

What

The delete_ontology and list_ontologies ontology routes are async def, but call the synchronous OntologyService methods directly:

@router.delete("/{ontology_key}")
async def delete_ontology(...):
    ontology_service.delete_ontology(...)   # blocking stat/unlink on the event loop

@router.get("")
async def list_ontologies(...):
    ontology_service.list_ontologies(user)  # blocking metadata read on the event loop

Both service methods do blocking filesystem IO (Path.exists/resolve/unlink, metadata read), so they stall the event loop for the duration. The sibling upload_ontology route already awaits its async service method — these two were the inconsistent blocking paths.

Change

Dispatch the two synchronous calls via asyncio.to_thread. The service methods stay synchronous on purpose — their existing unit tests (tests/unit/api/test_delete_ontology.py) call them directly — so only the async routes change.

Test

Adds tests/unit/api/test_ontology_router_offload.py: extracts each route handler and asserts the blocking call is dispatched through asyncio.to_thread. Reverting either offload fails the corresponding test.

pytest tests/unit/api/test_ontology_router_offload.py tests/unit/api/test_delete_ontology.py10 passed; ruff clean.

@github-actions

Copy link
Copy Markdown
Contributor

Hello @ly-wang19, thank you for submitting a PR! We will respond as soon as possible.

Vasilije1990
Vasilije1990 previously approved these changes Jun 14, 2026
@Vasilije1990 Vasilije1990 changed the base branch from main to dev June 14, 2026 15:02
@Vasilije1990 Vasilije1990 dismissed their stale review June 14, 2026 15:02

The base branch was changed.

@ly-wang19 ly-wang19 force-pushed the fix/ontology-routes-blocking-io branch 2 times, most recently from 7ba3eb3 to 82a67c0 Compare June 15, 2026 05:47
@ly-wang19 ly-wang19 closed this Jun 15, 2026
@ly-wang19 ly-wang19 reopened this Jun 15, 2026
The delete_ontology and list_ontologies routes are async def but called the
synchronous OntologyService methods directly, which perform blocking filesystem
IO (stat/unlink, metadata read) on the event loop. The sibling upload_ontology
route already awaits its async service method.

Dispatch both synchronous calls via asyncio.to_thread. The service methods stay
synchronous (their existing unit tests call them directly), so only the async
routes change. Adds a regression test asserting each route offloads via
asyncio.to_thread.

Signed-off-by: ly-wang19 <ly-wang19@users.noreply.github.com>
@ly-wang19 ly-wang19 force-pushed the fix/ontology-routes-blocking-io branch from 82a67c0 to cb8fb58 Compare June 18, 2026 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants