Skip to content

OpenConceptLab/ocl_online#703 | A release's search matches its own mapped codes - #1010

Merged
snyaggarwal merged 17 commits into
masterfrom
ocl_online-703-release-search
Nov 23, 2026
Merged

snyaggarwal merged 17 commits into
masterfrom
ocl_online-703-release-search

Conversation

@paynejd

@paynejd paynejd commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

OpenConceptLab/ocl_online#703. Builds on #985, now on master; this branch was rebased onto master on Nov 20.

What this does

A concept search in a release now matches that release's own mapped codes. Since #985, a release's concept page, concept list and mappings tab show the release's own mappings; search did not.

Why search differed. A concept unchanged since a release keeps one row, shared by HEAD and the release, so one search document serves both. That document's mapped codes were HEAD's. Searching a release by a mapped code found codes HEAD had added since, and missed codes HEAD had dropped. With seeding imports (#985), a new release can drop many mappings at once, so this gap gets much wider.

Index side. The concept document gets one new nested field, release_map_codes. It holds one entry per distinct set of codes, with that set's same_as_map_codes, other_map_codes and mapped_codes, and a source_version_id list naming every release that has it. The entries use ids, not names: a release made again under a deleted one's name gets a new id, so its documents can't pick up a stale entry. Only releases whose own active mappings give other codes than the document's own fields appear. A document whose releases all match carries no entries. MappedCodes loads the release codes for a chunk of rows in two queries. Full indexing (prepare, 100 docs a chunk) and the partial mapped-code updates (Concept.get_mapped_codes_actions) both use it, so every path that refreshes mapped codes refreshes the entries too.

One rule for a document's own codes. MappedCodes replaces Concept.get_indexed_mappings. The rule also covers three items from #985's final review (FE.5, FE.6 and the rest of FD.4):

  • HEAD's rows take HEAD's codes, as before: the versioned object and the latest version, which global search reads too. A concept dropped from HEAD keeps its latest row this way, and its releases read their codes from entries (FD.4).
  • So does a row that no release holds, such as a version only a collection holds: HEAD's active mappings only, not those HEAD dropped. Such a row lost its mapped codes on reindex (FE.6). Since it reads HEAD's codes, an import that changes or drops HEAD's mappings refreshes it too (Concept.get_unreleased_older_ids), as a mapping edit through the API already did.
  • Any other row takes the codes of every public release that holds it, so collection searches match as on the base branch, without a private release's codes. When a release's public_access changes, those rows' codes are rebuilt on the indexing queue (Source.index_release_rows_mapped_codes_async).
  • Each release that holds the row and has other codes is named in an entry, so a release search reads only that release's codes (FE.5).

Query side. In a release the user can view (/<version>/concepts/ or /latest/concepts/), ConceptDocument.scope_map_codes_to_release rewrites each clause on a mapped-code field after the query is built. The clause matches the document's entry for that release where there is one, and the document's own fields otherwise. That covers:

  • the search box: exact, wildcard and must-have/must-not words;
  • the targetRepo filter;
  • $match against a release URL: its filters, including those the kNN queries use, and its lexical clauses. The lexical clauses highlight an entry's matching field through named inner hits, which CustomESSearch.get_highlight folds into the hit's highlight. Without that, bestMatch would drop the hit.

$match SAME-AS input. $match built its SAME-AS clause on same_as_mapped_codes, which no document has, so that input never matched and the release rewrite skipped it. The clause now reads same_as_map_codes, the indexed field, which the Mapper already sends. same_as_mapped_codes is still read as the same input. This applies in HEAD as well: a SAME-AS input now counts toward $match scores (boost 0.1, as listed).

Facets. targetRepo and targetRepoMapType in a release count the release's own codes.

What stays the same.

  • HEAD's queries aren't rewritten. (The $match SAME-AS fix above is the one change HEAD sees.)
  • HEAD's documents are unchanged, apart from the new field.
  • A latest release equal to HEAD has no entries, so it matches and scores as before.
  • A release the user can't view, and fuzzy search (which isn't scoped to the URL's version), read each document's own codes, as before. A fuzzy search's facets read them too, so they match its hits.
  • A document without an entry for the release scores the same as before.
  • Global search across latest releases (the header-driven mode) still reads each document's own codes. It differs from the latest release only when HEAD was edited after that release.

Deploying

  1. Before deploying this code, run python manage.py concept_release_map_codes. It adds the field's mapping to the live concepts index and checks it. Nothing is reindexed.
    • It must run first. Once a document carries the field, ES maps it dynamically as an object, not as nested, and the nested queries fail.
  2. After deploying, python manage.py concept_release_map_codes --source <source URL> rewrites the mapped codes of every row that source's releases hold, and of every older row of the source. On master, every document holds HEAD's codes, rows only older releases hold included, so each source with releases needs this once. An older row no release holds, such as a version only a collection holds, had no mapped codes on master and now gets HEAD's active ones.
    • Finding a source's older rows is one sequential scan of concepts on production (the planner estimates about 851k older LOINC rows; many are release rows already counted below).
    • Start with LOINC: about 1.5 hours for its 814,844 release rows at the local rate.
    • Which other sources to run, and when, is for Sunny to decide.
    • A seeding import fills its own entries through the mapped-code updates it already runs.
    • A release made the usual way now writes its concepts and mappings in one transaction. Otherwise a document rebuilt between the two writes would get an entry with no codes for that release, which the release's indexing (an append) keeps.

Measurements

LOINC numbers come from production (read-only) and a local benchmark; details are in the measurements comment.

  • Index size: about 330 B per entry. At most about 95 MB for LOINC after 2.82 (286,477 entries), likelier about 43 MB.
  • Reindex time: the new queries add about 9 minutes of database time to a full LOINC reindex. The local benchmark showed no measurable overhead per document.

Testing

  • New: core/integration_tests/tests_release_map_codes.py. A seeded v1 → v2 where concepts A and B don't change, and their mappings do. A's mappings are dropped in v2; B gains one.
    • ReleaseMapCodesTest, no ES:
      • a shared row gets entries only for releases whose codes differ, and releases with the same codes share one;
      • the entries load in two queries;
      • the query rewrite, query in → query out;
      • FE.5: a row only releases hold keeps every release's codes as its own, and each release reads its own entry;
      • a release the user can't view isn't read;
      • a private release's codes stay out of a row's own fields;
      • a release's access change queues its release-only rows' rebuild;
      • a new release whose mapping write fails keeps none of its concepts (the two writes are one transaction);
      • FD.4: a dropped concept's releases read their own codes from entries;
      • FE.6: a row no source version holds reads HEAD's active mappings, not the ones HEAD dropped, and a HEAD-only import that edits one of them queues that row's refresh;
      • the kNN filters of a release $match name the release;
      • --source with --index is refused.
    • ReleaseMapCodesSearchTest, ES. HEAD, v1, v2 and latest, each:
      • finds the codes HEAD dropped in v1 only;
      • finds the code HEAD added in HEAD, v2 and latest, but not v1;
      • applies the targetRepo filter the same way;
      • facet counts;
      • $match against v1 and v2, by a NARROWER-THAN code and by a SAME-AS code (under both input keys), a filter-only $match, and the highlight of a hit matched through an entry;
      • a dropped concept is found in its release, and not by global search;
      • re-running a release's indexing keeps its entries;
      • a fuzzy search reads each document's own codes, and so do its facets;
      • the command adds the mapping and rewrites documents indexed as on master (HEAD's codes, no entries), and gives a collection-only row indexed as on master (no codes) HEAD's kept code, not the dropped ones; a later seed that drops that code takes it out of the row's doc, with no second backfill.
    • With the query rewrite switched off, the search, filter and command tests fail. v1 misses A's dropped codes and finds B's added one.
  • Changed: OpenConceptLab/ocl_online#655 | Isolated source versions #985's test_older_concept_version_indexes_its_releases_mappings asserts the document fields now that get_indexed_mappings is gone. test_mapped_codes_actions_update_just_the_mapped_codes expects the new field.
  • Full suite, as CI runs it, locally on 0952f28 (rebased on master):
    • TEST_ES=off --exclude-tag es --parallel=4: 3,465 tests, OK;
    • --tag es --parallel=1: 665 tests, OK.
  • Review rounds: Codex passes 1 to 3 and final checks FC.1 to FC.9 ran before the rebase. Passes 4 to 6 and FC.10 ran after it, with the replies to the reviewer's comments. Each pass is in its own comment.
  • Lint: pylint -j0 core/ gives 10.00 with no messages.

Not in this PR

  • Collection versions keep matching each document's own codes.
  • Fuzzy search, global or in a source, keeps matching each document's own codes (Codex F1.4, accepted).
  • The list view skips its permission check for the literal latest, so a private latest release's membership still filters the results. This predates the PR; its mapped codes are no longer read (F3.1).
  • Highlights of mapped-code fields in the search API show the document's own codes; only $match reads the entries'.
  • A collection reference that filters a pinned source release by a mapped code still reads each document's own codes (Codex F5.2).
  • A mapping whose from_concept is an older concept version isn't in HEAD's codes, as on master (Codex F6.1).
  • A fuzzy request's facets come from the regular query, as on master (Codex FC.10).

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qVSZwPgUucRdN8D9U9

@paynejd
paynejd requested a review from snyaggarwal November 19, 2026 15:38
@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

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

Verdict: findings: 3 P1, 3 P2.

  • F1.1 [P1] core/concepts/management/commands/concept_release_map_codes.py:72: The backfill skips existing documents whose top-level mapped codes need correction.
  • F1.2 [P1] core/concepts/management/commands/concept_release_map_codes.py:49: The backfill writes to the default concepts index when the operator selects a different index.
  • F1.3 [P1] core/concepts/search.py:325: Release-scoped $match leaves mapped-code filters unscoped in vector and filter-only requests.
  • F1.4 [P2] core/common/views.py:912: Fuzzy concept search ignores release overrides when the release is selected through source_version.
  • F1.5 [P2] core/concepts/search.py:50: Truncating the two facet branches before merging can omit the most frequent target repo.
  • F1.6 [P2] core/concepts/documents.py:105: Duplicating mapping snapshots per release can make previously valid concept documents fail to index.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "full",
  "commit": "bc1a10f5c07b3219256e92031d47f4beb0c501e7",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "F1.1",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/management/commands/concept_release_map_codes.py",
      "line": 72,
      "claim": "The backfill skips existing documents whose top-level mapped codes need correction.",
      "scenario": "A concept mapped to X in v1 was dropped from HEAD before deployment. Its existing document has empty HEAD codes. The new builder puts X in the top-level fields and emits no release entry because v1 is the only release holding the row. The backfill skips the document, so searching v1 for X still misses the concept.",
      "action": "Backfill documents whose top-level mapped-code fields need correction even when the release entries are empty. Add an upgrade test that starts with the old document fields.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.2",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/management/commands/concept_release_map_codes.py",
      "line": 49,
      "claim": "The backfill writes to the default concepts index when the operator selects a different index.",
      "scenario": "Running the command with `--index concepts-next --source <url>` installs the mapping on `concepts-next`, but the update actions still write to `concepts`. The selected index remains unfilled. If the live index lacks the field, those writes can dynamically map it as an object and prevent the required nested mapping from being installed in place.",
      "action": "Use the selected index for every backfill write and missing-document fallback, or reject `--index` with `--source` until that combination is supported.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.3",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/search.py",
      "line": 325,
      "claim": "Release-scoped `$match` leaves mapped-code filters unscoped in vector and filter-only requests.",
      "scenario": "A semantic match against v1 filters on `target_repo`. An unchanged concept whose mapping to that target was added in HEAD can still be returned by kNN because the rewrite applies only to the lexical query. Elasticsearch combines those result sets with OR. A filter-only row also bypasses the rewrite because it has no `wrapped_clauses`. [Elasticsearch kNN search](https://www.elastic.co/guide/en/elasticsearch/reference/8.15/knn-search.html)",
      "action": "Apply release-aware mapping filters to every `$match` retrieval path. Add coverage for a semantic match and a filter-only row against a release that lacks the HEAD mapping.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.4",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 912,
      "claim": "Fuzzy concept search ignores release overrides when the release is selected through `source_version`.",
      "scenario": "A request to `/concepts/` uses `fuzzy=true`, a name query, a `source_version` URL for v1, and a `target_repo` filter. The name matches an unchanged concept whose mapping to that target was added in HEAD. The version filter selects v1, but `map_codes_release` returns `None` because the route has no `source` parameter, so the concept incorrectly passes the mapped-code filter.",
      "action": "Scope the mapped-code filter using each resolved source version in the fuzzy query. Keep the source, owner, and version criteria together with that version's mapping clause.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.5",
      "severity": "P2",
      "tag": null,
      "file": "core/concepts/search.py",
      "line": 50,
      "claim": "Truncating the two facet branches before merging can omit the most frequent target repo.",
      "scenario": "A target repo has five mappings in each branch. Each branch also has 100 different target repos with six mappings apiece. Both branch aggregations discard the shared target, so the response omits the target with the highest combined count of ten and can return 200 buckets despite the existing 100-bucket cap.",
      "action": "Combine bucket counts before ranking and applying `FACET_SIZE`. Add a test where a bucket outside both branch cutoffs ranks first overall.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.6",
      "severity": "P2",
      "tag": null,
      "file": "core/concepts/documents.py",
      "line": 105,
      "claim": "Duplicating mapping snapshots per release can make previously valid concept documents fail to index.",
      "scenario": "An unchanged concept has 100 mappings with target source URLs across 100 releases. HEAD changes one mapping. The builder copies the same 100 historical mapping objects into each release entry, creating over 10,000 nested objects in one document. Elasticsearch rejects the write at its default limit, leaving the concept unindexed or stale. [Elasticsearch mapping limits](https://www.elastic.co/guide/en/elasticsearch/reference/8.15/mapping-settings-limit.html)",
      "action": "Share identical mapping snapshots across release IDs and handle histories with many distinct snapshots within the index limit. Test that a concept with a large release history remains searchable.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Pass 1 responses (fixed in 4aa28e5)

  • F1.1 [P1] fixed. On master, every concept document holds HEAD's codes, so the backfill must rewrite more than the documents that gain an entry. It now rewrites the mapped codes of every row the source's releases hold. Test: test_the_command_fills_existing_docs starts from documents with HEAD's codes and no entries, and covers an entry and a dropped concept.
  • F1.2 [P1] fixed. --source with --index is refused (test_the_backfill_refuses_another_index).
  • F1.3 [P1] fixed. $match in a release scopes filter_query, which feeds the kNN filters and the filter-only query, and each lexical clause once. Tests: test_match_scopes_its_vector_filters_to_the_release and test_a_filter_only_match_reads_the_release.
  • F1.4 [P2] fixed for one source_version. A fuzzy search in one source version reads that version's codes (test_a_fuzzy_search_in_one_source_version_reads_it). Accepted for several versions: a document in two of them would need a clause per version, for a rare query.
  • F1.5 [P2] fixed in part. The merged buckets are capped at FACET_SIZE. Accepted: a bucket below the cut-off in both branches can still be missed, the same approximation ES's own terms aggregation makes across shards.
  • F1.6 [P2] fixed. Releases with the same codes share one entry, whose version lists them, so the nested objects grow with the number of distinct code sets, not the number of releases (test_releases_with_the_same_codes_share_an_entry). Accepted: a concept whose mappings changed in many releases could still reach ES's per-document nested limit.

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

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

Verdict: findings: 3 P1, 3 P2. Pass 1: F1.1 resolved, F1.2 resolved, F1.3 resolved, F1.4 unresolved, F1.5 unresolved, F1.6 unresolved.

  • F2.1 [P1] core/common/views.py:589: Global fuzzy search can reveal mappings from a private source version.
  • F2.2 [P1] core/concepts/documents.py:100: Unversioned global search starts matching dropped concepts by their historical mapped codes.
  • F2.3 [P1] core/concepts/search.py:409: Lexical $match with bestMatch=true discards matches found only through a release override.
  • F2.4 [P2] core/concepts/documents.py:106: Recreating a source version can reuse the deleted version's mapped-code override.
  • F2.5 [P2] core/common/views.py:622: Facets for a fuzzy search in one source version count historical mappings from other sources.
  • F2.6 [P2] core/integration_tests/tests_release_map_codes.py:176: The vector regression test never checks whether Elasticsearch returns the right candidates.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "4aa28e52f9a1a8411e458a0fe40cf32b975a854e",
  "verdict": "findings",
  "prior": [
    {
      "id": "F1.1",
      "status": "resolved"
    },
    {
      "id": "F1.2",
      "status": "resolved"
    },
    {
      "id": "F1.3",
      "status": "resolved"
    },
    {
      "id": "F1.4",
      "status": "unresolved"
    },
    {
      "id": "F1.5",
      "status": "unresolved"
    },
    {
      "id": "F1.6",
      "status": "unresolved"
    }
  ],
  "findings": [
    {
      "id": "F2.1",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 589,
      "claim": "Global fuzzy search can reveal mappings from a private source version.",
      "scenario": "A public source has a private v1. A concept shared by v1 and HEAD is public, and only v1 maps it to a particular target repository. An anonymous fuzzy search can select v1 through `source_version` and match the concept with a `target_repo` filter. Version resolution checks existence, and the Elasticsearch visibility filter checks the public concept document. The direct v1 endpoint would deny access.",
      "action": "Check view access to each resolved source version before using it in search or facets. Add a regression test with a private version of a public source.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.2",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/documents.py",
      "line": 100,
      "claim": "Unversioned global search starts matching dropped concepts by their historical mapped codes.",
      "scenario": "In the existing fixture, v3 drops B and its mapping to X03, and B's v2 row keeps `is_latest_version=True`. The new builder puts X03 in that row's top-level fields. Global `/concepts/?q=X03` filters on `is_latest_version` without requiring HEAD membership, so it now returns B. The base branch indexed that row with HEAD's empty mapped-code fields.",
      "action": "Keep HEAD mapped-code behavior for documents eligible for unversioned global search. Store the older release's codes in its override and extend the dropped-concept test to cover global search.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.3",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/search.py",
      "line": 409,
      "claim": "Lexical `$match` with `bestMatch=true` discards matches found only through a release override.",
      "scenario": "A v1 `$match` request with `bestMatch=true` and `limit=10` searches for `other_map_codes=X05`. The concept matches only the nested release field. The request highlights the top-level fields, so the hit has no highlight. The view classifies it as `low` and drops it from the response. The new test ends at the Elasticsearch hit and misses this response filtering. [Elasticsearch nested highlighting](https://www.elastic.co/guide/en/elasticsearch/reference/8.15/nested.html#nested-fields-interaction)",
      "action": "Use the matched release clause or its nested highlight to classify release mapped-code hits. Test the `$match` response with `bestMatch=true`.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.4",
      "severity": "P2",
      "tag": null,
      "file": "core/concepts/documents.py",
      "line": 106,
      "claim": "Recreating a source version can reuse the deleted version's mapped-code override.",
      "scenario": "A shared concept's document has a v1 override for X after HEAD drops X. An editor deletes v1 and recreates it from HEAD without changing the concept. The release indexing job only appends the version label and updates the latest-release flag on existing documents. The old override still matches the reused label, so searching the new v1 for X returns the concept.",
      "action": "Key overrides by an immutable source-version ID or refresh them when an existing document gains release membership. Test deletion and recreation through the release indexing path.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.5",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 622,
      "claim": "Facets for a fuzzy search in one source version count historical mappings from other sources.",
      "scenario": "A fuzzy search selects source A's v1 through `source_version`. The hits query uses that resolved source, but the facet query builds a regular search without the source-version constraint and applies the bare `v1` override. A matching concept in source B can contribute a target repository present only in B's v1, even though B is outside the requested results.",
      "action": "Build facets from the same authorized source-version scope as the hits. Test with two sources that share a version label.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.6",
      "severity": "P2",
      "tag": null,
      "file": "core/integration_tests/tests_release_map_codes.py",
      "line": 176,
      "claim": "The vector regression test never checks whether Elasticsearch returns the right candidates.",
      "scenario": "If the v1 kNN filter accidentally selects v2's override, the serialized filter still contains `release_map_codes` and the test passes. The filter-only integration test issues no kNN query, so it cannot catch a vector candidate admitted by the wrong version's mapping.",
      "action": "Execute a semantic search on the CI Elasticsearch version with candidates reachable only through kNN. Assert that v1 admits a candidate with its mapping and excludes a candidate whose mapping was added in HEAD.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Pass 2 responses (fixed in 9dbc134)

  • F2.1 [P1] fixed by removing it. The single-source_version scoping for fuzzy search (F1.4) is gone, and F1.4 is accepted again. Doing it safely would also need a view-access check on the version and facets built from the same scope, which is more than a P2 warrants. The source_version URL check itself resolves only that a version exists, as before this PR.
  • F2.2 [P1] fixed. The versioned object and the latest version keep HEAD's codes as their own, as on the base branch, so unversioned global search behaves as before. A concept dropped from HEAD keeps its release codes in entries, so its releases still find it. Tests: test_a_dropped_rows_releases_read_their_own_codes, and test_a_dropped_concept_is_found_in_its_releases now also checks global search.
  • F2.3 [P1] fixed. In a release, each lexical mapped-code clause of $match names an inner hit that highlights the entry's field. CustomESSearch.get_highlight adds it to the hit's highlight under the field's own name, so the hit is classed as before. Test: test_a_match_highlights_a_releases_own_code.
  • F2.4 [P2] fixed. Appending a new release's name to its members' docs (APPEND_SOURCE_VERSION_SCRIPT, run only when a version is created) also takes that name out of their entries. A release has HEAD's codes when it's made, so any such entry was left by a deleted release of the same name. Test: test_a_new_release_drops_a_deleted_releases_entry_of_the_same_name.
  • F2.5 [P2] fixed by removing it, with F2.1.
  • F2.6 [P2] fixed in part. The test now checks that the kNN filter names v1. Accepted: a test that runs kNN needs an embedding model in CI. The kNN filter is the same filter_query that test_a_filter_only_match_reads_the_release runs against ES.
  • F1.4, F1.5, F1.6 (still open): accepted, with the reasons from pass 1.

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Measurements: index size and reindex time (OpenConceptLab/ocl_online#703 acceptance criterion 3)

LOINC on production (read-only queries):

  • Versions: HEAD holds 582,883 concept rows. 2.81 holds 286,477, 2.71.21AA 266,661 and 2.70.21AA 265,853. 814,844 distinct rows are in a release.
  • 2.81 shares all 286,477 rows with HEAD, with identical codes, so it gets no entries.
  • On master, every document holds HEAD's codes. Rows only an older release holds therefore need the backfill (--source) to read their own release, not only the shared rows that differ: 2.70.21AA's 931 shared rows include 37 that differ, with 141 codes.
  • After 2.82's seeding import, entries go only on 2.81 rows that are unchanged in 2.82 but whose mappings changed. Upper bound: 286,477 rows and 380,263 codes, all of 2.81's.

Local benchmark (a throwaway test, repro_703_bench, not in the PR):

  • Setup: 300 concepts seeded into v1 and v2, unchanged between them, with v2 dropping or adding mappings on half of them. That gives 600 documents and 150 release entries, without vectors. The index was force-merged before measuring with _disk_usage.
base (9c75a44) this PR
Index time, best of 3 5.5 s per 1,000 docs 4.4 s per 1,000 docs (within noise)
Store size 479,135 B 528,375 B (+49 KB, about 330 B per entry including _source)
release_map_codes field — 15,118 B

Extrapolated to LOINC

  • Size: about 330 B per entry. At the upper bound (286,477 entries) that is about 95 MB; at the likelier ~130,000 rows whose mappings 2.82 changed, about 43 MB. The vectors take far more.
  • Reindex time: the two new queries run once per 100 documents. On production, the release-codes query took about 50 ms per 100 mapped concepts. Across LOINC's ~1.1 million rows that adds about 9 minutes of database time to a full reindex, and HEAD-only rows add almost nothing. The local run shows no measurable overhead per document.
  • Backfill: --source /orgs/Regenstrief/sources/LOINC/ rewrites the mapped codes of LOINC's 814,844 release rows as partial updates, without vectors. Locally, with Codex running alongside, it took 6.9 s per 1,000 rows, one process. That puts LOINC at about 1.5 hours, run once.
  • Timing noise: in the same loaded run, full indexing took 10.3 s per 1,000 docs, against 4.4 s on a quiet machine. Read the local timings as orders of magnitude.
  • Entries: releases with identical codes share one entry, so a long release history adds one entry per distinct code set, not one per release.

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

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

Verdict: findings: 4 P1, 1 P2. Earlier: F1.1 resolved, F1.2 resolved, F1.3 resolved, F1.4 unresolved, F1.5 unresolved, F1.6 unresolved, F2.1 resolved, F2.2 resolved, F2.3 resolved, F2.4 regressed, F2.5 resolved, F2.6 unresolved.

  • F3.1 [P1] core/common/views.py:586: The latest-release concept search can expose mappings from a private release.
  • F3.2 [P1] core/common/views.py:912: A source-scoped fuzzy search can apply release mapping filters to a different source's concepts.
  • F3.3 [P1] core/common/es.py:17: Replaying a release indexing job removes valid mapping overrides.
  • F3.4 [P1] core/concepts/documents.py:98: Collection search loses mapped-code matches for concept rows shared by older source releases.
  • F3.5 [P2] core/common/views.py:1072: Ordinary release search loses requested highlights when mapped-code matches move into an override.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "9dbc13496d46f6500410cf78f340acc493faaf71",
  "verdict": "findings",
  "prior": [
    {
      "id": "F1.1",
      "status": "resolved"
    },
    {
      "id": "F1.2",
      "status": "resolved"
    },
    {
      "id": "F1.3",
      "status": "resolved"
    },
    {
      "id": "F1.4",
      "status": "unresolved"
    },
    {
      "id": "F1.5",
      "status": "unresolved"
    },
    {
      "id": "F1.6",
      "status": "unresolved"
    },
    {
      "id": "F2.1",
      "status": "resolved"
    },
    {
      "id": "F2.2",
      "status": "resolved"
    },
    {
      "id": "F2.3",
      "status": "resolved"
    },
    {
      "id": "F2.4",
      "status": "regressed"
    },
    {
      "id": "F2.5",
      "status": "resolved"
    },
    {
      "id": "F2.6",
      "status": "unresolved"
    }
  ],
  "findings": [
    {
      "id": "F3.1",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 586,
      "claim": "The latest-release concept search can expose mappings from a private release.",
      "scenario": "A public HEAD shares a public concept with its newest release, which is private and has a mapping absent from HEAD. The list view looks up the literal version label `latest`, finds no parent, and skips the permission check. The search then resolves `latest` to the private release and uses its mapping to match the concept or count its target repository in facets.",
      "action": "Resolve `latest` before checking permissions and use the same authorized source version for hits and facets. Add an anonymous search and facet test for a private release of a public source.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F3.2",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 912,
      "claim": "A source-scoped fuzzy search can apply release mapping filters to a different source's concepts.",
      "scenario": "Sources A and B both have a v1. A's v1 is public and B's v1 is private. A fuzzy search under A's v1 can select B's v1 through `source_version`. The query checks access to A but selects B's public concept documents and applies the bare `v1` mapping override, exposing mappings that exist only in B's private release.",
      "action": "Bind the fuzzy hits query and its mapping rewrite to the exact authorized source version. Add a regression test with two sources that share a release label.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F3.3",
      "severity": "P1",
      "tag": null,
      "file": "core/common/es.py",
      "line": 17,
      "claim": "Replaying a release indexing job removes valid mapping overrides.",
      "scenario": "Release v1 maps an unchanged concept to X. HEAD later drops X, and the mapped-code update correctly saves a v1 override. If the original release indexing job is delayed or rerun, the append script deletes that override even though v1 is already present on the document. A v1 search then falls back to HEAD and misses X until another reindex.",
      "action": "Identify overrides by immutable source-version ID or recompute the release's mapping fields during the append. Test that replaying the append after a HEAD-only mapping change preserves the release's search results.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F3.4",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/documents.py",
      "line": 98,
      "claim": "Collection search loses mapped-code matches for concept rows shared by older source releases.",
      "scenario": "A collection expansion holds a concept row shared by source releases v1 and v2. Only v1 maps the concept to X, and the concept was edited in v3. The base indexes X on the shared older row, so the collection finds it. After reindexing this change, X exists only in the v1 override and collection search reads the top-level v2 fields, so the same search misses it.",
      "action": "Preserve existing mapped-code search behavior for collection members while applying exact mapping snapshots to source-release searches. Add a collection search regression test using a pinned historical concept row.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F3.5",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 1072,
      "claim": "Ordinary release search loses requested highlights when mapped-code matches move into an override.",
      "scenario": "An older concept row was shared by v1 and v2, and only v1 mapped it to X. On the base, a v1 search for X with `includeSearchMeta=true` can highlight the mapped code in the top-level field. The new search still finds the concept through its v1 override, but the list query requests only top-level highlights, so the response loses the mapped-code highlight.",
      "action": "When release list search requests highlights, collect nested mapped-code highlights and return them under the same response keys. Add an API test for a release-only mapped-code highlight.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Pass 3 responses (fixed in dbf017e)

  • F3.1 [P1] fixed. A search in a release, by version or latest, reads that release's codes only if the user can view it (Source.has_view_access). Otherwise it reads each document's own codes, as before this PR. Test: test_a_release_the_user_cant_view_isnt_read.
    • Not fixed here: the list view skips its permission check for the literal latest, so a private latest release's membership still filters the results. That predates this PR and goes to its own ticket.
  • F3.2 [P1] fixed. Fuzzy search no longer rewrites its mapped-code filters. It isn't scoped to the URL's source version (it returns B's versioned object and latest row alike), so it reads each document's own codes, as before. Test: test_a_fuzzy_search_reads_the_docs_own_codes.
  • F3.3 [P1] fixed, and F2.4 at its root. Entries name their releases by source version id (release_map_codes.source_version_id), not by name. A release re-made under a deleted one's name gets a new id, so no entry goes stale, and APPEND_SOURCE_VERSION_SCRIPT is back to the base branch's. Re-running a release's indexing keeps its entries (test_appending_a_release_again_keeps_its_entries). Views and $match resolve the release's id: $match from its repo params, only when exactly one source version matches.
  • F3.4 [P1] fixed. A row only releases hold keeps the codes of every release that holds it as its own, as the base branch does, so collection searches match as before. Each release whose codes differ reads its own entry, so release searches stay exact (FE.5). Test: test_a_row_only_releases_hold_reads_every_releases_codes_and_each_its_own_entry.
  • F3.5 [P2] accepted. The search API doesn't highlight a mapped code matched through an entry. Highlighting nested entries means inner hits on clauses that can sit in filter and must-not contexts, for a highlight only includeSearchMeta shows. $match, whose match type reads highlights, has them (F2.3).
  • F2.4: superseded by F3.3. F2.6, F1.4, F1.5, F1.6: accepted, with the reasons given earlier.

That was the last Codex defects pass. Next come a simplification review, then a Codex check of the commits after 9dbc134.

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Simplification review (fresh Claude subagent, commit dbf017e), applied in 48648ce

  • S1 (shrink), applied. A row's own code key is computed once, not once per release.
  • S2 (delete), applied. The empty-id guard in MappedCodes is gone; an empty __in runs no query.
  • S3 (yagni), declined. Inlining scope_map_codes would add branches and locals to __get_search_results, which already carries pylint's too-many disables; the call stays one line.
  • S4 (yagni), applied in part. The expected mapping is read inline. get_source stays for its error message.
  • S5 (dup-test), applied. test_partial_updates_carry_the_entries is gone. test_the_command_fills_existing_docs covers partial updates that carry entries, end to end.
  • S6 (dup-test), declined. The filter-only $match test pins F1.3's fix (P1).
  • S7 (dup-test), declined. The two unit tests pin different P1 fixes: F2.2 (a dropped concept's latest row keeps HEAD's codes) and F3.4 (a row only releases hold keeps every release's codes).

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits 9dbc134..48648ce (codex-cli 0.169.0)

Verdict: findings: 2 P1, 1 P2.

  • FC.1 [P1] core/concepts/documents.py:96: Public collection search can reveal mappings from a private source release.
  • FC.2 [P1] core/common/views.py:919: Fuzzy search ignores release mappings even when the request explicitly selects one public release.
  • FC.3 [P2] core/concepts/search.py:205: $match drops release mapping filters when target_repo resolves to both an organization source and a user source.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "48648cea774a28c8d8faf412d0192d6ed6264295",
  "verdict": "findings",
  "prior": [
    {
      "id": "F3.1",
      "status": "resolved"
    },
    {
      "id": "F3.2",
      "status": "regressed"
    },
    {
      "id": "F3.3",
      "status": "resolved"
    },
    {
      "id": "F3.4",
      "status": "regressed"
    }
  ],
  "findings": [
    {
      "id": "FC.1",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/documents.py",
      "line": 96,
      "claim": "Public collection search can reveal mappings from a private source release.",
      "scenario": "A public collection pins a concept row from public v2. Private v1 shares that row and is the only release that maps it to code X. HEAD has since edited the concept. At 9dbc1349, collection search read v2's top-level codes and did not match X. The new union puts X in the top-level fields, so an anonymous search for X returns the concept even though the caller cannot view v1.",
      "action": "Keep private-release codes out of fields searched by all collection readers. Use those codes only after checking access to the release, and add an anonymous collection search test for a row shared by public and private releases.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "FC.2",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 919,
      "claim": "Fuzzy search ignores release mappings even when the request explicitly selects one public release.",
      "scenario": "A concept matches the fuzzy text query and maps to a target repository in public v1. HEAD drops the mapping without editing the concept. A request to the v1 concept list with `fuzzy=true`, `source_version` pointing to that same v1, and a `target_repo` filter returned the concept at 9dbc1349. The current query still selects v1 but applies the mapping filter to HEAD's fields, so the concept disappears.",
      "action": "Apply the mapped-code rewrite using the authorized source versions that actually constrain the fuzzy query. Test an explicitly selected public release and retain coverage for requests whose URL and selected source differ.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "FC.3",
      "severity": "P2",
      "tag": null,
      "file": "core/concepts/search.py",
      "line": 205,
      "claim": "$match drops release mapping filters when `target_repo` resolves to both an organization source and a user source.",
      "scenario": "An organization and a user share a name and both publish public releases with the same source mnemonic and version. A structured `target_repo` with no `owner_type` is accepted and searches both releases. At 9dbc1349, the rewrite matched each release's own mappings. The new lookup finds two IDs and skips the rewrite, so a concept whose mapping exists in its release but was dropped from HEAD no longer matches.",
      "action": "Pass the authorized release IDs from target resolution into the search and apply each ID within its repository's query. Add a test with both owner types.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Responses to the check of 9dbc134..48648ce (fixed in 27d7b26)

  • FC.1 [P1] fixed. A row only releases hold takes its own fields from the public releases that hold it. A private release's codes go only into its entry, which a search reads only for a user who can view that release (F3.1). The base branch's union had the same exposure. Test: test_a_private_releases_codes_stay_out_of_a_rows_own_fields.
  • FC.2 [P1] fixed. A fuzzy concept search that selects exactly one source version with source_version, and that the user can view, reads that version's codes by its id. The id names that version alone, so F3.2's case of a URL naming another source's version of the same name doesn't arise. Test: test_a_fuzzy_search_in_one_viewable_source_version_reads_it, which also makes v1 private. Several source_version values still read each document's own codes (F1.4).
  • FC.3 [P2] accepted. $match skips the rewrite when an org and a user of the same name both have the source and version, with no owner_type given. That is rare, and the search then reads each document's own codes, as before this PR.

One more Codex check of the commits after 48648ce follows.

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Codex check of commit 27d7b26 (codex-cli 0.169.0)

Verdict: findings: 2 P1, 1 P2.

  • FC.4 [P1] core/common/views.py:931: Fuzzy search results and mapped-code facets use different release scopes.
  • FC.5 [P1] core/concepts/documents.py:100: Changing a release's visibility leaves its shared documents' mapped-code fields stale.
  • FC.6 [P2] core/common/views.py:605: A collection version can authorize a mapped-code lookup against an unrelated source release ID.

Responses (fixed in 5cb2495)

  • FC.4 [P1] fixed by removing it. The single-source_version fuzzy rewrite (FC.2) is gone again, so fuzzy results and facets both read each document's own codes, as before this PR. FC.2 joins F1.4 as accepted: before this PR, fuzzy search didn't read a release's codes either.
  • FC.5 [P1] fixed. When a release's public_access changes, the rows only releases hold get their mapped codes rebuilt on the indexing queue (Source.index_release_rows_mapped_codes_async, 5,000 ids a task). Test: test_a_releases_access_change_rebuilds_its_release_only_rows.
  • FC.6 [P2] fixed by removing it, with FC.4.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "27d7b2632dfca3066507b7592627c61bcec7cf44",
  "verdict": "findings",
  "prior": [
    {
      "id": "FC.1",
      "status": "unresolved"
    },
    {
      "id": "FC.2",
      "status": "resolved"
    },
    {
      "id": "FC.3",
      "status": "unresolved"
    },
    {
      "id": "F3.2",
      "status": "resolved"
    }
  ],
  "findings": [
    {
      "id": "FC.4",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 931,
      "claim": "Fuzzy search results and mapped-code facets use different release scopes.",
      "scenario": "With IncludeFacets enabled, the new fuzzy search test's v1 request returns concept A using its v1 mappings. The targetRepoMapType facet omits NARROWER-THAN, which is present on A in v1, because get_facets still searches HEAD for that request.",
      "action": "Apply the fuzzy search's resolved release to both the facet query and the mapped-code aggregations. Extend the integration test to assert the v1 map-type bucket.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "FC.5",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/documents.py",
      "line": 100,
      "claim": "Changing a release's visibility leaves its shared documents' mapped-code fields stale.",
      "scenario": "A public collection contains a historical concept row shared by two releases. The row is indexed while the only release with a particular mapping is private. Making that release public leaves collection search unable to find the concept by that code. The source update does not rebuild mapped-code fields for release members. In the reverse direction, a newly private release's code remains searchable.",
      "action": "Rebuild the mapped-code fields of the release's member documents when its visibility changes. Cover both transitions through the source-version update API.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "FC.6",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 605,
      "claim": "A collection version can authorize a mapped-code lookup against an unrelated source release ID.",
      "scenario": "The reference resolver can return a public collection version for source_version. If a source has the same owner, mnemonic, and version label, its concept rows pass the fuzzy filter. When a shared row also has an entry for a private source release whose numeric ID matches the collection version's ID, the filter evaluates the private release's mappings after checking access only to the collection.",
      "action": "Require the resolved object to be a Source before using its ID for the rewrite. Add a regression test with overlapping collection and source version IDs.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Codex check of commit 5cb2495 (codex-cli 0.169.0)

Verdict: findings: 4 P2, no P1.

  • FC.7 [P2] core/sources/models.py:761: The mapped-code refresh can run before the release access change commits.
  • FC.8 [P2] core/sources/models.py:761: Overlapping access refreshes can overwrite current mapped codes with a stale result.
  • FC.9 [P2] core/sources/models.py:761: Retrying an access update cannot recover chunks that failed to queue.
  • FC.10 [P2] core/integration_tests/tests_release_map_codes.py:369: The remaining fuzzy-search test would pass if the removed rewrite were restored.

Responses (0793a72)

  • FC.7 fixed. The rebuild is queued with transaction.on_commit. The test asserts nothing is queued before the commit.
  • FC.8 accepted. Two overlapping access changes can race their rebuilds, as any two partial updates of the same docs can in this codebase. Running concept_release_map_codes --source again settles it.
  • FC.9 accepted. A chunk that fails to queue isn't retried by repeating the access change. The same command rebuilds the source's release rows.
  • FC.10 fixed. The fuzzy test also selects v1 with source_version and still gets only B.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "5cb2495a209da9953703d5ed29d0be7f031a006e",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "FC.7",
      "severity": "P2",
      "tag": null,
      "file": "core/sources/models.py",
      "line": 761,
      "claim": "The mapped-code refresh can run before the release access change commits.",
      "scenario": "A caller makes v1 private inside a transaction. An indexing worker runs the queued task before commit, reads v1 as public, and finishes without removing v1's codes. No refresh runs after commit, so public collection searches can still match those codes.",
      "action": "Publish the refresh through transaction.on_commit. Test that it is queued only after the access change commits.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "FC.8",
      "severity": "P2",
      "tag": null,
      "file": "core/sources/models.py",
      "line": 761,
      "claim": "Overlapping access refreshes can overwrite current mapped codes with a stale result.",
      "scenario": "An owner briefly makes v1 public and then makes it private again. One worker computes mapped codes while v1 is public. A second worker writes the corrected fields after v1 goes private. If the first worker writes last, public collection searches can match v1-only codes even after both tasks succeed.",
      "action": "Serialize mapped-code refreshes for overlapping concept rows from database read through Elasticsearch write, or reject writes computed from an older revision.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "FC.9",
      "severity": "P2",
      "tag": null,
      "file": "core/sources/models.py",
      "line": 761,
      "claim": "Retrying an access update cannot recover chunks that failed to queue.",
      "scenario": "An owner makes a release private. The database save commits and the broker accepts the first chunk, but publishing the second chunk fails after retries. The request errors. Repeating it sees that the release is already private and queues nothing, leaving the second chunk's old codes searchable.",
      "action": "Persist the refresh work with the access change and make unpublished or failed chunks retryable independently of the access update.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "FC.10",
      "severity": "P2",
      "tag": null,
      "file": "core/integration_tests/tests_release_map_codes.py",
      "line": 369,
      "claim": "The remaining fuzzy-search test would pass if the removed rewrite were restored.",
      "scenario": "The test selects v1 in the URL path and omits the source_version query parameter. The removed rewrite activated only with one resolved source_version. Restoring it would leave this test green while an explicit source_version=v1 fuzzy request would again match A through v1's mapped codes.",
      "action": "Add the explicit source_version request to the test and assert that the target-repository filter returns only B.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Codex check of commit 0793a72 (codex-cli 0.169.0)

Verdict: clean, no findings.

findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "0793a72b8d7cc81234c1af00ed119ec17999cbcd",
  "verdict": "clean",
  "prior": [],
  "findings": []
}

Base automatically changed from ocl_online#655 to master November 20, 2026 02:22

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

I found two mapped-code gaps on this head. The direct $match SAME-AS input misses the indexed field, and collection-only rows can gain codes from mappings that HEAD dropped.

Merge blocker: GitHub reports conflicts with master. I reproduced them against 44010f59 in the concept document/model, importer model/tests, and source model. Now that #985 is on master, replaying the release-search commits on top of it would make it easier to preserve the final seeding changes and verify the intended diff.

I ran focused checks against the query-rewrite and mapping-selection code. Django and Elasticsearch integration tests were unavailable from this session.

Comment thread core/concepts/search.py

wrapped_clauses = [
Q("bool", must=[Q(filter_query), clause])
Q("bool", must=[Q(filter_query), scoped(clause, highlight=True)])

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.

[P2] Route direct SAME-AS inputs through the release lookup. Both priority lists build the $match clause against same_as_mapped_codes, while the index and release rewriter use same_as_map_codes. The rewriter leaves the existing misspelled clause untouched, so a row whose only matching input is a SAME-AS code from the selected release still returns no hit. The new test covers other_map_codes only. Keep the existing input key if callers use it, translate it to the indexed field when building the clause, and test a SAME-AS code present in v1 and dropped in v2.

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 f98d947. Both priority lists now build the clause on same_as_map_codes, the indexed field, so the release rewriter scopes it like other_map_codes. An input row's same_as_mapped_codes is still read, as the same input, unless the row also sends same_as_map_codes. The Mapper already sends same_as_map_codes, which this list never read.

test_match_reads_the_releases_same_as_codes sends X01 (SAME-AS in v1, dropped in v2) under both keys: v1 finds A; v2 and HEAD find nothing; HEAD finds B by X03. It failed before the fix: v1 returned every row, since no clause read the input.

One effect beyond releases: SAME-AS codes now count in every $match, HEAD included, at boost 0.1 (the boost already listed). Before this, a SAME-AS input never matched anything anywhere.

Comment thread core/concepts/documents.py Outdated
def get_fields(self, concept):
releases = self.releases.get(concept.id, [])
if concept.is_versioned_object or concept.is_latest_version or not releases:
codes = to_mapped_codes(concept.get_unidirectional_mappings().values(*MAPPING_VALUES))

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.

[P2] Exclude dropped HEAD mappings for collection-only rows. This adds top-level codes for older rows that have no source-release membership. get_unidirectional_mappings() applies is_active=True only to the versioned object and the latest row, so this new path also indexes inactive HEAD mappings for old rows. The new test at tests_release_map_codes.py:246 demonstrates the mismatch: v2 dropped A's X01 and X05, yet the collection-only row is expected to get both. That makes collection search match codes absent from HEAD, contrary to the stated fallback. Please filter this branch to active HEAD mappings and test with both a retained and a dropped mapping.

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 4a2b177. A row no release holds now takes HEAD's active mappings only (get_unidirectional_mappings().filter(is_active=True)), the same rule HEAD's own rows follow.

test_a_row_no_source_version_holds_reads_heads_active_mappings replaces the test you pointed at. v3 edits A with M7 (SAME-AS X07) and M8 (NARROWER-THAN X08); v4 edits A again, keeping M7 and dropping M8. A's v3 row, with its source versions cleared, now gets (['X07'], []). Before the fix it got (['X07', 'X01'], ['X08', 'X05']): M8, plus M1 and M5, which v2 dropped.

paynejd and others added 11 commits November 20, 2026 01:04
…pped codes

A concept unchanged since a release keeps one row, shared by HEAD and the
release, and so one search document, whose mapped codes are HEAD's. Searching
the release by a mapped code found HEAD's codes: those HEAD added, and not
those it dropped.

- The concept document gets release_map_codes: one entry per release whose own
  active mappings (as Concept.get_version_mappings reads them) give other codes
  than the document's. Documents without a difference carry none, so HEAD and a
  latest release equal to HEAD index as before.
- ReleaseMapCodes loads the releases' codes for a chunk of rows in two queries;
  full indexing and the partial mapped-codes updates both use it.
- A search in a release (a version or latest) rewrites each clause on a
  mapped-code field to read the release's entry where the document has one,
  else its own fields: the search box, the target repo filter, and $match
  against a release URL. Documents without an entry match and score as before.
  HEAD's queries are unchanged.
- The targetRepo and targetRepoMapType facets in a release count the release's
  own codes.
- concept_release_map_codes adds the field's mapping to an existing concepts
  index (no reindex), and with --source fills it on the documents of that
  source's releases that need an entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVSZwPgUucRdN8D9U9
…mapped codes

From the final review of #985 (FE.5, FE.6 and the rest of
FD.4). MappedCodes now decides all of a document's mapped-code fields, and
replaces Concept.get_indexed_mappings:
- a row HEAD holds, or that no source version holds (a version only a
  collection holds), takes HEAD's mappings, as it did before
  #985. Such a row lost its
  mapped codes on reindex (FE.6).
- any other row takes the codes of the latest release that holds it, not the
  union of every release's (FE.5). A concept dropped from HEAD keeps its
  latest row, which no longer follows HEAD (FD.4).
- each other release whose codes differ gets its release_map_codes entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVSZwPgUucRdN8D9U9
…doc, scope $match filters, group entries

- F1.1: the backfill rewrites the mapped codes of every row the source's
  releases hold. Documents indexed before this carry HEAD's codes, and a row
  HEAD doesn't hold now takes its latest release's, with or without entries.
- F1.2: --source with --index is refused; the updates go to the concepts index.
- F1.3: $match in a release scopes its filters, so the kNN filters and a
  filter-only row read the release's codes too, not only the lexical clauses.
- F1.4: a fuzzy concept search in one source_version reads that version's codes.
- F1.5: the release facets keep FACET_SIZE buckets after merging.
- F1.6: releases with the same codes share one entry, whose version lists them,
  so a long release history doesn't repeat the same codes per release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVSZwPgUucRdN8D9U9
… codes, $match highlights entries, new releases drop stale entries

- F2.2: the versioned object and the latest version keep HEAD's codes as their
  own, since global search reads the latest version. A concept dropped from
  HEAD keeps its latest row's codes in entries, so its releases still find it.
- F2.3: $match in a release puts each lexical mapped-code clause's entry match
  in named inner hits, highlighted; CustomESSearch.get_highlight adds them to
  the hit's highlight under the field's own name, so bestMatch keeps the hit.
- F2.4: appending a new release's name to its members' docs also takes that
  name out of their entries. A release has HEAD's codes when made, so an entry
  naming it was left by a deleted release of the same name.
- F2.1, F2.5: a fuzzy search's source_version no longer selects the release
  whose codes it reads (back to F1.4 as accepted).
- F2.6: the kNN filter test checks the filter names v1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVSZwPgUucRdN8D9U9
…e id, viewable releases only, union kept for collection search

- F3.3 (and F2.4 at its root): entries name their releases by source version
  id, not name. A release made again under a deleted one's name has a new id,
  so no entry is stale, and the append script is back as it was: running a
  release's indexing again no longer drops its entries.
- F3.1: a search in a release (a version or latest) reads the release's codes
  only if the user can view it; otherwise each document's own, as before.
- F3.2: a fuzzy search no longer rewrites its mapped-code filters: it isn't
  scoped to the URL's source version.
- F3.4: a row only releases hold keeps the codes of every release that holds
  it as its own, as the base branch does, for collection searches; each release
  whose codes differ reads its own entry.
- $match resolves its release's id from the repo params, if exactly one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVSZwPgUucRdN8D9U9
…Codes and command, one test fewer

- S1: a row's own code key is computed once, not once per release.
- S2: MappedCodes doesn't guard an empty id list; the queries return nothing.
- S4: the command reads the expected mapping inline.
- S5: test_partial_updates_carry_the_entries goes; the command test covers
  partial updates that carry entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVSZwPgUucRdN8D9U9
…only in entries, fuzzy search in one viewable version

- FC.1: a row only releases hold takes its own fields from the public releases
  that hold it. A private release's codes are only in its entry, which a
  search reads only for a user who can view that release.
- FC.2: a fuzzy concept search that selects one source version with
  source_version, which the user can view, reads that version's codes by its
  id. The id names that version alone, so a URL naming another source's
  version of the same name changes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVSZwPgUucRdN8D9U9
…e rebuilds its rows' codes; fuzzy search back to each doc's own codes

- FC.5: when a release's public_access changes, the rows only releases hold
  (whose own fields take the public releases' codes) get their mapped codes
  rebuilt on the indexing queue, 5,000 ids a task.
- FC.4, FC.6: the fuzzy search rewrite for one source_version (FC.2) is
  removed. Fuzzy search reads each document's own codes, as it did before this
  PR (F1.4, accepted).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVSZwPgUucRdN8D9U9
…ebuild on commit; fuzzy test selects v1 too

- FC.7: the mapped-code rebuild after a release's access change is queued once
  the change commits, so the tasks read the new access.
- FC.10: the fuzzy search test also selects v1 with source_version and still
  gets only B.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVSZwPgUucRdN8D9U9
…D's active mappings

get_unidirectional_mappings filters is_active only for the versioned object and the latest version, so an older row that only a collection holds took the mappings HEAD had dropped too. Its own fields now take HEAD's active mappings, as HEAD's rows do. The test keeps one mapping and drops another.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qUwCLvLBDodjZbS2Yn
…e_as_map_codes, so a release reads its own

$match built its SAME-AS clause on same_as_mapped_codes, which no document has, so the clause matched nothing and the release rewrite skipped it. The clause now reads same_as_map_codes, the indexed field, which the Mapper already sends; same_as_mapped_codes is still read as the same input. In a release, the clause reads that release's codes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qUwCLvLBDodjZbS2Yn
@paynejd
paynejd force-pushed the ocl_online-703-release-search branch from 0793a72 to f98d947 Compare November 20, 2026 06:13

@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: request changes. One P2 remains in the rollout path. The backfill skips existing collection-only documents affected by the new indexing rule.

The two earlier code findings are fixed. Both SAME-AS input keys reach the release-scoped indexed field, and documents prepared for collection-only rows now exclude inactive mappings. GitHub reports that the branch merges cleanly with master.

Focused checks passed for both fixes and confirmed the backfill omission. I did not run the Django or Elasticsearch integration suites.

@staticmethod
def backfill(source):
"""Rewrites the mapped codes of the docs of every row `source`'s releases hold. Returns how many."""
concept_ids = sorted(set(Concept.sources.through.objects.filter(

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.

[P2] Backfill the collection-only rows that now read active HEAD codes. This query can only return members of source releases. An existing older concept row held by a collection alone can have empty mapped-code fields under the old indexing rule. The new MappedCodes branch would give that row its active HEAD codes, but running the documented --source backfill leaves the old fields in place. Include collection-held rows without release membership in the backfill, and extend the backfill test to assert that an already indexed collection-only row gains the retained code without regaining the dropped one.

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 ff19577. --source now also rewrites every older row of the source: every row except the versioned object and the latest version, whether or not a release holds it. That covers a row only a collection holds, and any older version nothing holds. Both read HEAD's active codes under the new rule and had none before. That's simpler than checking collections: the older rows a release holds were already in the backfill.

test_the_command_fills_a_collection_only_row sets up A's v3 row with no source version holding it, alongside M7 (kept in HEAD), M8 (dropped in v4) and M1/M5 (dropped in v2). It indexes the row as it was before this PR, with no codes, runs the command, and checks the doc reads (['X07'], []). Before the fix the doc stayed ([], []).

Cost: finding LOINC's older rows on production is one sequential scan of concepts; the planner estimates about 851k of them. Many are release rows the backfill already rewrote (814,844 for LOINC). I didn't count how many no release holds, because that would take another full scan on production.

…s and mappings are written together

A release is seeded in two writes, its concepts, then its mappings. A concept's search doc rebuilt between them saw the release hold the concept with no mappings, so it got an entry with no codes for that release, and the release's indexing, an append, kept it: a search in the release missed that concept's codes until another rebuild. The two writes are now one transaction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qUwCLvLBDodjZbS2Yn
…r rows too, so a collection-only row gets HEAD's active codes

--source rewrote only the rows the source's releases hold. An older row no release holds, such as a version only a collection holds, was indexed with no mapped codes before, and now takes HEAD's active ones, so the backfill rewrites every older row of the source as well. The test indexes such a row as before and checks it gains the code HEAD kept, not those HEAD dropped.

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

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 4 (codex-cli 0.169.0, commit f98d947)

New round after the rebase onto master and the fixes for the review at 0793a72. Previously accepted findings (F1.4/FC.2, F1.5, F1.6, F2.6, F3.5, FC.3, FC.8, FC.9) are unchanged.

Verdict: findings (3 P1, 1 P2 as Codex rated them)

  • F4.1 (P1, core/concepts/documents.py:107): a concept doc rebuilt between a new release's concept write and its mapping write gets an entry with no codes for that release, which the release's append indexing keeps.
  • F4.2 (P1, core/common/views.py:586): /latest/ now reads the newest release's codes, so a code HEAD added after that release no longer finds the concept there.
  • F4.3 (P1, core/concepts/search.py:147): the SAME-AS fix changes $match candidates against HEAD (a SAME-AS input now matches).
  • F4.4 (P2, core/common/views.py:592): with two sources whose names differ only in case, the release lookup is exact while the index's source filter isn't.

Responses

  • F4.1: fixed in d44bc9e. Real, though it needs a rebuild of that concept in the gap between the two writes; I'd call it P2. Seeding now writes a release's concepts and mappings in one transaction, so a rebuild sees both or neither. A HEAD edit inside that transaction, after the mappings were read, leaves the doc on HEAD's codes, which is how it worked before this PR. Test: a release whose mapping write fails keeps none of its concepts.
  • F4.2: by design, not changed. /latest/ is the newest release, and since OpenConceptLab/ocl_online#655 | Isolated source versions #985 its concept list shows that release's mappings, so its search matches that release's codes (the ticket's first criterion). The "results don't change" criterion covers HEAD, and a latest release whose codes equal HEAD's.
  • F4.3: intended, not changed. The reviewer asked for the SAME-AS input to reach the indexed field; it now counts in every $match, HEAD included, at the listed 0.1 boost. Before, a SAME-AS input never matched anything. It's stated in the PR body.
  • F4.4: predates this PR, not changed. The list view's source filter already lets a case-twin source's docs into the results on master. Those docs have no entry for the other release's id, so they match on their own codes as before.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "f98d9474",
  "verdict": "findings",
  "prior": [
    {
      "id": "F1.4",
      "status": "unresolved"
    },
    {
      "id": "FC.2",
      "status": "unresolved"
    },
    {
      "id": "F1.5",
      "status": "unresolved"
    },
    {
      "id": "F1.6",
      "status": "unresolved"
    },
    {
      "id": "F2.6",
      "status": "unresolved"
    },
    {
      "id": "F3.5",
      "status": "unresolved"
    },
    {
      "id": "FC.3",
      "status": "unresolved"
    },
    {
      "id": "FC.8",
      "status": "unresolved"
    },
    {
      "id": "FC.9",
      "status": "unresolved"
    }
  ],
  "findings": [
    {
      "id": "F4.1",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/documents.py",
      "line": 107,
      "claim": "A concept indexed during source seeding can keep an empty mapped-code override after the release finishes seeding.",
      "scenario": "HEAD concept A has an active mapping to X01. The async seed writes A's release membership before writing the release's mapping memberships. If an indexing worker rebuilds A in that interval, MappedCodes writes an empty override for the release. The subsequent source-version append preserves that override, so the completed release's search for X01 misses A until another rebuild.",
      "action": "Recompute release mapped codes after both membership writes and add an integration test that indexes a concept between them, then runs the normal release indexing path.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F4.2",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 586,
      "claim": "The mapped-code rewrite changes results on the `/latest/` alias when HEAD changes after the newest release.",
      "scenario": "Release v2 contains A and its mapping to X01. A stays unchanged while HEAD replaces the mapping with X02. Before the PR, `/latest/concepts/?q=X02` finds A through the shared document's HEAD codes. The rewrite scopes that request to v2 and removes A from the results. The alias tests use HEAD and newest-release fixtures with identical mapped codes.",
      "action": "Preserve the alias's existing mapped-code behavior while scoping named version URLs. Test a HEAD-only mapping edit after the newest release.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F4.3",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/search.py",
      "line": 147,
      "claim": "The SAME-AS fix changes `$match` candidates for an explicit HEAD target.",
      "scenario": "The Mapper submits `{ \"id\": \"A\", \"same_as_map_codes\": \"X03\" }` against HEAD, where X03 is a SAME-AS code for B. The base matches A by ID. The new priority list adds a live OR clause for X03, so B appears too. The new HEAD assertions encode the changed behavior.",
      "action": "Apply the corrected SAME-AS clause and alias handling to version-scoped matching while preserving HEAD's existing candidate set. Add a HEAD regression test with both an ID and a mapped code.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F4.4",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 592,
      "claim": "The release lookup and the Elasticsearch query can select different repositories when their names differ only in case.",
      "scenario": "An organization has public sources `LOINC` and `loinc`, each with a `v1`. A search on `/sources/LOINC/v1/concepts/?q=X01` resolves the exact-cased release for its override, but the normalized Elasticsearch source filter also admits documents from `loinc/v1`. Those documents have no entry for `LOINC/v1`, so a matching code in their own fields can appear in the other release's results.",
      "action": "Constrain the rewritten search to the exact owner and source used to resolve the release ID, using the existing exact-case index fields. Cover two public sources whose names differ only in case.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Rebased onto master (fb7c8e6). Replaying the nine release-search commits gave no conflicts, and their diff against master matches this PR's diff at 0793a72 apart from hunk offsets, so #985's final seeding changes (a59f88f) stay as they landed. The PR now merges cleanly.

Since then:

  • 4a2b177 and f98d947: your two P2s from the first review.
  • d44bc9e: Codex pass 4 (F4.1). Seeding now writes a new release's concepts and mappings in one transaction.
  • ff19577: your backfill P2.

Each has a reply on its thread, and pass 4 is in the comment above. Pylint is 10.00, and the full suite passed on f98d947 (3,463 + 663 OK). The run on ff19577 is in progress.

…HEAD's mappings refreshes the older rows no release holds

An older row no release holds, such as a version only a collection holds, reads HEAD's codes. A mapping edit through the API reindexes every row of the concept, but an import refreshed only the versioned object and the latest row, both for the mappings it imports and for those a seeding import drops. So the older row kept codes HEAD no longer has. Both paths now refresh those rows too (Concept.get_unreleased_older_ids). Rows a release holds keep their release's codes, as before.

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

@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: request changes. The backfill fix now includes older collection-only rows and deduplicates rows shared with releases. The atomic seeding change also closes the gap between writing a release's concept and mapping memberships. One P2 remains because those collection-only documents can become stale again on a later seed.

I checked the backfill and mapping-drop selectors against this head. Pylint passed. The CI test job was still running when I posted this review.

if concept.is_versioned_object or concept.is_latest_version or not releases:
# HEAD's active mappings: for an older row, get_unidirectional_mappings keeps those HEAD dropped
codes = to_mapped_codes(
concept.get_unidirectional_mappings().filter(is_active=True).values(*MAPPING_VALUES))

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.

[P2] Refresh collection-only rows when HEAD drops a mapping. After backfill, the older row in test_the_command_fills_a_collection_only_row has X07 in its top-level fields. If the next seed keeps A unchanged and drops M7, the mapping-drop refresh selects A's versioned object and latest row only. The older collection row keeps X07, so collection search can still match a code absent from HEAD after the indexing jobs finish. Include older rows with no source-release membership in the mapped-code refresh for affected concepts. Extend the regression test through a second seed that drops M7 and verify the existing indexed row loses X07 without another manual backfill.

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.

14561fb fixed the drop path (Source.index_dropped_children now also refreshes Concept.get_unreleased_older_ids). Its test only checked that the row was selected, so b83d400 extends test_the_command_fills_a_collection_only_row the way you asked. After the backfill gives the row X07, a second seed (v5) keeps A and drops M7. The test replays that seed's mapped-code refreshes as its indexing jobs would, without another backfill, and checks the doc now reads ([], []). With core/sources/models.py as it was at ff19577, the same test fails with (['X07'], []).

@paynejd

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 5 (codex-cli 0.169.0, commit ff19577)

Verdict: findings. F4.1 is resolved. F4.2, F4.3 and F4.4 remain as answered in pass 4. New findings: 2 P1 and 2 P2, as Codex rated them.

  • F5.1 (P1, core/sources/models.py:314): an older row no release holds reads HEAD's codes. An import that changes or drops one of HEAD's mappings refreshes only the versioned object and the latest row, so that older row keeps a code HEAD no longer has.
  • F5.2 (P1, core/collections/models.py:831): a collection reference that filters a pinned source release by a mapped code (q=X01) reads the shared doc's own codes, not that release's.
  • F5.3 (P2, core/mappings/views.py:357): deleting a mapping version doesn't refresh the concept docs, so a release's entry keeps the deleted mapping's code.
  • F5.4 (P2, core/common/views.py:586): a release published during a /latest/ request can make that one request use two different releases.

Responses

  • F5.1: fixed in 14561fb. A mapping edit through the API already reindexes every row of the concept. Imports, both the mappings they bring in and those a seeding import drops, now also refresh the concept's older rows that no release holds (Concept.get_unreleased_older_ids, an index scan on versioned_object_id). Rows a release holds keep their release's codes, as before. Test: after the collection-only row is indexed, a HEAD-only import that edits M7 queues it, and a seeding import that drops M7 refreshes it.
  • F5.2: not changed; out of this PR's scope. Collection searches and reference filters read each doc's own codes, as the PR body says under "Not in this PR". This isn't a regression: for a row HEAD shares, those codes were HEAD's before, and they still are. For a row only releases hold, they're now the public releases' codes. Scoping a reference's filter to its pinned release would be follow-up work.
  • F5.3: not changed. Only an admin can delete a mapping version, and on master that delete doesn't refresh concept docs either: HEAD's codes go stale the same way. Rerunning concept_release_map_codes --source repairs the docs.
  • F5.4: not changed. The window is one request racing a release being published. That request returns a mix of the two releases, and the next request is correct.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "ff19577f",
  "verdict": "findings",
  "prior": [
    {
      "id": "F4.1",
      "status": "resolved"
    },
    {
      "id": "F4.2",
      "status": "unresolved"
    },
    {
      "id": "F4.3",
      "status": "unresolved"
    },
    {
      "id": "F4.4",
      "status": "unresolved"
    },
    {
      "id": "F1.4",
      "status": "unresolved"
    },
    {
      "id": "FC.2",
      "status": "unresolved"
    },
    {
      "id": "F1.5",
      "status": "unresolved"
    },
    {
      "id": "F1.6",
      "status": "unresolved"
    },
    {
      "id": "F2.6",
      "status": "unresolved"
    },
    {
      "id": "F3.5",
      "status": "unresolved"
    },
    {
      "id": "FC.3",
      "status": "unresolved"
    },
    {
      "id": "FC.8",
      "status": "unresolved"
    },
    {
      "id": "FC.9",
      "status": "unresolved"
    }
  ],
  "findings": [
    {
      "id": "F5.1",
      "severity": "P1",
      "tag": null,
      "file": "core/sources/models.py",
      "line": 314,
      "claim": "An isolated import can leave obsolete HEAD mapping codes searchable on a concept version held only by a collection.",
      "scenario": "The backfill gives a pinned older row code X07 from an active HEAD mapping. The next isolated import keeps the concept and drops that mapping. The drop job updates the versioned object and latest row, so the pinned row keeps X07 and collection search still returns it after indexing finishes.",
      "action": "Include older rows with no release membership in mapped-code refreshes for affected concepts. Cover an import that drops a mapping after a collection-only row has been indexed.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F5.2",
      "severity": "P1",
      "tag": null,
      "file": "core/collections/models.py",
      "line": 831,
      "claim": "A collection reference that filters concepts within a specific source release still searches the shared document's mapped codes.",
      "scenario": "An editor pins an intensional reference to v1 and filters it with q=X01. The unchanged concept A maps to X01 in v1, and HEAD later drops that mapping. The reference correctly limits candidates to v1's concept rows, but the Elasticsearch query reads the shared document's top-level fields and omits A from the expansion.",
      "action": "Pass the resolved, viewable source version into the reference's concept filter and apply the release query rewrite. Test a mapped-code filter against a pinned release after HEAD drops the mapping.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F5.3",
      "severity": "P2",
      "tag": null,
      "file": "core/mappings/views.py",
      "line": 357,
      "claim": "Deleting a mapping version can leave its code searchable in a release.",
      "scenario": "Release v1 has an indexed override for X01 because HEAD dropped that code. An admin soft-deletes the mapping version held by v1. The release's mapping list excludes the inactive mapping, but the delete only saves the mapping row and never refreshes the concept document. Searching v1 for X01 still finds the concept.",
      "action": "After a mapping-version deletion commits, refresh mapped-code fields for the affected concept rows in releases that held the mapping. Add a regression test through the delete endpoint.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F5.4",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 586,
      "claim": "A release published during a `/latest/` request can make that request use two different releases.",
      "scenario": "A search builds its membership filter while v1 is latest. Before `map_codes_release` resolves the alias again, v2 becomes latest. If only v2 maps shared concept A and new concept B to X02, the search can return just A by applying v2's mapped codes to v1's members. The correct result is empty for v1 and A plus B for v2.",
      "action": "Resolve `/latest/` once per request and reuse the same source version for permissions, membership filters, mapped-code clauses, and facets.",
      "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.

Verdict: approve. I reviewed the full discussion, including the pass 5 findings and responses. The outstanding collection-only refresh issue is fixed. The normal import and seeding-drop paths both refresh older rows with no source-release membership, and the regression test checks that both paths select the affected row. The shared selector excludes older rows held by a release so they retain their release-specific codes.

I found no new merge blocker in this revision. I left a non-blocking inline suggestion to make the backfill help match its current scope. Focused selector checks passed. CI was still in progress on this head when I posted, and I did not run the integration suites locally.

Comment on lines +31 to +32
help="A source's URL, such as /orgs/Regenstrief/sources/LOINC/, whose release docs to rewrite. "
"Repeatable; not with --index.")

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.

Non-blocking suggestion. The option help still says it only rewrites release docs. Include the older rows so operators can see the scope before running the backfill.

Suggested change
help="A source's URL, such as /orgs/Regenstrief/sources/LOINC/, whose release docs to rewrite. "
"Repeatable; not with --index.")
help="Rewrite mapped codes for release members and older concept rows of this source. "
"Use the source URL, for example /orgs/Regenstrief/sources/LOINC/. "
"Repeatable. Do not combine with --index.")

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 in 0952f28.

paynejd and others added 3 commits November 20, 2026 01:45
…ps M7 through to the collection-only row's doc

After the backfill gives the collection-only row X07, the next seed keeps A and drops M7. The test now runs that seed's mapped-code refreshes and checks the doc loses X07 with no second backfill. The import test keeps the HEAD-only import path, and one fixture helper builds an edited A.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qUwCLvLBDodjZbS2Yn
… read each doc's own codes, as its hits do

A fuzzy search in a release matches each doc's own codes, but its facets came from the release's codes, so they could offer a map type no hit has. A fuzzy request now isn't scoped to the release at all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qUwCLvLBDodjZbS2Yn
… rows it also rewrites

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

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

After your approval at 14561fb I pushed three commits:

  • b83d400 (tests only): your second-seed check, on the thread at documents.py:99.
  • a87f61b (one line, plus a test): Codex pass 6 F6.2. A fuzzy search in a release matched each doc's own codes, but its facets came from the release's codes, so they could offer a map type no hit has. map_codes_release now returns None for a fuzzy search, so its facets read the same codes as its hits. This is the only behaviour change since your review.
  • 0952f28: your help text.

Pass 6 and the final check of these commits are in the comments below.

@paynejd

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 6 (codex-cli 0.169.0, commit 14561fb)

Verdict: findings. F5.1 is resolved. F5.2, F5.3 and F5.4 remain as answered in pass 5. New: 2 P1, as Codex rated them. This was the third and last pass of this round.

  • F6.1 (P1, core/common/tasks.py:457): a HEAD mapping whose from_concept is an older version of A. The release's lookup (by versioned object) has its code, but the latest row's doc (HEAD's lookup) doesn't, and publishing only appends release membership, so the release search misses it.
  • F6.2 (P1, core/common/views.py:630): a fuzzy search in a release matches each doc's own codes, but its facets came from the release's codes, so a facet could offer a map type (NARROWER-THAN from A's v1 entry) that no hit has.

Responses

  • F6.1: not changed; it predates this PR. On master, the latest row's doc takes get_unidirectional_mappings() (Concept.get_indexed_mappings), which this PR doesn't change. That lookup matches only mappings from the row itself, its versioned object or the latest row, so a mapping from an older version was already missing from the doc, and HEAD and every release missed its code. A probe reproduced this: with a mapping from A's v1 row to X09, the latest row's lookup returned [] and the lookup by versioned object returned ['X09']. A rebuild or --source now gives the release an entry for it. HEAD's own lookup is left for follow-up work.
  • F6.2: fixed in a87f61b. A fuzzy request isn't scoped to the release, so its facets read each doc's own codes, as its hits do. Test test_a_fuzzy_searchs_facets_read_the_docs_own_codes failed before the change (['SAME-AS', 'NARROWER-THAN']) and passes after.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "14561fb4",
  "verdict": "findings",
  "prior": [
    {
      "id": "F5.1",
      "status": "resolved"
    },
    {
      "id": "F5.2",
      "status": "unresolved"
    },
    {
      "id": "F5.3",
      "status": "unresolved"
    },
    {
      "id": "F5.4",
      "status": "unresolved"
    },
    {
      "id": "F4.1",
      "status": "resolved"
    },
    {
      "id": "F4.2",
      "status": "unresolved"
    },
    {
      "id": "F4.3",
      "status": "unresolved"
    },
    {
      "id": "F4.4",
      "status": "unresolved"
    },
    {
      "id": "F1.4",
      "status": "unresolved"
    },
    {
      "id": "FC.2",
      "status": "unresolved"
    },
    {
      "id": "F1.5",
      "status": "unresolved"
    },
    {
      "id": "F1.6",
      "status": "unresolved"
    },
    {
      "id": "F2.6",
      "status": "unresolved"
    },
    {
      "id": "F3.5",
      "status": "unresolved"
    },
    {
      "id": "FC.3",
      "status": "unresolved"
    },
    {
      "id": "FC.8",
      "status": "unresolved"
    },
    {
      "id": "FC.9",
      "status": "unresolved"
    }
  ],
  "findings": [
    {
      "id": "F6.1",
      "severity": "P1",
      "tag": null,
      "file": "core/common/tasks.py",
      "line": 457,
      "claim": "Publishing a release can leave it unable to find mappings linked to an older concept version.",
      "scenario": "Edit concept A, then add a HEAD mapping to X01 using the first version of A as `from_concept_url`. Let indexing finish before publishing v1. The release holds A's newer row and the mapping. The release's mapping lookup follows A's versioned object ID and returns X01, but the newer row's existing document has no X01 because HEAD's lookup excludes the older row. Publication only appends release membership, so v1 search still misses A until the document is rebuilt.",
      "action": "Refresh mapped codes for release members whose release mappings differ from their existing document fields during publication. Add a regression test that indexes the concept before publishing and searches the release after the normal indexing job.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F6.2",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 630,
      "claim": "A fuzzy release search can advertise a mapped-code facet that produces no results.",
      "scenario": "In the release fixture, search v1 with `fuzzy=true`, `q=name`, `source_version` pointing to v1, `target_repo` set to ICD-10, and `IncludeFacets: true`. The results contain only B because fuzzy search reads the document's own codes. The facets use v1's overrides and advertise `NARROWER-THAN` from A. Adding `target_repo_map_type=NARROWER-THAN` returns no fuzzy hits.",
      "action": "Build the mapped-code facets for fuzzy requests from the same query and document fields as the fuzzy hits. Test the results and facets together in one response.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits 14561fb..0952f28 (codex-cli 0.169.0, commit 0952f28)

Verdict: findings (1 P1, as Codex rated it)

  • FC.10 (P1, core/common/views.py:586): with a87f61b, the facets of a fuzzy request come from the regular query, which reads each doc's own codes again. A code-only query (q=X03&fuzzy=true in v1) counts B through HEAD's X03 while the fuzzy hits, on names and synonyms, return nothing.

Response: not changed; it predates this PR. On master, get_facets builds a fuzzy request's facets from the regular search, not the fuzzy one, so this happens there too. a87f61b makes a fuzzy request in a release behave as on master throughout. Building a fuzzy request's facets from its fuzzy query would be a separate change to search.

findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "0952f284",
  "verdict": "findings",
  "prior": [
    {
      "id": "F6.2",
      "status": "regressed"
    }
  ],
  "findings": [
    {
      "id": "FC.10",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 586,
      "claim": "Fuzzy facets can count concepts that the fuzzy hit query cannot match. The new guard removes release scoping from the regular query used to select documents for facets, so that query can now match a code added after the release.",
      "scenario": "In the LOINC fixture, B belongs to v1 but gains the mapped code X03 in v2. Request v1 concepts with `q=X03&fuzzy=true` and `IncludeFacets: true`. The fuzzy hit query searches names and synonyms and returns no concepts. The facet query now matches B through its HEAD code X03 and reports a SAME-AS bucket that was empty before this change.",
      "action": "Use the fuzzy hit criteria to select documents for fuzzy facets, preserving the requested release filter and the document-level mapped-code aggregations. Add a test for a query that matches only a mapped code.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@snyaggarwal
snyaggarwal merged commit 11a2766 into master Nov 23, 2026
3 checks passed
@snyaggarwal
snyaggarwal deleted the ocl_online-703-release-search branch November 23, 2026 03:24
paynejd added a commit that referenced this pull request Nov 23, 2026
…earch and cascade-scope branch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWTbiSiJ56vAgWwb9D
paynejd added a commit that referenced this pull request Nov 23, 2026
…MappedCodes' fields, and runs are time-boxed

Review changes after merging master (#1010 moved concept mapped
codes into MappedCodes):
- The latest-flags update sends everything MappedCodes.get_fields gives a row,
  release_map_codes included, built once per batch. get_latest_flags_fields takes the
  batch. A version only a private release holds then keeps that release's codes in
  release_map_codes once an import supersedes it.
- A run indexes for at most 5 minutes, then queues the next run behind the indexing
  tasks queued meanwhile, so the window no longer holds an indexing slot throughout.
- A run renews its lock only while the lock still holds its token, and stops once it
  doesn't.
- A window shorter than the 10 minutes between beat runs pauses the job and logs an
  error, as a value that doesn't parse does.

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