Repository navigation
OpenConceptLab/ocl_online#452 | Stored $expand needs next to no shared memory, and its 422 reads the same for hidden content as for missing content - #1092
Open
paynejd wants to merge 9 commits into
Conversation
…ouldn't apply only where the base shows it A stored expansion that couldn't apply a value set with no default expansion answers $expand with a 422 that says so. Whether the caller may see that reason was decided by their OCL access, which shows a private value set to its owner's members and to staff wherever they ask. FHIR's global base shows public content only, so there the 422 told those callers about a private value set that the base doesn't show them. The reason is now kept only when the request's base shows the caller every version of the value set the entry names (FhirResolver.viewable_rows). Otherwise the entry answers as a value set not found, byte for byte the same as one that doesn't exist. Owner bases are unchanged: a private value set is still named to those who may view it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qV1oQiqKSRsQxqEmDy
…or a hidden code system or value set as for a missing one - A value set the expansion couldn't apply is judged by the versions of it the expansion recorded: the one its URL names when it names a version, else each recorded version of that value set. When its URL now names a value set the expansion recorded no version of, it answers as one not found. - A pinned concept or mapping, or a filter, of a reference whose code system the base doesn't show the caller answers as that code system not found. That is the entry an expansion records first for a code system that doesn't exist, so the two answers are the same, byte for byte. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qV1oQiqKSRsQxqEmDy
…y by every version its URL may name - A value set the expansion couldn't apply also counts the recorded versions whose canonical URL its URL names. A canonical URL that has since come to name a public value set no longer stands in for the private one recorded. - A pinned concept or mapping, or a filter, is judged by every one of the version's references with its expression, so a reference to a public code system can't stand in for one to a hidden code system. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qV1oQiqKSRsQxqEmDy
…s own references and its value set's canonical URL - A pinned concept or mapping, or a filter, is judged by the version's references that match the entry's expression and the namespace and include flag the entry records. An exclude in another namespace no longer decides for an include. - A value set's canonical URL is also read from its HEAD, so a release with no canonical URL of its own still counts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qV1oQiqKSRsQxqEmDy
…ter entry by every reference with its expression Back to every reference with the entry's expression, whatever namespace or include flag the entry records: when one of them is of a code system the base doesn't show the caller, the entry answers as that code system not found. A stored entry can outlive the reference it was recorded for, so when in doubt the answer is the one for something that doesn't exist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qV1oQiqKSRsQxqEmDy
…ences in the order the expansion evaluates them Includes first, then excludes, each by id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qV1oQiqKSRsQxqEmDy
paynejd
added a commit
that referenced
this pull request
Nov 30, 2026
…es), which the FHIR series builds on fhir-452-b-codes ends the queue of OCL API PRs, so the FHIR series sits on all of them: #1085, #1086, #1089, #1088, #1087, #1090, #1091, #1092 and #1093, and the core changes that need them together. No conflicts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qV2gzsF5GhF5BwTJ6x
Brings in #1085, #1086 and #1082. Merged cleanly; no change to this branch's own code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWUTom6BGgjQy6oehZ
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
$expand finds the members of a large expansion that a caller is shown with parallel joins (#1093). PostgreSQL keeps the hash tables those joins share between workers in shared memory, about 45 MB a request. This repository's compose files give the database 128 MB, so a few requests at once failed. Its statements no longer share hash tables: each worker builds its own, about 1 MB a request. The setting ends with $expand's transaction; searches and other operations keep theirs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
paynejd
marked this pull request as ready for review
December 4, 2026 09:53
snyaggarwal
approved these changes
Dec 4, 2026
snyaggarwal
left a comment
Contributor
There was a problem hiding this comment.
Verdict: approve.
Merge order: together with #1093, as the description asks, so no release has #1093 without 9ac0986. Use merge commits, both before #1094, which already contains them. Their only conflict is in core/fhir/tests_ops_expand.py (imports and a helper, both kept). This PR also conflicts with #1090 and #1103 in the imports of core/fhir/ops/expand.py. Whichever merges second needs a master merge and CI. It doesn't depend on the #1087 → #1090 → #1103 stack.
9ac0986, $expand and shared memory:
SET LOCAL enable_parallel_hash = offruns insidewithin_search_timeout's owntransaction.atomic(), so it ends with$expand's transaction. Searches and the other operations keep the server's setting, andExpandSharedMemoryTestchecks both sides on a real transaction. No path wraps the request in an outer transaction:ATOMIC_REQUESTSisn't set, so in production the setting is always applied.- The cost is in the description. Alone, every request stays under 5 s. With four at once on the 92,670-member value set selected at HEAD, a
filterrequest reaches 5.5 s and would be a 422. That's the case the FHIR lead accepted for #1093 on Dec 3, and the table shows it here at four at once rather than one. Not blocking.
The 422 that reads the same for hidden and missing content (as_shown):
- A value set keeps "has no default expansion" only when the base shows the caller every version the expansion recorded for that entry. Otherwise the reason is dropped, which is the answer for a value set that doesn't exist. At
/fhir/that's public content only, whatever the caller's OCL access. The API'sget_unresolved_repo_versions_foris unchanged. - A pinned version or a filter on a code system the base doesn't show becomes the same
reference.systementry the build records for a missing code system ({url, namespace, version, type}). The tests byte-compare both answers. - When in doubt, the code answers not-found. You already listed what's left in the description and on the ticket: the filter match ignores
include, and the entries don't record version ids (Codex F2.2–F2.4, F3.2). Those cases over-redact. They don't leak, and recording the ids belongs in a follow-up in the core.
CI is green at 9ac0986. Nothing here is commercial logic.
This branch has not been deployed
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.
Added Dec 4:
$expandneeds next to no shared memory. One commit,9ac09865, about 10 lines with a test. Review it on its own. It should go to master together with #1093, so that no release has that one alone.What was wrong: OpenConceptLab/ocl_online#452 | Stored $expand, $validate-code and $translate show a member only where a version the base shows holds its row #1093 finds the members of a large expansion that the caller is shown with parallel joins. PostgreSQL keeps the hash tables those joins share between workers in shared memory (
/dev/shm). So OpenConceptLab/ocl_online#452 | Stored $expand, $validate-code and $translate show a member only where a version the base shows holds its row #1093 makes$expand's use of it much worse than on master, and this commit puts that right:Who it would hit: a server whose database has little shared memory. This repository's
docker-compose.ymlanddocker-compose.prod.ymlgive it 128 MB. A query that gets none fails, and the request was a 422, "An unexpected error occurred while processing the request".Reproduced on PostgreSQL 14.7 with 128 MB of shared memory, on value sets of 38,362 and 92,670 members, with the request's time limit raised so that only the memory decides:
work_mem4 MB (PostgreSQL's default)work_mem64 MBThe change:
SET LOCAL enable_parallel_hash = offin$expand's own transaction. The workers stay, and each builds its own hash table in its own memory. Searches,$translateand every other operation keep the server's setting.What it costs: median seconds for one request / for 4 at once, with
work_mem4 MB and JIT off, the three measured one after the other on one machine. The last column was measured with the same setting made on the database role, which gives the same plans. A request may take 5 s, and these too were measured with that limit raised.filter,count=10filter,count=10filter,count=10With
work_memat 4 MB, each request alone stays below 5 s. With 4 at once on the 92,670 members selected at HEAD, it goes just past that.Not measured: a managed database's own limit on shared memory.
Test:
ExpandSharedMemoryTestreads the setting inside$expand, after it and in a search. It fails without the change.Full gate on
9ac09865, aspr.ymlruns it: pylint 10.00; 4,289 of 4,290 ordinary tests (2 skipped) and 815 search-index tests pass; coverage 97%. The one failure ismaster's owntest_mapped_codes_read_mappings_for_a_few_concepts_a_query, which this PR doesn't touch. It compares lists in an order its query doesn't set, so it fails now and then, and it passes when its class runs alone.Part of OpenConceptLab/ocl_online#452.
What changes
When a value set's stored expansion is incomplete, FHIR
ValueSet/$expandanswers 422 with an OperationOutcome naming the first thing the expansion couldn't resolve. That answer now reads the same whether the thing is hidden from the caller at the request's FHIR base or doesn't exist. Onlycore/fhir/ops/expand.pychanges./fhir/that means public value sets only, whoever asks. At an owner base it also means private value sets the caller may view by their own rights. Before, OCL access decided rather than the base, so at/fhir/an owner's members and staff were told about a private value set the global base doesn't show them.Unchanged:
Expansion.get_unresolved_repo_versions_forand the API's expansion views are untouched.Tests
core/fhir/tests_ops_expand.py, run with the URL registry off and on:test_a_value_set_that_could_not_be_applied_is_named_as_one_only_where_the_base_shows_it: anonymous, an outsider, an owner's member and staff, at/fhir/(type and instance level) and at the value set owner's base. A hidden value set's answer is byte-compared with the answer when it doesn't exist. Also covered: a public value set whose recorded release is private, a URL that now names a value set the expansion recorded nothing of, an explicitly versioned public import beside a private release, and a canonical URL that now names a public copy.test_a_reference_to_a_code_system_the_base_does_not_show_answers_as_one_to_a_missing_code_system: pinned version, filter, and two references with one expression. Each is byte-compared with the answer the expansion gives when the code system doesn't exist.test_an_expansion_that_cannot_be_served_is_a_422now sets up what a build records (the value set version it resolved, and the code system its pinned references name) so it keeps checking the messages it checked before.Full local gate on b47f858 (pylint, then the whole suite in CI's form): pylint clean; 4,064 tests without Elasticsearch and 803 with it, all passing; coverage 97% (
core/fhir99%). The two commits after it change onlycore/fhir/ops/expand.pyand its tests. On the final commit, lint and the FHIR$expand,$validate-codeand collections tests pass.Review
🤖 Generated with Claude Code
https://claude.ai/code/session_01AaZ4qV1oQiqKSRsQxqEmDy