Skip to content

OpenConceptLab/ocl_online#687 | Seeded versions link codes that have two HEAD rows; a source version's export lists only its own hierarchy - #1037

Merged
snyaggarwal merged 6 commits into
masterfrom
ocl_online-687-version-parents
Nov 24, 2026
Merged

snyaggarwal merged 6 commits into
masterfrom
ocl_online-687-version-parents

Conversation

@paynejd

@paynejd paynejd commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

TL;DR: fixes wrong parents in seeded source versions and in their exports. A seed now links each code's new version to its parents in that version, even when the code or its parent has two HEAD rows. A source version's export lists only that version's own links. For OpenConceptLab/ocl_online#687.

What was wrong

LOINC 2.82 was seeded on staging, and for 4,178 concepts its /parents/ was empty or wrong (for example, GET …/LOINC/2.82/concepts/3282-1/parents/ returns []). There are two causes.

1. Codes with two HEAD rows.

  • An old LOINC load left 4,123 codes with two versioned objects at the same URL; the other one is retired.
  • The content step writes each code's new version under the lowest id, because ConceptImporter.get_queryset().first() orders by primary key.
  • The hierarchy step resolved URLs through Concept.get_versioned_objects_by_uri. That builds a dict from an unordered query, so the last row read won.
  • So for a duplicated code, the two steps could pick different versioned objects:
    • the version's row got no links of its own;
    • the links went to the other duplicate's rows;
    • a child of a duplicated parent was linked to a row that isn't a member of the version.

2. A version export added HEAD's links to every row (ocl_online#687). ConceptVersionExportSerializer.get_shared_hierarchy_urls added the versioned object's links whether or not the row was still the latest, and it listed the linked rows as they were. So:

  • an export of v1, regenerated after v2 moved a child, listed both parents;
  • the 2.82 export hid most of cause 1, because HEAD's older links mostly name the right codes.

The version API doesn't do this. get_version_hierarchy_queryset reads only the version row's own links and maps them to the version's members.

Changes

Area File Change
Hierarchy step of an import core/concepts/models.py get_versioned_objects_by_uri resolves a URL that several versioned objects share to the lowest id, the same row the importers' .first() lookups write to. In a seed, a parent URL that names a version of such a code, when the seed imports that code, resolves the same way (ImportHierarchy.resolve_parents). make_hierarchy and ordinary imports keep the version a URL names. Every import's hierarchy step uses it, along with make_hierarchy and the large-drop guard's mapping matcher.
Source version export core/concepts/serializers.py, core/common/utils.py The export of a source version other than HEAD lists only the version's own hierarchy, by the rules of get_version_hierarchy_queryset, which the version API uses. Its parents are the row's own parent links, given as the version's rows of those concepts. Its children are the version's rows that link to any row of the concept. Only the version's active rows (the rows the export holds) are listed, every one of them where a concept has more than one. HEAD's links are never listed, and neither are concepts outside the version, such as other sources'. HEAD and collection exports are unchanged.

Tests

In core/importers/tests.py (IsolatedVersionImportTest):

  • test_isolated_import_links_codes_that_have_two_head_rows: a seed where both a child and a parent have a second, retired HEAD row, plus a child whose parent URL names a version of the duplicate. v2's /parents/ and /children/ follow the file, and v1 keeps its parent. Fails on master: v2 lists no parent.
  • test_version_export_lists_only_its_own_hierarchy: v1's export is the same before and after v2 moves a child and another source's public concept links to v1's parent. v2's export lists only v2's links. Fails on master: v1's export lists both parents, plus HEAD rows as children.
  • test_isolated_import_keeps_the_version_a_url_names_outside_the_import: a seed whose parent URL names a version of a duplicated concept in another source keeps that version.
  • test_hierarchy_repair_keeps_the_version_a_url_names: make_hierarchy with a URL naming a version of the higher-id duplicate links that duplicate.
  • test_version_export_links_every_row_it_holds_and_no_other: a version with an inactive member row and two rows of one parent concept. Every hierarchy URL is a row the export holds, and the child lists both parent rows.
  • test_version_export_lists_children_that_link_an_older_row_of_their_parent: a release made after an ordinary import changes only the parent still lists the unchanged child under it, as the version API does.

