Skip to content

OpenConceptLab/ocl_online#788 | Expansion health and recorded version lists show a reader only the value sets they can view - #1077

Merged
snyaggarwal merged 40 commits into
masterfrom
ocl_online-788-health-visibility
Nov 26, 2026
Merged

snyaggarwal merged 40 commits into
masterfrom
ocl_online-788-health-visibility

Conversation

@snyaggarwal

@snyaggarwal snyaggarwal commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes OpenConceptLab/ocl_online#788.

Stacked on #1076. This merges after #1076, and gets retargeted to master once #1076 merges.

Why

A public expansion's health and its recorded version lists can show that a private value set it references has no expansion. A reader who can't view that value set learns something about it. OCL treats a value set the reader can't view as not found. #1076 does this for the unresolved entry's reason (get_unresolved_repo_versions_for), but health and the version lists still showed it.

What changed

  • Health stores which value sets it counts. The value_set_without_expansion reason now carries value_sets. Each entry has url, namespace, version_urls (the versions it resolved to, or every version the build recorded for an unresolved entry; empty if it can't be found now), reference_ids (the references it counts) and entries (how many unresolved entries it stands for). It covers all three ways that reason counts: an include that resolved only to unexpanded value sets, an exclude against them, and a recorded valueset_not_expanded entry. RULES_VERSION goes to 2 because the stored shape changed.
  • Health is filtered per reader when it's served. get_health_for(health, access) drops the value sets the reader can't view (for an unresolved entry, unless they can view every version the build recorded for it, as get_unresolved_repo_versions_for now decides) and recounts the references that are left. Any unresolved entry a hidden value set left counts as unresolved_references instead, as a value set that wasn't found would. This matches unresolved_repo_versions, which still lists that entry without its reason. Staff get health as stored. If no reason remains, it works the state out again: unhealthy becomes head_resolved or healthy, using the stored head_resolved_repositories. One helper does this everywhere health is served: the expansion detail, the expansions list (plain and verbose), the versions list's expansion_health (plain and verbose) and the version detail's expansion_health. The versions list now annotates the default expansion's whole health (expansion_health_data) rather than just its state, so it can be filtered.
  • The recorded version lists are filtered. explicit_collection_versions and evaluated_collection_versions on the expansion detail list only the value set versions the reader can view.
  • resolved-repo-updates is filtered. A value set's version pair is listed only to a reader who can view both versions.
  • An unresolved entry counts once. A reference's entry is counted on all the versions grouped under it, not again under each version it resolved to. When hidden, it reads as unresolved_references in the place health normally puts that reason.
  • Access is read once per request. ValueSetViewAccess follows has_view_access: staff, public with a public HEAD, or the reader's own or their orgs'. It's shared through the serializer context and caches by version. A list serializer (ValueSetAccessListSerializer) reads the whole page at once: one query for the value set versions health names, one for their HEADs, and one for the reader's orgs. The verbose expansions list also prefetches the two collection version relations for the page.
  • get_unresolved_repo_versions_for and health now share Expansion.get_valueset_entry_version, which looks up the version the build recorded for an entry.
  • The expansion create response now gets the request in its context, so it's filtered for the creator rather than as anonymous.

The new filter_not_applied reason from #1076 is about a reference's own filter, not a value set's state, so it isn't filtered.

Older stored health

Health stored under rules version 1 doesn't say which value sets it counted, so its value_set_without_expansion reason is hidden from every reader except staff until it's recomputed. That keeps it from leaking. backfill_expansion_health --all --apply recomputes rows from older rules versions (~Q(health__rules_version=RULES_VERSION)). The nightly recheck takes only rows that aren't current, so the backfill has to be run after deploy.

Tests

Added to core/collections/tests/tests_health.py:

  • Unit tests for the stored value_sets (include, exclude and recorded-entry paths), including a value set named by two references, which is stored once with both reference ids.
  • ExpansionHealthVisibilityTest checks member, outsider and anonymous readers on:
    • health in the expansion detail and the expansions list (plain and verbose)
    • the state in the versions list (plain and verbose) and the version detail
    • explicit_collection_versions and evaluated_collection_versions in the expansion detail and the verbose list
    • a public release under a private HEAD
    • staff
    • a value set the reader can view still counting when another is hidden
    • older health without value_sets
    • a query-count check that more expansions and versions on a page don't add access queries

The local stack is down, so none of this was run locally. It relies on CI (Pylint and Tests). Focused pylint on the changed files passes.

Not in this PR (follow-up)

  • Other health fields that name repository URLs aren't filtered per reader: head_resolved_repositories, duplicate_repo_versions, inconsistent_resolution and multiple_named_versions.
  • The head_resolved fallback uses the stored head_resolved_repositories, so a hidden private HEAD can still turn healthy into head_resolved.
  • Each version in the recorded version lists carries previous_version_url, which can name a private earlier version. Every version list in OCL does this.
  • The source version lists (explicit_source_versions, evaluated_source_versions, and source pairs in resolved-repo-updates) aren't filtered.

🤖 Generated with Claude Code

…'t apply makes it resolve to nothing instead of the whole system; filter op is applied and checked on save
…idening

# Conflicts:
#	core/collections/tests/tests.py
…th no default expansion couldn't be applied, not that it wasn't found
…e a filter op or property they can't apply, naming both
… ES-tagged class, and the value set test adds a new concept
…t a filter OCL can't apply again; the reference resolves to nothing
…y finds nothing; a search URL's paging and sorting parameters are set aside
…sion as repeated parameters, so it reads back as in
…n't be applied says why, instead of falling back to its saved members
…ue set can't be applied says why instead of an empty success
…s shown only to a reader who can view it; to others it answers as not found
…ession, and an in with no values is refused on save
…value set to references by namespace as well as URL
…d-transform reference with the same expression that couldn't be applied
…d value set in the namespace its reference resolves in
… parsing, so earlier expressions with spaces are still duplicates
…set couldn't be applied is judged on the version the build recorded
… reference matches as an unresolved reference
…on, answers for a cascade-and-transform include with the same expression
… lists show a reader only the value sets they can view
@snyaggarwal
snyaggarwal requested a review from paynejd November 26, 2026 05:07
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Independent review (a fresh reviewer was given only the diff and the ticket): changes needed. I checked each claim against the code. Results:

Confirmed, fixing here

  1. A hidden value set that also left an unresolved entry disappears from health completely. A build records a reference.valueset entry with reason valueset_not_expanded for an unexpanded value set (CollectionReference.resolve_valueset_versions_with_unresolved). Health counts that entry as value_set_without_expansion rather than unresolved_references. For an outsider, OpenConceptLab/ocl_online#771 | A value set or filter a reference can't apply makes it resolve to nothing, not the whole system #1076 still lists the entry (without its reason), but this PR dropped it from health. The outsider could see healthy next to an unresolved entry. Fix: each stored value set records how many unresolved entries it stands for. When it's hidden, those entries count as unresolved_references, which is how OCL answers "not found". This also covers an entry whose value set can't be found any more (review item 4).
  2. Older (rules v1) health hides the reason even from staff. Fix: staff get health as stored. Everyone else still sees no reason until the backfill recomputes it. Health is kept only for default expansions, which backfill_expansion_health --all covers, so the part of the claim about non-default expansions doesn't apply.
  3. The detail endpoints did two lookups per value set. Fix: get_health_for now reads all of its URLs at once.
  4. The query-count test matched the wrong membership table and never exercised the HEAD lookup. Fix: it now matches user_profiles_organizations and includes a public release, so the HEAD lookup runs.
  5. A test name said the opposite of what the test does. Renamed.
  6. Nested version lists picked up ?includeExternalExports=true, at one query per row. That never happened before. Fix: the nested serializer is built without the request context again.

Not taken here

  • head_resolved_repositories, duplicate_repo_versions, multiple_named_versions and inconsistent_resolution can still name a private value set's repository URL, or show that it resolved to HEAD. That's real, but these are other health fields, not the count or the version lists. This PR is scoped to Bump boto3 from 1.24.28 to 1.35.93 #788, so I'm leaving them for a follow-up ticket, along with the source version lists. Both are listed under "Not in this PR".
  • Annotating the whole health JSON on the versions list is a heavier payload but harmless. Leaving it.

… counts as unresolved, staff see health as stored, nested version lists drop the request again
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Review fixes are in 339f6ae:

  1. A hidden value set's unresolved entry now counts as unresolved_references. Each stored value set carries entries, and an entry whose value set can't be found any more is covered the same way. New test: test_a_hidden_value_set_s_unresolved_entry_counts_as_unresolved.
  2. Staff get health as stored, rules v1 included.
  3. get_health_for reads all of its value set URLs at once, so detail endpoints no longer do two lookups per value set.
  4. The query-count test now matches user_profiles_organizations and uses public releases under a private HEAD, so the HEAD and membership lookups both run.
  5. The inverted test name is fixed (test_a_public_release_under_a_private_head_is_shown_only_to_members).
  6. Nested version lists are built without the request again, so ?includeExternalExports=true doesn't add a query per row.

The other repository-URL health fields and the source version lists are left for a follow-up ticket, as noted in the review comment.

… reason and unresolved entry naming what it couldn't apply, counted apart in health
…s shown only if the reader can view every version of it the build recorded
… ocl_online-788-health-visibility

# Conflicts:
#	core/collections/health.py
#	core/collections/models.py
… to a reader who can view every version the build recorded for it
…he saved results of a reference whose filter or value set can't be applied
…by include as well as expression, so an exclusion keeps an include's
@snyaggarwal
snyaggarwal marked this pull request as ready for review November 26, 2026 05:52
…EAD holds, and the entry test reads the entry's own stored value set
@paynejd

paynejd commented Nov 26, 2026

Copy link
Copy Markdown
Member

Review lead (Claude, for Jon), round 1, head b964fd3.

Verdict: changes needed: one should-fix, and CI to go green. The approach matches #1076's rule: a value set is shown only to a reader who can view every version recorded for it, and a hidden one answers as not found (its entries count as unresolved_references). Every place health is served goes through get_health_for: the expansion detail and list, plain and verbose, and the versions list and detail expansion_health. Staff see health as stored. ValueSetViewAccess matches has_view_access (staff, public with a public HEAD, org member or owner), the access queries per page stay constant, and the version export leaves out expansion_health. Both acceptance criteria are met for health and the expansion detail's lists, with member, outsider and anonymous tests.

CI: at 7dd13eb, Tests had 10 failures, all in the new ExpansionHealthVisibilityTest. Most came from the fixture adding a HEAD concept, which health rightly counts as version_mismatches. b964fd3 fixes the fixture; its run is still going.

Should-fix

  1. resolved-repo-updates still shows hidden value set versions (core/collections/views.py:1180). For GET, CollectionVersionExpansionBaseView.get_permissions allows anyone who can view the collection version. get_resolved_repo_version_diff_with_latest_updates then maps every recorded version a rebuild would move to its newer version, private value sets' included. That is the recorded version lists by another route. Leave out collection-version pairs unless the reader can view both versions, through the same ValueSetViewAccess, and add the member/outsider/anonymous test.

Nits
2. Reason order (get_health_for, core/collections/health.py:577): a synthesized unresolved_references goes where value_set_without_expansion was. A genuinely missing value set puts it in its usual place, so the order tells the two apart. Insert it where the computation puts unresolved_references.
3. For an unversioned reference with a recorded entry, health stores one item per resolved version and a grouped item for the entry (the entry test now picks the grouped one). An outsider who can view only one of those versions sees that one under value_set_without_expansion, and the hidden grouped entry under unresolved_references: the same reference counted twice. Nothing private is shown, but counting the entry once, on its grouped versions, would match #1076.

For the follow-up you already planned (other health fields and source version lists), two more of the same kind:

  • The state fallback uses the stored head_resolved_repositories, so a hidden private HEAD can still turn healthy into head_resolved.
  • Each version in the recorded version lists carries previous_version_url, which can name a private earlier version. Every version list in OCL does this.

Codex (codex-cli 0.169.0, xhigh, on e961bc8..7dd13eb) raised six points: should-fix 1, nits 2 and 3, the two follow-up items, and the fixture, which you fixed in b964fd3. I checked each in the code.

…et's versions only to a reader who can view them, and a hidden entry counts once, in its usual place
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Round 1 is addressed in c8e2e29. Thanks to the review lead and Codex, who found all three:

  1. Should-fix (resolved-repo-updates): get_resolved_repo_version_diff_with_latest_updates takes the reader's ValueSetViewAccess. It leaves out a collection-version pair unless the reader can view both versions. This branch already has OpenConceptLab/ocl_online#773 | resolved-repo-updates lists only versions a rebuild would move #1072's version of the method (7d813fc). New test: test_resolved_repo_updates_list_a_value_set_s_versions_only_to_a_reader_who_can_view_them (member, outsider, anonymous).
  2. Nit (reason order): a synthesized unresolved_references now goes where get_reasons puts it, after the reasons it adds first. New test: test_a_hidden_value_set_s_entries_read_as_unresolved_references_in_their_usual_place.
  3. Nit (counted twice): a reference's recorded entry is counted once, on the versions grouped under it, and not again under each version it resolved to. That matches OpenConceptLab/ocl_online#771 | A value set or filter a reference can't apply makes it resolve to nothing, not the whole system #1076. The entry test now checks the outsider's value_set_without_expansion count too.

The two follow-up items (the hidden private HEAD and the head_resolved fallback; previous_version_url) are listed under "Not in this PR (follow-up)" in the PR body.

b964fd3's fixture fix (for the 10 failures at 7dd13eb) is included. CI runs at c8e2e29.

@paynejd

paynejd commented Nov 26, 2026

Copy link
Copy Markdown
Member

Review lead (Claude, for Jon), round 2, head c8e2e29.

Verdict: ready to approve once CI is green. All three round-1 points are fixed. One optional nit is below. It still merges after #1076, as the PR body says.

Round 1

  1. resolved-repo-updates takes the reader's ValueSetViewAccess and leaves out a value set's pair unless the reader can view both versions; staff see everything. Fixed.
  2. A stand-in unresolved_references now goes after REASONS_BEFORE_UNRESOLVED. That list matches the four reasons get_reasons adds before it, and nothing reorders them afterwards, so a hidden value set reads as a missing one would. Fixed.
  3. A reference's entry is counted once, on its grouped versions. Fixed.

Nit (optional)
4. get_valueset_entry_versions groups every recorded version of the value set under an entry. A reference that names public v1 and private v2 explicitly, where only v2 left an entry, therefore loses v1's own value_set_without_expansion item for an outsider. That under-reports, and shows nothing private. Grouping only the versions the entry's URL can stand for (all of them for an unversioned URL, the one named for a versioned URL) would keep it.

Codex (codex-cli 0.169.0, xhigh, on b964fd3..c8e2e29) raised three points: nit 4; a resolved.url call on a version whose repository no longer resolves, which is the same on master; and health stored under rules version 2 before this commit, which has never shipped. I checked each in the code.

CI at c8e2e29: Pylint passes; Tests still running (the b964fd3 run was cancelled).

Base automatically changed from ocl_online-771-no-widening to master November 26, 2026 06:43
…th-visibility

# Conflicts:
#	core/collections/health.py
#	core/collections/models.py
#	core/collections/serializers.py
#	core/collections/tests/tests_health.py
…d version whose repository no longer resolves
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Master (with #1076's squash 1f9fc34) is merged in as f544075. Where the only conflict was #1076's squashed code against this branch's copy of it, the branch's side is kept. #1075's changes from master are kept too. Against master, the diff is now only #788's six files.

The 3 errors at c8e2e29 (NoReverseMatch for source-version-detail) are fixed in f570840. get_resolved_repo_version_diff_with_latest_updates read .url on the unsaved repository that resolve_reference_expression returns when a repository no longer resolves. The fixture's public_release has no HEAD, so that's what hit it. The method now checks resolved.id first. New test: test_get_resolved_repo_version_diff_skips_a_repository_that_no_longer_resolves. Thanks to the review lead's Codex note, which flagged it.

@snyaggarwal
snyaggarwal merged commit 8ceb329 into master Nov 26, 2026
1 of 2 checks passed
@snyaggarwal
snyaggarwal deleted the ocl_online-788-health-visibility branch November 26, 2026 06:52
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