Skip to content

OpenConceptLab/ocl_online#736 | Fuzzy concept search keeps to the URL's repository version; a reference's cascade walks only source versions its creator can view - #1024

Merged
snyaggarwal merged 10 commits into
masterfrom
ocl_online-736-fuzzy-cascade-scope
Nov 23, 2026
Merged

snyaggarwal merged 10 commits into
masterfrom
ocl_online-736-fuzzy-cascade-scope

Conversation

@paynejd

@paynejd paynejd commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Part of OpenConceptLab/ocl_online#736 (items 1 and 2).

What changes

  1. Fuzzy concept search keeps to the repository version in the URL. A ?fuzzy=true search that names no source_version targets now applies the same URL scope as the plain search: owner, source and version (or the requester's orgs on a members view). Until now it applied no repository filter, so it could return concepts from outside the repository version the URL names.

  2. A collection reference's cascade walks a source version it names only if the reference's creator can view it. When cascade.source_version names a version by label, that version gets the same check as the reference's system version (can_view_all_content for the reference's creator). A version the creator can't view is walked as if it didn't exist, so the reference adds only the concept, as it already does for a label that doesn't resolve. omit_if_exists_in already treats a repository its creator can't view this way.

  3. From the review passes:

    • The cascade check also covers the reference's system or value set version when the cascade walks that one.
    • A search scope that names a version that doesn't resolve (latest with no release) returns no results, where plain search used to fail with an Elasticsearch error.
    • On /user/ routes, the scope reads the owner from the requester (url_username), as the owner filter already did. Search on /user/collections/<c>/concepts/ and latest/ under /user/sources/<s>/ works again.

Behaviour change to check

  • A fuzzy search under a repository URL now returns only that repository version's concepts; until now it matched concepts in every repository. That includes HEAD URLs such as /orgs/O/sources/S/concepts/?fuzzy=true: they now keep to source S's HEAD, where they used to match the latest revisions of every source. No OCL client sends fuzzy=true (oclmap, oclweb3, oclweb2, ocl-cli checked).
  • Unchanged: fuzzy searches with source_version targets, and the global /concepts/?fuzzy=true.

How

  • BaseAPIView.__apply_scope_filters: the URL-scope block moves out of __get_search_results, and both searches call it. It gains two changes from the review passes: a scope value that doesn't resolve matches nothing (match_none), and the /user/ owner filter skips collection routes, since a collection's concepts can come from any owner's source.
  • CollectionReference._get_viewable_cascade_version: called from _apply_cascade for each concept. It resolves a source_version label once, among the source versions that hold the concept (as the walk does), checks that version, and hands the walk the checked version, or None. Each version's check is cached while one reference is evaluated.

Tests

core/integration_tests/tests_cross_repo_access.py:

These tests fail on master and pass here. At 91628a7 the full suite passed (3,453 tests in the parallel run, 653 tagged es). After master was merged in (up to #1010), tests_cross_repo_access and tests_release_map_codes pass (55 tests) and pylint is clean. A trial merge of 396efe3 with #1023's head 0b217d7 passes tests_cross_repo_access, tests_access_control and tests_release_map_codes (242 tests), so the two PRs can merge in either order.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qUzz3wjAx46pzoRCsC

paynejd and others added 2 commits November 21, 2026 15:18
…ository version in the URL, as plain search does

A fuzzy search that names no source_version targets now applies the URL's owner, source and version filters. The
block that builds them moves unchanged out of __get_search_results into __apply_scope_filters, which both searches
call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qUzz3wjAx46pzoRCsC
…version it names only if the reference's creator can view it

A version the creator can't view is walked as if it didn't exist, so the reference adds only the concept, as for a
label that doesn't resolve; omit_if_exists_in already works this way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qUzz3wjAx46pzoRCsC
@paynejd
paynejd requested a review from snyaggarwal November 21, 2026 20:18
…em or value set version it walks too; a search scope naming no version matches nothing

The cascade check now covers every repo version a cascade walks, not only one named by label. A search scoped to a
version that doesn't resolve (latest with no release) now returns no results, rather than an Elasticsearch error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qUzz3wjAx46pzoRCsC
@paynejd

paynejd commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 1 (codex-cli 0.169.0, commit 78d8bbc)

Verdict: findings (4 P1, 1 P2). The full findings and the evidence are on the tracking ticket. Responses:

… requester on /user/ routes

A collection's owner URL and the release `latest` resolves to now use the requester on the /user/ shortcut, as the
owner filter already did, so searches there keep to the requester's own repositories.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qUzz3wjAx46pzoRCsC
@paynejd

paynejd commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 2 (codex-cli 0.169.0, commit 0024aca)

Verdict: findings (2 P1, 4 P2). It marks F1.2 and F1.4 resolved; F1.1, F1.3 and F1.5 stand as answered in pass 1 (covered by #1023, or present in plain search already). Responses:

  • F2.1 (P1), search on the /user/collections/ shortcut: fixed in c9e891c. The scope now reads the owner from the requester on /user/ routes (url_username), and plain search there works again too (it failed before this PR). Test added. Ordinary fuzzy search on collection concept lists still fails as it did before this PR (it was never wired up there); left as it is.
  • F2.2 (P1), latest/ on the /user/sources/ shortcut: fixed in c9e891c, the same way: latest resolves against the requester. Plain search there was also wrong before this PR. Test added.
  • F2.3 (P2), members-view scope on analyzed username tokens: accepted. Plain search uses the same filter, so it predates the PR.
  • F2.4 (P2), a reference's concept list searched by expansion membership: accepted. Plain search on that route has the same scope, so it predates the PR.
  • F2.5 (P2), references saved before this change: accepted for code. Cleaning up existing data is a separate step and is noted on the tracking ticket.
  • F2.6 (P2), signed-out case: added. A signed-out reference PUT answers 401 and leaves the collection unchanged.

…cut keeps to the collection's members; search stats with no hits answer an empty list

- A search under /user/collections/<c>/ no longer adds the requester as the
  concepts' owner: a collection's members come from any owner's source, as on
  the /users/<u>/collections/<c>/ route.
- Search stats (searchStatsOnly) with no hits return [] instead of failing on
  a null max score.
- The signed-out reference test now names the cascade version too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXcjfVFHsP2kYdP9tH
@paynejd

paynejd commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 3 (codex-cli 0.169.0, commit c9e891c)

Verdict: findings (3 P1, 1 P2). It marks F2.2 resolved and F2.1 unresolved only because fuzzy search on collection concept lists still fails (F3.1 below); the /user/collections/ lookup error F2.1 described is gone. F1.1, F1.3, F1.5 and F2.3 to F2.5 stand as answered in passes 1 and 2. Responses:

  • F3.1 (P1), fuzzy search on a collection's concept list answers 500: not changed here. Collection concept views never set up fuzzy search's inputs, so it fails the same way on master on every collection route. Wiring fuzzy search into collections is a separate change, noted on the tracking ticket.
  • F3.2 (P1), search on /user/collections/<c>/concepts/ kept only the requester's own concepts: fixed in 695c24c. On that shortcut the scope no longer adds the requester as the concepts' owner, so a collection's members from any owner's source match, as on /users/<u>/collections/<c>/. Test: a personal collection holding a concept from an organization's source finds it on both routes.
  • F3.3 (P1), search stats with no hits answered 500: fixed in 695c24c. With no hits there's no maximum score, and the stats now come back as an empty list. Plain search had the same failure before this PR; scoping fuzzy search makes it easier to reach. Test for fuzzy and plain search.
  • F3.4 (P2), signed-out test: fixed in 695c24c. The signed-out request now sends the same versioned cascade as the signed-in ones, and the collection gains no concepts or mappings.

Pylint is clean and the full suite passes locally on 695c24c (3453 tests, plus 653 Elasticsearch tests).

@paynejd

paynejd commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits c9e891c..695c24c (codex-cli 0.169.0)

Verdict: findings (2 P1). F3.3 and F3.4 resolved. Codex marks F3.2 regressed because the /user/collections/<c>/ shortcut now returns what /users/<u>/collections/<c>/ returns, including two known gaps of that route. Responses:

  • FC.1 (P1), a reference's concept list on the shortcut matches the collection's members, not the reference's: accepted. This is F2.4 (pass 2): the explicit /users/<u>/ route has the same scope, before and after this PR. On the shortcut it covers only the requester's own collection.
  • FC.2 (P1), an unversioned search on the shortcut matches members of every HEAD expansion, not only the default one: accepted. The expansion filter is applied only when the URL names a version (get_kwargs_filters), so unversioned search on /users/<u>/collections/<c>/concepts/ behaves the same way on master. On the shortcut it covers only the requester's own collection.

Neither is narrowed here: the shortcut now matches the explicit route, and both gaps are noted on the tracking ticket.

Simplification review (claude subagent, 695c24c)

Two low-confidence items, both declined:

  • S1 (shrink), split _can_view_cascade_version into a version-object check before the loop and a label cache inside it: declined. One helper keeps both cases on one access check.
  • S2 (shrink), fold the repeated user_is_self blocks in __apply_scope_filters: declined. That code is moved verbatim from plain search, so the diff reads as a move.

No commits after 695c24c.

…ce version it walks as the walk finds it, among the versions that hold the concept

The label check looked the version up under the source's current name, while
the walk looks it up among the source versions that hold the concept. When
those differ (after a source is renamed, its releases keep the old name), the
check found nothing and let the walk through. It now resolves the label the
way the walk does and checks every version it finds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXcjfVFHsP2kYdP9tH
@paynejd

paynejd commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Adversarial review (claude subagent, on 695c24c)

A fresh reviewer looked for other paths that reach the same data while skipping this PR's checks.

  • One gap in the new cascade check, fixed in 9e1826c: the check looked up a version label differently from the walk it guards, so the two could disagree about which version a label names. The check now resolves the label exactly as the walk does and checks every version it finds. Test added (red before, green after).
  • Two pre-existing paths outside this PR's change are recorded on the tracking ticket for follow-up.
  • The other search entry points (stats, facets, export, other lists, shortcuts), the cascade and clone operations, reference preview, re-evaluation and the FHIR operations were checked and found consistent with the change.

…urce version it walks once and hands the checked version to the walk

The check and the walk each resolved the cascade's version label. The check
now resolves it once, as the walk did (among the source versions that hold
the concept, exactly one), checks it, and passes that version to the walk, or
None, which adds only the concept as an unknown label does. One lookup per
concept instead of the walk's two, and nothing changes between the check and
the walk.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXcjfVFHsP2kYdP9tH
@paynejd

paynejd commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits 695c24c..9e1826c (codex-cli 0.169.0)

Verdict: findings (1 P1, 1 P2), both about the cascade check from the adversarial fix. One change answers both, in 91628a7:

  • FC2.1 (P1), one more query per cascade root: fixed. The check now resolves the version label once per root and passes the resolved version to the walk, which no longer resolves it itself. Each root costs one lookup instead of the walk's two before this PR.
  • FC2.2 (P2), the walk could resolve a version the check never saw: fixed by the same change. The walk gets the checked version, or none (it then adds only the concept, as for an unknown label). Nothing is resolved again in between.

Pylint is clean and the full suite passes locally on 91628a7 (3454 tests, plus 653 Elasticsearch tests).

@paynejd

paynejd commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits 9e1826c..91628a7 (codex-cli 0.169.0)

Verdict: clean. FC2.1 and FC2.2 resolved; no findings. Head 91628a7.

@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.

Reviewed at 91628a7, after your Codex passes, the adversarial pass and the final clean check. The cascade check and the fuzzy-search scope hold on the paths I traced:

  • A fuzzy search without source_version targets keeps to the URL's repository version.
  • The cascade check finds a label's version the way the walk does, and hands the walk the version it checked.
  • latest with no release answers an empty list.

I haven't run the tests.

Before merge (inline): one case in FuzzySearchScopeTest fails once #1023 is also merged, because #1023 answers 404 for a missing source. The two PRs merge without text conflicts, so only CI would catch it.

Agreed to leave for later: fuzzy search on a collection's concept list answering 500 (your pass 3, F3.1).

Nits (inline): HEAD URLs belong with the behaviour change; the How section's method name and "moves unchanged" are out of date; and one inline comment is easy to misread.

for user in [None, self.outsider, self.member]:
self.assertEqual(self.search(public_release_url, user), (200, []), user)
self.assertEqual(self.search(self.public_source.uri + 'latest/', user), (200, []), user)
self.assertEqual(self.search('/users/outsider/sources/NoSuchSource/v9/', user), (200, []), user)

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.

Before merge: this case fails once #1023 is merged. #1023's check_source_version_access answers 404 for a source or version that doesn't exist, and its test_a_missing_source_or_version_is_not_found asserts that. So this request gets (404, None) there.

The two PRs merge without text conflicts (git merge-tree of ae48cfa and 91628a7 is clean), so only CI on whichever merges second would show it. #1023 covers the missing-source case, so dropping it here keeps this test green whichever PR merges first:

Suggested change
self.assertEqual(self.search('/users/outsider/sources/NoSuchSource/v9/', user), (200, []), user)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Dropped as you suggested, in f03ca38. A missing source or version is now left to #1023's test_a_missing_source_or_version_is_not_found.

Checked on trial merges with #1023:

Comment thread core/common/views.py
self.__get_source_versions_es_criterion(source_versions)
)
else:
results = self.__apply_scope_filters(results)

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.

Nit (PR body). Without source_version targets, this now applies the URL scope on HEAD URLs too: owner, source and source_version=HEAD under /orgs/O/sources/S/concepts/. Before, the fuzzy path had no repository filter, so a fuzzy search there matched every source's latest revisions. The body lists HEAD URLs under "Unchanged", but they belong with the behaviour change. No client sends fuzzy=true, so the impact is small.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed. HEAD URLs are now under the behaviour change in the PR body: a fuzzy search on /orgs/O/sources/S/concepts/ keeps to S's HEAD, where it used to match every source's latest revisions.

Comment thread core/common/views.py Outdated
if is_members_view:
kwargs_filters['ownerType'] = 'Organization'
kwargs_filters['owner'] = self.get_members_view_org_mnemonics() or ['UNKNOWN-ORG-DUMMY']
elif self.user_is_self and is_authenticated and 'collection' not in self.kwargs: # members have any owner

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.

Nit. Two lines up, "members" means the requester's orgs (is_members_view). Here it means the collection's member concepts. Spelling it out keeps the next reader from undoing the condition:

Suggested change
elif self.user_is_self and is_authenticated and 'collection' not in self.kwargs: # members have any owner
elif self.user_is_self and is_authenticated and 'collection' not in self.kwargs:
# a collection's concepts can come from any owner's source, so only other routes filter by owner

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Applied your wording in f03ca38.


return Concept.objects.filter(id__in=concept_ids), Mapping.objects.filter(id__in=mapping_ids)

def _get_viewable_cascade_version(self, concept, repo_version, viewable_by_version):

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.

Nit (PR body). The How section calls this CollectionReference._can_view_cascade_version. It also says the URL-scope block moves unchanged out of __get_search_results, but __apply_scope_filters gains the match_none branch and the 'collection' not in self.kwargs condition. Both are listed under "From the review passes", so only the How section is out of date.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in the PR body: the How section names _get_viewable_cascade_version and says what __apply_scope_filters gains on the move (the match_none branch and the 'collection' not in self.kwargs condition).

paynejd and others added 3 commits November 22, 2026 22:12
…d cascade-scope branch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWTbiSiJ56vAgWwb9D
…ing source to the version-access tests; clearer owner-filter comment

A missing source or version is the version-access check's case (#1023 answers 404
and tests it), so this test no longer asserts an answer for one and passes whichever PR merges first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWTbiSiJ56vAgWwb9D
…earch and cascade-scope branch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWTbiSiJ56vAgWwb9D
@paynejd

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits 91628a7..396efe3 (codex-cli 0.169.0)

