Skip to content

Do not scan vendored packages that refuse to import on our floor - #8252

Merged
danielhanchen merged 1 commit into
unslothai:mainfrom
danielhanchen:fix-py39-floor-vendor-guard
Aug 9, 2026
Merged

danielhanchen merged 1 commit into
unslothai:mainfrom
danielhanchen:fix-py39-floor-vendor-guard

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

The red

tests/test_python39_compatibility.py runs as the python floor compatibility (HARD GATE) step in consolidated-tests-ci.yml. On current main it fails on all three Core matrices, so every open PR is red through no fault of its own:

studio/backend/vendor/truststore/_api.py:30: str | bytes (type alias)
studio/backend/vendor/truststore/_api.py:31: str | bytes | typing.Callable[[], str | bytes] (type alias)

Two tests fail: test_studio_evaluated_unions_do_not_grow and test_no_pep604_unions_are_evaluated_on_the_declared_floor. The files arrived with #8108 as vendored third-party code.

Why it is a false positive

studio/backend/vendor/truststore/__init__.py opens with

if _sys.version_info < (3, 10):
    raise ImportError("truststore requires Python 3.10 or later")

so _api.py cannot be reached on our 3.9 floor: the package raises before that module loads. The sole caller, studio/backend/utils/native_tls.py:79, wraps import truststore in try/except Exception: pass, so the raise is already handled. The unions the gate is pointing at can never evaluate.

The change

package_files() now skips files under a package whose __init__.py declares a floor above ours.

The exemption is keyed on the guard, not on the path. A blanket vendor/ exclusion would have been shorter, but it would silently stop scanning any unguarded code later dropped into the same directory, and it would keep the exemption alive if upstream ever removes the version guard, at which point the unions really would be reachable and the gate should go red again.

The guard must both compare version_info against a tuple above our floor and actually raise. A warnings.warn under the same condition still imports, so it does not exempt.

Verification

2 failed, 2 passed before, 8 passed after, plus four tests covering the exemption itself. Three mutations, each run with cleared bytecode:

Mutation Result
drop the skip filter from package_files 2 failed (the original red returns)
exempt on any guard rather than one above our floor 1 failed
exempt without requiring the guard to raise 1 failed

ruff check clean; scripts/run_ruff_format.py under the pinned ruff 0.6.9 touches only the added lines.

tests/test_python39_compatibility.py is a hard gate in Core CI and it is
currently red on main for every open PR:

  studio/backend/vendor/truststore/_api.py:30: str | bytes (type alias)
  studio/backend/vendor/truststore/_api.py:31: str | bytes | ... (type alias)

Those unions cannot be reached on 3.9. truststore/__init__.py raises
ImportError below 3.10, and its only caller wraps the import in try/except,
so the package is gone before _api.py is ever loaded.

Skip files under a package whose __init__ declares a floor above ours,
keyed on the guard rather than the path so unguarded code added to the same
vendor directory is still scanned.
@danielhanchen
danielhanchen force-pushed the fix-py39-floor-vendor-guard branch from ada6416 to 4a2e261 Compare August 9, 2026 11:05
@danielhanchen
danielhanchen merged commit d458029 into unslothai:main Aug 9, 2026
14 of 19 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ada6416ed6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if "__pycache__" not in p.parts and "node_modules" not in p.parts
if "__pycache__" not in p.parts
and "node_modules" not in p.parts
and not any(d in p.parents for d in skip)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep the guarded initializer in the floor-syntax scan

When a guarded package's own __init__.py uses syntax newer than the declared floor, guarded_floor() can parse it on the current CI interpreter and this predicate then excludes the initializer itself. The version guard cannot protect such syntax because Python must compile __init__.py before executing the guard; for example, adding a match statement after the 3.10 guard makes this test scan no files while importing on 3.9 fails before the ImportError. Exclude only descendants of the guarded package, while retaining its initializer in the parse/compile checks.

Useful? React with 👍 / 👎.

if "__pycache__" not in p.parts and "node_modules" not in p.parts
if "__pycache__" not in p.parts
and "node_modules" not in p.parts
and not any(d in p.parents for d in skip)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check guarded descendants on their supported floor

On Python 3.10 and later the truststore guard does not raise, so every descendant remains reachable and must at least parse on the package's guarded floor. Excluding the entire directory from every package_files() consumer means a future vendored child that requires 3.11 syntax—or does not compile at all—passes both the declared-floor parser and test_every_packaged_module_compiles, yet Studio's native-TLS import fails on supported Python 3.10. Scan descendants using their detected guarded floor rather than omitting them wholesale.

Useful? React with 👍 / 👎.

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.

1 participant