fix: keep jev_classify ids collision-free and tally on a null prototype - #36
Merged
Merged
Conversation
Generated fallback ids (item0/class0 style) could collide with explicit ids of the same shape: an item omitting its id took the fallback item0 and a later item explicitly named item0 kept it too, duplicating result ids; for classes the same collision also collapsed probabilities keys, silently overwriting one class's distribution with another's. Duplicate supplied ids were rejected, but fallbacks were never checked against supplied ones. Apply the two-phase pattern jev_rerank already uses: collect supplied ids first (still rejecting duplicates), then let every generated fallback avoid any supplied or already-used id. The by_class summary tally was a plain object, so a caller-supplied class id like __proto__ was swallowed by the prototype setter and constructor read the inherited function. Tally on Object.create(null), matching the criteria map already used in the same tool. Both issues were reported in the "found along the way" section of jkudish#34.
shivasymbl
added a commit
to shivasymbl/jev-mcp
that referenced
this pull request
Sep 26, 2026
jkudish
added a commit
that referenced
this pull request
Sep 26, 2026
The third test now selects constructor as well and asserts the full by_class; expected object is JSON.parsed so __proto__ stays an own key. Amp-Thread-ID: https://ampcode.com/threads/T-01a0d53e-c271-716f-94dd-6df00c40c7b8
Owner
|
Contributor
Author
|
Thanks for the quick review and merge! And good call strengthening the third test — exercising the constructor tally directly makes it a much better regression guard than what I had. Glad this made it into 0.10.0. |
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
Two
jev_classifydefects reported in the "found along the way" section of #34:item0/class0style) were never checked against supplied ids, so an item omitting its id took the fallbackitem0while a later item explicitly nameditem0kept it too — duplicated result ids. For classes the same collision also collapsedprobabilitieskeys, silently overwriting one class's distribution with another's. Duplicate supplied ids were already rejected; the gap was fallbacks vs supplied.by_classwas a plain object literal, so a caller-supplied class id like__proto__was swallowed by the prototype setter and never counted, whileconstructorread the inherited function and produced a garbage string.How
jev_rerankalready uses for candidate ids: collect supplied ids first (still rejecting duplicates), then let every generated fallback avoid any supplied or already-used id.by_classonObject.create(null), matching thecriteriamap already built that way in the same tool.No tool arguments, results, or README examples change.
Verification
npm run build✓ ·npm run typecheck✓npm test— 227/227 offline (baseline 224 + 3 new regression tests)src/(224 pass / 3 fail), confirming they catch both defects:jev_classify fallback item ids never collide with explicit ones,jev_classify fallback class ids never collide with explicit ones,jev_classify tallies __proto__ and constructor class ids as plain keys.Both issues were reported in #34; this PR fixes only the
jev_classifyitems and leaves the rest of that list untouched.