Skip to content

[Server] Fix memory growing with every tools/call - #574

Open
chr-hertel wants to merge 1 commit into
modelcontextprotocol:mainfrom
chr-hertel:fix-schema-validator-leak
Open

chr-hertel wants to merge 1 commit into
modelcontextprotocol:mainfrom
chr-hertel:fix-schema-validator-leak

Conversation

@chr-hertel

Copy link
Copy Markdown
Member

SchemaValidator decoded the tool schema into a new stdClass on every call, and Opis' SchemaLoader caches every new schema object for good => ~7 KB leaked per tools/call in long-lived processes (stdio, FrankenPHP workers).

  • memoize the decoded schema per schema JSON, so input and output schema validation reuse the same object
  • drop the dead InvalidArgumentException branch, the signature already narrows to array|object

Fixes chr-hertel#62

🤖 Generated with Claude Code

@chr-hertel chr-hertel added this to the 0.9.0 milestone Oct 10, 2026
@chr-hertel chr-hertel added bug Something isn't working Server Issues & PRs related to the Server component labels Oct 10, 2026
@chr-hertel
chr-hertel requested a balanced review from Copilot October 12, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused memoization correctly addresses the reported cache growth and is covered by an appropriate regression test.

0 open findings

What changed in this PR

Fixes repeated schema decoding that caused Opis cache growth during long-lived tools/call workloads.

Changes:

  • Memoizes decoded schemas by JSON representation.
  • Removes unreachable exception handling.
  • Adds regression coverage and a changelog entry.
File Description
src/​Capability/​Discovery/​SchemaValidator.php Reuses decoded schema objects.
tests/​Unit/​Capability/​Discovery/​SchemaValidatorTest.php Verifies stable Opis cache size.
CHANGELOG.md Documents the memory fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Reuse the decoded schema object, Opis caches each new one forever.
@chr-hertel
chr-hertel force-pushed the fix-schema-validator-leak branch from 0365008 to 86c20db Compare October 12, 2026 20:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Server] Every tools/call leaks ~7 KB in long-lived processes

2 participants