Skip to content

Tests: let the ST cache_dir guard follow the cache_folder mapping - #19310

Merged
danielhanchen merged 1 commit into
mainfrom
ci/st-cache-dir-guard-alias
Nov 24, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci/st-cache-dir-guard-alias

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

tests/test_prefetch_snapshot_scope.py::test_st_cache_resolutions_honor_explicit_hf_cache_dir fails on main since #19170, and with it the Core legs of every PR based on main (seen first on the staging run for #19181):

AssertionError: an ST cache_dir resolution must read an explicit kwargs.get('cache_dir') first

Cause

#19170 added _refuse_network_share_raw_adapter_base(...) before both SentenceTransformer(...) loads. On the for_inference = True route it passes

cache_dir = st_kwargs.get("cache_folder")
or os.environ.get("SENTENCE_TRANSFORMERS_HOME"),

The code is right. A few lines earlier the same function maps an explicit HF cache_dir onto st_kwargs["cache_folder"]:

_st_cache = kwargs.get("cache_dir") or kwargs.get("cache_folder")
if _st_cache is not None:
    st_kwargs["cache_folder"] = _st_cache

so st_kwargs.get("cache_folder") already reads cache_dir first, and it is the same value the neighbouring _check_modules_json_types(..., cache_dir = st_kwargs.get("cache_folder")) call and the SentenceTransformer(**st_kwargs) load use. The guard only looked for the literal 'cache_dir' inside the expression, so it could not see the mapping. #19170's own CI ran on an older base and the failure showed up only after it merged.

Fix

Test only, no product code changes. The guard now accepts a resolution that either:

  • reads kwargs.get("cache_dir") as its first operand, or
  • reads <dict>.get("cache_folder") first, where the same function, earlier, assigns <dict>["cache_folder"] only from expressions whose first operand reads cache_dir (directly or through one local name).

This is stricter than before in one way: cache_dir has to come first, not just appear somewhere in the expression.

Verification

  • tests/test_prefetch_snapshot_scope.py: 43 passed (1 failed on main).
  • Sabotage, one at a time on sentence_transformer.py, each makes the guard fail:
    • swapping the mapping to kwargs.get("cache_folder") or kwargs.get("cache_dir");
    • dropping st_kwargs["cache_folder"] = _st_cache;
    • changing the delegated route's resolution to kwargs.get("cache_folder") or os.environ.get("SENTENCE_TRANSFORMERS_HOME").
  • With tests/test_adapter_unc_base_guard.py (the tests Refuse a network-share adapter base that transformers resolves by itself #19170 added): all pass.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T16:58:36.336627Z ecae071 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: ecae071346

ℹ️ 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".

@danielhanchen
danielhanchen merged commit 190f7ad into main Nov 24, 2026
1 of 17 checks passed
@danielhanchen
danielhanchen deleted the ci/st-cache-dir-guard-alias branch November 24, 2026 17:00
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