Repository navigation
test(lazy-import): pin laya.mcp's documented no-extra import surface - #1259
Conversation
laya/mcp/__init__.py promises that device, remote and tools import without the mcp extra and that only server requires it. Both CI lanes that run the suite list install -e ".[mcp,serve,langchain]", so `import mcp` always succeeds there, and tests/test_mcp.py exits 0 when the extra is missing -- so nothing exercised the promise, and a module-level mcp import added to tools.py would break every install without the extra with CI still green. Block mcp through sys.meta_path (the file's existing shape for torch and tensorflow) and pin: the three submodules import, laya.mcp pulls in neither mcp nor torch, and server fails as an ImportError that names the extra and the install line.
|
Short answer: this branch also goes green against my own #1257, which edits
|
|
Short answer: the one red lane is a pre-existing Windows crash in a suite this PR does not touch.
The same run's log also shows the Windows runner reaching this with |
|
Merged in 0.4.9. This closes a gap that was invisible by construction. Blocking it as an The second probe is the one I would have asked for: this file's premise is that the surface is pure Python, and The Windows check that failed here is not yours, and your run is the one that solved it. With the stage markers from 0.4.8 the log printed |
…hild The stage markers from 0.4.8 answered on their first occurrence. NandhaKishorM#1259's Windows run printed [stage] state reused once [stage] autocast ... tests/test_runtime_fixes.py [exit 3221225501 (0xC000001D)] so the intermittent fault is inside the autocast section, which is the only one that asks torch for a bf16 CPU forward. 0xC000001D is STATUS_ILLEGAL_INSTRUCTION: oneDNN selects a kernel for an instruction set the CPU does not have. Same class as NandhaKishorM#1065, where fbgemm raised SIGILL on a CPU with SSE4.2 and no AVX2. It is intermittent on one runner label because a hosted fleet is not one CPU model. Three parts: * The suite asks whether this CPU can run a bf16 autocast forward at all, in a child process, because the answer on some machines is a fault no handler can see. Where it runs, the three checks are unchanged. Where it does not, the suite says so with get_cpu_capability() and the child's exit code instead of taking the lane down. Verified both ways: 86 passed with the probe succeeding, 84 passed and the SKIPPED marker printed when it is forced to fail. * _cpu_amp_dtype says what the failure looks like. It already said bf16 is for hardware with native BF16 instructions; it did not say that the alternative is a native fault, nor that _infer's autocast retry catches RuntimeError and therefore cannot see one. * docs/reference/agent.md gains the section a user needs before setting LAYA_CPU_AMP=bf16: the capability reading to check, and a child-process probe, since a fault in the parent cannot be caught. It sits above the NandhaKishorM#1065 note, which is the same failure from the quantization side. laya's own behaviour is unchanged. LAYA_CPU_AMP was opt-in before and still is. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
What
tests/test_lazy_import.pygains amcp-blocked probe that pins the import surfacelaya/mcp/__init__.pydocuments. Test-only: +69/-0, one file, no production line touched.Why
laya/mcp/__init__.py:12-15promises:The sentence is true today and checked by nothing.
tests/test_mcp.py:26-28is the suite that wouldhave the most to say about it, and it is the one suite that cannot: it exits 0 at the top of the file
when
import mcpfails, so on an install without the extra it reports nothing, and both CI lanes thatrun the shared suite list install the extra —
pip install -e ".[mcp,serve,langchain]"at.github/workflows/ci.yml:94and:225, withpython scripts/test_suites.pyat:116and:250. Soimport mcpalways succeeds where the suite runs, and the documented pure-Python path is neverexercised anywhere.
That is exactly the shape of gap
tests/test_lazy_import.pyexists to close — the file already blockstorchandtensorflowthroughsys.meta_pathand pins what survives (import laya,laya.detect_script,laya.PINNED_REVISIONS, andimport laya.servestaying cheap) — and it nevercovers the one package that documents a dependency of its own.
laya/mcp/tools.pyis where toolschemas are written, so a future
from mcp.types import ...at its top is a plausible edit; it wouldbreak the documented install path for every user without the extra and leave CI green, because in CI
the import succeeds.
The new block adds six checks in two subprocess arms, following the file's existing pattern of
reporting what happened rather than asserting blindly:
mcpblocked:laya.mcp,.device,.remote,.toolsall import, andmcpis absent fromsys.modulesafterwards — the four are oneassert, so a leak fails the arm rather than printinga green line.
mcpblocked:laya.mcp.serverfails as anImportErrorwhose text names bothlaya[mcp]andpip install. The two substrings are pinned, not the sentence: a reworded hint stays green,No module named 'mcp'— which is what thetry/exceptatlaya/mcp/server.py:45-52becomes if thatre-raise is ever removed — does not.
mcpandtorchblocked: the same three submodules still import and neither dependencyreaches
sys.modules.remotereaches..routerand..serve,toolsreaches..confidence/..hooks/..presets, so this is the file's own torch-free premise extended to theMCP layer rather than a second copy of the first arm.
Blocking is done with a
find_spechook that raises, so the probe is meaningful whether or not theextra is installed here: it is the absence of a module-level import under test, not the absence of
a package.
How it was verified
Both mutation arms were run against this branch's test file and reverted with
git checkout --:from mcp.types import ToolCallToolResultadded tolaya/mcp/tools.py→13 passed, 6 failed: every new check fails, the 13 pre-existing ones still pass. This is the
edit the docstring forbids, and before this branch nothing in the repo noticed it.
laya/mcp/server.py's guard neutered toexcept ImportError: pass(so the rawNameErrorfromMCPServer(...)escapes instead of the install hint) → 16 passed, 3 failed:no-mcp/import laya.mcp succeeds,no-mcp/server fails as an ImportError, andno-mcp/server names the extra and how to install it. The three submodule-import checks stay green,which is the scoping being right rather than lucky.
Measured on the environment as it is:
mcpis installed in the venv(
.venv/lib/python3.14/site-packages/mcp/__init__.py) andfind_spec("mcp")resolves, so theBlocker is refusing a dependency that is really present, not a module that was never there.
Deconfliction: of the 66 currently open PRs, none touches
tests/test_lazy_import.py. Four touchlaya/mcp/— #1242 (device.py,server.py), #1203 (tools.py), #738 (server.py,tools.py),#687 (
remote.py) — and none of them edits this file, so there is no competing hunk. Since the newchecks read those modules' behaviour, each was merged against
4ac226d5withgit merge-tree --write-treeand itslaya/mcp/*.pyread out of the result tree: all four mergedtrees have 0 module-level
import mcp/from mcplines in__init__.py,device.py,remote.pyand
tools.py, and none adds a module-leveltorch/numpy/laya.agentimport anywhere underlaya/. So these checks go green with each of them, not against them.Rebased on current
main:git ls-remote upstream refs/heads/main=4ac226d5ee88ed6df8db288a05c766d7a34ee682, this branch's parent. No new dependency, no hostedservice, no behaviour change. Diff scanned for credentials: 0 matches on the 69 added lines.
Checklist
mainFixes #