Skip to content

OpenConceptLab/ocl_issues#3057 | Facet counts follow the retired rule; expansion active counts exclude retired - #1019

Open
paynejd wants to merge 5 commits into
masterfrom
issues#3057
Open

paynejd wants to merge 5 commits into
masterfrom
issues#3057

Conversation

@paynejd

@paynejd paynejd commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

API half of OpenConceptLab/ocl_issues#3057. The TBv3 PR for the same ticket is being built in parallel against this behaviour.

Summary

Filter (facet) counts included retired concepts while the result list left them out: in CIEL v2026-10-23, Class=Drug showed 8,765 against a list of 8,289 (476 retired). Since ffe371b (2023), get_facets() built its search without the retired rule the results use.

  • Facets follow the results' retired rule for concepts, mappings and repositories. The rule, plus any retired= filter, is passed to FacetedSearch as the retired facet's filter.
  • The retired facet still counts both values: a facet ignores its own filter, as in any multi-select facet, so a client can show how many are retired. Every other facet counts within the retired rule.
  • Collections and expansions show retired members by default and honour includeRetired=false in the database list, the search and the facets alike. Before, a collection's database list ignored includeRetired=false.
  • An expansion's active_concepts / active_mappings leave out retired (and inactive) members, like a collection version's, and the expansion summary adds retired_concepts / retired_mappings. The only caller of these properties is ExpansionSummarySerializer (expansion list and detail with includeSummary=true); collection and version summaries use their own stored counts and don't change.

Behaviour

Context Params Results Other facets retired facet
Source, global search, repository lists none, includeRetired=false or retired=false not retired not retired both values
Source, global search, repository lists includeRetired=true all all both values
Source, global search, repository lists retired=true retired only retired only both values
Collection or expansion members none or includeRetired=true all all both values
Collection or expansion members includeRetired=false or retired=false not retired not retired both values

Facet entries keep their [value, count, selected] shape.

An explicit includeRetired=false leaves retired out in every context, also with retired=true. A retired filter reads True/1/False/0 the way the rule does (before, retired=True matched nothing, because the field is indexed as true/false).

What changes for API clients:

  • Searching a collection's concepts or mappings outside an expansion URL (for example /orgs/X/collections/Y/concepts/?q=…) now includes retired members by default, as that URL's unfiltered list and the expansion URLs already did. Before, the search left them out while the unfiltered list showed them.
  • That search, and its facets, now stay within the collection's HEAD default expansion when the URL has no version, as its unfiltered list does. Before, they took in members of every HEAD expansion.
  • Repository facets search only the sources and collections indexes.
  • Cached facets of released source versions (cached for a day) keep their old counts until they expire.

Not changed: the unfiltered database lists at /orgs/X/sources/ and /orgs/X/collections/ still show retired repositories, as before, while their search and facets leave them out by default. Fixing that reaches the FHIR CodeSystem, ValueSet and ConceptMap views built on them, so it's left for a follow-up (no repository on production is retired).

Tests

New, in their own @tag('es') classes except the summary test:

  • ConceptRetiredFacetCountsTest (core/integration_tests/tests_concepts.py): facet counts and results in a source, an expansion and a collection, with no param, includeRetired=true|false, retired=true|false (other spellings and key case too) and a conceptClass filter; the retired facet keeps both counts; a collection's search stays within its default expansion, a reference's doesn't change.
  • MappingRetiredFacetCountsTest (core/integration_tests/tests_mappings.py): the same for mappings.
  • ReposListRetiredFacetCountsTest (core/repos/tests.py): repository list facets, which search only the repository indexes.
  • CollectionVersionExpansionViewTest.test_get_summary_counts_retired_members_apart_from_active_ones: expansion summary fields; CollectionVersionExpansionsViewTest.test_get updated for the two new fields.

Run locally in a compose stack (Django 5.2.17, elasticsearch-dsl 8.18, ES 8.15.2), as CI runs it:

  • pylint -j2 core (pylint 4.0.9): no messages.
  • TEST_ES=off manage.py test --exclude-tag es --parallel=4: Ran 3452, OK (2 skipped).
  • manage.py test --tag es --parallel=1: Ran 664, OK.
  • The 15 new or changed tests against master's code (master's six changed source files mounted over this branch): 14 fail, as expected; the one that passes guards a reference's member search, which keeps master's scope.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qVNufohRXPK1DHpx7i

paynejd and others added 2 commits November 20, 2026 13:48
…; expansion active counts exclude retired

- Facets of concepts, mappings and repos count within the same retired rule and `retired` filter as the
  results; the `retired` facet still counts both values (multi-select), so clients can show how many are retired.
