fix: OpenAI tool-parameter cache permanently retains every runtime's schema graphs - #1107
Open
sam-saffron-jarvis wants to merge 1 commit into
Open
Conversation
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.
What changed
sync.Mapwith a mutex-protected identity cache capped at 4,096 entries.sync.Onceon each resident entry, preserving one lowering computation for concurrent callers that share a cached schema identity; returned parameter maps are still deep-copied.Why this is high-value
OpenAI Responses and ChatGPT both use this cache for every tool-enabled request. Jarvis repeatedly creates short-lived web, Telegram, job, child-agent, and model-swap runtimes, and many built-in tools create fresh nested schema maps for each registry. The old global cache retained every source graph and lowered graph for the entire process lifetime, so heap retention and GC work grew with runtime churn.
The new fixed cap makes retained cache memory plateau instead of growing with every runtime. Hot schemas still avoid reparsing and normalization, while O(1) eviction avoids adding cache-size-dependent work once the cap is reached.
Validation
gofmt -w internal/llm/json_schema_lowering.go internal/llm/json_schema_model_test.gogo test ./internal/llm -run 'Test(OpenAIParameters|SanitizedResponsesParameters)' -count=1go test -race ./internal/llm -run 'Test(OpenAIParameters|SanitizedResponsesParameters)' -count=1go build ./...git diff --checkgo test ./...ran; allinternal/llmtests passed. The repository-wide run was blocked by unrelated existing environment/main failures: twocmdskill-discovery tests saw the host's configured skill list instead of their temporary fixtures, andinternal/serveuireported the freshly generated main-branch bundles slightly above existing gzip budgets. No failing test exercises the changed cache.