Queries

A source version's export adds two queries per batch of 1,000 concepts, and no longer prefetches child links or HEAD's links. EXPLAIN on production (no ANALYZE), with LOINC 2.81:

  • The version's rows of the linked parents: a hash join, using the versioned_object_id index and concepts_sources_source_concept_idx.
  • The version's rows that link to the batch's concepts:
    • a parallel hash join of concepts_hierarchicalconcepts, 1.8M rows sequentially scanned, against the batch's concept rows through the versioned_object_id index;
    • then index lookups on concepts_sources_source_concept_idx and concepts_pkey;
    • estimated cost about 131k.

For 2.82 that's about 250 batches, against an export that runs about two hours.

After deploy

  • Stored exports aren't rebuilt. A version's export ZIP is cached, so an existing one keeps the old hierarchy. Rebuild any source version export that's used for checking with POST <version>/export/?force=true.
  • Already-seeded versions keep their links. The staging 2.82 load should be deleted and seeded again from the same import file. The version's /parents/ should then match the file, and its export should have no parent-link differences.
  • Production's LOINC HEAD has the same 4,123 duplicated codes. With this change, the production 2.82 seed links them correctly. For 11 codes, 2.81's row is under the higher-id duplicate. The importer already wrote under the lower one, so this PR doesn't change it. Their 2.82 versions continue the other duplicate's history: 15783-4 16082-0 21609-3 82003-5 interRAI LP376481-0 LP376482-8 LP40216-1 LP420186-1 LP6767-0 LP71348-4.
  • Old versions:
    • On production, 4,737 rows of 2.71.21AA have links only through HEAD. Their export now lists no parent for them, which matches what the version API already returns. 2.81 has 12 such rows.
    • A source version's export also no longer lists hierarchy links to other sources, which the version API doesn't show either.

Related

oclapi2#1021 (ocl_issues#3059) changes ConceptChildrenView and ConceptParentsView. This PR doesn't touch them. It changes the importer's hierarchy step and the export, so the two don't overlap.

Checklist

  • Both new tests fail on master and pass with the change.
  • Targeted suites pass: 1,440 tests in core.importers, core.concepts, core.common.tests and core.integration_tests tests_sources, tests_collections, tests_cross_repo_access and tests_concepts. Pylint 4.0.9 exits 0 on the changed files. (ConceptPropertyFilterViewTest fails on a stale local search index and passes once it's recreated, as on master.)
  • CI: full suite and Pylint.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qWFxV2q74bjstFDfjt

paynejd and others added 2 commits November 23, 2026 13:18
…two HEAD rows; a source version's export lists only its own hierarchy

- Concept.get_versioned_objects_by_uri resolves a URL several versioned objects share to the lowest id, the row the
  importers' .first() lookups write to, so a seed's hierarchy step links the version rows the import wrote.
- A source version's export (not HEAD, not a collection) lists each row's own links only: parents of its source as the
  version's row of them, children only when they are the version's rows. HEAD's links no longer leak into older
  versions' exports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWFxV2q74bjstFDfjt
…children by concept, members only in version exports

- ImportHierarchy.resolve_parents resolves a URL naming a version of a code with two versioned objects to the one
  get_versioned_objects_by_uri resolves the code's URL to (F1.1).
- A source version's export lists as children the version's rows that link to any row of the concept, as
  get_version_hierarchy_queryset does, not only those linking to the exported row (F1.2), and lists only the version's
  own rows as parents and children, never another source's (F1.3).

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

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

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

Verdict: 3 findings, all P1. All three reproduced as failing tests on 22a2d83 and are fixed in the next commit.

  • F1.1 (P1) core/concepts/models.py:1545: A versioned parent URL can still send a seed's hierarchy link to the duplicate that the seed drops.
  • F1.2 (P1) core/concepts/serializers.py:681: The export omits children whose links point to an older revision of the exported parent.
  • F1.3 (P1) core/concepts/serializers.py:711: A source version's export can include a public child from another source's HEAD, and that link can disappear after a later import.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "full",
  "commit": "22a2d83a",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "F1.1",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/models.py",
      "line": 1545,
      "claim": "A versioned parent URL can still send a seed's hierarchy link to the duplicate that the seed drops.",
      "scenario": "Two HEAD rows share code P. A seed imports P and C, and C's parent URL names a revision of the higher-ID P. The concept importer writes under the lower-ID P, but ImportHierarchy.resolve_parents bypasses the changed lookup for versioned URLs. It links C to the higher-ID P, which the seed then drops from membership. The seeded version's C /parents/ omits P and its P /children/ omits C.",
      "action": "For same-source parents in a seed, validate the referenced revision and resolve its code to the concept lineage the seed actually imported. Add a duplicate-parent test that supplies a versioned parent URL.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.2",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/serializers.py",
      "line": 681,
      "claim": "The export omits children whose links point to an older revision of the exported parent.",
      "scenario": "A regular bulk import renames parent P without updating child C, then a source version captures the new P revision and the unchanged C revision. C still links to the older P revision. The export maps C's parent URL to the new P revision, but P's child list is empty because it reads reverse links to that exact row. The version's /children/ endpoint returns C because it matches the parent's versioned object.",
      "action": "Resolve children in batches from the source version's member rows, matching each stored parent link by versioned object as /children/ does. Test a release created after a parent-only update.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.3",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/serializers.py",
      "line": 711,
      "claim": "A source version's export can include a public child from another source's HEAD, and that link can disappear after a later import.",
      "scenario": "Source A's v1 contains a revision of P. A seed of public source B makes C a child of P and links both C's HEAD and its revision to P. A's v1 export lists those out-of-version URLs. When a later B seed moves C to another parent, it removes C's HEAD link from P, changing A's v1 export.",
      "action": "Require source-version hierarchy URLs to resolve to members of the exported version. Keep the existing cross-source handling for HEAD and collection exports. Add a cross-source move case to the export test.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

Responses (fixed in dbf6358; each new test failed on 22a2d83 and passes now):

  • F1.1, fixed. ImportHierarchy.resolve_parents now resolves a URL naming a version of a code with two versioned objects to the one get_versioned_objects_by_uri picks for the code's URL. Test: test_isolated_import_links_codes_that_have_two_head_rows now also imports E, whose parent URL names a version of the higher-id duplicate.
  • F1.2, fixed. A source version's export now lists as children the version's rows that link to any row of the concept, by versioned object, as get_version_hierarchy_queryset does. It's one query per batch. Test: test_version_export_lists_children_that_link_an_older_row_of_their_parent.
  • F1.3, fixed. A source version's export now lists only the version's own rows as parents and children, the version API's rule. Links to other sources are no longer listed there; HEAD and collection exports keep them. Test: test_version_export_lists_only_its_own_hierarchy adds a public child in another source after v1 and checks that v1's export doesn't change.

…sions, active rows and every member row in version exports

- ImportHierarchy.resolve_parents redirects a URL naming a version of a duplicated code only in a seed
  (from_uri_map seed=True, from reconcile_import_hierarchy's replace_head); make_hierarchy and ordinary imports keep
  the version a URL names (F2.1).
- A source version's export links only its active member rows (F2.4), and every member row of a parent concept
  (F2.5).

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

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

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

Verdict: pass 1's F1.3 resolved. F1.1 and F1.2 marked regressed, with 5 new findings: 2 P1, 3 P2.

  • F2.1 (P1) core/concepts/models.py:2152: The shared resolver redirects explicit parent version URLs in hierarchy repairs.
  • F2.2 (P1) core/common/mixins.py:1327: Existing source-version downloads keep serving the old hierarchy.
  • F2.3 (P2) core/concepts/models.py:2188: A seed can add a parent link to a concept row already in a prior release.
  • F2.4 (P2) core/concepts/serializers.py:682: The hierarchy queries can emit URLs for soft-deleted rows omitted from the export.
  • F2.5 (P2) core/concepts/serializers.py:680: The export drops parent rows when a legacy source version contains multiple rows of one parent concept.

Responses (c0d1ae6; each new test failed on dbf6358 and passes now):

  • F2.1, fixed. A URL naming a version of a duplicated code is redirected only in a seed (from_uri_map(seed=True), from reconcile_import_hierarchy with replace_head). make_hierarchy and ordinary imports keep the version the URL names. Test: test_hierarchy_repair_keeps_the_version_a_url_names.
  • F2.2, handled as a deploy step. Stored exports aren't rebuilt by code. The PR's "After deploy" section now says to rebuild each source version export that's used for checking with POST <version>/export/?force=true; the staging LOINC 2.82 reseed makes a new one anyway. Clearing every stored version export across the server is a separate operational decision.
  • F2.3, accepted (P2). It needs a version that holds both duplicates of a parent as members. On production, each of LOINC's 4,123 duplicated codes has exactly one lineage in 2.81 (4,112 under the lower id, 11 under the higher).
  • F2.4, fixed. The parent and child lookups read only active member rows, the rows the export holds.
  • F2.5, fixed. Every member row of a parent concept is listed. Test (F2.4 and F2.5): test_version_export_links_every_row_it_holds_and_no_other.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "dbf63587",
  "verdict": "findings",
  "prior": [
    {
      "id": "F1.1",
      "status": "regressed"
    },
    {
      "id": "F1.2",
      "status": "regressed"
    },
    {
      "id": "F1.3",
      "status": "resolved"
    }
  ],
  "findings": [
    {
      "id": "F2.1",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/models.py",
      "line": 2152,
      "claim": "The shared resolver redirects explicit parent version URLs in hierarchy repairs.",
      "scenario": "An administrator repairs a historical child's hierarchy using the version URL of the higher-ID duplicate parent. The repair now links the child to the lower-ID parent's latest row, so the intended parent still has no child and another parent gains one.",
      "action": "Scope duplicate canonicalization of explicit version URLs to seed reconciliation. Preserve the named version's concept identity for hierarchy repairs and ordinary imports, and test the repair path with a duplicate parent.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.2",
      "severity": "P1",
      "tag": null,
      "file": "core/common/mixins.py",
      "line": 1327,
      "claim": "Existing source-version downloads keep serving the old hierarchy.",
      "scenario": "A version already has a ZIP containing HEAD links when the fix deploys. GET still redirects to that ZIP, and a normal export POST reuses it. Users continue to download the incorrect hierarchy until a forced rebuild.",
      "action": "Regenerate affected stored archives during rollout or invalidate them so normal export requests rebuild them. Verify an existing version through the download endpoint.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.3",
      "severity": "P2",
      "tag": null,
      "file": "core/concepts/models.py",
      "line": 2188,
      "claim": "A seed can add a parent link to a concept row already in a prior release.",
      "scenario": "A legacy v1 contains both rows for P, and C links to the higher-ID P. With duplicate-version prevention enabled, a v2 seed resubmits unchanged C with the same explicit parent URL. The hierarchy change check compares versionless URLs and reuses C's v1 row. Reconciliation adds the lower-ID P link to that row, so a regenerated v1 export now shows C under both parents.",
      "action": "Compare resolved parent concept identities before reusing a concept row. Create a new child row when canonicalization changes its parent identity, and compare the v1 export before and after that seed.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.4",
      "severity": "P2",
      "tag": null,
      "file": "core/concepts/serializers.py",
      "line": 682,
      "claim": "The hierarchy queries can emit URLs for soft-deleted rows omitted from the export.",
      "scenario": "In v2, C links to an older row of P. An administrator soft-deletes C's version row, leaving its source membership intact. The archive omits C from its concepts, but the new child lookup still lists C under P. The parent lookup can likewise select an inactive member row.",
      "action": "Apply the export's active-row filter to both parent and child membership queries. Add a regression test that verifies hierarchy URLs refer to rows present in the archive.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.5",
      "severity": "P2",
      "tag": null,
      "file": "core/concepts/serializers.py",
      "line": 680,
      "claim": "The export drops parent rows when a legacy source version contains multiple rows of one parent concept.",
      "scenario": "An older race left two rows of P flagged latest, and a source version copied both into its membership. For a child linked to P, the version API returns both member rows. The export's parent dictionary keeps only the higher-ID row, while both parent rows can still list the child.",
      "action": "Retain all eligible member URLs per parent identity, and test an export of a source version that contains both rows.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

…ersions of the codes it imports

ImportHierarchy.resolve_parents takes the seed's concept URLs and redirects a URL naming a version of a duplicated code
only when the seed imports that code; a parent outside the import keeps the version its URL names (F3.1).

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

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

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

Verdict: every P1 resolved. F2.2 (handled as a deploy step) and F2.3 (accepted) are still open. Two new P2s.

Prior: F1.1 resolved, F1.2 resolved, F1.3 resolved, F2.1 resolved, F2.2 unresolved, F2.3 unresolved, F2.4 resolved, F2.5 resolved

  • F3.1 (P2) core/concepts/models.py:2154: A seed redirects explicit parent version URLs even when the parent is outside the source being seeded.
  • F3.2 (P2) core/concepts/models.py:2198: The historical export change in F2.3 can occur when the prior release holds only one of the duplicate parents.

Responses:

  • F3.1, fixed in b5effed. resolve_parents takes the seed's concept URLs and redirects a URL naming a version of a duplicated code only when the seed imports that code. A parent outside the import keeps the version its URL names. Test: test_isolated_import_keeps_the_version_a_url_names_outside_the_import, which failed on c0d1ae6.
  • F3.2, accepted (P2). It needs a released row whose only parent links in its source point outside that release, plus a seed that reuses the row unchanged. The link it adds names the parent code the file gives. Adding links to a reused latest row is OpenConceptLab/ocl_online#655 | Isolated source versions #985's reconciliation, which this PR doesn't change. Creating new rows when reconciliation would change a published row's links is a larger change, kept out of this fix.

No P0 or P1 is open after 3 passes, so the loop stops here. A Codex check of the commits after c0d1ae6 follows.

findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "c0d1ae64",
  "verdict": "findings",
  "prior": [
    {
      "id": "F1.1",
      "status": "resolved"
    },
    {
      "id": "F1.2",
      "status": "resolved"
    },
    {
      "id": "F1.3",
      "status": "resolved"
    },
    {
      "id": "F2.1",
      "status": "resolved"
    },
    {
      "id": "F2.2",
      "status": "unresolved"
    },
    {
      "id": "F2.3",
      "status": "unresolved"
    },
    {
      "id": "F2.4",
      "status": "resolved"
    },
    {
      "id": "F2.5",
      "status": "resolved"
    }
  ],
  "findings": [
    {
      "id": "F3.1",
      "severity": "P2",
      "tag": null,
      "file": "core/concepts/models.py",
      "line": 2154,
      "claim": "A seed redirects explicit parent version URLs even when the parent is outside the source being seeded.",
      "scenario": "A seed of source A imports child C with a parent URL naming a revision of the higher-ID duplicate P in source B. Both P rows are active and have different names. The seed links C to the lower-ID P, and C's HEAD /parents/ returns that row's UUID and name. Source B was untouched by the seed.",
      "action": "Apply duplicate resolution to parent codes the seed imports. Preserve the lineage named by explicit version URLs for other parents.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F3.2",
      "severity": "P2",
      "tag": null,
      "file": "core/concepts/models.py",
      "line": 2198,
      "claim": "The historical export change in F2.3 can occur when the prior release holds only one of the duplicate parents.",
      "scenario": "A legacy v1 holds the lower-ID P and a revision of C whose stored link points to the higher-ID P outside v1. With duplicate-version prevention enabled and C's pre-reconciliation checksum still stored, an unchanged v2 seed can reuse C's v1 row. Reconciliation adds the lower-ID P link to that shared row. A v1 export generated before v2 shows no C\u2013P link, and a rebuild after v2 shows the link in both directions.",
      "action": "Compare resolved parent lineages before reusing a published child row. Create a new child revision when reconciliation would change its links, and test a prior release containing only the lower-ID parent.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

…map reads a concept id as the importer does

Concept.get_import_hierarchy_map reads a line's id as a string, as ConceptImporter does, so a numeric 0 is the code '0'
and a seed redirects a version of it like any other code it imports (FC.1).

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

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits c0d1ae6..b5effed (codex-cli 0.169.0)

Verdict: one P2, fixed in c0c9360.

  • FC.1 (P2) core/concepts/models.py:2152: A seed can lose a parent link when it imports duplicate code 0 with a numeric JSON ID.

Response:

  • FC.1, fixed. get_import_hierarchy_map now reads a line's id as a string, as ConceptImporter does, so a numeric 0 is the code '0'. A seed then redirects a version of it like any other code it imports. Test: test_isolated_import_redirects_a_version_of_a_code_whose_id_is_numeric_zero, which failed on b5effed. 1,441 targeted tests pass, and pylint exits 0.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "b5effeda",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "FC.1",
      "severity": "P2",
      "tag": null,
      "file": "core/concepts/models.py",
      "line": 2152,
      "claim": "A seed can lose a parent link when it imports duplicate code `0` with a numeric JSON ID.",
      "scenario": "A source has two HEAD rows for code `0`. The seed imports the parent with `\"id\": 0` and child C with a parent URL naming a revision of the higher-ID duplicate. The concept importer keeps the lower-ID row, but the hierarchy map skips the falsy numeric ID. The resolver links C to the higher-ID duplicate, which the seed drops. The new version's `/parents/` and export omit C's link to `0`. The previous resolver linked C to the retained row.",
      "action": "Treat numeric `0` as a supplied ID and convert it to a string before building the hierarchy map. Add a seed test with duplicate code `0` and an explicit parent version URL.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

…mport would apply a rejected numeric-0 row's links

This reverts commit c0c9360. Reading a numeric id 0 into the hierarchy map also makes an ordinary parallel import add a
rejected row's parent links (FC.2), which applies to other ids already and is outside this fix. FC.1, a seed of a
duplicated code 0 with a versioned parent URL, is accepted as a P2.

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

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits b5effed..c0c9360 (codex-cli 0.169.0)

Verdict: one P1, caused by c0c9360. That commit is reverted in ccbed33, so the PR's code is again exactly what the check of b5effed reviewed.

  • FC.2 (P1) core/concepts/models.py:1521: The numeric ID fix lets ordinary parallel imports add parent links from rejected concept rows.

Response:

  • FC.2, fixed by reverting c0c9360. An ordinary parallel import already applies a rejected row's parent links for every other id. c0c9360 extended that to a numeric 0. That older behaviour is outside this fix.
  • FC.1 is now accepted (P2). It needs a seed of a duplicated code 0 with a parent URL that names a version of it. The hierarchy map's skipping of a numeric 0 predates this PR.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "c0c93609",
  "verdict": "findings",
  "prior": [
    {
      "id": "FC.1",
      "status": "regressed"
    }
  ],
  "findings": [
    {
      "id": "FC.2",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/models.py",
      "line": 1521,
      "claim": "The numeric ID fix lets ordinary parallel imports add parent links from rejected concept rows.",
      "scenario": "A source already contains code `0` and a parent `P`. Submit a parallel import with `update_if_exists=false` and a row with numeric `id: 0` that names `P` as a parent. The worker rejects the row because `0` already exists, but the final hierarchy reconciliation adds the link to `P`. Before this commit, the hierarchy map skipped that row.",
      "action": "Keep numeric ID normalization for isolated seeds and restrict ordinary parallel hierarchy reconciliation to concept rows accepted by the workers. Add a regression test that checks the existing concept's parents after the rejected import.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Simplification review (fresh Claude subagent, Sonnet 5.5, commit ccbed33)

Verdict: the PR is already tight. There's no dead code and no single-caller layers to cut. Four small items were found, and I'm not applying any of them. Each would need another review and CI round before tomorrow's deploy, for no change in behaviour.

  • S1 (core/importers/tests.py:6833), the final per-concept loop repeats earlier checks. Kept. It is the only assertion that covers every row of the export, not just C and the overall set.
  • S2 (core/importers/tests.py:6732), HEAD's parent_concept_urls after the seed. Kept. It pins the stored list that HEAD's API serves, which the version-hierarchy assertion above it doesn't read.
  • S3 (core/concepts/serializers.py:693, :671), docstrings restate get_version_hierarchy_queryset. Not now. The rule is worth spelling out for the reviewer, and it can be trimmed in a later change.
  • S4 (core/concepts/models.py:2137), the seed explanation appears on both from_uri_map and resolve_parents. Not applied. The reviewer was unsure the pylint disable can go, and the duplication is two lines.

No commits after this review, so no further Codex check is needed.

simplify.json
{"perspective":"simplify","mode":"full","reviewer":"claude subagent (sonnet)","commit":"ccbed330","verdict":"findings","findings":[{"id":"S1","tag":"dup-test","file":"core/importers/tests.py","line":6833,"claim":"Final per-concept loop in test_version_export_links_every_row_it_holds_and_no_other repeats the exported-set check and C's parent_concept_urls equality.","action":"nothing replaces it","lines_delta":-2,"confidence":"medium"},{"id":"S2","tag":"dup-test","file":"core/importers/tests.py","line":6732,"claim":"sorted(child.parent_concept_urls) == ['.../Q/'] repeats the version_hierarchy(child,'parent_concepts','v1') assertion's intent.","action":"nothing replaces it","lines_delta":-2,"confidence":"low"},{"id":"S3","tag":"shrink","file":"core/concepts/serializers.py","line":693,"claim":"get_shared_hierarchy_urls and get_version_hierarchy docstrings restate Concept.get_version_hierarchy_queryset's rules.","action":"Keep one sentence pointing at get_version_hierarchy_queryset.","lines_delta":-6,"confidence":"medium"},{"id":"S4","tag":"shrink","file":"core/concepts/models.py","line":2137,"claim":"Seed explanation duplicated across from_uri_map and resolve_parents docstrings; pylint disable may be avoidable.","action":"Keep the explanation on resolve_parents only.","lines_delta":-3,"confidence":"low"}]}

@paynejd
paynejd requested a review from snyaggarwal November 23, 2026 19:35

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Quick review: looks right, and nothing blocks the merge.

  • Seeding links the rows it wrote. get_versioned_objects_by_uri now takes the lowest id, the row the importers' .first() lookups update, so a code with two HEAD rows gets its parents on the row the seed wrote. resolve_parents redirects a named version only for codes in the seed (seed=replace_head, which only the version commit passes). The admin repair (make_hierarchy) still resolves a named version exactly, and the test covers that.
  • The export reads the version's own hierarchy. The serializer's two call sites already use self., so the switch away from @staticmethod is safe. Collection and HEAD exports keep the old path.
  • Behaviour change worth stating in the release notes: a source version's export now lists only the version's own rows as parents and children. A parent in another (public) source, which the old union included, is left out. That matches the version API.
  • Existing exports keep the old hierarchy until rebuilt with ?force=true, as you note. Staging's 2.82 is deleted and reloaded anyway.

🤖 Review by Claude Code

@snyaggarwal
snyaggarwal merged commit 52bfa1c into master Nov 24, 2026
3 checks passed
@snyaggarwal
snyaggarwal deleted the ocl_online-687-version-parents branch November 24, 2026 02:17
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