Skip to content

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
masterfrom
fhir-452-expand-422
Open

paynejd wants to merge 9 commits into
masterfrom
fhir-452-expand-422

Conversation

@paynejd

@paynejd paynejd commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Added Dec 4: $expand needs 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.


Part of OpenConceptLab/ocl_online#452.

What changes

When a value set's stored expansion is incomplete, FHIR ValueSet/$expand answers 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. Only core/fhir/ops/expand.py changes.

  • An included value set with no default expansion. The 422 says the value set "has no default expansion" only when the base shows the caller every version of it the expansion recorded. Anyone else gets "Unable to find included value set …", the answer for a value set that doesn't exist. At /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.
  • A pinned concept or mapping version, or a filter, that couldn't be resolved on a reference to a code system the base doesn't show the caller. This is now answered as that code system not found, which is what the expansion records for a code system that doesn't exist. Before, it was named as itself, which differs from the answer for a missing code system.
  • When it's unclear which version or reference an entry came from (a canonical URL that now names another value set, or several references with one expression), the answer is the not-found one.

Unchanged:

  • OCL API users: Expansion.get_unresolved_repo_versions_for and the API's expansion views are untouched.
  • Owner bases still name private content to those who may view it there.
  • Answers about public content.

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_422 now 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/fhir 99%). The two commits after it change only core/fhir/ops/expand.py and its tests. On the final commit, lint and the FHIR $expand, $validate-code and collections tests pass.

Review

  • Defect review: three passes plus checks of the later commits. They found that the entry's version had to come from what the expansion recorded rather than from what its URL resolves to now; the pinned-version and filter case above; and several ways one version or reference could stand in for another. All are fixed. What's left is over-redaction in rare cases, by design.
  • Simplification review: nothing to cut.
  • Adversarial review (trust change): no leak found. Its one note was the order in which references sharing an expression are read; they're now read as the build evaluates them (includes first).

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qV1oQiqKSRsQxqEmDy

paynejd and others added 6 commits November 30, 2026 00:17
…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
paynejd and others added 2 commits December 4, 2026 04:21
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 paynejd changed the title OpenConceptLab/ocl_online#452 | Stored $expand's 422 reads the same for hidden content as for missing content 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 Dec 4, 2026
@paynejd
paynejd marked this pull request as ready for review December 4, 2026 09:53
@paynejd
paynejd requested a review from snyaggarwal December 4, 2026 09:53

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = off runs inside within_search_timeout's own transaction.atomic(), so it ends with $expand's transaction. Searches and the other operations keep the server's setting, and ExpandSharedMemoryTest checks both sides on a real transaction. No path wraps the request in an outer transaction: ATOMIC_REQUESTS isn'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 filter request 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's get_unresolved_repo_versions_for is unchanged.
  • A pinned version or a filter on a code system the base doesn't show becomes the same reference.system entry 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants