Skip to content

OpenConceptLab/ocl_online#655 | Isolated source versions - #985

Merged
snyaggarwal merged 9 commits into
masterfrom
ocl_online#655
Nov 20, 2026
Merged

snyaggarwal merged 9 commits into
masterfrom
ocl_online#655

Conversation

@snyaggarwal

@snyaggarwal snyaggarwal commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

OpenConceptLab/ocl_online#655, OpenConceptLab/ocl_online#672

What this does

This adds source versions seeded from an import, for publishers like LOINC who release each version as a complete, standalone artifact. Today every new version carries HEAD forward. A version seeded from an import instead makes HEAD exactly what the release contains, and then snapshots that HEAD.

You start one with seed_from_import=true on POST /importers/bulk-import/ or /importers/bulk-import-parallel-inline/. The import must contain the content, then exactly one Source Version line. It works with the JSON-lines and zip importers; npm imports are refused.

  • Checked first: before anything imports, the version line is checked: exactly one, after the content, a valid mode, a version that doesn't exist yet and edit access to the source. A failed check rejects the whole import.
  • Order: concepts and mappings import first, and the Source Version line runs last. The version is created only if no content failed. If some content fails, what did import stays on HEAD, but nothing is dropped.
  • One commit step for every path. IsolatedVersionCommit does the last step for the inline, parallel and zip/tar runners. It replaces HEAD's hierarchy, drops what the import didn't contain and creates the version in one transaction. If the commit is rejected (a validation error, or the hierarchy root would be dropped), the hierarchy and HEAD membership stay as they were. After the commit, retried tasks on the indexing queue (index_dropped_source_children, one per 5,000 ids) reindex the dropped codes and recount HEAD. Each Task saves its arguments, so it can be rerun, and shows a final failure. A parallel part that failed or has no result blocks the version.
  • The switch alone decides. seed_from_import=true makes the import seed the version; the Source Version line has no mode key. The zip importer reads the Source Version lines (only those) while it counts resources, so the line is checked before anything imports.
  • Hierarchy: HEAD's parent links are rebuilt from the import's parent_concept_urls and replace the old links, not add to them. A parent change forces a new concept version. ImportHierarchy resolves the links once into ids, then adds the latest-version links and replaces HEAD's links 5,000 children at a time. The parallel runner and the make_hierarchy task use it too.
  • Codes the release doesn't contain are dropped from HEAD. They aren't retired: the versioned object goes inactive and leaves HEAD's membership. Older versions keep their pinned rows. A code that comes back later is revived on the same versioned object. The hierarchy root can't be dropped.
  • No inheritance: a new concept or mapping version takes extras, external_id, datatype, sort_weight and the retire fields from the import, not from its previous version.
  • Metadata: the metadata fields the Source Version line sets overwrite HEAD's. Fields it leaves out keep HEAD's value. The version then copies HEAD as usual. The ticket's spec was updated to match.
  • Recording the seed: each version has a read-only seeded_from. A version made from HEAD records {"type": "repo_version", "url": ".../HEAD/"}, and one seeded from an import records {"type": "import", "task": "<import task id>"}. HEAD records the version an import last re-seeded it from, and is otherwise null. Migration 0047 added a versioning_mode column; 0048 replaces it with seeded_from and backfills it: existing versions as seeded from HEAD, or from an import where 0047 recorded one.
  • Version views: children/ and parents/ show the requested version's own members.

Changelog compare on large diffs

A 2.81 → 2.82 compare ran out of memory, and once it fit in memory, its result (1.4 GB) was over Postgres's 1 GB jsonb limit.

  • Changelog enrichment now loads concepts 1,000 at a time and loads only the mapping fields the summary uses.
  • Mappings are loaded per batch too. Between batches the changelog keeps only mapping ids. Display names for mapping-only changes come from one query per batch, with names prefetched.
  • Above CHANGELOG_ENRICHMENT_MAX_RESOURCES (default 50,000 new, removed or changed resources), a changelog skips names, descriptions and prev_*, and sets meta.enrichment_skipped.

Also fixed

  • Zip importer: numbers came through as Decimal (ijson), so any concept with a number in extras failed to save.

Behaviour changes to be aware of

  • HEAD is no longer append-only for sources that use import-seeded versions. A code can leave HEAD without being retired, so GET on HEAD returns 404 for it while older versions still have it.
  • Other sources' mappings to a dropped concept keep their FK, but the target is inactive.
  • Collection references to HEAD or the latest version re-resolve without dropped codes. Pinned references are unaffected.
  • HEAD metadata edits made between releases are overwritten by the next import-seeded version.
  • Deleting an import-seeded version doesn't restore HEAD.

Testing

  • New tests in core/importers/tests.py and core/integration_tests/tests_sources.py:
    • import-seeded v1 → v2 → v3: drop, revive, no inheritance, metadata overwrite;
    • a rejected version leaving HEAD, the hierarchy and search untouched;
    • an existing version or missing edit access rejected before any content imports;
    • a failed search update after the commit not undoing the version, and the repair being queued in chunks of retried, rerunnable tasks;
    • a failed or missing parallel part blocking the version;
    • the zip look-ahead reading only Source Version lines, of any JSON type;
    • mode conflicts rejected before anything imports;
    • parent replacement;
    • version-scoped children and parents;
    • hierarchy root guard;
    • zip and inline runners;
    • changelog batching and the enrichment skip.
  • pylint: pylint -j0 core/ exits 0.
  • Focused tests: core.importers core.sources core.integration_tests.tests_sources core.common core.concepts core.mappings ran 1,224 tests. BulkImportLimitsTest.test_grandfathered_npm_url_is_downloaded_and_handed_over_as_upload fails, as it does on master. A few tests that share the local ES fail only in parallel runs and pass on their own.
  • Local LOINC import: 2.82 was imported as an import-seeded version on top of 2.81, and the result was checked row by row against the release files.
    • All 252,212 concepts and 192,208 mappings match.
    • HEAD equals 2.82, its 252,969 parent links match the release, and 2.81 is unchanged.
    • ES is fully reindexed with vectors.
    • Details are on the ticket.

