Repository navigation
llm_api: anchor on the SDK's top-level package, not provider-named path segments (#4137) - #4149
Merged
Merged
Conversation
…th segments (#4137) The shared `\b(?:import|require|from)\b.*?(?:openai|anthropic)\b` shape fired on any import line containing a provider name anywhere -- airflow's `from airflow.providers.openai.hooks.openai import OpenAIHook` (which never imports the SDK) and JS/TS relative paths like `from './openai/client'`. Split llm_api into PY_LLM_API (python) and JS_LLM_API (javascript, typescript): - python: the module after `from`, or an item after `import`, must be the package itself (openai, anthropic, langchain_openai, langchain_anthropic), optionally with a submodule; anchored at a statement start. - js/ts: the quoted module specifier must name a package: openai, anthropic, @openai/*, @anthropic-ai/*, or a scoped adapter @scope/openai|anthropic. Adds regression tests (SDK imports fire; provider-named internal and relative paths don't; per-file counts through splice(); ReDoS payloads). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Contributor
squid-protocol
added a commit
that referenced
this pull request
Oct 3, 2026
…ameworks on the top-level package (#4150) (#4231) 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/*. Claude-Session: https://claude.ai/code/session_013sNMtAg6s9dyyjNgnjRHi8 Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Fixes #4137
Problem
llm_api("Cloud LLM API Integrations") used the shared\b(?:import|require|from)\b.*?(?:openai|anthropic)\bwrapper, so it fired on any import line that had a provider name anywhere on it:from airflow.providers.openai.hooks.openai import OpenAIHook(airflow's OpenAI operator never imports the SDK),from llama_index.llms.openai import ...,from . import openaiimport { x } from './openai/client',require('./providers/openai')Fix
llm_apiis split into two anchored patterns in_shared_patterns.py, covering every language that has the rule (python, javascript, typescript):PY_LLM_API(python): the module right afterfrom, or an item in animport a, blist, must be the SDK package (openai,anthropic, orlangchain_openai/langchain_anthropic), with an optional submodule (from openai.types.chat import ...,import openai as oa). It is anchored at the start of a statement (line start or;,re.M).JS_LLM_API(javascript + typescript): the quoted module specifier afterfrom/import/require(/import(must name a package:openai,anthropic,@openai/*,@anthropic-ai/*(sdk, bedrock-sdk, ...), or a scoped provider adapter@scope/openai|anthropic(@ai-sdk/openai,@azure/openai,@langchain/openai). Relative, absolute and alias paths (./,../,@/,~/,src/...) never match.Every positive the old rule had that is really a package import still fires. Some old matches are dropped on purpose because they are module paths, not the SDK:
llama_index.llms.openaiand the airflow provider.langchain_openaiandlangchain_anthropicwere kept because they are top-level provider packages, andllm_orchestrator'slangchain\bcan't see them.openai-*-prefixed npm packages (e.g.openai-edge) no longer match.ReDoS: every piece next to another uses disjoint character classes (
[\w.]/[ \t]/,), and the import-item list is bounded{0,16}. Both patterns are line-local, so the #3072 line gate still applies. I checked scaling by hand: linear from 10k to 160k chars.Evidence
galaxyscope --db-only) of a small repro repo,llm_apiper file before -> after: airflow-style operator1 -> 0; python SDK file2 -> 2; JS file with'openai'+'@anthropic-ai/sdk'+'./openai/client'3 -> 2.tests/extraction/languages/test_llm_api_anchor_4137.py(76 cases): rule wiring for all three languages, SDK imports fire, provider-named internal/relative paths don't, per-file counts throughStructuralExtractor.splice(), ReDoS payloads. It passes when run with the plainpytestconsole script from an unrelated directory.tests/extraction,tests/core_engine,tests/security_auditing: 11469 passed. 2 timing-based ReDoS tests (zig sweep, pli declare) failed under heavy machine load (load avg ~20) and pass when re-run on their own. Both are unrelated to this rule.tests/tools/audit_check.py: all clear (ruff baseline + format, mypy, dead-key, ast-accuracy).tests/tools/crucible_check.py: full_precision PASS, zero_dependency PASS. No golden-master change: the pinned crucible (v1.6.0) has nollm_apihits, before or after.how_to_add_a_language.md's AI/ML pack bullet forllm_apinow documents the anchoring. The contract sentence is unchanged.Not cross-repo: no crucible/rosetta change needed.
🤖 Generated with Claude Code