fix: merge native records that repeat a model key - #51
Open
dgnsrekt wants to merge 1 commit into
Open
Conversation
LM Studio can report one model once per host it is served from, each record listing only that host's `loaded_instances`. `Object.fromEntries` keeps whichever record is read last, so the other host's instances are discarded before `effectiveContextLength` runs. The minimum is then taken over one record's instances instead of all of them, and `limit.context` can exceed what a routed instance actually has — the overstatement the conservative-minimum policy exists to prevent. With hosts at 8,192 and 262,144 under one key, the plugin reported 262,144. Merge records sharing a key before mapping: union `loaded_instances` and de-duplicate by id so the minimum sees every instance, and keep the smallest `max_context_length` so a merged record never overstates one it replaces. Remaining scalar metadata comes from the first record, which observed duplicates repeat identically. `discovered` now counts distinct model keys rather than raw records, so it agrees with the generated model map, and `mergedDuplicates` reports how many records were collapsed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S7Wjrr4wy4Eiig1PqtHfpD
dgnsrekt
force-pushed
the
fix/merge-duplicate-model-keys
branch
from
August 16, 2026 16:03
41e1468 to
1092c24
Compare
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.
Fixes #50.
Problem
LM Studio can report one model once per host it is served from, each record listing only that host's
loaded_instances.enhanceConfigmaps records straight into an object, soObject.fromEntrieskeeps whichever is read last and the other host's instances are discarded beforeeffectiveContextLengthever sees them.The minimum is then taken over one record's instances instead of all of them, so
limit.contextcan exceed what a routed instance actually has — the exact overstatement the conservative-minimum policy exists to prevent:Not synthetic — my server reports 32
llmrecords under 29 distinct keys, 3 of them duplicated across two hosts. #50 has the full payload shapes.Change
Merge records sharing a key before mapping:
loaded_instances, de-duplicated by id, so the minimum sees every reported instance;max_context_length, so a merged record never overstates any record it replaces;format,quantization,capabilities,max_context_length), differing only in routing.discoverednow counts distinct keys rather than raw records, so it agrees with the generated model map instead of overstating it, andmergedDuplicatesreports how many records were collapsed.I deliberately kept model identity unchanged. Giving routed instances distinct IDs would let a user target a specific host, but that is a contract change and belongs with #42 — this PR only stops the silent data loss.
Verification
6 tests added (27 → 33), covering distinct keys left untouched, instance union, id de-duplication, smallest-maximum, and the two integration cases from #50. Both integration tests fail on
main:npm run validateclean (lint, typecheck, 33 tests, build).End-to-end against LM Studio 0.4.x via
opencode models lmstudio:discoveredmergedDuplicatesdiscoveredand the model map now agree. On this server every instance of a duplicated key happens to be allocated the same 262,144 context, so no reported limit changes here — the merge is what keeps that true once allocations differ.Notes
Independent of #48 and #49, and based directly on
main. It does touchenhanceConfigalongside #49, so whichever lands second may need a trivial rebase — happy to do that. Verifying against a live server needed #48 applied locally, since without it this server returns no models at all.🤖 Generated with Claude Code
https://claude.ai/code/session_01S7Wjrr4wy4Eiig1PqtHfpD