Repository navigation
OpenConceptLab/ocl_online#452 | Version rules in OCL's core: wildcards, a declared version algorithm and the version parameters, behind the per-evaluation switch - #1087
Conversation
…sionEvaluation the caller may supply An ExpansionEvaluation says how one expansion is evaluated: which rules it follows (fhir_rules: OCL's new EXPANSION_FHIR_RULES_TOGGLE decides for API requests, read only when asked; a caller can set them) and how what its references and system-version entries name resolves. Its resolve() is the one entry point for both, ahead of the shared resolver, so a caller with content of its own can answer for a canonical first, even with the URL registry on. The version is passed apart from the URL. add_references and seed_children take an optional evaluation and set it on each reference while they evaluate it. Callers that pass none are unchanged: each reference resolves under its own default, which calls the resolver exactly as before. Nothing reads fhir_rules yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWrEkUwedkj6bUPC61
…est time, rolled back, with side effects refused and a deadline ExpansionEvaluation.at_request_time(seconds) opens an evaluation for one request: a transaction rolled back when it closes; side effects refused while it's open (Celery tasks and cache writes raise in tests and are skipped in production with an error logged; a search index write raises in both; an on_commit hook is refused at close, the rollback dropping it); and one deadline for all it runs. Each statement gets SET LOCAL statement_timeout from the time left, add_references checks it before each reference, and running out raises EvaluationTooCostly once rolled back. Under it, add_references and seed_children index nothing and write nothing back to the references or to health, and Expansion.build_at_request_time builds a new expansion of a collection version at once. The guard lives in core/side_effects.py: the task classes check it before they queue (a once task before it takes its lock), the cache backend is django_redis's with its writes checked (core.common.cache.RedisCache), and the search client's transport refuses writes (RefusingTransport). With no evaluation open they behave as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWrEkUwedkj6bUPC61
…ences to one source version in one query A reference to one concept by its code, with nothing else to apply (no concept version, cascade, transform or value set), is now evaluated with the others like it: add_references resolves each as before, then finds all their codes with one query per source version (CodeReferenceBatch), applies the expansion's parameters once to what they found, adds it once, and writes back and records each reference's result as it did one at a time. Each finds what it found on its own: in a version, the concept with that code, the newest if the version holds two; in HEAD, the concept itself; only in versions its creator can view. add_references also reads its owner's resolution namespace once rather than once per reference (a toggle read each). A request-time build of 10 or 40 code references now runs the same number of queries; one at a time it ran about six more per reference. Tests build each case both ways (batched and one at a time) and compare members, mappings, recorded versions, unresolved entries, each reference's reason, what's written back and what's indexed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWrEkUwedkj6bUPC61
…32-bit link sequences it advances A rollback gives back none of the ids a request-time evaluation used, so each request advances the sequences of the link tables it writes for good. LINK_SEQUENCE_TABLES lists the ones with 32-bit ids (concept and mapping source links, parent links, expansion members, reference results and an expansion's recorded versions), and link_sequence_usage() reads how much of each range is used. at_request_time() refuses to open (EvaluationUnavailable) once one reaches 90%, leaving the rest to OCL's own writes. A test checks that every table with 32-bit ids a request-time build inserts into is on the list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWrEkUwedkj6bUPC61
…ethod itself Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWrEkUwedkj6bUPC61
…der kept, the guard tightened - Code references excluded are evaluated together too, one query per source version. - A run of code references is applied before any other reference, which may read the expansion being built (a value set reference to its own collection), so every reference sees what it saw one at a time. - Members a request-time evaluation removes no longer mark the stored collection's last_child_removal_at, which held its row until the rollback. - Bulk indexing and the indexing signal tasks check the guard in the calling thread, before their worker threads (which don't see it) start. - An on_commit hook is refused when it's registered, savepoints included, not only at close. - The deadline covers the sequence check, and an evaluation that finishes past it is too costly. - A relative url|version is split for the evaluation's resolve too, unless the resolver reads it as canonical. - The test runner's no-op cache refuses writes at request time, as the deployed cache does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWrEkUwedkj6bUPC61
…e deadline, one search per version, nested guards - Search index reads during a request-time evaluation get only the time its deadline leaves, with no retries, and a search ends on the index's side too (its timeout); out of time, or timed out, is too costly. - A code batch is told every code the expansion's code references name, so each source version is searched once, however other references split them into runs. - Expansion parameters that read members (exclude-system, date) apply reference by reference, as before, since an earlier reference's concepts can change what a later one adds. - The sequence check runs inside the evaluation, within its deadline. - A nested evaluation restores the outer one's on_commit guard when it closes. - Fix: the bulk index guard named its document with __name__, which an instance doesn't have, on every bulk index. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWrEkUwedkj6bUPC61
…erence at a time did - What batched code exclusions removed is queued for indexing as a list: a set isn't JSON, so a build that indexes outside tests failed (found by crew fhir-b-versions' review). - With a parameter that reads members (exclude-system, date), what's indexed is re-read once added, as one reference at a time did, so the same members are indexed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWrEkUwedkj6bUPC61
…ested deadlines, read routes, indexing re-read - A savepoint's rollback or release, and a statement in a failed transaction, run without the deadline's SET LOCAL, so an error caught in a savepoint leaves the evaluation usable. - A nested evaluation ends by the outer one's deadline, for statements and search reads alike. - A search request is a read by its endpoint (the first segment starting with _), so a document whose id looks like a read's endpoint is still a write. - With a parameter that reads members, what's indexed is the parameters' own query re-read once added, as one reference at a time did (a text filter's matches stay as matched). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWrEkUwedkj6bUPC61
…tes, one forwarding test less - The search transport takes for reads only the endpoints OCL sends (_search, _count, _msearch, _mget and a scroll); any other request is a write. - A test that seed_children forwards its evaluation goes: the request-time tests go through it. - Import order and a long line (lint). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWrEkUwedkj6bUPC61
…queries, a test stub's model - A search of every index (_all) is a search: _all names indexes, it isn't an endpoint. - The deadline wrapper passes a composed query (psycopg2.sql) through; only a string can be a savepoint's rollback. - The equivalence test's text filter stand-in answers with the model it was given (mappings too). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWrEkUwedkj6bUPC61
…s core core.common.versions says which versions a version or a wildcard names (1.x.x, 1.0.x, *; 1 is not a wildcard) and which of several versions is the newest by a version algorithm (semver, integer, date, alpha, natural; without one, semver when both versions are semver, else natural), as the HL7 Terminology Ecosystem IG's version cases use them. Nothing reads it yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qXS11M1AtafcqStqmm
…ared version algorithm, under FHIR's rules Behind the per-evaluation switch (ExpansionEvaluation.fhir_rules: on for FHIR's evaluations, OCL's toggle for API requests, off until the cards are decided): - B-1: a version with an x, X or * segment, in a reference, a value set named url|version or a system-version entry, names the newest release it matches (released, active, not retired, never HEAD). Any other version names itself only, as before; 1 doesn't name 1.0.0. - B-2: a source may declare its version algorithm (the new optional Source.version_algorithm, empty by default, copied to new versions). A source that declares one has its latest release, and the newest a wildcard matches, by it; without one, by when they were created, as today. ReferenceResolution carries the rules (version_rules, off by default, so $resolveReference and FHIR's own resolver are unchanged). An evaluation's default resolution follows its fhir_rules and asks for them only when a version needs them: a wildcard, or a source that declares an algorithm. Neither exists in production, so API requests read no toggle and run no new query. The migration adds one nullable text column to sources, with no default: a catalog-only change on PostgreSQL 11+, with no rewrite and no data change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qXS11M1AtafcqStqmm
…rsion and default-valueset-version, under FHIR's rules Behind the per-evaluation switch, an expansion applies the version parameters it has so far stored and ignored (core.collections.version_rules): - B-3: a code system's version is, in the HL7 Terminology Ecosystem IG's order, force-system-version's, else the version the reference names, else system-version's, else check-system-version's, else OCL's default (the lock, the latest release, HEAD). force-system-version overrides even a version the reference names, or one that doesn't exist; check-system-version checks the version used, and one it doesn't name is recorded on the expansion as a failed check (reference.version_check; health's version_check_failed), the reference keeping its members. A rule naming no version that exists leaves the reference unresolved. Both apply by the repository an entry names, to inclusions and exclusions alike; a forced version is recorded as the expansion's choice (evaluated). - B-4: default-valueset-version gives the version of a value set a reference names by its canonical URL without one, ahead of the value set lock; one that doesn't exist leaves the value set not found, never a fallback. The API accepts the parameter only while the toggle is on, and refuses it as before otherwise. With the rules off nothing is read or applied: the parameters are read only when an expansion has one of them, and the toggle only then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qXS11M1AtafcqStqmm
… in its place, parameters match by repository, one version order Under FHIR's rules: - system-version is one of the version parameters, in its place in the IG's order (after force-system-version and the version a reference names, before check-system-version): an entry naming no version that exists leaves the references to its code system unresolved instead of falling back to the check or the default. Without the rules it applies as before. - default-valueset-version applies to the value set an entry names whatever URL a reference names it by (its canonical URL or its OCL path), as force- and check-system-version apply by repository. - A reference with only a value set is evaluated whether or not the lock toggle is on, as it is with it on. - check-system-version reads its version as the resolver does (decoded), so 1.0.0%2Bbuild checks 1.0.0+build. core.common.versions.newest orders a set of versions by one key for them all (order_key: the algorithm's when every version fits it, else semver's when every one is semver, else natural), so the newest doesn't depend on the order they come in. An expansion with version parameters reads OCL's toggle once per build at most. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qXS11M1AtafcqStqmm
…s, concept-version references, and a CodeSystem write keeps the algorithm - A version parameter naming the code system by its OCL path with |version (/orgs/O/sources/S/|1.x) keeps the version it asks for: checks compare with it, and one naming no version that exists still finds its repository. - A reference to a concept or mapping version keeps its own resolution: the version parameters neither choose nor check its source version. - A FHIR CodeSystem update keeps the version algorithm HEAD declares: an R4 CodeSystem has no versionAlgorithm, and the update starts from a release that may have none. - system-version entries resolve under the build's own evaluation, so a build reads OCL's toggle once at most. - A natural version order reads only decimal digits as numbers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qXS11M1AtafcqStqmm
…once a build, and record only what decides a version - References to one code system resolve its repository once a build for the version parameters, not once each, so a value set listing many codes stays a few queries. - system-version alone is applied under the rules only when one of its entries doesn't resolve, the one case where the rules apply it differently, so a build whose system-version entries all resolve doesn't read OCL's toggle. - Under the rules an unresolved system-version entry is recorded only where it decides a reference's version: one force-system-version overrides is not unresolved. - A failed version check is replaced only when its reference is evaluated again, so a build that reuses saved results (after another reference is removed) keeps it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qXS11M1AtafcqStqmm
…compare and newest, fewer repeated tests compare() uses order_key for its two versions, so one function states the ordering rule. A reference's repository URL is cached per build by the version rules only. Tests that repeated each other are folded together. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qXS11M1AtafcqStqmm
…ries for one code system, the first counts Under FHIR's rules, system-version entries that name two versions of one code system go through the per-repository rules, where the first entry counts, not the path that applies both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qXS11M1AtafcqStqmm
…t by owner and code, and aliases of one release are one - The version parameters match a reference's code system by its type, owner and short code, read exactly, not by an OCL path with its version cut off, which runs two code systems together when their owner is named like a resource type (/orgs/sources/sources/a/ and .../b/). - system-version entries that name one release twice (a canonical URL and an OCL path) don't turn the rules on: only two different versions of one code system do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qXS11M1AtafcqStqmm
… the URL match would run together go through the rules Under FHIR's rules, system-version alone is applied by the per-code-system rules whenever two resolved entries share a URL without version, since the path that applies system-version as before matches entries to references by that URL: two versions of one code system, or two code systems whose owner is named like a resource type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qXS11M1AtafcqStqmm
… grouped by code system and by URL Under FHIR's rules, system-version alone goes through the per-code-system rules when two resolved entries name different versions of one code system or share a URL without version, whichever groups them: an OCL path cut at its version can split a code system's HEAD from its releases as well as run two code systems together. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qXS11M1AtafcqStqmm
…only for a code with no exact match The code reference batch read EXPANSION_FHIR_RULES_TOGGLE on every build, through a default evaluation made for it, whether or not any rule applied. Matching a code ignoring case (under FHIR's rules, in a source that isn't case-sensitive) matters only for a code with no exact match, so the batch now searches exactly first and asks the build's evaluation, and whether the source is case-sensitive, only for such a code, once a version. A build whose codes all match reads no toggle and runs no more queries, as the version rules (#1087) require. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWqZpkKF5gppdmP1JP
…anonical URL applies whichever repository with it holds the version A version parameter (system-version, force-system-version, check-system-version, default-valueset-version) applied by the repository its entry resolves to. A reference that names a canonical URL and no version resolves to the repository the resolver picks for it, while FHIR's resolution serves a version named with a canonical URL from another repository with that URL when the picked one holds none so named. So an entry naming a version only another repository with the canonical URL holds missed every reference to that URL. - An entry that names a canonical URL now also applies to every reference naming that URL (as written, without a |version) where the URL alone names the same repository (in each one's namespace, so OCL's URL registries can still tell two apart), whichever repository the reference or the entry resolves to, even when the URL alone names no version. One naming an OCL path still applies by its repository only, and so does a reference by OCL path. The first entry that applies counts. - system-version alone goes through the rules when such an entry resolves to another repository than its URL without a version does, since the path without the rules matches entries to references by repository. Only an evaluation that resolves in its own way (FHIR's) is asked: the shared resolver serves a canonical URL's versions from the repository it picks, so builds that use it resolve, and read the toggle, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWnJcYXZ5geiBgML73
…52-b-versions) into versions kept apart Brings in #1087's follow-up: a version parameter naming a canonical URL applies whichever repository with it holds the version (version_rules keys parameters by repository and canonical URL). One import line conflicted; both kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWnJcYXZ5geiBgML73
…sion found by canonical URL too, as the version rules key it The version rules now key a parameter by the repository its entry names and, for one naming a canonical URL, by that URL (#1087). So force-system-version can send a reference to another repository with the URL. - The two places here that ask whether force-system-version fixes a reference's version (MemberVersions.forced, ImportedValueSet.forced) ask the rules the same way, so they agree with the version the build gives the reference. - An imported value set's reference is read as of the repository its own force-system-version sends it to, not the one its system resolves to, when the import is asked what it holds there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWnJcYXZ5geiBgML73
…ion it used by its id check-system-version's failed check named the code system as the reference wrote it and the version's label. Another repository can hold a version with the same canonical URL and label, and a repository's HEAD can change its URL while its releases keep theirs, so what may be shown of the entry can't be decided from those. The entry now names the version it used by its id too (version_id). The expansion's readers are given the entry without it, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVWYYmWDsL1uzvh9q7
…mport keeps the version it used A failed version check recorded through an imported value set is the imported expansion's own entry, so it keeps the id of the version that evaluation used (#1087). The route's ids join that id among the ones OCL records for its own checks and leaves out of what readers are given, in one place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVWYYmWDsL1uzvh9q7
… expansion whose locked version was deleted falls back, as without them An expansion built with lock has the lock in its system-version. When a locked source version is deleted, its entry no longer resolves. Without the rules the entry is recorded as unresolved, references fall back to their default and health reports locked_version_deleted. Under the rules an unresolved entry decided the reference's version, so it was left unresolved and a rebuild emptied it. On a lock-built expansion an unresolved system-version entry now decides nothing under the rules too, and is recorded as before. Entries that resolve still decide as the rules say. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVC3osEQxNxh6dcRnV
…ilt with lock keeps the versions HEAD's wildcards used A version built with lock gives the same members on a rebuild. Under the rules a wildcard names the newest release that matches, so a wildcard copied from HEAD moved to each newer release. - Parameters: when a version is built with lock, each wildcard entry of system-version, force-system-version and default-valueset-version is swapped for the version HEAD's expansion used for its repository. check-system-version stays as written: it checks, and the system-version entry the lock writes decides before it. - References: a wildcard reference names a version, so system-version doesn't reach it. A lock-built expansion keeps the versions HEAD's wildcard references picked (copied when the version is built, then its own explicit versions, kept through a rebuild as value set locks are), and a wildcard reference there uses the newest kept version it names. Only under the rules, where a wildcard names versions: without them nothing is pinned or kept, and the toggle is read only when an entry or a reference has a wildcard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVC3osEQxNxh6dcRnV
…diff resolves as a rebuild does get_repo_version_ids_a_rebuild_keeps, which the expansion's "what a rebuild would move" view reads, resolved with the plain resolver. With the rules' toggle on it reported moves a rebuild won't make: - a wildcard reference's pick, which the plain resolver reads as a version named exactly, so as no version; - a version force-, check- or system-version decided; - under a declared version algorithm, a release the algorithm doesn't make the latest (a 1.1.0 fix created after 1.2.0); - in a version built with lock, the version a wildcard reference keeps. It now resolves under a default expansion evaluation, as a rebuild given none does (wildcards and the algorithm only under the rules), keeps the versions the version parameters decide and a lock-built expansion's wildcard picks, and names a move's target by the same resolution. Without the rules it resolves as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVC3osEQxNxh6dcRnV
… wildcard is found by its name; no test-only helpers - Under the rules, a version string with an x or * segment went straight to the wildcard's newest release, so a version named exactly 1.x (two collection versions in production are named like that) was never found by its name. It's looked up by its name first. - compare and pick were used only by tests; they're gone. The module's docstring said versions are ordered as semver, else natural, without an algorithm, but a repository that declares none has its newest release by creation; that fallback applies only to versions that don't fit a declared algorithm. - Source.version_algorithm says what will write it (the FHIR CodeSystem write, then an API field, each checking it's one of the five codes) and how an unknown value ranks meanwhile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVC3osEQxNxh6dcRnV
…rules, read back, before the check, by name, in health and in the rebuild diff From a Codex check of the commits answering the review: - A pinned version is written percent-encoded, as the resolver reads it back (1.2.0+b was read as "1.2.0 b"). - A deleted lock on a lock-built expansion still comes before check-system-version: the reference falls back to its default, which the check then checks, instead of the check deciding and leaving it empty. - A wildcard reference that names a version so named exactly keeps it by its name; the lock's kept picks don't replace it. - A kept pick deleted is recorded as a deleted lock on the lock-built expansions that keep it (under the rules; the toggle is read only when there are some), so health says so, as for any lock. - The rebuild diff reads each reference in its namespace, as a rebuild does, and lets the version parameters decide each reference's version (rule_for) instead of keeping every version a parameter names, so a check that force overrides keeps nothing. Each has a test that fails on the previous commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVC3osEQxNxh6dcRnV
… words; a kept pick's own name in add_references Comments and tests say the lock rules in words. The version a wildcard reference keeps is kept_pick, not kept, which the function holding it may use for something else. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVC3osEQxNxh6dcRnV
…d reference's version by the name it was recorded under From a second Codex check: a draft named exactly as a wildcard (1.x), created after a version was built with lock, replaced the release the lock kept for that wildcard, as the reference was found by the draft's name first. A lock-built expansion now keeps every explicit version, and a wildcard reference there takes the kept one named exactly as its wildcard is written, else the newest kept release its wildcard names. A version named so after the lock was built isn't kept, so it changes nothing. A deleted kept version of any kind is a deleted lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVC3osEQxNxh6dcRnV
…ock keeps only the versions HEAD's wildcard references picked From a third Codex check: building a version with lock copied every version HEAD's expansion records as explicit, and HEAD's list can still hold versions only references since removed named (a private draft, say). The new version's expansion then listed them, and deleting one recorded a deleted lock. It now copies, for each wildcard reference, only the version HEAD's expansion picked for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVC3osEQxNxh6dcRnV
|
Every point is answered in its thread. New head
Four Codex checks of these commits found seven P1s: six are fixed with tests, and one is accepted as by design (which version a lock keeps when HEAD records several its wildcard names). Two P2s are also accepted; reasons for all three are in the body. Full gate: pylint 10.00; 4,246 tests and 803 search-index tests OK; coverage 97%. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVC3osEQxNxh6dcRnV
…ort cleanup its version delete queues, as its siblings do Deleting a source version queues delete_s3_objects; without the patch the test needs a task broker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qV2gzsF5GhF5BwTJ6x
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qV2gzsF5GhF5BwTJ6x
…es), which the FHIR series builds on fhir-452-b-codes ends the queue of OCL API PRs, so the FHIR series sits on all of them: #1085, #1086, #1089, #1088, #1087, #1090, #1091, #1092 and #1093, and the core changes that need them together. No conflicts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qV2gzsF5GhF5BwTJ6x
snyaggarwal
left a comment
There was a problem hiding this comment.
Review round 2 (Sunny): verdict approve
Reviewed at 98899e0, against round 1 at b52ac69. All seven round-1 findings are fixed or answered. One new should-fix and two nits, all with the switch on. Nothing is blocking, and with the switch off API behaviour is still unchanged. Please fix the should-fix here or in a follow-up, before EXPANSION_FHIR_RULES_TOGGLE goes on.
| # | Round 1 | Status | Commit |
|---|---|---|---|
| 1 | should fix: under the rules, a deleted locked version empties the reference (models.py:2412) |
fixed: on a lock-built expansion, an entry that no longer resolves falls back. It's recorded as unresolved and still comes before check-system-version. Tested with the rules on and off. The fallback reaches more than deleted locks, though (new finding 1). |
0638349, 6ff5c44 |
| 2 | should fix: expansion: lock doesn't pin wildcard picks (common/models.py:850) |
fixed: wildcard entries of system-version, force-system-version and default-valueset-version are written as the version HEAD used. A lock-built expansion keeps the versions HEAD's wildcard references picked, through rebuilds. Deleting a kept pick is recorded as a deleted lock. |
77aa140, 6ff5c44, 6c46c28, 5b7527a |
| 3 | should fix: the rebuild diff doesn't know the rules (models.py:2504) |
fixed: resolves under a default ExpansionEvaluation. The parameters decide through rule_for, kept picks are kept, and each reference is read in its namespace. Tests cover all three cases. One edge case is accepted in the PR body. |
1cc4106, 6ff5c44 |
| 4 | nit: compare/pick used only by tests (versions.py:93) |
fixed: removed, and the docstring says a repository with no algorithm ranks by creation | 725bbf5 |
| 5 | nit: an exact wildcard-like name is never matched (common/models.py:851) |
fixed: the exact name is tried first, then the wildcard. A lock keeps it by that name. | 725bbf5, 6ff5c44, 6c46c28 |
| 6 | nit: version_algorithm has no writer or validation (sources/models.py:124) |
answered: the comment names the writer and says it will validate | 725bbf5 |
| 7 | nit: FhirResolution never reads version_rules (evaluation.py:159) |
answered: it comes with the FHIR workspace change (phase B W1), noted in the PR body | thread reply |
New findings
| Severity | Where | Finding |
|---|---|---|
| should fix (switch on only) | core/collections/version_rules.py:156, core/collections/models.py:2409 |
On a lock-built expansion, every unresolved system-version entry falls back, not only deleted locks. get_locked_system_version_parameter (models.py:2805) copies HEAD's own entries as written. Scenario, with the switch on: HEAD's system-version is cs|9.9, which doesn't exist, so HEAD leaves its cs references unresolved, with no members. Create v1 with lock: is_lock_built makes the entry fall back, so v1 gets the latest release's members. The frozen version then has members HEAD never had. Fix: fall back only for an entry whose version is in deleted_locked_repo_versions (or one that resolved when the version was built). Add a test: HEAD with an unresolved entry, then a version created with lock, with the same members. |
| nit | core/collections/models.py:3483 |
get_kept_wildcard_pick_holders also counts exact references, as its docstring says. With the switch on, deleting a version that a lock-built expansion names exactly records a deleted lock, so health says locked_version_deleted where a reference named the version. It also reads the toggle at delete time, so it reaches lock-built expansions built before the switch was on. Consider limiting it to expansions with a wildcard reference to that source. |
| nit | core/collections/version_rules.py:207 |
version_id on a failed check is written and then removed for readers. Nothing in this PR reads it. Please name the change that will. |
Does merging change behaviour for existing users with the switch off? No. I checked each path changed since b52ac69 against the base:
seed_from_head_expansion_in_snapshot:pin_wildcard_parametersreturns the parameters unchanged. Kept picks are set only underExpansionEvaluation().fhir_rules. Cost: one URL-registry toggle read for each version created with lock. The FHIR toggle is read only when an entry or reference has a wildcard-like version.add_references:wildcard_picksis loaded only for a lock-built expansion with a wildcard-like reference, and used only underbuild_evaluation.fhir_rules.is_lock_builtonly feedsVersionRules.of, which returns None off. So unresolvedsystem-versionentries are recorded as before.VersionRules(falls_back,is_lock,hides,version_id): never built with the switch off.get_unresolved_repo_versions_for: removesversion_id, which only a failed check writes. Readers get the same output off.- Rebuild diff:
EvaluationResolutiondiffers from the defaultReferenceResolutiononly inversion_rules, which is false off, and the wildcard and kept-pick branches needfhir_rules. So the kept set and the diff match the base. plan_deleted_locks: one extra query per source version delete. Off, nothing is added. The PR body says so.ReferenceResolution.version: the exact-name-first lookup only applies underversion_rules.versions.py: the removed functions were used only by tests.sources/models.py: comment only.
Migration: 0052_source_version_algorithm hasn't changed since round 1. It adds one nullable text column with no default, a catalog-only change. It's still the only sources 0052: master ends at 0051, and no other open PR adds one. Per #797, it reaches staging through master.
Credit: the author answered every thread and updated the PR body. Their Codex checks of these commits found seven P1s, fixed with tests or accepted: among them the pinned + read back as a space, the deleted lock deciding before the check, an exact 1.x losing to a kept pick, a deleted kept pick not recorded as a deleted lock, the diff's namespace and force over check, a draft named like the wildcard after the lock, and stale HEAD versions copied into a lock. The accepted cases are theirs, and I agree with them as written. Their full gate on 5b7527a: pylint 10.00, 4,246 + 803 tests, coverage 97%.
CI: Pylint, Tests and Snyk pass on 98899e0.
What I could not verify: I ran no tests and made no staging or production queries. I found the should-fix by reading the code, not by running it. I relied on CI and on the author's production counts (no wildcard-like references or entries, no declared algorithm, no force- or check-system-version). I didn't re-review the merge of #1086's head, which is reviewed there.
Brings in the squash merge of #1086, whose original commits this branch already holds, and #1085 and #1082. Both conflicts keep this branch's side: the squash matches the original commits byte for byte, and the merged tree equals this branch's previous head merged cleanly with #1085 and #1082. No change to this branch's own code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWUTom6BGgjQy6oehZ
Brings in #1089, #1109 and #1106. The one conflict is the constants import in core/collections/models.py, where both sides add a name: both are kept. The toggles are master's, so REFERENCE_SEARCH_OPTIONS_TOGGLE is on in every environment. No change to this branch's own code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
…into fhir-452-b-apart Takes #1087's new head, which brings in master (#1089, #1109 and #1106): REFERENCE_SEARCH_OPTIONS_TOGGLE is on in every environment, as on master. Merged cleanly; no change to this branch's own code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
Its column takes a lock on sources that every read of the table waits for. Behind a long transaction, the migration and all those reads waited until it ended. It now gives up after 0.3 s and changes nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
|
One commit since the approval, 47f331f, so please look at it before merging: migration It's from the review of #1090, where you found the same thing in its migration. Adding the column takes a lock on
The schema is the same, and nothing else in the PR changes. The description's Migration section says what a failed try means. |
snyaggarwal
left a comment
There was a problem hiding this comment.
Verdict: approve, at 47f331f.
Since my round-2 approval at 98899e0, the branch has two master merges and this one commit.
- The merges (730d005, 16b6722) only resolve conflicts. Both sides are kept.
- 47f331f bounds
sources.0052's lock wait at 0.3 s, applied and reversed, as #1090's0078now does. The schema is unchanged, and the new test pins where the timeout sits in both directions. CI is green at 47f331f.
Merge order: #1088 first. This PR still conflicts with it in core/collections/evaluation.py and core/collections/models.py, so merge master into this one after #1088 lands, let CI run, then merge it with a merge commit. #1090 follows, retargeted to master.
|
The should-fix from your second review (a lock-built release whose
The nit about a version a reference names exactly being reported as a deleted lock is left as it is. |
…into fhir-452-b-apart Takes #1087's new head, with master's recounts of a collection (OpenConceptLab/ocl_issues#3058). Merged cleanly; no change to this branch's own code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
Not part of the Dec 1 run.
Stacked on #1086: merge that first. This PR is rebased onto master after it merges (oclapi2 squash-merges, so it's a
rebase --ontoPR 2's tip, not a plain retarget).Part of OpenConceptLab/ocl_online#452 (phase B, PR 3: version rules in OCL's core).
What it does
Version rules for expansions, behind the per-evaluation switch PR 2 adds (
ExpansionEvaluation.fhir_rules). FHIR's request-time evaluations will turn it on; for API requests theEXPANSION_FHIR_RULES_TOGGLEtoggle decides, and it isn't set anywhere, so nothing changes for API users until it is.With the rules on:
x,Xor*segment (1.x.x,1.0.x,*), in a reference, a value set namedurl|versionor asystem-versionentry, names the newest release it matches: released, active, not retired, never HEAD. Any other version still names itself only, so1doesn't name1.0.0.Source.version_algorithm(semver,integer,date,alphaornatural), empty by default. When a source declares one, its latest release (and the newest a wildcard matches) is ranked by it. Without one, the latest release is still the most recently created.force-system-versionandcheck-system-version, stored and ignored today, take effect. A code system's version comes from, in this order:force-system-version, the version the reference names,system-version,check-system-version, then OCL's default (the expansion's lock, the latest release, HEAD). A parameter that decides a version but names none that exists leaves the reference unresolved; it never falls back. A version used thatcheck-system-versiondoesn't name is recorded on the expansion (reference.version_check, health reasonversion_check_failed), and the reference keeps its members.default-valueset-version: the version of a value set a reference names without one, ahead of the value set lock. One that doesn't exist leaves the value set not found. The API accepts this parameter only while the toggle is on; otherwise it's refused as an unknown parameter, as today.The parameters apply by the repository they name, whatever URL a reference uses for it. References to a concept or mapping version keep their own resolution.
Locks don't change under the rules:
system-version. When a locked version is deleted, its entry no longer resolves, and the reference falls back to its default, as without the rules: the entry is recorded as unresolved, health reportslocked_version_deleted, and the deleted lock still comes beforecheck-system-version, which then checks the version used.system-version,force-system-versionanddefault-valueset-versionare written as the version HEAD's expansion used, percent-encoded as the resolver reads them.check-system-versionstays as written: it checks, and thesystem-versionentry the lock writes decides first. A wildcard reference names a version, sosystem-versiondoesn't reach it. The lock-built expansion keeps the versions HEAD's wildcard references picked: only those are copied when the version is built, and they're kept through a rebuild as value set locks are. A wildcard reference there uses the kept version named exactly as its wildcard is written, else the newest kept release its wildcard names. A version named so after the lock was built changes nothing. Deleting a kept version is a deleted lock.A version named like a wildcard (
1.x) is found by its name before the wildcard's newest. Two collection versions in production are named like that.Source.version_algorithmhas no writer yet. The FHIR CodeSystem write will set it from a code system'sversionAlgorithm, and later an API field, and each will check it's one of the five codes. FHIR's own resolver (FhirResolution) gets the rules in the FHIR workspace change (phase B's W1, not yet a PR), which reads them from its own evaluation.Version strings, wildcards and version algorithms live in
core/common/versions.py; the rules live incore/collections/version_rules.py;ReferenceResolutiongains aversion_rulesflag, off by default, so$resolveReferenceand FHIR's own resolver are unchanged.With the switch off
Every rule has a test with the switch on, off, and left to the toggle. Builds read the toggle only when the rules could change something: a wildcard version, a source that declares an algorithm, a stored
force-/check-system-versionordefault-valueset-version, orsystem-versionentries that don't resolve (on an expansion not built with lock) or that name two versions of one code system. Creating a version with lock reads it only when a parameter entry or a reference has a wildcard; the rebuild diff, when the expansion has version parameters; deleting a released source version, when a lock-built expansion holds it as an explicit version. Without the rules nothing is pinned or kept, and the diff resolves as before. In production (Nov 29) no reference, value set reference orsystem-versionentry names a wildcard-like version, no source declares an algorithm (the field is new), and no expansion setsforce-orcheck-system-version.Migration
sources.0052_source_version_algorithmadds one nullable text column,version_algorithm, with no default, to thesourcestable. It doesn't rewrite the table or change any data (PostgreSQL 11+ only updates the catalog for this). Production'ssourcestable has about 4,000 rows. Code without this PR ignores the column, so a database shared with an older deployment is unaffected.Adding the column takes an ACCESS EXCLUSIVE lock on
sources, which every read of the table waits for. So the wait for it is bounded at 0.3 s (SET LOCAL lock_timeout, the first operation applied and reversed). If another transaction holds the table for longer, the migration fails ("canceling statement due to lock timeout") and nothing has changed; run it again once that transaction is over.Tests
core/common/tests_versions.py: version strings, wildcards, version orders.core/collections/tests/tests_version_rules.py: each rule on stored content with the switch on and off, following the HL7 Terminology Ecosystem IG's version cases.core/code_systems/tests.py: a FHIR CodeSystem update keeps the version algorithm HEAD declares.--parallel=4plus the ES-tagged run): pylint 10.00; 4,187 + 803 tests OK; coverage 97%.Review
Reviewed with three Codex defect passes (6, 7 and 4 findings; every P0/P1 fixed), a simplification review (5 cuts applied) and follow-up checks of the later commits, whose remaining findings were edge cases around owners named like a resource type, all fixed.
Follow-up: a version parameter that names a canonical URL (
system-version,force-system-version,check-system-version,default-valueset-version) now also applies to every reference naming that URL where the URL alone names the same repository, whichever repository with it the reference or the entry resolves to. FHIR's resolution can serve a named version from another repository with the canonical URL. One naming an OCL path still applies by its repository (b52ac69; three Codex passes and four checks of later changes, every P0/P1 fixed, two P2s accepted).Follow-up: #1086's review answers merged in (dc7908e): a request-time evaluation answers its caller, and a version the caller can't view is answered as one not found. Adapted here (87918a2): a version that a version parameter resolves to and the caller can't view counts as one that parameter names and that doesn't exist, so it never decides a reference's version, supplies a check's version or keys a rule to another repository with the canonical URL;
check-system-versionis checked against the versions the caller can view. Tests for each. Codex checks: one P1 and one P2 fixed; one P1 answered as #1086's own rule (a newer release the caller can't view is answered as not found, as for a reference's default); two P2s accepted.Follow-up: a failed version check now also names the version it used by its id (
version_id, d9d765d). Another repository can hold a version with the same canonical URL and label, and a repository's HEAD can move to another URL while its releases keep theirs, so what may be shown of the entry is decided by the version it names. The expansion's readers get the entry without the id, as before. A test fails without it. Full suite: 4,228 + 803 tests OK, coverage 97%, pylint 10.00. Codex check of the follow-up: nothing in this PR.Sunny's review (Nov 30), answered:
compareandpick, used only by tests, are gone, and the module docstring now says a repository with no algorithm ranks by creation. A version named like a wildcard is found by its name. Theversion_algorithmcomment says what will write it.FhirResolution: see above.A Codex check of these commits found five P1s and a P2 in them (a pinned
+read back as a space; a deleted lock leaving the check to decide; an exact1.xlosing to a kept pick; a deleted kept pick not a deleted lock; the diff losing a reference's namespace, and keeping a check's version that force overrides). All are fixed with tests (6ff5c44). Later checks found a draft named like a wildcard after the lock replacing its pick (6c46c28) and stale versions from HEAD copied into a locked version (5b7527a), both fixed with tests; a variable that would shadow one #1090 uses is renamed (285cf8a). Accepted:dry_run_rebuildis exact.order_key), as a wildcard's candidates are, so the fallback can differ between the two sets. That ranking rule is card B-2's.Full test gate on
5b7527ab: pylint 10.00; 4,246 tests (2 skipped) and 803 search-index tests OK; coverage 97%.Merged master after #1085 and #1086 (
730d005d), then after #1089, #1109 and #1106 (16b6722b); no change to the reviewed code.🤖 Generated with Claude Code
https://claude.ai/code/session_01AaZ4qXS11M1AtafcqStqmm