Not in this PR

  • API version create always seeds from HEAD; versions seeded from an import come from imports only, as decided on the ticket. seeded_from can't be set in a request.
  • Counts of what a version adds or no longer includes (OpenConceptLab/ocl_online#674, Bump boto3 from 1.24.28 to 1.34.94 #675).
  • Imported versions don't take HEAD's match_algorithms.
  • New mappings without an id are slow: each runs a MAX(mnemonic) scan, 2–6 s each.
  • The import status API returns 500 after a chord member dies.

The frontend part, showing the versioning mode in version details, is in OpenConceptLab/oclweb3 on the branch of the same name.

🤖 Generated with Claude Code

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Findings

  • [P1] Failure atomicity: hierarchy and HEAD membership can change before version persistence completes, so a failed version write can leave partially applied data. The parallel import path also reconciles hierarchy after rejecting a version line. Specific locations and remediation are on the linked tracker issue: OpenConceptLab/ocl_online#655.
  • [P2] Mode selection: the workflow path and the persisted mode can diverge when the request flag and Source Version line disagree. Details and expected behavior are on OpenConceptLab/ocl_online#655.
  • [P3] OOP / duplicated logic: isolated-version orchestration is implemented separately in the inline, parallel JSON-lines, and archive subtask paths. Consolidating validation, hierarchy reconciliation, and sweep coordination into a shared importer service would prevent their current behavior from drifting; see OpenConceptLab/ocl_online#655 for the concrete differences.

I found no additional P4/P5 findings or nits.

@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Addressed in 308432d:

  • [P1] Failure atomicity. The new IsolatedVersionCommit replaces HEAD's hierarchy, drops what the import didn't contain and creates the version in one transaction, so a rejected version rolls all of it back.
    • It checks content failures, an existing version, edit access and the mode before it opens the transaction.
    • Search and count updates for dropped codes now run on commit.
    • The parallel runner no longer reconciles the hierarchy in isolated mode: the commit owns it, so a rejected version leaves it untouched.
    • Tests cover a failed version save, the hierarchy-root guard, an existing version and missing edit access.
  • [P2] Mode selection. isolated_version decides the mode, and Source.resolve_versioning_mode is the one place that checks a line's versioning_mode against it. A conflicting line rejects the whole import before anything runs: up front in the inline and parallel runners, and while counting resources in the zip importer. SourceVersionImporter applies the same rule to any line that reaches it, and the version records the resolved mode.
  • [P3] Duplicated orchestration. All three runners now hand their version line, hierarchy map, seen ids and content-failure count to IsolatedVersionCommit.

pylint is clean. The isolated-version tests pass with Redis unreachable, and the focused suite has only the BulkImportLimitsTest failure that is also on master.

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Second review

The prior hierarchy/sweep/version transaction finding and duplicated orchestration finding are addressed. Remaining/new findings:

  • [P1] Post-commit ordering can leave a committed version unseeded. The fallible indexing callback is registered before the version-seeding callback; if indexing raises, later callbacks do not run and the import can report failure after the DB commit.
  • [P1] A rejected final version still leaves earlier content imports on HEAD. The shared transaction starts after concept/mapping tasks have committed, and the existing-version test only reimports unchanged content.
  • [P2] Mode resolution still differs from the linked requirement. The request flag is authoritative instead of the Source Version line/HEAD default, and API version creation still ignores the requested mode.
  • [P2] Omitted isolated metadata is inherited. The implementation and test retain fields such as website, while the linked requirement says missing payload metadata is cleared.
  • [P2] Archive look-ahead scans every string versioning_mode field and skips non-string values. This can reject a valid archive because of a Source line or defer an invalid Source Version value until after content imports.

Full reproductions and suggested fixes are on OpenConceptLab/ocl_online#655. No additional P3-P5 findings or nits.

@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Second review addressed in a5a1fd7. Details are on OpenConceptLab/ocl_online#655.

  • [P1] Post-commit ordering: fixed. The search and count update for dropped codes is a robust on_commit callback, so a failure there no longer stops the version's seeding. A regression test covers it.
  • [P1] A rejected version left content on HEAD: an isolated import now preflights the version line before any content imports. That checks the id, that the version doesn't exist yet, the mode and edit access. It runs on all three paths. Content that imports before a later content failure or a commit failure still stays on HEAD, and the ticket and the PR text now say so.
  • [P2] Mode resolution and [P2] omitted metadata: no code change. Both are human decisions, now written into the ticket's spec.
  • [P2] Archive look-ahead: fixed. Only Source Version lines are read, and a non-string versioning_mode is rejected before any content imports.

Comment thread core/sources/models.py Resolved
Comment thread core/concepts/models.py Resolved
Comment thread core/common/checksums.py Resolved
Comment thread core/importers/importer.py Resolved
Comment thread core/importers/models.py Resolved

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Third-round review

The earlier rejection/transaction and callback-order findings are addressed in the current head. This pass found one remaining reliability blocker plus four performance/architecture issues in the new large-import paths. Each finding is posted inline with reproduction impact and a concrete remediation.

Summary: 1× P1, 3× P2, 1× P3. No additional P4/P5 findings or nits.

@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Third review addressed in da8dc58.

  • [P1] Search repair was log-only: fixed. After the commit, drop_unseen_children queues index_dropped_source_children on the indexing queue with the source and the dropped ids. A Task record tracks it, so a final failure shows there. It retries with backoff (5 retries, up to 10 minutes apart), reindexes the dropped concepts and mappings, and recounts HEAD. Queuing is still a robust on_commit callback, so it can't stop the version's seeding. New tests check that the task is queued with the right ids and Task, and test its retry settings and what it runs.
  • [P2] Hierarchy resolved three times: fixed. The new ImportHierarchy resolves every child and parent URI once and checks access once. It keeps only versioned-object ids, then works 5,000 children at a time. In each chunk it adds the latest-version links and either adds or replaces HEAD's links. reconcile_import_hierarchy, the parallel runner and the make_hierarchy task all use it, so the separate graph-building in make_hierarchy and replace_versioned_object_hierarchy is gone. A test checks that the URIs are resolved only once. The tests that used to mock make_hierarchy now check the stored links.
  • [P2] Changelog mappings unbounded: fixed. The mapping index holds (mnemonic, id) pairs only. Mappings, and their v1 rows when enriching, are fetched per concept batch and per mapping batch, then dropped. Display names for changed_mappings_only come from one query per batch, with names prefetched and each source loaded once. The existing batch-of-one changelog test now runs the mapping side in batches of one too.
  • [P2] Version worker held every result: fixed. The archive path reads earlier subtask results one task at a time (iter_previous_results). Each is folded into the seen ids and a failure count, then dropped. I kept one status per resource in the subtask results, because the import summary counts them.
  • [P3] Results read three times: fixed. IsolatedVersionCommit.add_runner_result and add_subtask_results fold each result in a single pass. The parallel runner and the archive path both use them, in place of the three separate walks.

pylint -j0 core/ exits 0. The focused suite ran 1,224 tests. The only failure is the BulkImportLimitsTest npm test, which also fails on master. A few tests that use the local ES fail in parallel runs and pass on their own. ConceptPropertyFilterViewTest fails locally both with and without these changes.

Comment thread core/importers/models.py Resolved
Comment thread core/sources/models.py Resolved
Comment thread core/sources/models.py Resolved

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verdict: Request changes

Reviewed current head d9d8091e. The five findings from the prior round are materially addressed, including the hierarchy consolidation, batched changelog/import aggregation, and retryable dropped-code indexing.

Remaining/new findings:

  1. P1 — failed or missing parallel child results are ignored. The version can still be committed and unseen HEAD content swept after a child task failure.
  2. P2 — dropped-code repair arguments are not persisted. The stranded-task/manual rerun path requeues the repair without its required arguments.
  3. P3 — the repair uses one unbounded Celery payload. A large replacement can send hundreds of thousands of IDs in one broker message.

I left detailed inline comments with concrete remediations and regression cases. No additional P4/P5 findings or nits.

Verification: 55 focused tests passed (IsolatedVersionImportTest, IsolatedVersionZipImportTest, BulkImportParallelRunnerTest, and SourceVersionsChangelogOutputViewTest). The P1 failed-child scenario and replayability of the repair task are not covered by those tests.

@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Fourth review addressed in 76f0a23.

  • [P1] Failed or missing parallel parts were ignored: fixed. Before committing, the parallel runner checks every part. A part that didn't succeed, or whose result is missing, expired or not a result dict, counts as a content failure. The version is then refused, and nothing is dropped or swept. The archive path already counted these. A new test covers a part that raised and a part whose result is missing: no version is created and HEAD keeps its codes.
  • [P2] Repair arguments weren't saved: fixed. Each repair Task now stores its arguments and the registered task name when it's created, and is queued with persist_args=True. A rerun from the stranded-indexing sweep, or by hand, gets the original arguments. If queuing fails, the Task is marked failed with the error, so it can still be rerun. New tests check the saved arguments, and that a Task that couldn't be queued reruns with them.
  • [P3] One unbounded payload: fixed. The repair is queued as one Task per 5,000 concept ids and 5,000 mapping ids. The first chunk also recounts HEAD; counts come from the database, so the order doesn't matter. A test checks the chunking.

pylint -j0 core/ exits 0. The isolated-version, zip and parallel runner tests pass with Redis unreachable. In the focused suite, the only failures are the BulkImportLimitsTest npm test, which also fails on master, and LoadFixturesCommandTest, which fails only in parallel runs.

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verdict: Approve

Reviewed current head 76f0a239. The three findings from the previous round are addressed:

  • failed, lost, or missing parallel parts now block the isolated-version commit and preserve HEAD;
  • dropped-code repair tasks persist their arguments and leave a replayable failed task when enqueueing fails;
  • repair work is split into bounded 5,000-ID chunks, with HEAD recounted once.

I found no new P1-P5 findings or nits in this round.

Verification:

  • 58 focused isolated-import, archive, parallel-runner, hierarchy, and changelog tests passed;
  • targeted pylint passed at 10.00/10;
  • GitHub Tests, Pylint, and Snyk checks are green.

@snyaggarwal

Copy link
Copy Markdown
Contributor Author

ab81129f renames this PR's new field and import switch before they become public API (OpenConceptLab/ocl_online#672). What the import does hasn't changed.

  • seeded_from replaces versioning_mode. Each version records what it was seeded from, once, when it's created:

    • a version made from HEAD: {"type": "repo_version", "url": "/orgs/<org>/sources/<source>/HEAD/"};
    • a version seeded from an import: {"type": "import", "task": "<import task id>"}. The zip/tar path now passes the import's task id to its version subtask;
    • HEAD: the version an import last re-seeded it from, otherwise null.

    It's read-only: a seeded_from sent to version create is ignored.

  • seed_from_import=true replaces isolated_version=true on both import endpoints. The Source Version line no longer takes versioning_mode, and an old isolated_version=true is ignored.

  • Migration 0048_source_seeded_from adds seeded_from, backfills it, then removes versioning_mode. Existing versions are recorded as seeded from HEAD, or from an import where 0047 recorded one. A dry run on a local copy of LOINC, rolled back afterwards, gave 2.81 seeded from HEAD, 2.82 seeded from an import, and HEAD re-seeded from 2.82.

The names are the proposed ones and may still change after the decisions on OpenConceptLab/ocl_online#671. oclweb3#97 shows the seed as "Seeded From" (e144c20, with a lint fix in 01a2fc4).

Testing: pylint -j0 core/ exits 0 and makemigrations --check finds no missing migrations. The tests haven't run locally because the local search service is down, so this CI run is their first on this change. In oclweb3, npm test passes 125 tests and eslint src is clean.

@paynejd paynejd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Claude review, pass 2, with a Codex check (commit b14c5f0)

Verdict: fix-first. The rename in ab81129f and b14c5f0f does what D1 to D4 recommend, and I found nothing wrong with it on the main paths. The two P1s below come from the first review, at 76f0a239, which we held back until the version model was settled, so this is the first time they're posted. Your design page lists "Review P1s on #985" as approved; these two are still open. Neither commit touches the code they point at, and both still reproduce at b14c5f0f. That page and this PR's description both say version-scoped children/ and parents/ work, but through the API they don't (item 1).

Fix before merge

  1. [P1] core/concepts/views.py:626 (and the parents view): is_source_version() reads parent_resource, which these views never set, so it's always False. /sources/S/<version>/concepts/X/children/ is answered from HEAD's links, and H4 isn't delivered. Probe at b14c5f0f: v1 to v3 each with P, A and B (A and B children of P), then v4 with P and A. children/ of P returns A and B on all four versions, though v4 holds only A. The model method alone returns only A. The PR's API test passes because HEAD gives the same answer in its case. @snyaggarwal: resolve the repo version from the URL before branching, and add a test where a version differs from HEAD. The HEAD fallback was already there before this PR.
  2. [P1] core/concepts/models.py:1419: after an import drops a child, the parent's HEAD children/ still lists it, and opening it gives a 404. The sweep removes the dropped concept's own links but keeps the links its version rows hold (H3), and the HEAD lookup returns them without an active or membership filter. Same probe: B is 404 on HEAD, yet HEAD P/children/ returns A and B. Filter HEAD hierarchy lookups to active HEAD members in get_hierarchy_related_queryset. With oclapi2#990 merged, get_viewable_hierarchy_concept_urls wraps that lookup, so it gets the fix too.

Not blocking

  • [P2] core/importers/models.py:1160: mappings nested in a Concept line are created but not recorded as seen, so the sweep drops them while the import reports success. Probe at b14c5f0f: the version and HEAD end with 0 mappings. LOINC doesn't nest mappings. Track their ids, or reject nested mappings when seed_from_import=true. (Codex rated this P1 in pass 1.)
  • [P2] core/importers/models.py:458: the dropped counts are returned and thrown away, so the import result never says how many concepts and mappings left HEAD. Probe at b14c5f0f: a file with concepts but no mapping lines made a version with 0 mappings and no error. This is behaviour 6 on the Decisions tab.
  • [P2] New in this pass: seed_from_import=true on the deprecated /importers/bulk-import/upload/ and /importers/bulk-import/file-url/ is accepted, then dropped. queue_bulk_import passes the switch only to inline tasks, and bulk_import doesn't take it. The file runs as a plain import and returns 202: its Source Version line makes a version from HEAD, and nothing is dropped. Neither endpoint lists the switch in Swagger, but import_response validates it there. Reject it with a 400 on the non-inline path, as npm imports are; there are three one-click suggestions for this inline, plus a test that expects the 400. This was already the case before the rename.
  • [P2] core/importers/models.py:369: outside tests, a queued task copies the version's membership from HEAD, so a change to HEAD before it runs changes the release. Tests seed at once in TEST_MODE. The pattern predates this PR, but the sweep makes it worse. Snapshot membership in the commit transaction, or refuse a new seeding import while the previous version is still processing.
  • [P2] core/importers/models.py:456: two seeding imports into one source can run at once, and the first commit's sweep drops what only the second sent. A per-source reservation from preflight to commit would stop it.
  • [P2] core/mappings/models.py:425: a seeding import's mapping update keeps relation-derived text, such as to_concept_name, when the release line leaves it out. LOINC lines carry no names, so LOINC isn't affected.
  • [P3] core/concepts/models.py:1272: seeding imports still queue the per-concept hierarchy task, and a late one could write old parents over a newer commit. You noted on the ticket that you'd skip them.
  • [P3] core/concepts/models.py:1461: the new hierarchy resolver skips a parent URL that names a concept version, which the old make_hierarchy accepted. Not reproduced on the inline runner, and the parallel runner isn't covered by tests. Codex now rates it P2.
  • [P3] New: core/common/tasks.py:285: the deprecated /importers/bulk-import-inline/ honours the switch, but bulk_import_inline isn't bound, so its version records {"type": "import", "task": null}. A TODO in queue_bulk_import says that task can't be reached, but BulkImportInlineView reaches it with threads=None. Bind the task and pass self.request.id (one-click suggestion inline). Codex rates this P1; I don't, because only the audit id is missing.
  • [P3] New: core/sources/models.py:243: get_version_url rebuilds a version's URL from its label. Use the new version's own uri, which is the same string today, so the seed and the version's own URL can't drift apart.
  • [P3] New: 0047 adds versioning_mode and 0048 removes it. Neither has shipped, so folding them into a single migration that adds seeded_from drops the round trip, and the reverse-migration gap Codex found in 0048 with it. Do it unless a shared database (staging?) already ran 0047. oclapi2#955 also adds a sources 0047; whichever merges second renumbers.

The rename (ocl_online#672). Each case below was probed at b14c5f0f:

  • An import-seeded version records {"type": "import", …}, and HEAD records that version, as D4 recommends.
  • POST …/versions/ records HEAD and ignores a seeded_from in the payload.
  • PUT on a version can't change it.
  • HEAD keeps its seed through later versions made from HEAD.
  • The HEAD and version details return seeded_from and no versioning_mode.
  • A Source or Source Version import line can't set it, since neither importer's allowed_fields includes it.
  • The inline, parallel and zip/tar runners pass the import task id. The deprecated inline endpoint doesn't (above).
  • On production, every source version has a HEAD, so the backfill never writes a seed with no URL.

An old isolated_version=true is now ignored. That's fine, since the name never shipped, but any runbook for the LOINC 2.82 staging run needs the new name.

Decisions

The six behaviour questions are D8 on the Decisions tab of the Repo Versions Model doc, for today's meeting. Please note the outcomes here once they're settled.

How it was checked

  • Read your design page, the two new commits and the earlier findings against b14c5f0f. The branch merges cleanly with master at 015eaaa2 (#987, #990, #991 and #992 in). CI is green.
  • Re-ran the first review's probes at b14c5f0f on a throwaway stack, plus new probes for seeded_from: HEAD, import-seeded versions, POST with a spoofed seed, PUT, and the HEAD detail.
  • Codex (codex-cli 0.169.0, xhigh), pass 2: all nine earlier findings unresolved, plus three new ones (P1, P2, P2 by its rating; P3 each here, explained above). I found the deprecated-endpoint switch on my own.
findings.json
[
 {
  "id": "C1",
  "severity": "P1",
  "file": "core/concepts/views.py",
  "line": 626,
  "claim": "Version-scoped children/ and parents/ branches never run: is_source_version() reads parent_resource, which is not the source version in get_queryset, so it is always False.",
  "scenario": "Version URL children/ is answered from HEAD's links; in a 4-import run /v4/concepts/P/children/ returned A and B although B is not in v4.",
  "action": "Resolve the repo version from the URL kwargs before branching and add a test where a version differs from HEAD.",
  "confidence": "high",
  "source": "both",
  "codex_check": "partly",
  "introduced_by_pr": false,
  "status_b14c5f0f": "unresolved",
  "codex_pass2": "unresolved",
  "probe_b14c5f0f": "reproduced"
 },
 {
  "id": "C2",
  "severity": "P1",
  "file": "core/concepts/models.py",
  "line": 1419,
  "claim": "HEAD children/ of a parent lists a dropped concept: version-row links are kept and HEAD lookup has no active/membership filter.",
  "scenario": "v1-v3 with P, A, B; v4 with P, A: HEAD P/children/ returns A and B while B is 404 on HEAD.",
  "action": "Return only active HEAD members from HEAD hierarchy lookups.",
  "confidence": "high",
  "source": "both",
  "codex_check": "confirmed",
  "introduced_by_pr": true,
  "status_b14c5f0f": "unresolved",
  "codex_pass2": "unresolved",
  "probe_b14c5f0f": "reproduced"
 },
 {
  "id": "C3",
  "severity": "P2",
  "file": "core/importers/models.py",
  "line": 1160,
  "claim": "Mappings nested in a Concept line are not recorded as seen, so the sweep drops them.",
  "scenario": "Concept with a nested mapping plus a version line: version and HEAD end with 0 mappings.",
  "action": "Track nested mapping ids or reject nested mappings in isolated imports.",
  "confidence": "high",
  "source": "both",
  "codex_check": "partly",
  "introduced_by_pr": true,
  "status_b14c5f0f": "unresolved",
  "codex_pass2": "unresolved",
  "probe_b14c5f0f": "reproduced"
 },
 {
  "id": "C4",
  "severity": "P2",
  "file": "core/importers/models.py",
  "line": 458,
  "claim": "Dropped counts are discarded; the import result never says how much left HEAD.",
  "scenario": "Concepts-only isolated import leaves 0 mappings in the version and HEAD with no error.",
  "action": "Return the counts; optionally a dry run or a drop threshold.",
  "confidence": "high",
  "source": "claude",
  "codex_check": "partly",
  "introduced_by_pr": true,
  "status_b14c5f0f": "unresolved",
  "codex_pass2": "unresolved",
  "probe_b14c5f0f": "reproduced"
 },
 {
  "id": "C5",
  "severity": "P2",
  "file": "core/importers/models.py",
  "line": 369,
  "claim": "The version's membership is seeded from HEAD by a queued task, so later HEAD changes alter the release.",
  "scenario": "A second import or edit changes HEAD before the seed task runs.",
  "action": "Snapshot membership in the commit transaction or block a new isolated import while processing.",
  "confidence": "medium",
  "source": "codex",
  "codex_check": "partly",
  "introduced_by_pr": false,
  "status_b14c5f0f": "unresolved",
  "codex_pass2": "unresolved"
 },
 {
  "id": "C6",
  "severity": "P3",
  "file": "core/concepts/models.py",
  "line": 1272,
  "claim": "Isolated imports still queue per-concept hierarchy tasks that can run late.",
  "scenario": "A late task overwrites HEAD parents after a newer commit.",
  "action": "Skip those tasks in isolated imports.",
  "confidence": "medium",
  "source": "both",
  "codex_check": "partly",
  "introduced_by_pr": false,
  "status_b14c5f0f": "unresolved",
  "codex_pass2": "unresolved"
 },
 {
  "id": "C7",
  "severity": "P2",
  "file": "core/mappings/models.py",
  "line": 425,
  "claim": "Isolated mapping updates keep relation-derived text such as to_concept_name.",
  "scenario": "Release 2 omits to_concept_name; the new version keeps the old label.",
  "action": "Reset omitted optional fields before resolving relations.",
  "confidence": "medium",
  "source": "both",
  "codex_check": "partly",
  "introduced_by_pr": true,
  "status_b14c5f0f": "unresolved",
  "codex_pass2": "unresolved"
 },
 {
  "id": "C8",
  "severity": "P2",
  "file": "core/importers/models.py",
  "line": 456,
  "claim": "Two isolated imports into one source can run at once.",
  "scenario": "The first commit's sweep drops what only the second import sent.",
  "action": "Per-source reservation from preflight to commit.",
  "confidence": "medium",
  "source": "both",
  "codex_check": "partly",
  "introduced_by_pr": true,
  "status_b14c5f0f": "unresolved",
  "codex_pass2": "unresolved"
 },
 {
  "id": "C9",
  "severity": "P3",
  "file": "core/concepts/models.py",
  "line": 1461,
  "claim": "The hierarchy resolver skips parent URLs that name a concept version.",
  "scenario": "Parallel import with a version URL parent: the link is never made. Not reproduced.",
  "action": "Resolve versioned and versionless URLs to the versioned object.",
  "confidence": "low",
  "source": "codex",
  "codex_check": "not-run",
  "introduced_by_pr": true,
  "status_b14c5f0f": "unresolved",
  "codex_pass2": "unresolved",
  "codex_pass2_severity": "P2"
 },
 {
  "id": "C10",
  "severity": "P2",
  "file": "core/common/utils.py",
  "line": 466,
  "claim": "seed_from_import=true on the deprecated upload/ and file-url/ endpoints is validated, then never reaches the runner.",
  "scenario": "POST /importers/bulk-import/upload/?seed_from_import=true with a release file: 202, plain import, a version made from HEAD, nothing dropped.",
  "action": "Reject the switch with a 400 on endpoints that can't seed.",
  "confidence": "high",
  "source": "claude",
  "introduced_by_pr": true
 },
 {
  "id": "C11",
  "severity": "P3",
  "file": "core/common/tasks.py",
  "line": 285,
  "claim": "bulk_import_inline isn't bound, so a seeding import through the deprecated bulk-import-inline endpoint records task null.",
  "scenario": "POST /importers/bulk-import-inline/?seed_from_import=true: seeded_from is {type: import, task: null}.",
  "action": "Bind the task and pass self.request.id as self_task_id.",
  "confidence": "high",
  "source": "codex (F2.3, rated P1)",
  "introduced_by_pr": true
 },
 {
  "id": "C12",
  "severity": "P3",
  "file": "core/sources/models.py",
  "line": 243,
  "claim": "HEAD's seeded_from URL is rebuilt from the version label rather than taken from the version's uri.",
  "scenario": "A label needing URL encoding gives a seed URL that doesn't resolve (as the version's own URI already would).",
  "action": "Use the new version's uri.",
  "confidence": "medium",
  "source": "codex (F2.9, rated P2)",
  "introduced_by_pr": true
 },
 {
  "id": "C13",
  "severity": "P3",
  "file": "core/sources/migrations/0048_source_seeded_from.py",
  "line": 49,
  "claim": "0047 adds versioning_mode and 0048 removes it; reversing 0048 loses which versions were import-seeded.",
  "scenario": "Migrate a database with import-seeded versions back to 0047 and forward again: they become HEAD-seeded.",
  "action": "Fold 0047 and 0048 into one migration while neither has shipped.",
  "confidence": "high",
  "source": "codex (F2.10, rated P2) + claude",
  "introduced_by_pr": true
 }
]

Comment thread core/importers/constants.py Resolved
Comment thread core/importers/views.py Resolved
Comment thread core/importers/views.py Resolved
Comment thread core/importers/views.py Resolved
Comment thread core/common/tasks.py Resolved
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Pass 2 review: changes in 85a6d41.

Fixed

  • P1, version-scoped children/ and parents/. The views now take the source version from the URL (source and version kwargs, latest included) instead of parent_resource. HEAD and collection URLs keep the HEAD lookup.
  • P1, HEAD lists dropped children. get_hierarchy_related_queryset returns only active HEAD concepts, so get_viewable_hierarchy_concept_urls is fixed too.
    • New test test_hierarchy_endpoints_follow_each_version runs your probe: v1 {P, A, B} and v2 {P, A}. P/children/ returns A and B on v1, and only A on v2 and on HEAD. B returns 404 on HEAD, and v1/.../B/parents/ returns P.
  • P2, deprecated upload/ and file-url/. These now reject seed_from_import=true with a 400 (your suggestions, plus a test).
  • P3, bulk_import_inline. The task is bound and records its task id. The stale TODO in queue_bulk_import is gone.

Still open, not in this push: the nested-mapping sweep, the dropped counts (D8.6 / ocl_online#674, which is on today's meeting agenda), queued membership seeding, concurrent seeding imports, mapping relation text, late hierarchy tasks, the versioned parent URL resolver, get_version_url using uri, and folding 0047 into 0048. Before folding the migrations I need to know whether a shared database (staging) already ran 0047.

The local stack was down, so CI is running the tests for this push. Pylint -j0 core/ passes.

🤖 Addressed by Claude Code

@paynejd

paynejd commented Nov 18, 2026

Copy link
Copy Markdown
Member

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

Verdict: fix-first. There are two P1s, and both reproduce on a test stack at 85a6d41d. C1, C10 and C11 are resolved. C3 to C9, C12 and C13 are still open, as your comment says.

Rechecked on 38aa036e, the current head, which only merges master since 85a6d41d: both P1s still reproduce.

  • [P1] F3.1 (core/concepts/models.py:1420), from C2's fix. The is_active=True filter in get_hierarchy_related_queryset also reaches historical concept versions, through parent_concept_urls and child_concept_urls.
    • Probe: import v1 with P and C (C under P), then a seeding import of v2 with C only. GET /orgs/Regen/sources/LOINC/v1/concepts/C/?includeParentConceptURLs=true returns parent_concept_urls: [], while v1/concepts/C/parents/ returns P. TBv3's version comparison reads these lists.
    • By reading, not probed: the same property supplies prev_parent_uris when a concept is saved, so a parent whose HEAD is inactive also drops out of the concept's next version.
    • Fix: filter to active HEAD members in the HEAD-scoped reads (the HEAD branch of children/ and parents/, and, since the master merge in 38aa036e, get_viewable_hierarchy_concept_urls), not in the shared helper. Add an assertion on the historical detail.
  • [P1] F3.2 (core/importers/models.py:456): the commit transaction starts after the content import has already rewritten HEAD's parent links. post_version_create calls update_versioned_object(), which sets HEAD's parents from the new version, and then the hierarchy task runs. If the commit is rejected, those changes stay.
    • Probe: the scenario of test_hierarchy_root_drop_rolls_back_the_hierarchy. Before the import, C's parents on HEAD are {P1}. The import is rejected on hierarchy_root and no v2 is made, yet afterwards C has no parents on HEAD. The test checks only membership, so it passes.
    • Fix: in seeding imports, leave HEAD's links alone until the commit, which already rebuilds them from hierarchy_map inside the transaction. Assert that C keeps P1 after a rejection.
findings.json
{
    "reviewer": "codex-cli 0.169.0",
    "perspective": "defects",
    "mode": "verify",
    "commit": "85a6d41d",
    "verdict": "findings",
    "prior": [
        {
            "id": "C1",
            "status": "resolved"
        },
        {
            "id": "C2",
            "status": "regressed"
        },
        {
            "id": "C3",
            "status": "unresolved"
        },
        {
            "id": "C4",
            "status": "unresolved"
        },
        {
            "id": "C5",
            "status": "unresolved"
        },
        {
            "id": "C6",
            "status": "unresolved"
        },
        {
            "id": "C7",
            "status": "unresolved"
        },
        {
            "id": "C8",
            "status": "unresolved"
        },
        {
            "id": "C9",
            "status": "unresolved"
        },
        {
            "id": "C10",
            "status": "resolved"
        },
        {
            "id": "C11",
            "status": "resolved"
        },
        {
            "id": "C12",
            "status": "unresolved"
        },
        {
            "id": "C13",
            "status": "unresolved"
        }
    ],
    "findings": [
        {
            "id": "F3.1",
            "severity": "P1",
            "tag": null,
            "file": "core/concepts/models.py",
            "line": 1420,
            "claim": "The C2 fix makes historical hierarchy URLs depend on current HEAD membership.",
            "scenario": "Import v1 with P and C\u2192P, then v2 with C parentless and P omitted. GET /v1/concepts/C/?includeParentConceptURLs=true now returns an empty parent_concept_urls list: historical serializers call this helper with versioned=False, and P's inactive HEAD is excluded despite P remaining a v1 member. The new version-scoped parents/ view still returns P, so the two API representations disagree.",
            "action": "Apply the active-membership restriction to HEAD-scoped reads while preserving historical hierarchy links in version serializers. Add a historical-detail assertion after dropping its parent from HEAD.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "F3.2",
            "severity": "P1",
            "tag": null,
            "file": "core/importers/models.py",
            "line": 456,
            "claim": "The transaction starts after concept imports have already changed HEAD's hierarchy.",
            "scenario": "Start with ROOT, P1 and C\u2192P1, set ROOT as hierarchy_root, then import C parentless while omitting ROOT. Concept version creation calls update_versioned_object(), which replaces HEAD's parent links before IsolatedVersionCommit.run(). The root-drop check subsequently rejects the version, but rolling back this transaction leaves C's HEAD hierarchy changed. test_hierarchy_root_drop_rolls_back_the_hierarchy uses this scenario but asserts only concept membership, so it misses the failure.",
            "action": "Defer HEAD hierarchy mutations, including per-concept hierarchy tasks, until the isolated commit transaction. Assert that HEAD's original parent links survive a rejected import.",
            "lines_delta": null,
            "confidence": "high"
        }
    ]
}

@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Codex pass 3: both P1s are fixed in adde0b0.

  • F3.1, historical hierarchy URLs. The active filter no longer applies to every read. get_hierarchy_related_queryset applies it only when the concept being read is HEAD's own row. HEAD reads still hide dropped concepts: children/ and parents/, get_viewable_hierarchy_concept_urls, and the counts. A version row's links come back as they were, and so does prev_parent_uris, which is read from the previous latest version.
    • New test test_version_detail_keeps_parents_dropped_from_head runs your probe: v1 C/?includeParentConceptURLs=true returns P, and HEAD's C returns [].
    • test_hierarchy_endpoints_follow_each_version now also checks that v1 P's detail still lists A and B in child_concept_urls.
  • F3.2, HEAD links changed by a rejected import. In a seeding import, the content step no longer writes HEAD's parent links. Neither update_versioned_object nor the per-concept hierarchy task touches them; the task has a new update_head argument. The commit already rebuilds them from the import's parent map inside its transaction, so a rejected commit leaves HEAD's hierarchy as it was.
    • test_hierarchy_root_drop_rolls_back_the_hierarchy now asserts that C keeps P1.
    • This also covers the HEAD half of C6: a late hierarchy task from a seeding import can't overwrite HEAD's parents any more.

Checked locally: core.importers, core.concepts and core.sources ran 870 tests with one failure, BulkImportLimitsTest.test_grandfathered_npm_url_is_downloaded_and_handed_over_as_upload. It fails the same way at 38aa036 without these changes, and CI passed there, so the cause is local. Pylint -j0 core/ passes.

Since pass 2: 38aa036e merged master. Our source migrations are now 0048_source_versioning_mode and 0049_source_seeded_from, after master's 0047_source_supplements, and a seeding version line can also set supplements, supplement_type and supplement_global. C3 to C5, C7 to C9, C12 and C13 are still open.

🤖 Addressed by Claude Code

@paynejd

paynejd commented Nov 18, 2026

Copy link
Copy Markdown
Member

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

Verdict: fix-first. The main path works on a full LOINC 2.82 load: the version holds exactly the release, nothing carries forward, and parent links are replaced correctly. Five P1s and three P2s remain. F4.1 to F4.7 were reproduced on a test stack, and F4.8 comes from reading the test.

Decisions from Jon (2026-11-18)

  • F4.1, F4.2, F4.4 and F4.5 block the merge.
  • The large-drop guard ships with this PR: the import reports what it will drop and refuses a large drop unless that is confirmed.
  • F4.3 doesn't block this PR. It moves to OpenConceptLab/ocl_online#687.
  • C3 to C9, C12 and C13 from the earlier passes are still open.

Findings

  • [P1] F4.1 (core/importers/models.py:636), must fix. Seeding imports can still publish hierarchy changes before the commit. Fix: Defer hierarchy tasks for both new and updated concepts in seeding imports. Write the HEAD and concept-version links in the version transaction and test the HEAD API after a rejected import.
  • [P1] F4.2 (core/importers/models.py:327), must fix. Import-seeded versions lose repository configuration that POST versions inherit. Fix: Apply explicitly supplied metadata to HEAD and reuse the POST version defaults when constructing the seeded version. Add a test that compares both creation paths with configured HEAD metadata.
  • [P1] F4.3 (core/concepts/serializers.py:639), tracked in OpenConceptLab/ocl_online#687. A regenerated release export includes hierarchy links from current HEAD. Fix: Pass the source version into the export serializer and resolve its hierarchy from the exported release. Add an export assertion before and after a later import moves a child.
  • [P1] F4.4 (core/importers/models.py:457), must fix. An owner or source mismatch between the content and version line can empty the target HEAD. Fix: Validate that each concept and mapping line targets the source named by the Source Version line before importing any content.
  • [P1] F4.5 (core/importers/models.py:200), must fix. An ordinary import can report a dropped concept as updated while it remains absent from HEAD. Fix: Handle dropped rows explicitly in ordinary imports so the update result, HEAD visibility, and membership used for later snapshots agree.
  • [P2] F4.6 (core/importers/models.py:1485), should fix. A parallel import silently falls back to HEAD seeding when another version line precedes the Source Version in its batch. Fix: Give the validated Source Version line its own commit step, or reject the mixed input during preflight.
  • [P2] F4.7 (core/concepts/serializers.py:805), should fix. Version-scoped hierarchy endpoints still expose out-of-release links in their optional nested fields. Fix: Use the resolved source version for the optional children and parents fields and the has_children flag. Test a retained row whose related concept was dropped.
  • [P2] F4.8 (core/importers/tests.py:6951), should fix. The dropped-concept 404 assertion uses a code that the test never imports. Fix: Request P in the 404 assertion, or move the B assertion back to the fixture that imports and drops B.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "adde0b05",
  "verdict": "findings",
  "prior": [
    {
      "id": "C1",
      "status": "resolved"
    },
    {
      "id": "C2",
      "status": "resolved"
    },
    {
      "id": "C3",
      "status": "unresolved"
    },
    {
      "id": "C4",
      "status": "unresolved"
    },
    {
      "id": "C5",
      "status": "unresolved"
    },
    {
      "id": "C6",
      "status": "unresolved"
    },
    {
      "id": "C7",
      "status": "unresolved"
    },
    {
      "id": "C8",
      "status": "unresolved"
    },
    {
      "id": "C9",
      "status": "unresolved"
    },
    {
      "id": "C10",
      "status": "resolved"
    },
    {
      "id": "C11",
      "status": "resolved"
    },
    {
      "id": "C12",
      "status": "unresolved"
    },
    {
      "id": "C13",
      "status": "unresolved"
    },
    {
      "id": "F3.1",
      "status": "resolved"
    },
    {
      "id": "F3.2",
      "status": "unresolved"
    }
  ],
  "findings": [
    {
      "id": "F4.1",
      "severity": "P1",
      "tag": null,
      "file": "core/importers/models.py",
      "line": 636,
      "claim": "Seeding imports can still publish hierarchy changes before the commit.",
      "scenario": "In an archive or single-thread inline import, add a new child C under existing P and omit the configured hierarchy root. The new-concept task writes C's HEAD and initial-version parent links outside the transaction. The root check rejects the version, but HEAD can still list C under P. Existing-concept updates also write the new concept-version links outside the transaction, and HEAD hierarchy reads include that latest row.",
      "action": "Defer hierarchy tasks for both new and updated concepts in seeding imports. Write the HEAD and concept-version links in the version transaction and test the HEAD API after a rejected import.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F4.2",
      "severity": "P1",
      "tag": null,
      "file": "core/importers/models.py",
      "line": 327,
      "claim": "Import-seeded versions lose repository configuration that POST versions inherit.",
      "scenario": "Give HEAD property definitions, filters, FHIR meta, and semantic matching. POST /versions/ carries those settings forward through SourceVersionListView.create. A seeding import that omits those fields creates a version with empty properties, filters, and match algorithms and null meta. Supplying new properties, filters, or meta on the Source Version line also has no effect on HEAD because the importer strips them.",
      "action": "Apply explicitly supplied metadata to HEAD and reuse the POST version defaults when constructing the seeded version. Add a test that compares both creation paths with configured HEAD metadata.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F4.3",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/serializers.py",
      "line": 639,
      "claim": "A regenerated release export includes hierarchy links from current HEAD.",
      "scenario": "Seed v1 with C under P1, then seed v2 with C under P2. Regenerate the v1 export. C's v1 row still links to P1, but the export unions it with C's HEAD links, so v1 now exports both P1 and P2 as parents.",
      "action": "Pass the source version into the export serializer and resolve its hierarchy from the exported release. Add an export assertion before and after a later import moves a child.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F4.4",
      "severity": "P1",
      "tag": null,
      "file": "core/importers/models.py",
      "line": 457,
      "claim": "An owner or source mismatch between the content and version line can empty the target HEAD.",
      "scenario": "An editor uploads a release whose concept and mapping lines name LOINC-Staging, while its Source Version line names LOINC. Both sources are editable. The rows succeed in LOINC-Staging, and the commit treats every existing LOINC member as unseen. It drops them and reports a successful empty LOINC release.",
      "action": "Validate that each concept and mapping line targets the source named by the Source Version line before importing any content.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F4.5",
      "severity": "P1",
      "tag": null,
      "file": "core/importers/models.py",
      "line": 200,
      "claim": "An ordinary import can report a dropped concept as updated while it remains absent from HEAD.",
      "scenario": "Seed a release that drops A, then submit an ordinary bulk import with update_if_exists=true and a changed name for A. The importer finds the inactive HEAD row and reports UPDATED. The new concept version joins HEAD's source membership, but the HEAD row stays inactive. GET /concepts/A/ still returns 404, while a subsequent POST /versions/ can seed A from the same HEAD.",
      "action": "Handle dropped rows explicitly in ordinary imports so the update result, HEAD visibility, and membership used for later snapshots agree.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F4.6",
      "severity": "P2",
      "tag": null,
      "file": "core/importers/models.py",
      "line": 1485,
      "claim": "A parallel import silently falls back to HEAD seeding when another version line precedes the Source Version in its batch.",
      "scenario": "Import a valid Concept line followed by a Collection Version line and the sole Source Version line, with seed_from_import=true. Preflight accepts the order. The runner groups both version lines together and checks only the first row for Source Version. The ordinary worker creates the source version from HEAD and leaves omitted codes in place.",
      "action": "Give the validated Source Version line its own commit step, or reject the mixed input during preflight.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F4.7",
      "severity": "P2",
      "tag": null,
      "file": "core/concepts/serializers.py",
      "line": 805,
      "claim": "Version-scoped hierarchy endpoints still expose out-of-release links in their optional nested fields.",
      "scenario": "Seed v1 with X under P and B under X. Seed v2 with unchanged P and X, with duplicate-version prevention enabled so X's row is reused, and omit B. GET /v2/concepts/P/children/?includeChildConcepts=true returns X with B in its nested children field, even though /v2/concepts/X/children/ is empty.",
      "action": "Use the resolved source version for the optional children and parents fields and the has_children flag. Test a retained row whose related concept was dropped.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F4.8",
      "severity": "P2",
      "tag": null,
      "file": "core/importers/tests.py",
      "line": 6951,
      "claim": "The dropped-concept 404 assertion uses a code that the test never imports.",
      "scenario": "The fixture imports P and C, then drops P. The final request checks B, so it still returns 404 if dropped concepts remain reachable through the HEAD detail endpoint.",
      "action": "Request P in the 404 assertion, or move the B assertion back to the fixture that imports and drops B.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member

@paynejd decided on Nov 18 that the guard against large drops goes into this PR before it merges, not as a follow-up.

The behaviour: an import into an isolated version reports how many resources it drops from HEAD, and refuses a large drop unless the request says the drop is intended. Without it, anyone with edit access could run an import that drops almost everything from HEAD and use up the version id, which is hard to undo. The design treats this as the one behaviour to guard rather than accept.

He also confirmed decisions D1 to D7 as built (tracked on OpenConceptLab/ocl_online#672).

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member

Next steps for LOINC 2.82 (Jon, 2026-11-18)

@snyaggarwal, the rebuilt LOINC 2.82 import file is ready (OpenConceptLab/ocl-content#7), so the staging run can use it directly.

  • Target date: push the fixes for F4.1, F4.2, F4.4 and F4.5, plus the large-drop guard, by Mon Nov 23, then merge and deploy to staging. If that date doesn't work, please say so here.
  • Review: comment here when the fixes are pushed. Codex pass 5 will review the new commits and be posted here.
  • Staging: skip the trial load of the old 2.82 files. Load the rebuilt file once, as one seed_from_import import. Its location, the steps and the checks are on OpenConceptLab/ocl_online#363.

@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Rebased onto master (dada9386) and force-pushed as 5776c402, to resolve the conflict with #999.

Checked locally on a fresh test database, so the renumbered migrations apply from scratch: core.importers, core.concepts, core.sources, core.common and core.integration_tests.tests_sources ran 1276 tests with one failure. That's BulkImportLimitsTest.test_grandfathered_npm_url_is_downloaded_and_handed_over_as_upload, which fails locally without this PR's changes as well. Pylint -j0 core/ passes.

🤖 Addressed by Claude Code

…rchy root and line metadata before any content, link concepts with assigned ids and versioned parent URLs, and report archive drops
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Codex pass 5 is addressed in cf31316. It's a normal push on top of 5776c40.

The guard and hierarchy-root check now run before any content imports (F5.1, F5.2)

  • Every runner already calls IsolatedVersionCommit.preflight before content: inline, parallel, and archive through validate_versioning. Preflight now compares HEAD's active codes with the file's Concept and Mapping lines.
  • A file that leaves out HEAD's hierarchy_root, or that would drop a large share of HEAD without allow_large_drop, is refused before anything is written. A refusal leaves HEAD's content, names and hierarchy as they were.
  • The share is now counted against HEAD's codes before the import, so new codes no longer dilute it.
  • Concepts are matched by id. A mapping line without an id is matched at import by from/to/map_type, so preflight counts each one as keeping one HEAD mapping. The pre-content count can therefore be lower than what the sweep then drops, but it can't be higher.
  • The commit still reports the actual dropped counts and keeps its own hierarchy-root check as a backstop.
  • Tests:
    • test_refused_drop_leaves_head_content_unchanged: a renamed P and a new N. After the refusal, P keeps its name, N doesn't exist and C stays under P.
    • test_new_codes_do_not_dilute_the_drop.
    • test_large_drop_needs_allow_large_drop and the two hierarchy-root tests now expect the refusal up front.
    • test_rejected_version_leaves_new_and_moved_children_unlinked now triggers a commit-time rejection with a failing content line, so it still covers the deferred hierarchy.

Findings

  • F5.3: a seeding import records the parents of a concept whose ID it assigned, by the saved concept's URI, and the commit links them. This works on the inline, parallel and archive paths, which pass it through seen.hierarchy. Test: test_concept_with_an_assigned_id_keeps_its_parents, covering HEAD and the new version.
  • F5.4: ImportHierarchy.from_uri_map resolves a parent URL that names a concept version to that concept, so it also covers C9 on every runner. Test: test_parent_url_naming_a_concept_version_links_the_concept.
  • F5.5: the archive commit adds {"dropped": …} to its subtask results, and ImportTaskSummary has a new dropped field. The zip tests assert the counts.
  • F5.6: Source.get_import_target, IsolatedVersionCommit.get_head and get_import_hierarchy_map now read owner_type as the content importers do: only user means a user. Test: test_plural_user_owner_type_is_read_as_the_importers_read_it.
  • F5.7: the inherited child_concepts and parent_concepts objects read from the source version in the context. The nested-fields test asserts both representations for the reused X row.
  • F5.8: the properties, filters, match_algorithms and meta a version line sets are validated before persisting: in preflight for seeding imports, and in SourceVersionImporter.process for ordinary ones. Values a version takes from HEAD aren't validated again, so a source with older malformed metadata can still release. Test: test_version_line_metadata_is_validated_before_content.
  • F5.9: match_algorithms is now seeding metadata and reaches HEAD, as the acceptance criterion says. POST is unchanged. Test: test_seeding_line_match_algorithms_reach_head.

Checked locally: core.importers, core.concepts, core.sources, core.common and core.integration_tests.tests_sources ran 1301 tests with one failure, BulkImportLimitsTest.test_grandfathered_npm_url_is_downloaded_and_handed_over_as_upload. It fails locally without this PR's changes as well. Pylint -j0 core/ passes on the committed tree.

Still open: C3, C5, C7, C8, C12 and C13; F4.3 is tracked on ocl_online#687.

🤖 Addressed by Claude Code

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member

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

Verdict: fix-first. One P0 and five P1s, all reproduced on a test stack (F6.3 and F6.5 up to the preflight step), plus six P2s. The P0, F6.1, is new in cf31316 and breaks the task status of every archive import, not only seeding ones.

Rebase check: cc94bd4 and 254d5b2 match 825bf09 and 2496d91 apart from the merged field list in core/sources/serializers.py, and 5776c40 only renumbers the two source migrations.

Pass 5 findings at cf31316

  • Resolved: F5.1, F5.2, F5.3, F5.4 (C9 with it), F5.6 and F5.7. Checked on the stack: a refused import leaves P's name, N and C's link as they were; 100 new codes over a 10-code HEAD are refused; a concept with an assigned ID keeps its parent in HEAD and the version; a parent URL naming a concept version links; filters: ["status"] is refused up front on the inline path. Seeding the same release again, with idless mappings or with IDs such as A B, A/B and Ä, drops nothing and isn't refused.
  • Not fully resolved: F5.5 (see F6.1), F5.8 on archives (see F6.5) and F5.9 (see F6.10).
  • Other statuses from Codex: C4 and F4.4 resolved; C6 and F4.1 open again (nearest: F6.11); F4.7 open (F6.7); F4.3 unchanged (OpenConceptLab/ocl_online#687); C3, C5, C7, C8, C12 and C13 still open.
  • F5.1's lost child still follows a commit-time rejection (one failing content line, with P renamed): HEAD's P/children/ is empty while C/parents/ lists P. Master dada938 does the same in the test harness when P is renamed by the API or an ordinary import, with no seeding involved, so it isn't from this PR. An accepted seeding import relinks the children.

Findings

  • [P0] F6.1 (core/importers/importer.py:83): ImportTaskSummary.dropped: dict = None is stored as "dropped": null in every scheduled archive import's summary, and pydantic 2.10 refuses that null when the task is read back. Repro: ImportTask.import_task_from_json on the stored summary raises "initial_summary.dropped: Input should be a valid dictionary"; without the key it reads fine. The task detail serializer and import_finisher both read it this way. Fix: dropped: dict | None = None, and test the round trip.
  • [P1] F6.2 (core/importers/models.py:510): idless mapping lines hide a mapping drop from the guard, and nothing after preflight checks it. Repro (minimum 1, 10%): HEAD has 10 concepts and 20 idless mappings; a release keeps the concepts and sends the same 20 pairs with a renamed map_type. Preflight passes, the sweep drops all 20 old mappings (two thirds of HEAD) and v2 is created without allow_large_drop. The LOINC 2.82 import file has 250,840 Mapping lines and none has an id, so on that release the guard never counts a dropped mapping. Fix: match idless lines to HEAD's mappings with the importer's own key in preflight, or check the actual drop again before anything is published.
  • [P1] F6.3 (core/importers/importer.py:548): archive preflight counts __action: "DELETE" lines as kept, but archive workers skip them, so the sweep drops those codes. Repro (preflight): 8 of 10 HEAD codes sent as DELETE lines pass preflight; the same 8 left out are refused. A skipped hierarchy-root line also slips past the up-front root check. Fix: give preflight the lines the archive workers actually import.
  • [P1] F6.5 (core/importers/importer.py:554): the archive scanner keeps only top-level scalars of the Source Version line, so preflight validates filters: [] in place of ["status"] (and empty properties and meta). Repro (preflight): the archive preflight passes while the inline preflight refuses the same file. Content then imports and the commit refuses the line, leaving HEAD's content changed. Fix: read the whole Source Version object before validating it.
  • [P1] F6.8 (core/sources/models.py:327): a HEAD comparison still counts dropped codes. Repro: after v2 drops B, comparing v1 with v2 shows B removed, but comparing v1 with HEAD shows both codes the same. HEAD's checksum queryset (concepts_set) doesn't filter is_active, and the sweep doesn't move last_child_update, so after a release that only drops codes, cached HEAD comparisons and HEAD exports aren't refreshed either. Fix: leave dropped rows out of HEAD's checksum maps and treat the sweep as a HEAD change.
  • [P1] F6.9 (core/concepts/models.py:1326): dropped mappings still show on concepts. Repro: after v2 drops M1 (A to B), HEAD's A/?includeMappings=true and A/mappings/ list M1, and so does v2/concepts/A/mappings/, while mappings/M1/ returns 404 and HEAD's mappings/ is empty. Fix: use active HEAD mappings (and the version's members on version-scoped requests) for concept mappings and mapped codes.
  • [P2] F6.4 (core/importers/models.py:498): mapping IDs sent as JSON numbers don't match their stored strings in preflight, which can refuse a release that keeps every mapping.
  • [P2] F6.6 (core/importers/models.py:391): meta.display.concept_filter_order isn't validated; a malformed value breaks source detail when the source has filters.
  • [P2] F6.7 (core/concepts/serializers.py:47): includeChildConceptURLs on a version's children/ still lists a dropped child through a reused row.
  • [P2] F6.10 (core/sources/models.py:272): when a seeding line changes match_algorithms on HEAD, the vector sync a HEAD edit would queue isn't queued.
  • [P2] F6.11 (core/importers/models.py:736): a DELETE line in an inline or parallel seeding import changes the hierarchy before the commit, so a rejected version leaves it changed.
  • [P2] F6.12 (core/common/tasks.py:714): the admin hierarchy repair now skips a child URL that names a concept version.
findings.json
{
    "reviewer": "codex-cli 0.169.0",
    "perspective": "defects",
    "mode": "verify",
    "commit": "cf31316e",
    "verdict": "findings",
    "prior": [
        {
            "id": "C1",
            "status": "resolved"
        },
        {
            "id": "C2",
            "status": "resolved"
        },
        {
            "id": "C3",
            "status": "unresolved"
        },
        {
            "id": "C4",
            "status": "resolved"
        },
        {
            "id": "C5",
            "status": "unresolved"
        },
        {
            "id": "C6",
            "status": "unresolved"
        },
        {
            "id": "C7",
            "status": "unresolved"
        },
        {
            "id": "C8",
            "status": "unresolved"
        },
        {
            "id": "C9",
            "status": "resolved"
        },
        {
            "id": "C10",
            "status": "resolved"
        },
        {
            "id": "C11",
            "status": "resolved"
        },
        {
            "id": "C12",
            "status": "unresolved"
        },
        {
            "id": "C13",
            "status": "unresolved"
        },
        {
            "id": "F3.1",
            "status": "resolved"
        },
        {
            "id": "F3.2",
            "status": "resolved"
        },
        {
            "id": "F4.1",
            "status": "unresolved"
        },
        {
            "id": "F4.2",
            "status": "resolved"
        },
        {
            "id": "F4.3",
            "status": "unresolved"
        },
        {
            "id": "F4.4",
            "status": "resolved"
        },
        {
            "id": "F4.5",
            "status": "resolved"
        },
        {
            "id": "F4.6",
            "status": "resolved"
        },
        {
            "id": "F4.7",
            "status": "unresolved"
        },
        {
            "id": "F4.8",
            "status": "resolved"
        },
        {
            "id": "F5.1",
            "status": "resolved"
        },
        {
            "id": "F5.2",
            "status": "resolved"
        },
        {
            "id": "F5.3",
            "status": "resolved"
        },
        {
            "id": "F5.4",
            "status": "resolved"
        },
        {
            "id": "F5.5",
            "status": "regressed"
        },
        {
            "id": "F5.6",
            "status": "resolved"
        },
        {
            "id": "F5.7",
            "status": "resolved"
        },
        {
            "id": "F5.8",
            "status": "unresolved"
        },
        {
            "id": "F5.9",
            "status": "regressed"
        }
    ],
    "findings": [
        {
            "id": "F6.1",
            "severity": "P0",
            "tag": null,
            "file": "core/importers/importer.py",
            "line": 83,
            "claim": "Archive import results fail to deserialize, breaking task status and completion reporting.",
            "scenario": "A ZIP or TAR import schedules subtasks and serializes its initial summary with `dropped: null`. Pydantic accepts the omitted default when constructing the summary, but rejects explicit null when `ImportTask.import_task_from_json` reads it back because the field is declared as `dict`. Polling the task returns 500 and `import_finisher` fails, including for ordinary archive imports and successful seeded imports.",
            "action": "Declare `dropped` nullable and test the round trip from the archive runner through the finisher and task-detail response, with and without counts.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "F6.2",
            "severity": "P1",
            "tag": null,
            "file": "core/importers/models.py",
            "line": 510,
            "claim": "Idless mapping lines can hide a large drop on every runner.",
            "scenario": "HEAD contains 2,000 concepts and 2,000 mappings. A release keeps the concepts and supplies 2,000 idless mappings with changed target codes. The importer creates new mapping identities. Preflight credits those lines with retaining every old mapping, then the sweep drops all 2,000 old mappings and uses the version ID without confirmation. If omitted concepts alone trigger a refusal, its message still underreports the mappings.",
            "action": "Resolve distinct retained mapping identities using the importer's matching and update rules. Where preflight cannot establish the identity, stage the writes and check the actual drop against the original HEAD before publishing any changes.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "F6.3",
            "severity": "P1",
            "tag": null,
            "file": "core/importers/importer.py",
            "line": 548,
            "claim": "ZIP and TAR preflight count DELETE lines that the archive workers skip.",
            "scenario": "An archive lists 1,500 existing mappings with `__action: \"DELETE\"` and keeps the concepts. Preflight counts all 1,500 mappings as retained. The workers skip those lines without recording a failure, so the sweep can drop them all without confirmation. If a skipped Concept line names the hierarchy root, preflight also misses that omission and the root check refuses only after other content writes have landed.",
            "action": "Use the same effective content lines for preflight, archive processing, and hierarchy collection. Test both a large drop and a root omission through the archive runner.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "F6.4",
            "severity": "P2",
            "tag": null,
            "file": "core/importers/models.py",
            "line": 498,
            "claim": "Numeric JSON mapping IDs can make preflight refuse a release that retains every mapping.",
            "scenario": "A source has numeric mapping mnemonics stored as strings. A release sends those same IDs as JSON integers. The mapping importer's Django `CharField` lookup matches each integer to its stored string, while preflight compares the raw integers against strings. If the apparent omissions cross the threshold, the release is refused even though the actual drop would be zero.",
            "action": "Normalize explicit IDs using the same representation as the importer lookup. Test a release that retains numeric mapping IDs supplied as JSON numbers.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "F6.5",
            "severity": "P1",
            "tag": null,
            "file": "core/importers/importer.py",
            "line": 554,
            "claim": "Archive preflight validates empty placeholders in place of version metadata.",
            "scenario": "A ZIP or TAR contains a renamed concept, a new concept, and a Source Version line with `filters: [\"status\"]`. The scanner passes `filters: []` to preflight, so the content workers run. The version subtask then sees the actual array and rejects it. The renamed concept, its new version, and the new concept remain in HEAD.",
            "action": "Read the complete Source Version object during archive preflight and validate it before scheduling any content. Test that an invalid nested value leaves HEAD and its concept versions unchanged.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "F6.6",
            "severity": "P2",
            "tag": null,
            "file": "core/importers/models.py",
            "line": 391,
            "claim": "Malformed display metadata can still break HEAD and release detail responses.",
            "scenario": "A seeding line sets `meta` to `{\"display\":{\"concept_filter_order\":1}}` and the source has at least one filter. The dictionary check passes and the import saves it to HEAD and the release. Both detail serializers call `filters_ordered`, which attempts to unpack the integer and returns 500.",
            "action": "Validate the shape of the display metadata that source responses consume. Add a rejection case with existing filters and confirm both source details remain readable.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "F6.7",
            "severity": "P2",
            "tag": null,
            "file": "core/concepts/serializers.py",
            "line": 47,
            "claim": "The optional hierarchy URL fields still expose concepts outside the requested release.",
            "scenario": "In the existing nested-hierarchy test, v1 contains P, X under P, and B under X. Version v2 reuses X and omits B. Request v2's P/children/ with `includeChildConceptURLs=true`. The inherited `child_concept_urls` field still lists B because it ignores `repo_version`, even though the version-scoped `children` and `child_concepts` fields are empty.",
            "action": "Pass the resolved source version to the inherited hierarchy URL fields and extend the reused-row test to request those fields.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "F6.8",
            "severity": "P1",
            "tag": null,
            "file": "core/sources/models.py",
            "line": 327,
            "claim": "HEAD comparisons and existing HEAD exports can still report dropped codes.",
            "scenario": "Export HEAD, then seed a release that only drops codes. The sweep leaves the dropped rows' timestamps intact, so HEAD can still serve the cached export under the same key. A fresh `$compare` against HEAD also includes the dropped rows because the HEAD checksum query selects versioned objects without filtering `is_active`.",
            "action": "Exclude dropped identities from HEAD checksum maps and invalidate HEAD export and comparison caches when membership changes. Test a drop-only import against previously generated results.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "F6.9",
            "severity": "P1",
            "tag": null,
            "file": "core/concepts/models.py",
            "line": 1326,
            "claim": "Dropped mappings remain visible on HEAD concepts and in mapped-code search.",
            "scenario": "A seeded release keeps A and drops its mapping to code X. A HEAD concept detail request with `includeMappings=true` still returns that mapping because the relation query ignores `is_active`. The drop task reindexes the mapping alone, and even rebuilding A's search document uses the same unfiltered relation and keeps X as a mapped code.",
            "action": "Use active HEAD mappings for the concept response and search document. Refresh the mapped-code documents of concepts affected by the sweep.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "F6.10",
            "severity": "P2",
            "tag": null,
            "file": "core/sources/models.py",
            "line": 272,
            "claim": "Applying `match_algorithms` to HEAD bypasses HEAD's vector synchronization.",
            "scenario": "HEAD is the only semantic version of a source. A seeding import with `index=false` keeps its existing codes and changes `match_algorithms` to `[\"es\"]`. The direct save updates HEAD and creates a lexical release. Neither path queues the sync that a regular HEAD edit would run, so HEAD's concept documents retain vectors after semantic matching has been disabled.",
            "action": "Queue the existing HEAD vector sync after commit when the semantic flag changes, and test that the import schedules it for HEAD.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "F6.11",
            "severity": "P2",
            "tag": null,
            "file": "core/importers/models.py",
            "line": 736,
            "claim": "Inline and parallel concept deletions can change hierarchy before the version transaction.",
            "scenario": "An isolated import includes a DELETE for C, which is under P, followed by an invalid Concept line. Retirement uses the ordinary concept-version path, which clears C's HEAD parent relation and can queue hierarchy work. The invalid line blocks the version commit, but C's hierarchy has already changed.",
            "action": "Defer hierarchy effects for concept retirement in seeded imports, or reject DELETE actions during preflight if they are unsupported in a standalone release.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "F6.12",
            "severity": "P2",
            "tag": null,
            "file": "core/common/tasks.py",
            "line": 714,
            "claim": "The admin hierarchy repair silently skips explicit child version URLs.",
            "scenario": "An admin calls `amend-hierarchy` with an existing parent URL and the URL of a historical child version. The previous task linked the named child row and its latest version. The replacement resolves only versioned-object rows for child URLs, so it completes without adding either link.",
            "action": "Preserve exact child-row resolution for the admin repair and test it with a historical child URL.",
            "lines_delta": null,
            "confidence": "high"
        }
    ]
}

…ings, refuses delete lines and reads archive lines whole; dropped codes leave HEAD's comparisons and concept mappings; archive summaries round-trip
@snyaggarwal

snyaggarwal commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Codex pass 6 is addressed in 820cb32. It's a normal push on top of cf31316.

  • F6.1 (P0): ImportTaskSummary.dropped is now dict | None = None. Test: test_import_summary_round_trips_with_or_without_drop_counts serialises a summary with and without counts and reads it back.
  • F6.2: preflight matches mapping lines without an id to HEAD's mappings the way MappingImporter does (the new MappingKeys). A line matches by map type plus the concepts it links, resolved from versionless URLs, or by map type, the codes and the target source. The old one-for-one allowance is gone. Test: test_unnamed_mappings_count_toward_the_drop. The same release seeded again drops nothing; a renamed map_type counts all three old mappings as dropped and is refused.
  • F6.3 and F6.11: a seeding import with a __action: delete line is refused in preflight on every runner, since leaving a code out is how a release drops it. Archive workers skipped those lines, and inline workers changed the hierarchy before the commit. Test: test_delete_lines_are_refused.
  • F6.4: IDs are compared as strings. Test: test_numeric_ids_match_their_stored_codes. Concept IDs sent as JSON numbers already fail in the concept importer without this PR, so the test sends numeric mapping IDs only.
  • F6.5: the archive scan builds each line of a seeding import whole (ijson.ObjectBuilder), so preflight sees the real filters, properties and meta, and each line's __action. Test: test_archive_preflight_reads_each_line_whole. test_categorize_resources_keeps_only_source_version_lines now expects the nested extras.
  • F6.6: meta must be an object, meta.display an object, and meta.display.concept_filter_order a list of strings. Test: test_malformed_display_metadata_is_refused.
  • F6.7: ViewableHierarchyUrlsField reads repo_version from the context, so child_concept_urls and parent_concept_urls on version-scoped children/ and parents/ follow that version. The nested-fields test checks the reused X row.
  • F6.8: HEAD's get_concepts_queryset and get_mappings_queryset leave out dropped rows. These are what the comparison checksum maps and the HEAD counts read. The sweep also sets updated_at on the rows it drops, so last_child_update moves and cached HEAD comparisons and exports are rebuilt. Test: test_dropped_codes_leave_heads_queries_and_bump_its_last_update.
  • F6.9:
    • A concept's mappings leave out mappings dropped from HEAD; this covers the mappings endpoint, includeMappings and mapped codes.
    • Version-scoped concepts/X/mappings/ now lists that version's mappings.
    • After a drop, the concepts of dropped mappings get their mapped codes reindexed.
    • Test: test_dropped_mappings_leave_head_and_newer_versions_concepts. HEAD and v2 list no M1, and v1 still lists it.
  • F6.10: when a seeding line turns HEAD's semantic matching on or off, HEAD's vector sync is queued after commit, as an edit of HEAD does. Test: test_semantic_change_on_head_syncs_its_vectors.
  • F6.12: make_hierarchy links a child URL that names a concept version through that row and its concept's latest version, as master's task did (ImportHierarchy.link_child_versions). Test: test_hierarchy_repair_links_a_child_version_url.

Lost child after a commit-time rejection, from your notes: this matches what I hit while testing pass 4. A concept with children gets one extra version on its first identical re-import, and its children keep pointing at the old row. It happens on master without seeding, so it isn't changed here, and it needs its own ticket.

Checked locally: core.importers, core.concepts, core.sources, core.common and core.integration_tests (sources, concepts, mappings) ran 1519 tests with one failure, BulkImportLimitsTest.test_grandfathered_npm_url_is_downloaded_and_handed_over_as_upload. It fails locally without this PR's changes as well. Pylint -j0 core/ passes.

Still open: C3, C5, C7, C8, C12 and C13; F4.3 is tracked on ocl_online#687.

🤖 Addressed by Claude Code

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member

Codex check of commits cf31316..820cb32 (codex-cli 0.169.0)

Verdict: fix-first. Five P1s and two P2s. All five P1s were reproduced on a test stack, and each one passes at cf31316, so each comes from 820cb32.

Pass 6 findings at 820cb32

  • Resolved: F6.1, F6.3, F6.4, F6.5, F6.6, F6.7, F6.10 and F6.11. Checked on the stack: an archive summary with dropped: null reads back; delete lines are refused up front; archive preflight sees filters: ["status"] and refuses it.
  • F6.2: the pass 6 case is fixed. Twenty id-less mappings with a renamed map_type are now refused, and the same release seeded again drops nothing. Codex marks it regressed because of FC.1 and FC.2.
  • F6.8: v1 compared with HEAD now shows the dropped code as removed. A code restored afterwards stays removed in the cached comparison (FC.4).
  • F6.9: HEAD's A/?includeMappings=true, A/mappings/ and v2/concepts/A/mappings/ no longer list the dropped M1. An older release's concept detail now hides it too (FC.5).
  • F6.12: regressed (FC.7).
  • On the stack, the reported dropped counts matched the rows the sweep made inactive in every probe. A LOINC-shaped file (id-less URL-to-URL mappings, one pair listed twice) seeded again drops nothing. Lines naming an external target by to_source_url + to_concept_code and seeded again drop nothing. The 2.82 import file names every mapping target by URL, and the production LOINC source has no two mappings sharing a map type, from and to, so FC.1 and FC.2 don't affect that release.

Findings

  • [P1] FC.1 (core/importers/models.py:475): an id-less line credits every HEAD mapping that shares its key, but the importer updates only one of them (the non-retired one, else the newest). Repro (minimum 1, 10%): HEAD has 10 pairs, each a retired mapping and an active one with the same map type, from and to. A release sends one id-less line per pair. Preflight passes, and the sweep drops the 10 retired mappings (a third of HEAD) without allow_large_drop. cf31316 refused this release. Fix: credit one HEAD mapping per line, chosen as MappingImporter.process chooses it.
  • [P1] FC.2 (core/importers/models.py:466): a release that names targets by code alone (from_concept_url + to_concept_code, no to_source_url) is refused when HEAD's mappings store a to_source_url, though the importer updates every one of them. Repro: 10 such mappings. Preflight says the import "would drop 0 concepts and 10 mappings"; with allow_large_drop the import drops 0 and updates 10. cf31316 accepted it. Fix: use the importer's own predicates, which add a target source only when the line gives one or a target URL.
  • [P1] FC.3 (core/sources/models.py:1028): HEAD's querysets now skip dropped rows, and sequential ID allocation reads its highest existing ID from them, so a new resource can get a dropped one's ID. Repro: mappings with explicit IDs 1 and 2 (sequential mapping IDs are the default); v2 drops 2; an ordinary import of an id-less mapping is given 2, and HEAD now holds two mappings with ID 2. The same happens with concepts on a source with sequential concept IDs: a new concept got 9 after 9 and 10 were dropped. cf31316 assigned 3 and 11. Fix: take the highest ID over all of HEAD's rows, inactive ones included.
  • [P1] FC.4 (core/sources/models.py:1347): a cached HEAD comparison keeps a restored code as removed. Repro: v2 drops B; v1 compared with HEAD shows B removed; an ordinary import of B, unchanged, makes it active again and HEAD's concepts/ lists it, but the comparison still shows B removed. restore_to_head saves only is_active, so last_child_update doesn't move and the cached checksum map isn't rebuilt. Fix: move updated_at on restore as the sweep now does on drop.
  • [P1] FC.5 (core/concepts/models.py:1326): an older release's concept detail loses the mappings a later release dropped. Repro: after v2 drops M1 (A to B), v1/concepts/A/?includeMappings=true lists no mappings, while v1/concepts/A/mappings/ and v1/mappings/ list M1. cf31316 listed it. Codex adds that the drop task's mapped-code reindex can remove the target code from search for a release's concept row. Fix: use the release's members for embedded mappings and mapped codes on version-scoped requests, and the active-HEAD filter only for HEAD.
  • [P2] FC.6 (core/concepts/models.py:1333): version-scoped concepts/X/mappings/ follows membership only, so it can return a mapping revision an admin soft-deleted. Not run.
  • [P2] FC.7 (core/concepts/models.py:2096): the admin hierarchy repair strips a parent URL's version before resolving it, so a parent version URL that doesn't exist still links the child to the current parent. Master required the named parent row. Not run.

Also seen on the stack, not from these commits: a Source Version line with properties: 5 raises TypeError in seeding preflight (clean_properties), a server error instead of a 400. It does the same at cf31316.

findings.json
{
    "reviewer": "codex-cli 0.169.0",
    "perspective": "defects",
    "mode": "final",
    "commit": "820cb326",
    "verdict": "findings",
    "prior": [
        {
            "id": "F6.1",
            "status": "resolved"
        },
        {
            "id": "F6.2",
            "status": "regressed"
        },
        {
            "id": "F6.3",
            "status": "resolved"
        },
        {
            "id": "F6.4",
            "status": "resolved"
        },
        {
            "id": "F6.5",
            "status": "resolved"
        },
        {
            "id": "F6.6",
            "status": "resolved"
        },
        {
            "id": "F6.7",
            "status": "resolved"
        },
        {
            "id": "F6.8",
            "status": "unresolved"
        },
        {
            "id": "F6.9",
            "status": "regressed"
        },
        {
            "id": "F6.10",
            "status": "resolved"
        },
        {
            "id": "F6.11",
            "status": "resolved"
        },
        {
            "id": "F6.12",
            "status": "regressed"
        }
    ],
    "findings": [
        {
            "id": "FC.1",
            "severity": "P1",
            "tag": null,
            "file": "core/importers/models.py",
            "line": 475,
            "claim": "One id-less mapping line can credit multiple HEAD mappings as retained and bypass confirmation.",
            "scenario": "HEAD has 1,500 source-target pairs with two distinct mapping IDs per pair, one retired and both still active. A release keeps every concept and sends one id-less mapping per pair. Preflight credits all 3,000 mappings because both IDs share the same key. MappingImporter selects the non-retired row for each pair, so the sweep drops 1,500 mappings without confirmation. The previous guard would have refused this release.",
            "action": "Count the specific mapping identity each line will update using the importer's candidate selection and ordering. Test a release with duplicate candidates and verify that refusal leaves HEAD unchanged.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FC.2",
            "severity": "P1",
            "tag": null,
            "file": "core/importers/models.py",
            "line": 466,
            "claim": "Preflight rejects releases whose id-less mapping lines identify existing targets by code alone.",
            "scenario": "HEAD has 1,500 mappings with stored target source URLs and a unique match for each from-concept, map type and target code. A release keeps all concepts and supplies those same triples using `from_concept_url` and `to_concept_code`, with no target URL. MappingImporter applies no target source predicate and would update all 1,500 identities. Preflight instead requires their stored target URLs to match a key containing `None` and refuses the release as a large drop.",
            "action": "Use the same optional target source and encoded-code predicates in preflight and MappingImporter. Add a threshold-crossing test for code-only targets.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FC.3",
            "severity": "P1",
            "tag": null,
            "file": "core/sources/models.py",
            "line": 1028,
            "claim": "Sequential ID allocation can reuse a mnemonic that still belongs to a dropped mapping.",
            "scenario": "A source with the default sequential mapping IDs imports an explicit mapping ID `1`, leaving its sequence at the initial value. A seeded release drops that mapping. The next ordinary id-less import creates a different mapping, and the maximum-ID query skips the inactive row. The allocator assigns `1` again. Two identities now share the same source and mnemonic, and an explicit import of `1` can select and reactivate the older row.",
            "action": "Calculate the maximum allocated mnemonic across all existing identities, including inactive rows, for both mapping and concept sequences. Keep active membership filtering on read paths.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FC.4",
            "severity": "P1",
            "tag": null,
            "file": "core/sources/models.py",
            "line": 1347,
            "claim": "A cached HEAD comparison can keep reporting a code as missing after an ordinary import restores it.",
            "scenario": "A seeded release drops A. A subsequent `$compare` builds and caches a HEAD concept map without A. An ordinary import resends A unchanged and the duplicate-checksum path reactivates it through `restore_to_head()`. That method saves only `is_active` and reattaches the memberships, so `last_child_update` stays fixed. HEAD reads see A again, but the cached comparison still reports it missing.",
            "action": "Advance HEAD's cache revision on restoration even when the resource checksum is unchanged. Test a comparison cached between the drop and the restore.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FC.5",
            "severity": "P1",
            "tag": null,
            "file": "core/concepts/models.py",
            "line": 1326,
            "claim": "Dropping a mapping from HEAD now hides it from concept detail and mapped-code search in a release that still contains it.",
            "scenario": "Release v1 contains A and M1 mapping A to X. Release v2 keeps A and omits M1. The v1 mappings subresource still lists M1, but `v1/concepts/A/?includeMappings=true` loses it because the detail serializer reads active HEAD mappings. If M1's from-concept FK names the v1 concept row, the new drop task also refreshes that row's search document and removes X from v1 mapped-code search.",
            "action": "Use release membership for embedded mappings and version-scoped mapped-code search. Apply the active HEAD filter to HEAD requests and index fields that serve HEAD.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FC.6",
            "severity": "P2",
            "tag": null,
            "file": "core/concepts/models.py",
            "line": 1333,
            "claim": "The version-scoped concept mappings endpoint can return a soft-deleted mapping revision.",
            "scenario": "An ordinary v1 created through POST `/versions/` contains M1 targeting X. HEAD later changes M1 to target Y, and an admin soft-deletes the historical revision targeting X. The deletion leaves the v1 membership row intact. The new `v1/concepts/A/mappings/` query follows that membership and returns the deleted revision, even though the direct mapping API excludes inactive revisions.",
            "action": "Filter historical mapping members by `is_active=True` in the concept mappings endpoint. Test both an admin-deleted revision and an active historical revision whose HEAD identity was dropped.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FC.7",
            "severity": "P2",
            "tag": null,
            "file": "core/concepts/models.py",
            "line": 2096,
            "claim": "The admin hierarchy repair can add links using a parent version URL that does not exist.",
            "scenario": "An admin submits an existing historical child URL and a parent URL whose version suffix names a deleted or mistyped revision. The previous task required the supplied parent row to exist. The new historical-child path strips the suffix first and links both the historical child and its latest revision to the current parent.",
            "action": "Resolve explicit parent version URLs exactly before looking up each parent's latest revision. Test that a missing parent revision adds no links.",
            "lines_delta": null,
            "confidence": "high"
        }
    ]
}

…ings as the importer does; dropped ids aren't reused, restores refresh HEAD caches, releases keep their own mappings, and parent version URLs resolve exactly
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

The Codex check of cf31316..820cb32 is addressed in fd31cb8. It's a normal push on top of 820cb32.

  • FC.1 and FC.2: preflight now matches mapping lines without an id with MappingImporter's own conditions (the new MappingMatcher).
    • A line credits one HEAD mapping, chosen as process chooses it: the first one not retired, else the newest.
    • The target source and the code variations are applied only when the line gives them, as the importer does.
    • Tests:
      • test_unnamed_mapping_keeps_only_the_mapping_the_importer_updates: retired and active pairs, refused with three mappings dropped.
      • test_unnamed_mapping_naming_its_target_by_code_keeps_it: from_concept_url + to_concept_code with no target URL; drops nothing.
  • FC.3: sequential ID allocation reads the highest mnemonic over all of HEAD's concepts and mappings, dropped ones included. Read paths still leave dropped rows out. Test: test_new_ids_skip_those_of_dropped_codes.
  • FC.4: restore_to_head saves updated_at together with is_active, so last_child_update moves and cached HEAD comparisons and exports are rebuilt. Test: test_restoring_a_dropped_code_moves_heads_last_update.
  • FC.5:
    • A concept's detail on a source version URL now embeds that release's mappings. The detail view now has ConceptHierarchyMixin, so repo_version is in its context.
    • The active-HEAD filter in __get_mappings_from_relation applies only to HEAD's rows: the versioned object and the latest version. A concept version only an older release has keeps its mappings and mapped codes.
    • The drop task refreshes mapped codes only for the versioned objects and latest versions of the dropped mappings' concepts.
    • List preloading follows the same rule.
    • Test: v1/concepts/A/?includeMappings=true lists M1 after v2 drops it.
  • FC.6: get_version_mappings filters is_active=True, so an admin soft-delete of a version's mapping hides it from concepts/X/mappings/. Test added to the same API test.
  • FC.7: ImportHierarchy.resolve_parents resolves a parent URL that names a version to that exact row. A version that doesn't exist resolves to nothing. Both import reconciliation and the admin repair use it, and children and versionless parents are still looked up in one query. Test: test_hierarchy_repair_ignores_a_parent_version_that_does_not_exist.
  • properties: 5: properties, filters and match_algorithms on a version line must be lists; otherwise the line is refused with a 400 rather than a TypeError. Test: test_list_valued_metadata_must_be_lists.

Shared rows: when one concept version is in both an older release and HEAD (an unchanged row), its search document serves both. Its mapped codes follow HEAD.

Checked locally: core.importers, core.concepts, core.sources, core.common, core.mappings and core.integration_tests (sources, concepts, mappings) ran 1553 tests with one failure, BulkImportLimitsTest.test_grandfathered_npm_url_is_downloaded_and_handed_over_as_upload. It fails locally without this PR's changes as well. Pylint -j0 core/ passes.

Still open: C3, C5, C7, C8, C12 and C13; F4.3 is tracked on ocl_online#687.

🤖 Addressed by Claude Code

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member

Codex check of commits 820cb32..fd31cb8 (codex-cli 0.169.0)

Verdict: fix-first. Three P1s come from fd31cb8 and were reproduced on a test stack: FD.1, FD.2 and FD.4. Each one passes at 820cb32. FD.5 was also reproduced, but most of it predates this commit (see below). The LOINC 2.82 import file can't trigger FD.1 or FD.2: all 250,840 of its Mapping lines name both ends by URL, with no from_concept_code, to_concept_code or to_source_url. FD.2 also needs update_if_exists=false, which isn't the default.

c7 findings at fd31cb8 (reproduced at minimum 1 / 10% with c7's probes)

  • Resolved: FC.1, FC.2, FC.3, FC.4, FC.6, FC.7 and the properties: 5 error (FC.8 below).
    • FC.1: one id-less line per (retired, active) pair is refused: "would drop 0 concepts and 10 mappings". HEAD is unchanged.
    • FC.2: code-only targets update all 10 and drop 0.
    • FC.3: a new mapping gets 3 after 2 was dropped, and a new concept gets 11 after 9 and 10 were dropped.
    • FC.4: a restored B no longer shows as removed in the cached comparison.
    • FC.8: properties: 5, filters: "status" and match_algorithms: "es" are each refused with "… must be a list."
  • FC.5: c7's case passes: v1/concepts/A/?includeMappings=true lists M1 after v2 drops it. Codex keeps FC.5 open because the release's concept list and its search document still follow HEAD (FD.4, FD.shared).

Findings

  • [P1] FD.1 (core/importers/models.py:490): preflight credits a HEAD mapping for an id-less line that carries from_concept_code, but the importer's lookup puts the list of code variants into an exact from_concept_code filter, which matches nothing, so the importer creates a new mapping. Repro (minimum 1, 10%): HEAD has 10 mappings to X0…X9 with to_source_url. A release sends from_concept_url + from_concept_code + to_concept_code. The import is accepted with no allow_large_drop: it creates 10 mappings without a target source and drops all 10 originals. 820cb32 refused it. Fix: give preflight and the importer the same from-code predicate (an __in lookup in the importer, or no from-code credit in preflight).
  • [P1] FD.2 (core/importers/models.py:621): with update_if_exists=false (accepted together with seed_from_import=true), the importer creates rather than updates, but preflight still credits the HEAD mappings it would have updated. Repro: a mapping-only source with 10 mappings whose from-concepts are in another source. v2 is seeded with update_if_exists=false and code-only targets. It is accepted with no allow_large_drop, creating 10 new mappings and dropping all 10 originals. 820cb32 refused it ("would drop 0 concepts and 10 mappings"). Fix: pass the update mode into preflight and credit nothing in create-only mode, or refuse update_if_exists=false with seed_from_import.
  • [P2] FD.3 (core/importers/models.py:474): preflight chooses each line's mapping from a fixed snapshot of retired states, so two lines for one pair, where the first changes which row the second selects, can be counted as a drop. Not run.
  • [P1] FD.4 (core/concepts/serializers.py:284): an older release's concept list with includeMappings hides a mapping when the concept's row in that release is still flagged is_latest_version, including when the concept itself was dropped from HEAD. Repro: v1 has A, B and M1 (A to B); v2 keeps only B. v1/concepts/?includeMappings=true shows A with no mappings, while v1/concepts/A/?includeMappings=true and v1/concepts/A/mappings/ list M1. At 820cb32 the list showed M1 and the detail didn't (FC.5), so the gap moved from detail to list. A's v1 search document also loses B, at both commits. Fix: on source-version URLs, preload mappings from the release's members, as the detail now does.
  • [P1] FD.5 (core/concepts/models.py:1326): a concept row that only an older release has takes its mapped codes from the concept's current mappings, now including ones dropped from HEAD. Repro: v1 has A with no mapping. v2 edits A and adds M (A to X). v3 drops M. A's v1 row still indexes X after v3; at 820cb32 it lost X. At both commits that row already indexed X while M was active, and v1/concepts/?includeMappings=true lists M for A, so a historical row showing mappings from after its release predates this commit. What's new is that dropped mappings stay too. Fix: build a historical row's mapped codes from its release's members.
  • [P2] FD.6 (core/concepts/serializers.py:319): on an ordinary source (never seeded), v1/concepts/A/?includeMappings=true&mappingBrief=true now gives each mapping's url as its revision URL (/mappings/M1/116/), where 820cb32 gave /mappings/M1/. The full form keeps the versionless url. Reproduced.
  • [P2] FD.7 (core/sources/models.py:1041): the widened maximum-ID query casts every numeric mnemonic, dropped ones included, to an integer. A dropped mnemonic too large for a PostgreSQL integer makes the query fail, and allocation falls back to reusing an ID. Not run.
  • [P2] FD.8 (core/concepts/views.py:377): when latest resolves to HEAD (a released HEAD with no numbered version), latest/concepts/A/?includeMappings=true lists M1 twice, because HEAD's membership holds both the mapping and its latest revision. Reproduced; 820cb32 listed it once.
  • [P3] FD.shared (behaviour, recorded for the release decision; not a defect): for a concept unchanged between v1 and a later seeded release that drops one of its mappings, v1 shows two different pictures. Probe: v1 has A, M1 (A to B, SAME-AS) and M3 (A to D); v2 keeps A unchanged and drops M1.
    • v1/concepts/A/?includeMappings=true and v1/concepts/A/mappings/ list M1 and M3 (the release).
    • v1/concepts/?includeMappings=true lists only M3 for A (HEAD).
    • A's search document, which serves v1, v2 and HEAD, drops B from same_as_map_codes, so v1 mapped-code search, the same_as_map_codes filter and the targetRepo facet no longer count M1 (HEAD).
    • A concept that v2 changed (C, whose v1 row is v1's alone) keeps its dropped mapping on every path.
findings.json
{
    "reviewer": "codex-cli 0.169.0",
    "perspective": "defects",
    "mode": "final",
    "commit": "fd31cb86",
    "verdict": "findings",
    "prior": [
        {
            "id": "FC.1",
            "status": "resolved"
        },
        {
            "id": "FC.2",
            "status": "resolved"
        },
        {
            "id": "FC.3",
            "status": "resolved"
        },
        {
            "id": "FC.4",
            "status": "resolved"
        },
        {
            "id": "FC.5",
            "status": "unresolved"
        },
        {
            "id": "FC.6",
            "status": "resolved"
        },
        {
            "id": "FC.7",
            "status": "resolved"
        },
        {
            "id": "FC.8",
            "status": "resolved"
        }
    ],
    "findings": [
        {
            "id": "FD.1",
            "severity": "P1",
            "tag": null,
            "file": "core/importers/models.py",
            "line": 490,
            "claim": "Preflight credits existing mappings that the importer's exact from-code lookup cannot match.",
            "scenario": "HEAD contains 1,500 mappings with target source URLs. An id-less release resends each mapping with `from_concept_url`, a matching `from_concept_code`, and `to_concept_code` alone. The new matcher credits all 1,500. The importer's exact TextField lookup compares the stored from code to the string form of the whole list of variants, so each line creates a new mapping with no target source URL. The sweep drops all 1,500 existing identities without confirmation. The previous preflight refused the file because the stored target source URLs did not match the omitted URL.",
            "action": "Make preflight and the importer use the same from-code predicate. If variants are intended, use `__in` in the importer as well. Test the threshold with both from fields and a code-only target.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FD.2",
            "severity": "P1",
            "tag": null,
            "file": "core/importers/models.py",
            "line": 621,
            "claim": "The broadened code-only lookup lets create-only imports bypass large-drop confirmation.",
            "scenario": "A mapping-only source owns 1,500 mappings whose from-concepts are in another source and whose targets have stored source URLs. An inline or parallel seed with `update_if_exists=false` resends those from URLs and target codes without IDs or target URLs. The new preflight credits the existing mappings. The importer creates distinct mappings with no target source URL, and the sweep drops all 1,500 originals without confirmation. The previous preflight rejected these code-only lines.",
            "action": "Pass the runner's update mode into preflight and credit an existing identity only when that mode will update it. Cover the create-only case with a threshold-crossing test.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FD.3",
            "severity": "P2",
            "tag": null,
            "file": "core/importers/models.py",
            "line": 474,
            "claim": "Preflight can refuse a release that retains every mapping because it chooses against a fixed snapshot of retirement states.",
            "scenario": "Each of 1,500 pairs has an older non-retired mapping and a newer retired mapping, both active. An inline release sends two id-less lines per pair with the same endpoint URLs, both marked retired and with changed extras. The first line retires the older mapping. The second then selects the newer mapping because both candidates are retired. Preflight chooses the older row for both lines and refuses the release as a 1,500-mapping drop. The previous preflight credited both identities in this case.",
            "action": "Plan candidate selection in application order when lines can change later matches. Test two lines for one pair where the first line changes which identity the second selects.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FD.4",
            "severity": "P1",
            "tag": null,
            "file": "core/concepts/serializers.py",
            "line": 284,
            "claim": "An older release's concept list can lose a mapping even when the concept itself has left HEAD.",
            "scenario": "V1 contains A and its mapping M1. A later seed drops both. A's surviving v1 revision still has `is_latest_version=True` because the sweep removes HEAD membership without clearing that flag. The v1 list with `includeMappings=true` now filters out inactive HEAD identity M1. The previous list included it, and v1 detail and the mappings subresource still include its release revision.",
            "action": "Pass the resolved source version into the list serializer and preload mappings from that version's membership. Test a release list after dropping both a concept and its mapping.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FD.5",
            "severity": "P1",
            "tag": null,
            "file": "core/concepts/models.py",
            "line": 1326,
            "claim": "Reindexing a historical concept can add a mapped code that never belonged to its release.",
            "scenario": "V1 contains A without a mapping to X. V2 edits A and adds a mapping from A's versionless URL to X. V3 drops that mapping. A full reindex of v1 now follows A's identity to the inactive mapping and indexes X for the older-only concept revision. A v1 mapped-code filter can return A and the target repo can appear in its facets. Before this commit the active filter excluded the dropped mapping on that reindex.",
            "action": "Build mapped-code fields for historical revisions from the relevant release memberships. Test a reindex where the dropped mapping was introduced after the release being searched.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FD.6",
            "severity": "P2",
            "tag": null,
            "file": "core/concepts/serializers.py",
            "line": 319,
            "claim": "Embedded brief mapping URLs change from editable resource URLs to revision URLs on ordinary source versions.",
            "scenario": "A source that has never used seeding creates v1 through POST `/versions/`. A client reads `v1/concepts/A/?includeMappings=true&mappingBrief=true` and uses an embedded mapping's `url` for a HEAD edit. The earlier URL addressed the mapping identity. The new URL ends in the revision ID and rejects PUT or PATCH. The full form keeps the versionless `url` and now reports the snapshot revision's `uuid`, `version`, and `version_url`. Retirement and direct `mapTypes` and `targetRepoUrls` filters now apply to snapshot rows. Inverse mode still bypasses the map-type and target-repo filters.",
            "action": "Preserve the versionless `url` for brief embedded mappings and use `version_url` for the release revision. Cover the response contract on a source that has never used seeding.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FD.7",
            "severity": "P2",
            "tag": null,
            "file": "core/sources/models.py",
            "line": 1041,
            "claim": "A dropped numeric mnemonic outside the integer range can still cause sequential ID reuse.",
            "scenario": "A source with the default mapping sequence has explicit IDs `1` and `3000000000`, so its sequence still starts at 1. A seed drops only `3000000000`. In the next ordinary id-less import, the widened maximum query casts the dropped mnemonic to a PostgreSQL integer and fails. The allocator swallows that error and assigns 1 again. The previous query excluded the dropped row and advanced past the existing ID 1.",
            "action": "Use a range-safe maximum for sequence allocation and handle an out-of-range mnemonic without discarding the maximum of valid IDs. Test allocation with a dropped oversized numeric mnemonic.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FD.8",
            "severity": "P2",
            "tag": null,
            "file": "core/concepts/views.py",
            "line": 377,
            "claim": "Concept detail on `/latest/` can embed each mapping twice when that alias resolves to HEAD.",
            "scenario": "A source is created with `released=true` and has no numbered release. `/latest/concepts/A/?includeMappings=true` resolves to HEAD. The new serializer context treats HEAD as a release and reads its mapping membership, which contains both the identity and the latest revision for M1. The response embeds M1 twice. The previous detail path returned only the identity.",
            "action": "Use the HEAD serialization path whenever the resolved source is HEAD, including when the URL uses `latest`. Add a detail test for a released HEAD.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FD.shared",
            "severity": "P3",
            "tag": null,
            "file": "core/sources/models.py",
            "line": 315,
            "claim": "The older release's detail and mappings subresource show its snapshot. The concept list and mapped-code search follow HEAD for the unchanged concept row.",
            "scenario": "V1 contains A and M1 from A to X. A later seeded version keeps the same concept revision and drops M1. On a fresh v1 read, `concepts/A/?includeMappings=true` and `concepts/A/mappings/` still show v1's M1. The v1 concept list with `includeMappings=true` omits M1. After indexing, v1 search loses M1's mapped-code boost for X, A no longer matches X through the applicable `same_as_map_codes` or `other_map_codes` filter on account of M1, and M1 no longer contributes to the `targetRepo` facet count.",
            "action": "Record the behavior for the release decision.",
            "lines_delta": null,
            "confidence": "high"
        }
    ]
}

…tches from codes as the importer does; release concept lists and older concept versions use the release's own mappings; latest-as-HEAD reads HEAD
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

The Codex check of 820cb32..fd31cb8 is addressed in f027af0. It's a normal push on top of fd31cb8.

  • FD.1: MappingImporter matched from_concept_code with an exact filter on the whole list of code variants, so it never matched and always created a new mapping. It now uses from_concept_code__in, the same rule preflight applies. This also fixes ordinary imports that send a from code. Test: test_unnamed_mapping_naming_its_from_code_keeps_it; it keeps all three mappings and drops none.
  • FD.2: seed_from_import=true with update_if_exists=false is refused. The import endpoint returns a 400, and IsolatedVersionCommit.preflight refuses it for every runner. Tests: test_seed_from_import_refuses_create_only and test_seeding_needs_update_if_exists.
  • FD.3: MappingMatcher applies the lines in file order. After a line picks a mapping, that mapping takes the line's retired value (default False, as a seeding import leaves unsent fields at their defaults), so later lines choose as the importer will. Test: test_unnamed_mappings_choose_in_file_order, with two retired lines per pair; both mappings are kept.
  • FD.4: ConceptListView has ConceptHierarchyMixin, so a release's concept list preloads the release's own active mappings, matched by the concept's versioned object. ConceptListIncludeMappingsTest.test_source_version_list now adds the version's mappings, since a version's list no longer shows HEAD's. The batched and per-concept paths still agree.
  • FD.5: a concept row that HEAD doesn't serve (neither the versioned object nor the latest version) builds its mapped codes from the active mappings of the releases it is in (Concept.get_indexed_mappings). Test: test_older_concept_version_indexes_its_releases_mappings; v1's row never indexes the mapping that v2 added and v3 dropped.
  • FD.6: brief embedded mappings on a source-version URL use EmbeddedMappingMinimalSerializer, whose url is the versionless mapping URL, as the full form's is. Inverse mode still doesn't apply mapTypes and targetRepoUrls, the same as on HEAD.
  • FD.7: the highest-ID query casts to a big integer and only reads numeric mnemonics of up to 18 digits. Test: test_largest_dropped_id_counts_even_past_integer_range, with 3000000000.
  • FD.8: when latest resolves to HEAD, the hierarchy mixin treats it as HEAD. Test: test_latest_that_is_head_embeds_each_mapping_once.
  • FD.shared: after FD.4 and FD.5, a release's detail, list and mappings/ all show its own mappings. The one exception is a concept row both a release and HEAD hold, unchanged between them: its search document serves both, so its mapped codes follow HEAD. That's the remaining part for the release decision.

Checked locally: core.importers, core.concepts, core.sources, core.common, core.mappings and core.integration_tests (sources, concepts, mappings) ran 1560 tests.

  • The isolated-version and include-mappings classes pass.
  • One failure, BulkImportLimitsTest.test_grandfathered_npm_url_is_downloaded_and_handed_over_as_upload, fails locally without this PR's changes as well.
  • Five ConceptPropertyFilterViewTest cases fail locally without this PR's changes too, against this machine's Elasticsearch, and passed in CI before.
  • Pylint -j0 core/ passes.

Still open: C3, C5, C7, C8, C12 and C13; F4.3 is tracked on ocl_online#687.

🤖 Addressed by Claude Code

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member

Final review (codex-cli 0.169.0, commits fd31cb8..9c75a44)

Verdict: Ready to merge once 2 items are fixed. f027af0 fixes the FD scenarios as reported. Two small items remain. FE.2 changes how ordinary imports match mappings. The other is a product decision made today: a version line's match_algorithms stays off HEAD. Everything else can ship and be followed up in its own ticket. The merge 9c75a44 is git's automatic merge of f027af0 and master (no hand resolution). Only core/concepts/views.py changed on both sides, in hunks far apart, and nothing new from master reads what this PR changes.

Checked on a test stack at 9c75a44 (large-drop guard at minimum 1 / 10%):

  • FD.1: a release sending from_concept_code + to_concept_code updates all 10 mappings and drops none.
  • FD.2: update_if_exists=false with seed_from_import is refused before anything is written.
  • FD.4: v1/concepts/?includeMappings=true lists M1 for A after v2 drops A and M1.
  • FD.5: A's v1-only row never indexes X, before or after v3 drops the mapping.
  • FD.6: the brief embedded url is the versionless mapping URL.
  • FD.8: latest resolving to HEAD lists M1 once.
  • c7's and c8's earlier probes give the same results as at fd31cb8: FC.1 to FC.5, up-front refusals leave HEAD unchanged, list-field checks, and the LOINC-shaped files.

Codex marks FD.1 and FD.3 to FD.7 "regressed". In each case the original scenario is fixed, and the fix opened the side case listed below as FE.n.

Fix before merge

  1. [P1] FE.2 (core/importers/models.py:917): ordinary imports.

    • With from_concept_code__in, a mapping line that carries from_concept_code now matches the way a line without it already matches on master.
    • When the line's from_concept_url doesn't resolve, that includes a mapping from another source that shares the code.
    • Repro (ordinary inline import into a mapping source that holds S1/X → T/Y): a line from S2/X (S2 exists, X isn't loaded) with from_concept_code: X and the same target and map type.
      • Update: the line now updates the S1 mapping and moves its from-source to S2. Master created a separate mapping.
      • Delete: with __action: DELETE the line now retires the S1 mapping. Master reported it not found.
    • Fix, either of:
      • when the from URL doesn't resolve and the line carries from_concept_code, also require the mapping's from_source_url to be the URL's source, in MappingImporter.get_queryset and MappingMatcher alike;
      • or keep master's lookup for ordinary imports.
    • The rest of the change is a fix worth keeping. Re-importing an id-less line that carries from_concept_code failed on master ("Parent, map_type, from_concept, to_source, to_concept_code must be unique") and now updates the mapping, as the same line without the code always did. LOINC 2.82's mapping lines carry no from code, so the release load isn't affected either way.
  2. match_algorithms stays off HEAD (product decision, Nov 19; this reverses the F5.9 change in cf31316). A seeding import's Source Version line that sets match_algorithms should set it on the new version only. HEAD keeps its own, as it does after POST .../versions/.

    • Today apply_version_metadata_to_head copies every field in ISOLATED_METADATA_FIELDS to HEAD, match_algorithms included. When that adds llm, it also starts HEAD's vector sync for every HEAD concept.
    • On the LOINC 2.82 load, a version line naming es and llm (as 2.81 has) would switch HEAD to semantic matching.
    • Fix:
      • skip match_algorithms in apply_version_metadata_to_head. Keep it in ISOLATED_METADATA_FIELDS, which the version line's allowed fields and checks also use, so the version still takes it;
      • drop the vector-sync branch there if nothing else it copies can change HEAD's semantic flag;
      • make test_seeding_line_match_algorithms_reach_head assert that HEAD is unchanged and the version has the line's value.

Ship and ticket (none of these loses or corrupts content on the LOINC 2.82 load or changes ordinary imports; † = matters only while the large-drop guard exists)

  • [P1]† FE.1 (core/importers/models.py:474): preflight can credit a mapping the import never updates, so a large mapping drop gets through unconfirmed. Two ways:

    • a file that mixes id-less and named lines for one pair (a named line creates C, a later id-less line updates C, and preflight credits an older retired B instead);
    • a parallel import applying two lines for one pair out of file order.

    The drop itself is what the file says (B isn't in it); only the count is low. Not run.

  • [P2]† FE.3 (core/importers/importer.py:556): archive preflight leaves retired out of what it reads from each line. A zip/tar release that resends retired pairs can then be refused as a drop, and inline retired: "1" isn't read as true. Not run.

  • [P2]† FE.4 (core/importers/tests.py:7001): test_unnamed_mappings_choose_in_file_order ends up with one mapping per pair, because the retired duplicate fails validation. So the test doesn't cover two candidates.

  • Search on an older release (fits the existing search ticket ocl_online#703):

    • [P1] FE.5 (core/concepts/models.py:1345): a concept row two releases share takes its mapped codes from every release it's in, so v1's search can find a code only v2 mapped. Not run.
    • [P2] FE.6: on reindex, an old row that only a collection holds loses its mapped codes. Not run.
    • FD.shared stays as described.
    • Probe: after v2 drops A and M1, A's v1 search document loses B. The row is still flagged latest, so it reads HEAD.
  • [P2] FE.7 (core/mappings/serializers.py:207): brief embedded mappings on release URLs now return extras without includeExtras, because the extras rule checks class names and EmbeddedMappingMinimalSerializer isn't on its list. Checked in the code; one-line fix.

  • [P2] FE.8 (core/sources/models.py:1039): the 18-digit cut-off skips a 19-digit numeric ID that fits a bigint, so sequential allocation can reissue it. Not run.

  • [P2] FE.9 (core/concepts/views.py:209): on a release's concept list, has_children and onlyHierarchyRoot still read unscoped links, while the embedded hierarchy fields are now release-scoped. Not run.

  • On master, not from this PR: an id-less mapping line without from_concept_code whose from URL doesn't resolve already matches another source's mapping by code (update and DELETE). FE.2's fix, applied to both kinds of line, would close it too.

  • Still open from earlier passes:

    • [P2] C3: mappings nested in Concept lines are dropped by a seeding import. The guard catches this only when the drop is large; refusing nested mappings when seed_from_import=true would close it.
    • [P2] C5: a release's membership is copied from HEAD by a queued task.
    • [P2] C7: relation-derived mapping text is kept on a seeding import.
    • [P2] C8: two seeding imports can run on one source at once.
    • [P3] C12, [P3] C13.
    • F4.3 is on ocl_online#687.
    • F4.1 and F4.7: Codex marks them resolved.
  • A seeding import refused at commit time (a content line failed, as opposed to an up-front refusal) keeps the content changes it already made to HEAD. HEAD's P/children/ can then miss C after P was renamed, which master also does after a rename, as pass 6 noted. Rerunning the corrected file relinks the children.

findings.json
{
    "reviewer": "codex-cli 0.169.0",
    "perspective": "defects",
    "mode": "final",
    "commit": "f027af05",
    "verdict": "findings",
    "prior": [
        {
            "id": "FD.1",
            "status": "regressed"
        },
        {
            "id": "FD.2",
            "status": "resolved"
        },
        {
            "id": "FD.3",
            "status": "regressed"
        },
        {
            "id": "FD.4",
            "status": "regressed"
        },
        {
            "id": "FD.5",
            "status": "regressed"
        },
        {
            "id": "FD.6",
            "status": "regressed"
        },
        {
            "id": "FD.7",
            "status": "regressed"
        },
        {
            "id": "FD.8",
            "status": "resolved"
        },
        {
            "id": "FD.shared",
            "status": "unresolved"
        },
        {
            "id": "C3",
            "status": "unresolved"
        },
        {
            "id": "C5",
            "status": "unresolved"
        },
        {
            "id": "C7",
            "status": "unresolved"
        },
        {
            "id": "C8",
            "status": "unresolved"
        },
        {
            "id": "C12",
            "status": "unresolved"
        },
        {
            "id": "C13",
            "status": "unresolved"
        },
        {
            "id": "F4.1",
            "status": "resolved"
        },
        {
            "id": "F4.3",
            "status": "unresolved"
        },
        {
            "id": "F4.7",
            "status": "resolved"
        }
    ],
    "findings": [
        {
            "id": "FE.1",
            "severity": "P1",
            "tag": null,
            "file": "core/importers/models.py",
            "line": 474,
            "claim": "The guard can approve a large drop by crediting mappings the import never updates.",
            "scenario": "Repeat this pattern for 1,500 pairs in a source small enough to cross the percentage threshold. Each pair has an older live mapping A and a newer retired mapping B. In an inline seed, the first ID-less line retires A, the next line creates an explicitly named mapping C for the same pair, and the last ID-less line selects C. Preflight ignores the new C and credits B. In a parallel seed, a worker can apply a second line with omitted `retired` before the first line retires A. Both lines then select A, while file-order preflight credits A and B. Both imports can drop all 1,500 B identities without confirmation. The previous preflight would have refused.",
            "action": "Use the same mapping choices for admission and execution, including identities created during the import and ordering across chunks. Enforce the threshold against the identities actually retained before committing any changes to HEAD.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FE.2",
            "severity": "P1",
            "tag": null,
            "file": "core/importers/models.py",
            "line": 917,
            "claim": "An ordinary import can overwrite or retire a mapping from a different source when its `from_concept_url` does not resolve.",
            "scenario": "A mapping repository holds a mapping from `S1/X` to `T/Y`. An ID-less line supplies `S2/X` as its from URL, `X` as its from code, and the same target and map type. S2 exists but X has not been loaded there. The new predicate matches the S1 mapping by code and rewires it to S2. An inline or parallel delete line can retire the S1 mapping instead. Previously the exact lookup missed, so the update path created a separate S2 mapping and the delete found no match. Ordinary inline, parallel, and OCL archive updates share the new lookup. Explicit IDs and create-only writes still use their existing paths.",
            "action": "Constrain unresolved from URLs by both source and code. When the URL resolves, use that concept identity and reject conflicting codes. Cover ordinary imports with colliding codes and encoded variants.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FE.3",
            "severity": "P2",
            "tag": null,
            "file": "core/importers/importer.py",
            "line": 556,
            "claim": "ZIP and TAR preflight can refuse a release that keeps every mapping because it strips `retired` before simulating updates.",
            "scenario": "HEAD has 1,500 pairs of retired mapping identities. For each pair, the archive resends the older mapping by ID with `retired: true`, then sends an ID-less line for the same endpoints. The actual importer leaves the older mapping retired and chooses the newer one for the second line. Preflight makes the older one appear live, credits it twice, and reports 1,500 drops. Before the fix, the fixed retirement snapshot credited both. Inline preflight can make the same mistake with `retired: \"1\"`, which the model saves as true.",
            "action": "Keep `retired` in the archive preflight projection and share boolean normalization with the importer. Test the archive preflight and execution together.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FE.4",
            "severity": "P2",
            "tag": null,
            "file": "core/importers/tests.py",
            "line": 7001,
            "claim": "The new file-order test passes with one mapping per pair, so it misses the behavior it claims to test.",
            "scenario": "The setup imports the live mapping first, then tries to create its retired duplicate. `MappingValidationMixin.clean()` rejects the second row because a live mapping with the same endpoints and map type already exists. The test ignores the first import's failures. The second import can send both lines to the sole surviving identity and still report zero drops.",
            "action": "Create both mappings while retired, reactivate the older one, and assert that both identities are present before the test import and retained afterward.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FE.5",
            "severity": "P1",
            "tag": null,
            "file": "core/concepts/models.py",
            "line": 1345,
            "claim": "Reindexing a concept revision shared by two releases adds the later release's mapped codes to the earlier release.",
            "scenario": "V1 publishes A without mappings. V2 reuses A's revision and adds M from A to X. V3 edits A and moves M to start at B. Before the fix, a fresh index of the old A revision found no current mapping from A after the move. Now the index takes M from V2's membership, so a V1 mapped-code search can return A for X and count X's repository in its `targetRepo` facet. V1's mapping membership is still empty for A.",
            "action": "Make mapped-code matching and faceting use the requested release's mapping membership. Test two releases that share a concept revision and have different mappings.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FE.6",
            "severity": "P2",
            "tag": null,
            "file": "core/concepts/models.py",
            "line": 1345,
            "claim": "Reindexing removes mapped codes from older concept revisions held only by a collection.",
            "scenario": "A collection expansion pins an old revision of A and a mapping from A to X. The source has no numbered release containing that revision. Before the fix, the concept document picked up the mapping through A's identity. Now the historical lookup only checks the revision's source memberships, which are empty. The collection still lists the mapping, but its mapped-code search no longer finds A for X after a full reindex.",
            "action": "Preserve mapped-code matching for collection-held revisions and use the expansion's mapping membership for collection-scoped searches.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FE.7",
            "severity": "P2",
            "tag": null,
            "file": "core/mappings/serializers.py",
            "line": 207,
            "claim": "Brief embedded mappings on source-version URLs now include `extras` by default.",
            "scenario": "A client requests a release's concept detail or list with `includeMappings=true&mappingBrief=true`. A mapping with a populated `extras` field now returns it even though `includeExtras` was omitted. The new subclass misses the class-name check that strips extras from the previous brief response.",
            "action": "Apply the same extras rule to both brief serializers and assert the full brief response shape alongside the corrected URL.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FE.8",
            "severity": "P2",
            "tag": null,
            "file": "core/sources/models.py",
            "line": 1039,
            "claim": "The 18-digit cutoff can make the sequential allocator issue an existing 19-digit mapping ID.",
            "scenario": "A source with its sequence still at 1 imports explicit IDs `999999999999999999` and `1000000000000000000`. The new maximum lookup sees only the first ID. The next ID-less create advances the sequence and assigns `1000000000000000000` again. Mapping creation checks the temporary mnemonic before allocation, and the database uniqueness rule includes the revision, so both identities can persist. The previous overflowing cast left the sequence at its initial allocation and did not collide in this case.",
            "action": "Include 19-digit values that fit PostgreSQL bigint and check the allocated mnemonic for collisions. Test allocation itself with adjacent IDs across the digit boundary.",
            "lines_delta": null,
            "confidence": "high"
        },
        {
            "id": "FE.9",
            "severity": "P2",
            "tag": null,
            "file": "core/concepts/views.py",
            "line": 209,
            "claim": "A version's concept list now reports hierarchy fields and hierarchy flags from different scopes.",
            "scenario": "A source release has root A, whose only child is a visible concept in another source. Request the release's concept list with `onlyHierarchyRoot=true&includeChildConceptURLs=true`. The new version context returns an empty child URL list, while `has_children` still reads the unscoped links and returns true. Clients show an expandable root, but the release's `children/` endpoint returns no children. Before the fix, the flag and the embedded URL list both described the unscoped links.",
            "action": "Use the resolved release membership for the concept list's hierarchy flags and filters as well as its embedded hierarchy fields.",
            "lines_delta": null,
            "confidence": "high"
        }
    ]
}

Review by Claude Code (launch worker review-985-final), with Codex.

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member

@snyaggarwal Jon would like this merged Fri Nov 20 so the LOINC 2.82 staging load can run. The two items in the final review above (FE.2, and match_algorithms staying off HEAD) are all that's left.

To save you time, we're building both fixes tonight as a PR into this branch, with tests and a Codex check, and we'll link it here when it's ready. Merge it if it looks right to you. If you'd rather push your own fixes, do; we'll post the Codex check of your commits here within the hour.

@paynejd

paynejd commented Nov 19, 2026

Copy link
Copy Markdown
Member

@snyaggarwal Both "Fix before merge" items are in #1014, a PR into this branch. Merge it if it looks right to you.

  • FE.2: when a mapping line's from URL doesn't resolve to a concept, matching by code now also requires the mapping to be from that URL's source: by its from source link, resolved as on save, or else by its stored from source URL. This applies in MappingImporter and the seeding preflight's MappingMatcher alike, with or without from_concept_code. An id-less line naming its from code still updates its own source's mapping.
  • match_algorithms off HEAD: a seeding Source Version line sets it on the new version only. HEAD keeps its own, and the HEAD vector-sync branch in apply_version_metadata_to_head is gone.

Tests: new tests run inline and through a parallel part. core.importers, core.sources and the sources and mappings integration tests pass locally (825 without Elasticsearch, 39 tagged es), and pylint is clean. CI on 78eedaa passes (Pylint, and the full Tests suite).

Review: two Codex passes, a simplification review and a final check; no P0 or P1 is open. One answer to pass 2 was reverted after the final check. The accepted P2s (F1.3, F2.1 to F2.3) are listed on #1014.

Posted by Claude Code for Jonathan.

* OpenConceptLab/ocl_online#655 | A mapping line whose from URL doesn't resolve matches a mapping by code only within that URL's source, so an import never updates or retires another source's mapping (FE.2)

MappingImporter.get_queryset and the seeding preflight's MappingMatcher now
also require the mapping's from_source_url to be the line's from source when
the from concept URL doesn't resolve, with or without from_concept_code. The
same source's mapping still matches, so re-importing an id-less line that
names its from code updates it.

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

* OpenConceptLab/ocl_online#655 | A seeding import's Source Version line sets match_algorithms on the new version only; HEAD keeps its own and its vectors aren't resynced

apply_version_metadata_to_head skips match_algorithms, which stays in
ISOLATED_METADATA_FIELDS so the line still sets and checks it on the version,
as POST .../versions/ leaves HEAD's alone. Nothing else it copies can change
HEAD's semantic flag, so the HEAD vector sync that went with it is dropped.

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

* OpenConceptLab/ocl_online#655 | An unresolved from URL's source is matched as mappings are saved: by link to the source it resolves to, else by the stored URL (FE.2 review, pass 1)

A mapping saved from a canonical from URL is linked to the source the URL
resolves to and stores that source's own URL, so a text match on the line's
URL missed it: a re-import failed uniqueness and a DELETE found nothing. A
linked mapping now matches when it's linked to the source the line's URL
resolves to, and an unlinked one when its stored from source URL is the
line's, in MappingImporter and MappingMatcher alike. That also stops a stale
stored URL from matching a mapping linked to another source. Each update
variant in the cross-source test now starts from S1's mapping alone.

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

* OpenConceptLab/ocl_online#655 | The from source lookup moves into its criteria helper, inside pylint's local-variable limit for MappingImporter.get_queryset

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

* OpenConceptLab/ocl_online#655 | An unresolved from URL's source is compared by identity when both sides have one, else by the URLs a mapping stores for it (FE.2 review, pass 2)

The line's from source URL is resolved versionless, so an explicit HEAD path
names its source. A mapping's source is its from source link, else its from
concept's source; when the line's URL resolves to a source and the mapping has
one, the two must be the same. Otherwise the mapping's stored from source URL
must be one the URL is stored as, which includes the resolution URL a
version-qualified canonical URL is stored under. A mapping linked to a source
since retired is found again by its URL, as before this PR.

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

* OpenConceptLab/ocl_online#655 | Revert the pass 2 change to from source matching: its versionless lookup misreads some canonical URLs and its URL fallback matches mappings linked elsewhere

This reverts commit 42aa7a4, which answered pass 2's three P2 findings. The
final Codex check found it broke more than it fixed: stripping a version
segment can resolve a canonical URL to another source, and the fallback for a
URL that resolves to no source matched mappings linked to another source. The
tree returns to 1fdb827, which pass 2 found free of P0 and P1 defects; F2.1 to
F2.3 are accepted as P2 edge cases.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@snyaggarwal
snyaggarwal merged commit 44010f5 into master Nov 20, 2026
1 of 3 checks passed
@snyaggarwal
snyaggarwal deleted the ocl_online#655 branch November 20, 2026 02:22
paynejd added a commit that referenced this pull request Nov 20, 2026
…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
snyaggarwal pushed a commit that referenced this pull request Nov 23, 2026
…pped codes (#1010)

* OpenConceptLab/ocl_online#703 | A release's search matches its own mapped 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

* OpenConceptLab/ocl_online#703 | One rule for a search document's own 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

* OpenConceptLab/ocl_online#703 | Codex pass 1: backfill every release 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

* OpenConceptLab/ocl_online#703 | Codex pass 2: latest rows keep HEAD's 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

* OpenConceptLab/ocl_online#703 | Codex pass 3: entries keyed by release 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

* OpenConceptLab/ocl_online#703 | Simplification review: smaller MappedCodes 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

* OpenConceptLab/ocl_online#703 | Codex check: private releases' codes 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

* OpenConceptLab/ocl_online#703 | Codex check: a release's access change 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

* OpenConceptLab/ocl_online#703 | Codex check: queue a release's code rebuild 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

* OpenConceptLab/ocl_online#703 | A row no release holds reads only HEAD'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

* OpenConceptLab/ocl_online#703 | $match reads a SAME-AS input from same_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

* OpenConceptLab/ocl_online#703 | Codex pass 4: a new release's concepts 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

* OpenConceptLab/ocl_online#703 | The backfill rewrites a source's older 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

* OpenConceptLab/ocl_online#703 | Codex pass 5: an import that changes 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

* OpenConceptLab/ocl_online#703 | Backfill test follows a seed that drops 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

* OpenConceptLab/ocl_online#703 | Codex pass 6: a fuzzy search's facets 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

* OpenConceptLab/ocl_online#703 | --source help names the older concept rows it also rewrites

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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