Repository navigation
fix(ai-ml): anchor AI/ML import-pack rules on the top-level package (#4150) - #4231
Merged
Merged
Conversation
…ameworks on the top-level package (#4150) The shared `\b(?:import|require|from)\b.*?(?:names)\b` shape fired whenever a library name appeared anywhere on an import line (`from .langchain import`, `from airflow.providers.pinecone.hooks import`, `from myproj.models.torch import`, `require('../sklearn')`, `from './keras/loader'`). Generalise PR #4149's llm_api anchors into two builders, _py_package_import / _js_package_import (llm_api's compiled patterns are byte-identical), and build PY_*/JS_* patterns for all four rules. Python langchain_* distributions now count as llm_orchestrator (mirroring js/ts @langchain/*); js/ts scopes: @langchain/*, @llamaindex/*, llamaindex, @pinecone-database/*, @tensorflow/*, @tensorflow-models/*. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013sNMtAg6s9dyyjNgnjRHi8
…rt-and-feature-flags
Contributor
This was referenced Oct 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug-sweep PR: fixes #4150.
#4150: AI/ML import-pack rules matched library names anywhere on an import line
Root cause.
llm_orchestrator,llm_vector_store,ml_traditionalanddl_frameworkswere all built from_IMPORT_WRAPPER = r"\b(?:import|require|from)\b.*?(?:{names})\b", which matches when the name appears anywhere on an import line. PR #4149 fixed the same thing forllm_api(#4137) but left these four alone.Fix.
_shared_patterns.py: #4149's two pattern shapes become builders,_py_package_import(packages)and_js_package_import(packages).PY_LLM_API/JS_LLM_APIare rebuilt through them; their compiled patterns and flags are verified byte-identical. Each of the four rules gets aPY_*(python) andJS_*(javascript, typescript) pattern. Python requires the module afterfrom(or an item afterimport) to be the package, anchored at a statement start. JS/TS requires the quoted specifier to name the package, so relative and alias paths never match._IMPORT_WRAPPERand the fourGLOBAL_*constants are removed.Ownership decisions, which the issue asked to make explicit:
langchain_*(langchain_core,langchain_community,langchain_google_vertexai, ...) is nowllm_orchestrator. This mirrors js/ts, where the whole@langchain/*scope always counted. As a result,langchain_openai/langchain_anthropiccount under bothllm_orchestratorandllm_api(llm_api: anchor on the SDK's top-level package, not provider-named path segments (#4137) #4149), the same way@langchain/openaialready did.llm_orchestrator:langchain,llamaindex,@langchain/*,@llamaindex/*llm_vector_store:chromadb,@pinecone-database/*ml_traditional:sklearndl_frameworks:tensorflow/torch/kerasplus@tensorflow/*and@tensorflow-models/*. The bare names are kept so the strict test's documented positive still holds.torchvision,tensorflow_hub,chromadb-default-embed,keras-js) do not count, consistent with llm_api: anchor on the SDK's top-level package, not provider-named path segments (#4137) #4149.Docs updated:
how_to_add_a_language.md(rule descriptions),docs/domain_sensor_contracts.md, and a comment intests/test_signal_contract_sheet.py. Contract text is unchanged, so no re-render was needed.Tests. New file
tests/extraction/languages/test_ai_ml_import_anchor_4150.py(147 cases):StructuralExtractor.splice()Against unfixed main, 54 cases fail; all pass after the fix.
Corpus before/after. Old vs. new rules, both run through
splice(), on 4,041 py/js/ts candidate files. The candidates are every file in/nvme-data/gitgalaxy-datamatching a loose import grep, plus the airflow, scikit-learn, sentry, vscode, scipy, rdkit, networkx, pylint, freeCodeCamp, Python and tqdm checkouts.Overall, 1,423 hits were removed and 208 added. Every removed line was classified (from a sample of up to 8 lines per changed file):
>>> from sklearn...lines inside docstrings. This is the bulk of theml_traditionaldrop. They are documentation, not imports of the module, and are treated the same way llm_api: anchor on the SDK's top-level package, not provider-named path segments (#4137) #4149 treated them forllm_api.# from keras import ...).tf_upgrade_v2test fixtures, sympy's("import torch",)tables, docstrings).airflow.providers.pinecone.*,google.cloud.aiplatform...plugins.tensorflow,sympy.printing.tensorflow,safetensors.torch,ray.train.torch,openinference.instrumentation.langchain,from sklearn.externals.array_api_compat import torch.agentMonitoring.tsx).No real top-level import of a listed package was lost. All 208 added hits are python
langchain_*imports (langchain_core,langchain_google_vertexai,langchain_openai,langchain_google_spanner), which follows from the ownership decision above.#4114
#4114 is out of scope; it was closed as not-planned on 2026-10-03 (feature_flags is retired, removal to be done with the #4111 retrain).
Golden masters
Both legs were re-blessed: full (
galaxy_venv) and zero-dep (galaxy_zero_venv). A PATH shim printedENGINE …/fix-4150-4114/gitgalaxyfor each. There is no drift in either fixture. The pinned crucible (v1.6.0) contains no import of any of these packages (grepped), so the pack rules read 0 before and after, asdomain_sensor_contracts.mdalready records. No golden files are in this PR.signal_coverage_baseline.jsonis unchanged.Sibling bug-sweep PRs also re-bless golden masters. If one merges first, merge main and re-bless with
crucible_check.py --update/rebase_rebless.py. Never hand-merge golden files.pr_gates
Full
python tests/tools/pr_gates.pyafter merging current main: 7/7 pass (lint, audits, secrets, xray, gauntlet, golden, suite). There are no pre-existing failures. A pre-merge run had 3tests/cobol_mainframe/test_det_programs.pyfailures; these were fixed on main by #4220 and are gone after the merge.Cross-repo
None needed. keyword-rosetta plants no AI/ML pack imports, so rosetta counts do not move and
rosetta:rebless-owedis not applied.Closes #4150
🤖 Generated with Claude Code
https://claude.ai/code/session_013sNMtAg6s9dyyjNgnjRHi8