Skip to content

Cap MCP model loading, SHA-pin CodeQL actions - #8

Merged
RudrenduPaul merged 1 commit into
mainfrom
fix/security-audit-2026-08-24
Aug 25, 2026
Merged

Cap MCP model loading, SHA-pin CodeQL actions#8
RudrenduPaul merged 1 commit into
mainfrom
fix/security-audit-2026-08-24

Conversation

@Sourav-Nandy-ai

Copy link
Copy Markdown
Collaborator

Summary

  • Resource cap on MCP model loading (MEDIUM, self-disclosed in README). Adds
    neuronscope/core/limits.py with two independent, configurable caps enforced in
    core/trace.py's _load_and_validate (the one path both the CLI and the MCP server
    go through):
    • A parameter-count ceiling (NEURONSCOPE_MAX_MODEL_PARAMS, default 2B), checked via
      TransformerLens's own config lookup before any weights are downloaded.
    • A concurrency ceiling on in-flight model loads (NEURONSCOPE_MAX_CONCURRENT_LOADS,
      default 1), so several tool calls in flight at once can't each bring a full model
      into memory simultaneously.
    • Both reject with a clear, structured error (ModelTooLargeError,
      TooManyConcurrentModelLoadsError) instead of blocking or crashing — surfaced the
      same way as the existing UnsupportedModelError/PromptTooLongError/
      LayerOutOfRangeError in both the CLI's exit-code handling and the MCP server's
      structured-error responses.
    • README's "Known limitations" and MCP warning updated to describe the new caps; the
      process-level resource-limit recommendation (cgroup/ulimit/container) stays as
      defense in depth for untrusted deployments.
  • SHA-pin the CodeQL workflow (LOW). codeql.yml used mutable tags
    (actions/checkout@v4, github/codeql-action/*@v3) unlike the repo's other three
    workflows, which already SHA-pin. Pinned to the same actions/checkout SHA already
    used elsewhere (11bd719... / v4.2.2) and to github/codeql-action@2d92b76...
    (v3.30.0) for init/autobuild/analyze.

Test plan

  • pytest -v --cov=neuronscope --cov-report=term-missing45 passed (28
    pre-existing + 17 new in tests/test_limits.py), 0 failed.
  • Coverage: 87% overall (matches the README's existing claim), with the new
    neuronscope/core/limits.py at 100%.
  • New tests cover: env-var config parsing (default/override/invalid/non-positive
    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_validate via a stub backend (no network/model download required).

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

- 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>
@RudrenduPaul
RudrenduPaul merged commit e8864d2 into main Aug 25, 2026
6 checks passed
@RudrenduPaul
RudrenduPaul deleted the fix/security-audit-2026-08-24 branch August 25, 2026 15:45
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.

2 participants