The commits after Sunny's review: 3a31969 (master merged in, with #1022 and #1017), f03ca38 (his two suggestions) and 396efe3 (master merged in again, with #1010). Two checks, each asked only what those commits broke.

Verdict: no defect in this PR's own changes, and none from how they combine with #1022, #1017 or #1010.

Tests on 396efe3: tests_cross_repo_access and tests_release_map_codes pass (55 tests), and pylint -j0 core/ exits 0. On a trial merge with #1023's head 0b217d7, tests_cross_repo_access, tests_access_control and tests_release_map_codes pass (242 tests).

findings.json (f03ca38..396efe3)
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "396efe3a",
  "verdict": "clean",
  "prior": [],
  "findings": []
}

@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.

Approving at 396efe3. f03ca38 makes both inline changes: the missing-source line is gone, so FuzzySearchScopeTest passes whether #1023 merges first or second, and the owner-filter comment now says which members it means. The PR body lists HEAD URLs under the behaviour change and names _get_viewable_cascade_version. Both master merges are conflict-free.

CI is green at 396efe3. It merges cleanly with master, which now has #1007, and with #1023 (36f75b3). Your trial merge ran with #1023 at 0b217d7. #1023's later commit changes only reads with no owner named, which no test here uses. Still, whichever of the two merges second should take master and pass CI first. I haven't run the tests locally.

@snyaggarwal
snyaggarwal merged commit 24a8e90 into master Nov 23, 2026
3 checks passed
@snyaggarwal
snyaggarwal deleted the ocl_online-736-fuzzy-cascade-scope branch November 23, 2026 04:54
paynejd added a commit that referenced this pull request Nov 23, 2026
…1007) into ocl_online-718-query-collection-version

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qW8QKbfuEJubgQgsHR
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