Skip to content

Fix missing org context in local provider executor thread#1634

Merged
aliasaria merged 8 commits intomainfrom
fix/local-provider-queue-context-vars
Mar 26, 2026
Merged

Fix missing org context in local provider executor thread#1634
aliasaria merged 8 commits intomainfrom
fix/local-provider-queue-context-vars

Conversation

@aliasaria
Copy link
Copy Markdown
Member

Summary

  • local_provider_queue.py: run_in_executor wasn't setting org context in the thread pool thread, so launch_cluster couldn't see _current_org_id or _current_tfl_storage_uri. Now matches the pattern already used in remote_provider_queue.py.
  • storage.py: Added a guard in _get_fs_and_root() that raises RuntimeError when org-scoped storage is enabled but the context var isn't set. This fails fast with a clear message instead of silently resolving to the wrong (unscoped) storage root, which caused confusing "not found" errors.
  • dirs.py: Added require_organization_id() helper that raises if org context is missing, for use as an explicit guard in background tasks and executor threads.

Test plan

  • Run a local provider job with remote/localfs storage enabled and verify it completes successfully
  • Verify that a background task without org context now raises a clear RuntimeError instead of a silent "not found"
  • Run cd api && pytest to confirm no regressions

…ety guard

local_provider_queue used run_in_executor without setting org context in the
thread, unlike remote_provider_queue which already had the fix. Also adds a
RuntimeError guard in storage._get_fs_and_root() so missing org context fails
fast with a clear message instead of silently resolving to the wrong root.
@sentry
Copy link
Copy Markdown

sentry bot commented Mar 25, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...pi/transformerlab/services/local_provider_queue.py 0.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@dadmobile
Copy link
Copy Markdown
Member

I gotta admit I'm not really sure what is failing on the tests? I must be looking at the wrong thing...

 Container transformerlab-app-transformerlab-test-1  Started
 Container transformerlab-app-transformerlab-test-1  Waiting
container transformerlab-app-transformerlab-test-1 exited (3)

Copy link
Copy Markdown
Member

@dadmobile dadmobile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK looks like there is a failed test in applications logs from Playwright:

transformerlab-test-1  |   File "/app/api/api.py", line 119, in lifespan
transformerlab-test-1  |     temp_image_dir = storage.join(await get_workspace_dir(), "temp", "images")

This eventually trickles down to throwing the RuntimeError that this change introduces.

@dadmobile
Copy link
Copy Markdown
Member

I gotta admit I'm not really sure what is failing on the tests? I must be looking at the wrong thing...

Never mind! (you have to scroll down from the test failure see application logs for Playwright tests)

@aliasaria aliasaria merged commit 91cae25 into main Mar 26, 2026
12 of 13 checks passed
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.

3 participants