Skip to content

fix(runtime): stop leaking sys.path to subprocesses via PYTHONPATH - #885

Open
dalyathan wants to merge 1 commit into
pasteurlabs:mainfrom
dalyathan:fix/883-runtime-pythonpath
Open

dalyathan wants to merge 1 commit into
pasteurlabs:mainfrom
dalyathan:fix/883-runtime-pythonpath

Conversation

@dalyathan

Copy link
Copy Markdown

Relevant issue or PR

Fixes #883

Description of changes

Loading tesseract_api.py wrote the runtime's whole sys.path into PYTHONPATH, so every subprocess started from it inherited the runtime's stdlib and site-packages. A child running the same interpreter doesn't notice, but a different Python imports the runtime's modules instead of its own. With a 3.14 runtime, a Python 3.11 started from apply dies on start-up:

AssertionError: SRE module mismatch

load_module_from_path now exports only the module directory, ahead of any existing PYTHONPATH, and restores the previous value if loading fails. Children can still import tesseract_api.py and its sibling modules, and the sys.modules registration from #488 is unchanged.

Testing done

  • New test test_subprocesses_inherit_only_module_dir_on_pythonpath checks the PYTHONPATH a child process sees, with and without an outer PYTHONPATH. On main the child gets the runtime's full sys.path. test_load_module_from_path_restores_pythonpath_on_failure covers the failure path. Both fail on main and pass with this change.
  • The Python 3.11 repro above fails on main and runs with this change.
  • The Document sharp edges when using ProcessPoolExecutor in tesseract_api.py #356 case (a spawn ProcessPoolExecutor in apply mapping a function from tesseract_api.py and one from a sibling module) gives the same result before and after.
  • pytest --skip-endtoend passes locally (Python 3.14, without the jax extras). Not run: the end-to-end Docker tests and Python 3.10.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PasteurBot

PasteurBot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

CLA signatures confirmed

All contributors have signed the Contributor License Agreement.
Posted by the CLA Assistant Lite bot.

@dalyathan

Copy link
Copy Markdown
Author

@PasteurBot I have read the CLA Document and I hereby sign the CLA

1 similar comment
@dalyathan

Copy link
Copy Markdown
Author

@PasteurBot I have read the CLA Document and I hereby sign the CLA

@dalyathan
dalyathan marked this pull request as ready for review October 31, 2026 01:51

This branch has not been deployed

No deployments
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.

Runtime exports its whole sys.path as PYTHONPATH, breaking subprocesses that run a different Python

2 participants