- A collection's or expansion's concepts and mappings include retired ones by default, in the database
  list, the Elasticsearch search and the facets alike; includeRetired=false leaves them out.
- Expansion active_concepts/active_mappings leave out retired (and inactive) members, like a collection
  version's; expansion summaries add retired_concepts/retired_mappings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVNufohRXPK1DHpx7i
…tired=false wins, retired spellings, collection search scope, repo facet indexes

- An explicit includeRetired=false leaves retired out in every context, also with retired=true.
- A `retired` filter reads True/1/False/0 as the retired rule does (the field is indexed as 'true'/'false').
- A collection's concepts or mappings without a version in the URL are searched (and counted) within its HEAD
  default expansion, as its database list is, not every HEAD expansion.
- Repository facets search only the sources and collections indexes.
- Pylint: too-many-branches in the common search filters.

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

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 1 (codex-cli 0.169.0, commit 0e213ce)

Verdict: 6 findings (4 P1, 2 P2).

  • F1.1 P1 core/common/views.py:619: Standalone source and collection lists return retired repositories that their facets omit.
  • F1.2 P1 core/repos/search.py:9: The /repos/ retired facet counts concept documents as repositories.
  • F1.3 P1 core/common/views.py:93: The new collection search default includes retired members from nondefault expansions.
  • F1.4 P1 core/common/views.py:104: Supported truthy spellings can produce zero retired results.
  • F1.5 P2 core/common/views.py:94: An explicit includeRetired=false can be overridden in sources, global search, and repo lists.
  • F1.6 P2 core/integration_tests/tests_mappings.py:110: The facet tests miss required parameter cases on the direct collection routes.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "full",
  "commit": "0e213ce90155618b136990a5fafd40bc30795b1a",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "F1.1",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 619,
      "claim": "Standalone source and collection lists return retired repositories that their facets omit.",
      "scenario": "An org has a retired HEAD source. An unfiltered GET of /orgs/acme/sources/?includeRetired=false uses the database queryset, which still returns that source. The facet request excludes it from the sourceType count. The same mismatch occurs without the parameter and on the standalone collections list.",
      "action": "Apply the shared retirement rule to the database querysets for standalone source and collection lists. Test both results and counts with a retired repository.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.2",
      "severity": "P1",
      "tag": null,
      "file": "core/repos/search.py",
      "line": 9,
      "claim": "The /repos/ retired facet counts concept documents as repositories.",
      "scenario": "An org has one retired source and one retired HEAD concept. The repository list searches only sources and collections. RepoFacetedSearch has no index restriction, and copying the base search's request body drops its index list. The HEAD concept also matches the owner and version filters, so the retired facet reports two retired items.",
      "action": "Set the facet search's indexes to REPO_INDEXES. Add a HEAD concept to the repo facet test and verify it contributes to neither retired bucket.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.3",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 93,
      "claim": "The new collection search default includes retired members from nondefault expansions.",
      "scenario": "A HEAD collection has a default expansion and a second expansion containing a retired Drug concept absent from the default. The unversioned collection concepts URL lists only the default expansion on the database path. Its Elasticsearch search and facets are scoped to the collection's HEAD and include the retired Drug from the second expansion.",
      "action": "Scope collection concept and mapping searches and facets to the same resolved default expansion as the database path, including on unversioned URLs. Test with two HEAD expansions.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.4",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 104,
      "claim": "Supported truthy spellings can produce zero retired results.",
      "scenario": "A client sends retired=True or retired=1 for a source with retired concepts. The retirement rule recognizes both spellings as truthy, but the facet criterion sends the raw spelling to a case-sensitive keyword field indexed as true. The result list and non-retired facets come back empty.",
      "action": "Normalize supported boolean spellings to the indexed values when building the retired criterion for both results and facets.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.5",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 94,
      "claim": "An explicit includeRetired=false can be overridden in sources, global search, and repo lists.",
      "scenario": "A source request includes includeRetired=false and a retained retired=true facet filter. The truthy retired value skips the exclusion rule, so retired concepts are returned and counted despite the explicit exclusion. A collection request with the same parameters applies the exclusion.",
      "action": "Make explicit includeRetired=false take precedence in every context and keep the retired facet's own counts independent of both parameters.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.6",
      "severity": "P2",
      "tag": null,
      "file": "core/integration_tests/tests_mappings.py",
      "line": 110,
      "claim": "The facet tests miss required parameter cases on the direct collection routes.",
      "scenario": "The direct collection mapping test checks facet counts only with includeRetired=false. It would pass if unfiltered facets still excluded retired mappings, because the unfiltered assertion checks database results only. Neither direct collection test checks facet counts with includeRetired=true or retired=false, and the source mapping test omits includeRetired=false.",
      "action": "Assert both the ordinary facet counts and the two retired buckets for all four parameter cases on the source and direct collection concept and mapping routes.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Reply to Codex pass 1 (fixes in 2c901a1)

  • F1.1 P1, accepted and not fixed here. This was already the case before this PR: the unfiltered database lists at /orgs/X/sources/ and /orgs/X/collections/ never applied the retired rule, while their own search did. The facets now agree with that search. They also agree with these lists whenever a filter or includeRetired=true is sent, which is how TBv3 calls them. Applying the rule in these views' get_queryset would also reach the FHIR CodeSystem, ValueSet and ConceptMap views that subclass them (delete and lookup by id), and CollectionListView returns a union() that can't be filtered afterwards. No repository on production is retired. Left for a follow-up.
  • F1.2 P1, fixed. RepoFacetedSearch now searches only the sources and collections indexes. Through the API, the repository filters already dropped concept and mapping docs (concept docs have no public_can_view; a retired HEAD mapping didn't match either), but the facet search did run across every index. test_facets_search_only_repositories fails without the fix.
  • F1.3 P1, fixed. The scope gap was already there and the new default widened it. A collection's concepts or mappings without a version in the URL are now searched and counted within its HEAD default expansion, as its database list is (test_collection_search_is_its_default_expansion).
  • F1.4 P1, fixed. The list had the same problem before this PR. A retired filter now reads True/1/False/0 the way the retired rule does.
  • F1.5 P2, fixed. An explicit includeRetired=false leaves retired out in every context, also with retired=true.
  • F1.6 P2, fixed. The direct collection routes now check facets with no param, includeRetired=true|false and retired=false, for concepts and mappings, and the source mapping test adds includeRetired=false.

Also fixed in 2c901a1: Pylint's too-many-branches in the common search filters, which failed CI on 0e213ce.

…ope; a Retired filter key in any case stays out of its own facet

- The default-expansion scope applies to a collection's member lists only, not to a reference's members.
- The retired filter is found as the faceted filters find it (snake-cased key), for both the facet base search
  and the retired criterion.

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

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

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

Verdict: 3 findings (1 P1, 2 P2).

  • prior F1.1: unresolved

  • prior F1.2: resolved

  • prior F1.3: regressed

  • prior F1.4: resolved

  • prior F1.5: resolved

  • prior F1.6: resolved

  • F2.1 P1 core/common/views.py:575: The default-expansion fix drops valid results from unversioned collection reference searches.

  • F2.2 P2 core/common/views.py:578: Collection member facets use HEAD even when the list resolves a release through the version query parameter.

  • F2.3 P2 core/common/views.py:877: A retired filter accepted by facet-key normalization can still suppress its own bucket.

findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "2c901a1d1e97a8774a19da5f6556318ee043704a",
  "verdict": "findings",
  "prior": [
    {
      "id": "F1.1",
      "status": "unresolved"
    },
    {
      "id": "F1.2",
      "status": "resolved"
    },
    {
      "id": "F1.3",
      "status": "regressed"
    },
    {
      "id": "F1.4",
      "status": "resolved"
    },
    {
      "id": "F1.5",
      "status": "resolved"
    },
    {
      "id": "F1.6",
      "status": "resolved"
    }
  ],
  "findings": [
    {
      "id": "F2.1",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 575,
      "claim": "The default-expansion fix drops valid results from unversioned collection reference searches.",
      "scenario": "A collection reference contains an active Drug concept that is indexed in a secondary HEAD expansion and absent from the default expansion. The unfiltered `/orgs/acme/collections/C/references/42/concepts/` list still returns the concept. Adding `?conceptClass=Drug` now drops it because the search requires membership in the default expansion. The filtered request returned it before the fix commit.",
      "action": "Apply the new default-expansion constraint only to direct collection member routes. Add a regression test for a filtered reference member outside the default expansion.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.2",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 578,
      "claim": "Collection member facets use HEAD even when the list resolves a release through the version query parameter.",
      "scenario": "A collection's v1 default expansion contains a retired Drug that is absent from HEAD. `/orgs/acme/collections/C/concepts/?version=v1` returns that Drug, while adding `&facetsOnly=true` counts the HEAD default expansion and omits it from the retired bucket.",
      "action": "Build the Elasticsearch scope from the collection version and expansion already resolved by the list view. Test the version query parameter with distinct HEAD and release members.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.3",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 877,
      "claim": "A retired filter accepted by facet-key normalization can still suppress its own bucket.",
      "scenario": "A source has active and retired concepts. With `?Retired=false&facetsOnly=true`, the normal facet parser recognizes `Retired` as `retired`, but the code that removes the filter from the base query checks only the raw lowercase key. The retired facet therefore omits the `true` bucket.",
      "action": "Separate the retired criterion after normalizing facet keys, and use the same normalized parameter for results and facets.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Reply to Codex pass 2 (fixes in ad75850)

  • F1.1 stays accepted, for the reasons in the pass 1 reply (already the case before this PR, reaches the FHIR list views, no retired repository on production). Left for a follow-up.
  • F2.1 P1, fixed. The default-expansion scope from 2c901a1 now applies only to a collection's own member lists, not to references/<id>/concepts|mappings/, whose search keeps its earlier scope (test_reference_search_is_not_limited_to_the_default_expansion).
  • F2.2 P2, accepted. A ?version=v1 query parameter on /collections/Y/concepts/ was already searched within HEAD before this PR (collection_version=HEAD), and the facets follow that search. The version belongs in the URL path, where search, facets and list agree.
  • F2.3 P2, fixed. The retired filter is now found the way the faceted filters find it (snake-cased key), both when the facet base search leaves it out and when the retired criterion is built (test_retired_filter_key_in_any_case).

…r default-expansion scope; the retired rule reads a Retired key in any case

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

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

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

Verdict: 3 findings (1 P1, 2 P2).

  • prior F1.1: unresolved

  • prior F1.2: resolved

  • prior F1.3: resolved

  • prior F1.4: resolved

  • prior F1.5: resolved

  • prior F1.6: resolved

  • prior F2.1: regressed

  • prior F2.2: unresolved

  • prior F2.3: resolved

  • F3.1 P1 core/common/views.py:575: The reference fix broadens searches on versioned collection reference routes.

  • F3.2 P2 core/common/views.py:96: A normalized truthy retired filter produces empty results and ordinary facets.

  • F3.3 P2 core/common/views.py:619: Cached source-version facets can serve the old counts for up to a day after rollout.

findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "ad75850a71c8b12f0874602df0f9f7bbaac381ea",
  "verdict": "findings",
  "prior": [
    {
      "id": "F1.1",
      "status": "unresolved"
    },
    {
      "id": "F1.2",
      "status": "resolved"
    },
    {
      "id": "F1.3",
      "status": "resolved"
    },
    {
      "id": "F1.4",
      "status": "resolved"
    },
    {
      "id": "F1.5",
      "status": "resolved"
    },
    {
      "id": "F1.6",
      "status": "resolved"
    },
    {
      "id": "F2.1",
      "status": "regressed"
    },
    {
      "id": "F2.2",
      "status": "unresolved"
    },
    {
      "id": "F2.3",
      "status": "resolved"
    }
  ],
  "findings": [
    {
      "id": "F3.1",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 575,
      "claim": "The reference fix broadens searches on versioned collection reference routes.",
      "scenario": "Collection release v1 has a default expansion containing reference 42's Diagnosis and a secondary expansion containing an unrelated active Drug. A request to /orgs/acme/collections/C/v1/references/42/concepts/?conceptClass=Drug now returns that Drug. Before this commit, the explicit v1 route constrained the search to the default expansion. The new test covers only the unversioned route.",
      "action": "Keep the existing expansion constraint on versioned reference routes while restoring the unversioned route's scope. Add a versioned test that checks an unrelated secondary-expansion member is excluded.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F3.2",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 96,
      "claim": "A normalized truthy retired filter produces empty results and ordinary facets.",
      "scenario": "A source has a retired Drug. The facet parser accepts Retired=true and builds a retired=true criterion, but the default rule looks up only the raw lowercase key and also requires retired=false. The result list and ordinary facet counts are empty, while retired=true returns and counts the Drug. The new mixed-case test exercises only Retired=false, where both constraints agree.",
      "action": "Use the normalized retired key for the default rule and the explicit filter. Test Retired=true on both the results and facet paths.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F3.3",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 619,
      "claim": "Cached source-version facets can serve the old counts for up to a day after rollout.",
      "scenario": "A request for the latest released source version's concepts with facetsOnly=true warms Redis before deployment. The same request after deployment reads the existing key before calling get_facets(). If the release has retired Drugs, the cached class count still includes them while the default results exclude them. The mapping facet cache follows the same path.",
      "action": "Version the facets-only cache keys so the first request after deployment computes counts under the new rule.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

…onflicting retired keys, as the faceted filters do

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

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Reply to Codex pass 3 (fixes in 48b9601)

  • F1.1 and F2.2 stay accepted, for the reasons in the earlier replies (both were the case before this PR).
  • F3.1 P1, fixed. ad75850 had also dropped the default-expansion scope that master gives versioned reference routes. Only unversioned reference routes now skip the new lookup, so <version>/references/<id>/concepts/ keeps master's scope. test_reference_search_is_not_limited_to_the_default_expansion now checks both routes.
  • F3.2 P2, fixed. The retired rule now finds the retired key the way the faceted filters do, so Retired=true returns and counts the retired concepts (test_retired_filter_key_in_any_case).
  • F3.3 P2, accepted. Facets of released source versions cached before the deploy keep their old counts for at most a day; the PR body notes it as a deploy step. Versioning the cache keys would change the shared list cache for one transient.

This was the third pass. Commits ad75850..48b9601 get a final Codex check.

@paynejd

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits ad75850..48b9601 (codex-cli 0.169.0, commit 48b9601)

Verdict: 1 finding (1 P2).

  • prior F3.1: resolved

  • prior F3.2: regressed

  • FC.1 P2 core/common/views.py:96: The retired inclusion rule and the facet filter can select different values for the same parameter.

findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "48b9601b53229d5165b627fa305eb30ca40ce757",
  "verdict": "findings",
  "prior": [
    {
      "id": "F3.1",
      "status": "resolved"
    },
    {
      "id": "F3.2",
      "status": "regressed"
    }
  ],
  "findings": [
    {
      "id": "FC.1",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 96,
      "claim": "The retired inclusion rule and the facet filter can select different values for the same parameter.",
      "scenario": "On a source with retired concepts, `?Retired=false&retired=true` returned retired concepts before this commit. The inclusion rule now takes the first normalized key and adds `retired=false`, while the facet parser takes the last and requires `retired=true`. The results and concept class facet are empty.",
      "action": "Resolve normalized keys with the same last-value precedence as `get_faceted_filters` and add a regression test for conflicting aliases.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Reply to the Codex check of ad75850..48b9601 (fix in 8ccc62c)

  • F3.1 resolved.
  • FC.1 P2, fixed. With conflicting keys such as Retired=false&retired=true, the retired rule now takes the last one, as get_faceted_filters does, so the rule and the filter read the same value (regression assertion in test_retired_filter_key_in_any_case). Not re-checked by Codex: a one-line change, covered by the parent session's final check after its simplification review.

@paynejd

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Simplification review (Claude subagent, commit 8ccc62c). Nothing applied; one line per item:

  • S1 drop is_active=True from Expansion.active_*: kept. It's the same definition as CollectionVersion.set_active_concepts, so an expansion's active count and its version's stored count agree, which is what the ticket's "active means not retired" consistency is for.
  • S2 read the retired key once through get_faceted_filters: not applied. The rule's precedence (explicit includeRetired=false, key spellings, last of conflicting keys) went through four Codex rounds; merging the three reads would need another full round for about 4 lines.
  • S3 compact + reduce in get_retired_criterion: not applied. It relies on the truthiness of elasticsearch-dsl Query objects, and the current three cases read clearly.
  • S4 fold the facet/agree test pairs: not applied. They pin separate claims (facet counts vs results agreeing), and the mapping tests guard the shared mixin from the mappings side.

No new commits, so the final Codex check covers 48b9601b..8ccc62c2 (posted next).

@paynejd

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits 48b9601..8ccc62c (codex-cli 0.169.0, commit 8ccc62c)

Verdict: 1 P2, no P0/P1.

  • FC.2 P2 core/common/views.py:96: The fix makes the last alias win, but the retired rule and the facet filter interpret quoted values differently.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "8ccc62c2",
  "verdict": "findings",
  "prior": [
    {
      "id": "FC.1",
      "status": "regressed"
    }
  ],
  "findings": [
    {
      "id": "FC.2",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 96,
      "claim": "The fix makes the last alias win, but the retired rule and the facet filter interpret quoted values differently.",
      "scenario": "On a source containing retired concepts, `?retired=true&Retired=%22true%22` returned those concepts before this commit. The facet filter strips the quotes and asks for `retired=true`. The retired rule now reads the same quoted value, fails its truthy check, and adds `retired=false`. The conflicting filters return no results.",
      "action": "Apply the facet filter's quote normalization to the winning value before the retired rule checks it. Keep `includeRetired=false` authoritative and add a regression test for the quoted alias.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

Response

  • FC.2 P2: accepted. It needs a quoted boolean (Retired=%22true%22), which no OCL client sends for retired. A quoted ?retired="true" on its own already mismatches the rule and the faceted filter on master, so this commit doesn't introduce the class. If a client ever needs it, the fix is to apply the faceted filter's quote stripping in the rule.

@paynejd

paynejd commented Nov 21, 2026 •

Copy link
Copy Markdown
Member Author

Independent review (Claude, with Codex second opinion)

Reviewed at 8ccc62c against master (ff807fc), with OpenConceptLab/oclweb3#110 at 35ede39f as its pair. I wrote my findings before reading this PR's earlier review threads. Codex (codex-cli 0.169.0, xhigh, read-only) then ran a blind defect pass and a second pass that tried to refute each of my findings. The findings on the pair are here, and OpenConceptLab/oclweb3#110 links to them.

Verdict: not ready to merge. One P1 should be fixed first: an explicit includeRetired=false now beats retired=true, which breaks the OCL Mapper's Retired filter. The P2s each need a fix, a ticket or a deploy step. Codex refuted none of my findings. We differ on severity for 2 and 3, which Codex rates P1 and I rate P2.

P1

1. An explicit includeRetired=false now overrides retired=true in sources and global search, which breaks the OCL Mapper's Retired filter. core/common/views.py:92

  • The Mapper sends includeRetired=<project setting> with its candidate searches, false by default, and its filter panel offers the Retired facet.
  • With the setting off, a user picks Retired = true, then searches again or turns the page. The request is includeRetired=false&retired=true.
  • master returns the retired matches. This PR returns none, while the Retired facet, which now counts both values, still shows how many there are. The PR's tests assert the empty result (core/integration_tests/tests_concepts.py:3796, :3808).
  • The ticket only asks for includeRetired=false to work in collections (API AC 3). This precedence came in as the fix for Codex pass 1 F1.5. I'd reverse that answer.
  • Fix: outside collection and expansion member lists, keep master's precedence, where a truthy retired filter lets retired ones in. Let includeRetired=false win only in member lists, and update the two assertions.
  • Codex: confirmed. Its blind pass found it independently and rated it P1. Its check adds one detail: the Mapper leaves includeRetired out the first time it applies the facet, so the first search works and the rerun or the next page comes back empty.

P2

2. Unfiltered /orgs/X/sources/ and /orgs/X/collections/ lists now disagree with their own facets once a repository is retired. core/common/views.py:622

  • The database lists include retired repositories; their facets now leave them out by default.
  • The pass 1 reply (F1.1) says this "was already the case before this PR". That's true of list against search, but not of list against facets. On master the facets skipped the retired rule, so they matched the list.
  • No repository on production is retired, so nothing shows there today. A self-hosted install with a retired repository will see it.
  • The follow-up the reply names isn't ticketed yet. Either file it, or apply the rule to those two lists as /repos/ already does (core/repos/views.py:135) and check the FHIR list views that subclass them.
  • Codex: confirmed; P1 in both passes. I rate it P2 because no production repository is retired.

3. An expansion summary's active_concepts / active_mappings change meaning (every member → not retired), and other clients show the new numbers. core/collections/models.py:1622

  • The ticket asks for the change. Two clients read these fields:
  • The summary now runs four COUNT queries per expansion instead of two. One conditional aggregate per relation gives all four numbers in two queries.
  • Codex: confirmed; P1, and its blind pass called it a TBv2 regression. I rate it P2: the ticket decided the meaning, and in TBv2 it makes the expansion rows agree with the version rows. It belongs in the release notes.

P3

  1. Cached facets of released source versions keep their pre-deploy counts for up to 24h (core/common/mixins.py:191), so the ticket's own example can persist for a day: CIEL Drug reads 8,765 while the list shows 8,289.
    • The pass 3 reply (F3.3) accepted this "as a deploy step", but the PR body only says the entries expire.
    • Please make the step explicit. After the deploy, either:
      • delete the repo_cache: keys; or
      • for the latest released versions, call the admin DELETE …/sources/<source>/<version>/concepts/cache/ and …/mappings/cache/.
    • Codex: confirmed (P2 in both passes). It also notes that _force_cache_clear writes a new key and leaves the old one in place.
  2. Collection keyword searches now include retired members by default, for TBv2 too. TBv2 searches /orgs/X/collections/Y/[vN/]concepts/?q=… with no retired param when its route has no expansion, and master hid retired hits there. The new default is the ticket's decision; it needs a line in the release notes. Codex: partly. Its correction: TBv2 has no separate switch on that path, only the Retired checkboxes in its filter drawer.
  3. Reference member lists ignore includeRetired=false on the database path (core/collections/views.py:369, :384), while their search and facets apply it. master behaved the same. Fix: call filter_retired_members in both get_querysets. Codex: confirmed, and it existed before this PR (its blind pass rated it P2).
  4. No retired-count test at global scope (/concepts/ or /mappings/ with facetsOnly=true), which is the surface TBv3 global search uses. The ACs only ask for source and collection, and both are covered. Codex: partly. One older global facet test exists, but it doesn't vary the retired setting.

The pair (OpenConceptLab/oclweb3#110)

Contract. The two PRs agree:

TBv3 sends Source or global search Collection or expansion
switch off nothing → results and facets leave retired out retired=false → results and facets leave retired out
switch on includeRetired=true → all includeRetired=true → all
retired facet both values (the switch's count) both values

Deploy order.

  • API first is safe.
  • TBv3 first, or a rollback of this PR, brings back today's mismatch in sources, and in collections the switch loses its count while off. Nothing gets worse than today.
  • Codex's blind pass on oclweb3#110 rated that order risk P1 (F1.1). I rate it P3 because the PR body documents it.

8 (P2). Collections lose paging past 10,000 results with the switch off, though this PR makes a better request possible. oclweb3 src/components/search/retiredSwitch.js:23

  • TBv3 sends retired=false there. That's a facet filter, so the list goes to the search index and its 10,000-result window.
  • This PR's filter_retired_members (core/collections/views.py:101) makes includeRetired=false work on the database path of collection and expansion member lists, and get_retired_criterion applies it to their facets. With the API deployed first, TBv3 could send includeRetired=false and keep full paging whenever there's no keyword or other filter.
  • The trade-off: if TBv3 shipped first, or this PR were rolled back, includeRetired=false would be ignored there and retired members would show with the switch off.
  • Codex: confirmed in all three passes where it came up (P2). The base already sent retired=false for an active-only Retired filter, so the cap itself isn't new.

9 (P3). With no retired results, the switch shows no count instead of "(0)". oclweb3 src/components/search/retiredSwitch.js:61

  • Terms facets skip empty buckets, so the API returns no true bucket and the switch reads "Include Retired" with no number.
  • Once this PR is live, a retired facet with only a false bucket means 0. Either TBv3 shows "(0)" in that case, or the retired facet here sets min_doc_count=0.
  • Codex: raised by its blind pass on oclweb3#110 (F1.8, P2).

Changes to the public API's meaning, for the release notes:

  • facet counts follow the results' retired rule everywhere;
  • expansion active_* excludes retired members, and summaries gain retired_* (3);
  • includeRetired=false overrides a retired filter (1, if kept);
  • collection keyword search includes retired members by default and stays within the HEAD default expansion (5);
  • retired=True/1/0 now match, where retired=True used to match nothing.

Facet performance. No concern found:

  • every facet already sat inside a filter aggregation, and the retired term filter is cheap and cached;
  • an unversioned collection search adds two lookups (the HEAD version and its expansion);
  • item 3 adds two COUNT queries per expansion.
Codex blind defect pass on this PR (codex-cli 0.169.0, xhigh, commit 8ccc62c): 5 findings, all covered above (F1.1 = 1, F1.2 = 3, F1.3 = 2, F1.4 = 6, F1.5 = 4)
  • F1.1 P1 core/common/views.py:92: Giving includeRetired=false precedence breaks the OCL Mapper’s retired-only search.
  • F1.2 P1 core/collections/models.py:1623: Deploying the expansion summary change breaks total counts in TBv2.
  • F1.3 P1 core/common/views.py:622: The dedicated source and collection repository lists now disagree with their facets about retired repositories.
  • F1.4 P2 core/common/views.py:85: Collection reference member lists ignore includeRetired=false on the database path.
  • F1.5 P2 core/common/mixins.py:189: Cached source-version facets can retain the old counts through the rollout.
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "full",
  "commit": "8ccc62c26dbb2c1fe3ef1bad033bea68366e262f",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "F1.1",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 92,
      "claim": "Giving includeRetired=false precedence breaks the OCL Mapper’s retired-only search.",
      "scenario": "In a Mapper project with Include Retired off, select Retired = true in the Search tab and rerun the search. Mapper sends both includeRetired=false and retired=true. The base returned matching retired concepts. This commit requires retired to be both false and true, so the search returns zero results.",
      "action": "Preserve the existing precedence for an explicit retired=true filter on source and global searches, or deploy a Mapper change that stops sending the conflicting flag before this API change. Cover the Mapper request in a regression test.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.2",
      "severity": "P1",
      "tag": null,
      "file": "core/collections/models.py",
      "line": 1623,
      "claim": "Deploying the expansion summary change breaks total counts in TBv2.",
      "scenario": "Open the Versions tab for a TBv2 collection with an expansion containing 90 active and 10 retired concepts. TBv2 reads summary.active_concepts directly for its expansion Resources cell. The cell drops from 100 to 90 while the expansion still lists 100 concepts. The same regression affects mappings.",
      "action": "Deploy a TBv2 reader that adds the retired count when present and falls back to the legacy count when absent, or provide a versioned summary contract before changing the existing fields.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.3",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 622,
      "claim": "The dedicated source and collection repository lists now disagree with their facets about retired repositories.",
      "scenario": "An organization has one active and one retired source of the same type. A plain GET to its /sources/ endpoint returns both from PostgreSQL, with or without includeRetired=false. The corresponding facetsOnly request now counts one in sourceType. The /collections/ list has the same split. The new repository tests only exercise /repos/.",
      "action": "Use the same retired rule on the REST list and facet paths for each endpoint. Test /sources/ and /collections/ with the flag omitted, false, and true.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.4",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 85,
      "claim": "Collection reference member lists ignore includeRetired=false on the database path.",
      "scenario": "A collection reference and its default expansion both hold a retired concept. GET /collections/C/HEAD/references/R/concepts/?includeRetired=false still returns it from reference.concepts. The corresponding facet request excludes it from the class count. The mapping endpoint behaves the same way.",
      "action": "Apply the retired rule to the database querysets for reference concepts and mappings, and add a list-and-facets test with a retired reference member.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.5",
      "severity": "P2",
      "tag": null,
      "file": "core/common/mixins.py",
      "line": 189,
      "claim": "Cached source-version facets can retain the old counts through the rollout.",
      "scenario": "A first-page facetsOnly response for the latest released version of a source is in Redis when the API deploys. The key is unchanged, so an identical request still serves the old counts, including retired members, for up to 24 hours while the list hides them.",
      "action": "Version the facets-only cache key or invalidate the old facet entries during rollout.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@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 8ccc62c, after your three Codex passes, the checks after them and the simplification review. The change holds on the paths I traced:

  • Facets follow the results' retired rule, and the retired facet still counts both values. Storing an elasticsearch-dsl Query in _filters works for the other facets' aggregations, and a None criterion falls through to the base add_filter.
  • Collections and expansions show retired members by default and honour includeRetired=false in the database lists, the search and the facets. The new filter_retired_members calls are on the member-list views only.
  • The expansion's active_* counts match CollectionVersion.set_active_*, and retired_* matches the collection version's retired_*_count.
  • An unversioned collection search keeps to HEAD's default expansion (or NO_EXPANSION, never None), while unversioned reference routes keep master's scope.
  • The repository facets search only the repository indexes.

I haven't run the tests.

Before merge (inline): the conflict with master in get_kwargs_filters has to keep #1024's url_username. The branch is 11 commits behind master, and #1023, #1024 and #1027 all changed this search code, so CI, ES tests included, needs to run again on the merge.

Nit (inline): the retired facet entries are never marked selected, which TBv3's parallel PR needs to allow for.

Fine to leave as accepted: F1.1 (unfiltered source and collection lists, as before), F2.2 (a ?version= query parameter on member lists), F3.3 (cached facets for a day after the deploy) and FC.2 (quoted booleans).

Comment thread core/common/views.py
{**params, 'mnemonic': self.kwargs['collection']})
filters['collection_version'] = get(version, 'version')
elif is_collection_specified and 'expansion' not in self.kwargs:
params = {'user__username': self.kwargs.get('user'), 'organization__mnemonic': self.kwargs.get('org')}

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: keep #1024's url_username here. This block now conflicts with master. #1024 (merged Nov 23) changed this line to params = {'user__username': self.url_username, ...}. url_username reads the signed-in user on the /user/ shortcut, where self.kwargs has no user.

If the conflict is resolved in this branch's favour:

So the merged block should be this PR's restructure with self.url_username in params, used by both the latest lookup and the new HEAD lookup. A /user/ case in ConceptRetiredFacetCountsTest would pin it.

Comment thread core/common/search.py
A filter can also be an ES criterion: every facet but `name` counts within it, while the `name` facet
counts all its values (none of them shown as selected).
"""
if isinstance(filter_values, Query):

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. With a Query stored straight in _filters, filter_values is never set for retired, so every retired entry comes back with selected: false, even with ?retired=true applied. The PR body says this on purpose. Just make sure TBv3's parallel PR reads the Retired filter from its own state, not from the facet's selected flag.

Also, collection searches include retired members by default from the API's deploy onward, so it's worth deciding whether the API and TBv3 deploy together.

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