Skip to content

fix(agent): skip site dirs that have bad .pth files#167

Merged
efiop merged 1 commit intomainfrom
ruslan/fix-pth
May 16, 2025
Merged

fix(agent): skip site dirs that have bad .pth files#167
efiop merged 1 commit intomainfrom
ruslan/fix-pth

Conversation

@efiop
Copy link
Contributor

@efiop efiop commented May 16, 2025

.pth could be model weights or python path configuration files https://docs.python.org/3/library/site.html Running into the former will result in:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/isolate/connections/_local/agent_startup.py", line 45, in <module>
    load_pth_files()
  File "/usr/local/lib/python3.11/site-packages/isolate/connections/_local/agent_startup.py", line 31, in load_pth_files
    site.addsitedir(site_dir)
  File "<frozen site>", line 236, in addsitedir
  File "<frozen site>", line 188, in addpackage
  File "<frozen codecs>", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 128: invalid start byte

So we are now just skipping such dirs. There is a risk that we might miss some useful pth files, but I doubt there will ever be a situation where two are mixed.

@efiop efiop merged commit 43cbe0d into main May 16, 2025
6 checks passed
@efiop efiop deleted the ruslan/fix-pth branch May 16, 2025 17:50
@efiop efiop requested a review from Copilot May 16, 2025 18:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request addresses an issue with .pth files by adding error handling in site directory loading.

  • Introduces a try/except block around site.addsitedir to skip problematic directories.
  • Adds traceback and error notification output for debugging purposes.

# packages.
for site_dir in python_path.split(os.pathsep):
site.addsitedir(site_dir)
try:
Copy link

Copilot AI May 16, 2025

Choose a reason for hiding this comment

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

Consider using a logging framework instead of print and traceback for error reporting. This change would improve log aggregation and production diagnostics.

Copilot uses AI. Check for mistakes.
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