Repository navigation
OpenConceptLab/ocl_issues#3088 | Send each candidate's names to the AI Assistant once, at most 50 - #143
Conversation
…I Assistant once, at most 50 filterAndTrimNames now drops a name repeated with the same name, locale and name type, keeping the first copy, and caps each candidate at MAX_NAMES_PER_CANDIDATE (50) names. Past the cap the preferred and fully specified names are kept first, then names in the requested locales; the names kept stay in the source's order, and a list within the cap comes back unchanged. closes OpenConceptLab/ocl_issues#3088 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qTTqXZgsTrFbWhkGHs
… only when its locale's primary subtag is requested A name with a malformed tag such as "-US" passes the locale filter, but it no longer takes a requested-locale slot past the cap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qTTqXZgsTrFbWhkGHs
|
Codex review, pass 1 (codex-cli 0.169.0, commit c31e1bc) Verdict: findings: 3 findings, all P2.
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "full",
"commit": "c31e1bcdd1b925e285242123318d61dc690da5ea",
"verdict": "findings",
"prior": [],
"findings": [
{
"id": "F1.1",
"severity": "P2",
"tag": null,
"file": "src/components/map-projects/normalizers.js",
"line": 689,
"claim": "The deduplication key treats an omitted locale and an explicit null locale as identical, although they produce different JSON entries.",
"scenario": "A candidate has two entries with the same name and type. One omits locale and the other sets it to null. The old code sent both entries. The new code drops one even though the list is under the cap, changing the fingerprint and causing Auto Match to analyse the row again.",
"action": "Build the key from an object containing the three trimmed fields so omitted and null values remain distinct. Add a regression test for the resulting payload.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.2",
"severity": "P2",
"tag": null,
"file": "src/components/map-projects/normalizers.js",
"line": 701,
"claim": "The cap gives a name requested-locale priority whenever its locale is truthy, even when the locale has no usable primary subtag.",
"scenario": "With English requested, a candidate has an ordinary name tagged `-US` followed by 50 ordinary `en-US` names. The malformed tag survives the existing locale filter because its primary subtag is empty. It then takes a slot from the last English name.",
"action": "Use `set.has(primarySubtag(n.locale))` to assign requested-locale priority and cover this case in the cap test.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.3",
"severity": "P2",
"tag": null,
"file": "src/components/map-projects/MapProject.jsx",
"line": 1819,
"claim": "The PR documents the saved candidate cache but omits the separate per-row `matches` field and the Concept Details name list, which also consume the untrimmed names. [PR description](https://github.com/OpenConceptLab/oclmap/pull/143)",
"scenario": "When a user maps the same duplicate-heavy candidate on several rows, the save puts the full list in each row's `matches[].concept.names` as well as in the candidate cache. Opening that candidate's details also passes the full list to Names and Synonyms, where duplicate entries in the displayed locale can appear repeatedly.",
"action": "Add both consumers to the PR's list of paths that carry the untrimmed names.",
"lines_delta": null,
"confidence": "high"
}
]
} |
|
Replies to Codex pass 1
|
… picks the names kept Also shortens the constant's comment and drops a test assertion another test already covers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qTTqXZgsTrFbWhkGHs
|
Simplification review (claude subagent, commit 1382b5f) Verdict: findings: 4 cuts proposed; 3 taken in 50567d0, 1 kept.
Tests after the cuts: findings.json{
"reviewer": "claude subagent",
"perspective": "simplify",
"mode": "full",
"commit": "1382b5fde4e5785b2f48bfeadd7089f56a4a5710",
"verdict": "findings",
"prior": [],
"findings": [
{
"id": "S1",
"severity": null,
"tag": "dup-test",
"file": "src/components/map-projects/__tests__/normalizers.test.js",
"line": 1667,
"claim": "The buildRecommendableConceptEntry NE61 test repeats the 814-copies test through a wrapper. Its byte-size assertions (over 100000 and under 1000) pin an implementation detail rather than behaviour. Only the names.length === 1 check adds anything, and only if the wrapper passes names straight through.",
"action": "Delete the test, or cut it to the single names.length === 1 assertion and drop the two JSON.stringify size checks.",
"lines_delta": -4,
"confidence": "medium",
"scenario": null
},
{
"id": "S2",
"severity": null,
"tag": "dup-test",
"file": "src/components/map-projects/__tests__/normalizers.test.js",
"line": 1600,
"claim": "The second assertion in the 814-copies test (filterAndTrimNames(ne61Names, []).length === 1) is covered by the multi-case 'matched on name, locale and name type' test and by the cap-counts-after-dedupe test, both of which run with empty or non-matching locales.",
"action": "Remove that one assertion.",
"lines_delta": -1,
"confidence": "low",
"scenario": null
},
{
"id": "S3",
"severity": null,
"tag": "shrink",
"file": "src/components/map-projects/normalizers.js",
"line": 640,
"claim": "The doc comment on MAX_NAMES_PER_CANDIDATE restates corpus statistics (LOINC 49, ICD-11 2, about 40 CIEL drugs) that will go stale and are already on the ticket. The rest of the comment repeats the filterAndTrimNames docblock.",
"action": "Shorten to two lines: the most names one candidate sends to the AI Assistant, counted after duplicates are dropped (OpenConceptLab/ocl_issues#3088). Keep the stats on the ticket.",
"lines_delta": -5,
"confidence": "medium",
"scenario": null
},
{
"id": "S4",
"severity": null,
"tag": "shrink",
"file": "src/components/map-projects/normalizers.js",
"line": 702,
"claim": "The keep-set of indices can be replaced by a stable sort of the entries followed by a re-sort back to source order. This drops the index-tracking objects and the Set.",
"action": "const idx = new Map(out.map((n, i) => [n, i])); return out.slice().sort((a, b) => rank(a) - rank(b) || idx.get(a) - idx.get(b)).slice(0, MAX_NAMES_PER_CANDIDATE).sort((a, b) => idx.get(a) - idx.get(b)). A sort that is stable on rank alone, with the first sort keyed by rank only, makes the idx tie-break unnecessary, which saves roughly 2 more lines.",
"lines_delta": -2,
"confidence": "low",
"scenario": null
}
]
} |
|
Codex check of commits c31e1bc..50567d0 (codex-cli 0.169.0, commit 50567d0) Covers the F1.2 fix (1382b5f) and the simplification cuts (50567d0), asking only whether they broke anything. Verdict: clean, no findings. findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "final",
"commit": "50567d04b8b37b11e532cb250ac32d4b267a55eb",
"verdict": "clean",
"prior": [],
"findings": []
} |
|
Hand-back report (ready for review; Sunny reviews and merges) What's done. NE61 before and after. The test
Cap: 50. It leaves every LOINC concept whole (49 names at most across all locales) and every ICD-11 concept whole (2 distinct names at most). It cuts only about 40 CIEL drug products with long brand-name lists. A cap of 20 would have cut 186 CIEL concepts, and the translations of about 55,000 LOINC concepts in projects with no locale set. Review loop.
Still sending the full list (not changed here, since they don't go through
Possible next steps.
Left in place: the branch and my worktree, until the PR merges, for review replies. |
What this fixes
When the Mapper builds the candidates it sends to the OCL AI Assistant for a recommendation,
filterAndTrimNamesfiltered each candidate's names by locale only. It never dropped duplicates or capped the count. In a production run on 27 Nov 2026, ICD-11NE61went with 814 copies of the same name, and that row's prompt was about 5 times the median.closes OpenConceptLab/ocl_issues#3088
What changed
filterAndTrimNames(src/components/map-projects/normalizers.js):locale_preferred, the kept one is too.MAX_NAMES_PER_CANDIDATE(50) names per candidate, counted after duplicates are dropped. Past the cap, the preferred and fully specified names are kept first, then names in the requested locales, then the rest. The names kept stay in the source's order.The cap: 50, and why
The cap is a backstop for runaway lists. Dropping duplicates is the real fix for
NE61. I looked at how many distinct names concepts have in production (latest concept versions, not retired):ICD-11-WHO-MapperNE61sent.It's a named constant, so it's easy to tune.
NE61 before and after
The test
buildRecommendableConceptEntry: an NE61-shaped candidate is sent with one namebuilds an entry from 814 copies of NE61's name. The same fixture run through the code onmainand on this branch:mainOther requests that carry a candidate's full names (not changed here)
Neither goes through
filterAndTrimNames, so this PR leaves them alone:buildRerankRowsForRow(MapProject.jsx) sendsnames: def.namesstraight from the concept cache: every locale and every duplicate, so a candidate likeNE61goes to$rerank/with every copy.serializeCandidatesstores the whole concept cache, names included, in the project's saved candidates, and each row's mapped concept goes with its full names inmatches.The AI payload's bridge context sends only each bridge concept's display name, not its names, so it isn't affected.
Not in this PR
NE61inICD-11-WHO-Mapperholds 453 copies of one name at its latest version. The count has grown with each of its versions, so the import looks like it adds the names again every time. That's for the source's maintainers.namesfrom the API response as is (a lookup replaces them, it doesn't add to them), so the extra copies came from the server's response in that run. I haven't traced why.Tests
src/components/map-projects/__tests__/normalizers.test.js: duplicates matched on all three fields, the kept copy's position andlocale_preferred, a list within the cap left unchanged, what's kept past the cap, the cap counting names after duplicates are dropped, and the NE61-shaped entry.npm test: 831 pass.npm run test:integration: 20 pass. ESLint onsrc: clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01AaZ4qTTqXZgsTrFbWhkGHs