Cap MCP model loading, SHA-pin CodeQL actions - #8
Merged
Conversation
- Add neuronscope/core/limits.py: a configurable parameter-count cap (NEURONSCOPE_MAX_MODEL_PARAMS, default 2B) checked before weights are downloaded, and a configurable concurrency cap on in-flight model loads (NEURONSCOPE_MAX_CONCURRENT_LOADS, default 1), both enforced in core/trace.py's _load_and_validate (shared by the CLI and the MCP server) and surfaced as structured errors (ModelTooLargeError, TooManyConcurrentModelLoadsError) rather than a hang or a crash. Closes the self-disclosed "no resource cap on MCP model loading" gap in the README; the process-level resource-limit recommendation stays as defense in depth. - SHA-pin the three github/codeql-action steps and actions/checkout in codeql.yml to match the SHA-pinning already used by the repo's other three workflows. - Add tests/test_limits.py covering both caps (config parsing, the parameter-count check, the concurrency limiter under nested and real thread contention, and end-to-end enforcement through _load_and_validate). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
neuronscope/core/limits.pywith two independent, configurable caps enforced incore/trace.py's_load_and_validate(the one path both the CLI and the MCP servergo through):
NEURONSCOPE_MAX_MODEL_PARAMS, default 2B), checked viaTransformerLens's own config lookup before any weights are downloaded.
NEURONSCOPE_MAX_CONCURRENT_LOADS,default 1), so several tool calls in flight at once can't each bring a full model
into memory simultaneously.
ModelTooLargeError,TooManyConcurrentModelLoadsError) instead of blocking or crashing — surfaced thesame way as the existing
UnsupportedModelError/PromptTooLongError/LayerOutOfRangeErrorin both the CLI's exit-code handling and the MCP server'sstructured-error responses.
process-level resource-limit recommendation (cgroup/ulimit/container) stays as
defense in depth for untrusted deployments.
codeql.ymlused mutable tags(
actions/checkout@v4,github/codeql-action/*@v3) unlike the repo's other threeworkflows, which already SHA-pin. Pinned to the same
actions/checkoutSHA alreadyused elsewhere (
11bd719.../ v4.2.2) and togithub/codeql-action@2d92b76...(v3.30.0) for
init/autobuild/analyze.Test plan
pytest -v --cov=neuronscope --cov-report=term-missing— 45 passed (28pre-existing + 17 new in
tests/test_limits.py), 0 failed.neuronscope/core/limits.pyat 100%.fallback) for both caps; the parameter-count check raising/allowing/failing-open;
the concurrency limiter under nested calls, a higher configured cap, and real
multi-thread contention; and end-to-end enforcement of both caps through
_load_and_validatevia a stub backend (no network/model download required).Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com