Repository navigation
OpenConceptLab/ocl_issues#3003 | expansion health backfill (PR 4 of 4, stacked on #1029) - #1031
snyaggarwal wants to merge 9 commits into
Conversation
…ealth for expansions that need it, dry run by default
snyaggarwal
left a comment
There was a problem hiding this comment.
Verdict: ready to merge after CI, once #1029 lands. Three nits on 64e8a65, all about expansions that change or are stuck while a run is under way. Fixes follow in this PR.
What I checked:
- Selection:
--alltakes expansions with no health, health not current, or older rules. - Dry run: it's read-only, since the classifier's
compute()stores nothing. --apply: it goes throughupdate_health, so a concurrent change still marks the expansion out of date and queues its recompute. It's refused while the toggle is off.- Reliability: failures are isolated and resuming works.
- Order on production: the PR body states it, after #1030's rebuild.
Nothing is commercial, and the conventions are met.
| return expansion | ||
|
|
||
| def backfill(self, expansion_id): | ||
| expansion = Expansion.objects.filter(id=expansion_id).select_related('collection_version').first() |
There was a problem hiding this comment.
Nit (optional): an expansion that becomes current mid-run is still recomputed. --all lists the ids once, so one that a build makes current during a long run gets computed again when its turn comes. Unless --force is given, backfill() could re-check, skip it, and count it as skipped.
|
|
||
| def get_expansion_ids(self): | ||
| if not self.options['all']: | ||
| return [self.get_expansion(uri).id for uri in self.options['uris']] |
There was a problem hiding this comment.
Nit (optional): explicit URIs don't skip expansions being built. --all skips them, but a URI on the command line is computed mid-build. With --apply, that stores health judged from part of the members until the build's own update replaces it. The same check belongs in backfill().
| if not self.options['all']: | ||
| return [self.get_expansion(uri).id for uri in self.options['uris']] | ||
| expansions = Expansion.objects.filter( | ||
| is_active=True, collection_version__is_active=True, is_processing=False, |
There was a problem hiding this comment.
Nit (optional): expansions skipped as being built aren't counted. One whose build died with is_processing still set is never backfilled, and the totals don't show it. Counting and listing them would surface a stuck flag in the dry run.
…sions being built, and ones a build made current since the run listed them
|
All three review points are fixed in the latest commit. The description is updated.
There are three new tests, so 13 in all. They pass locally, and pylint is clean. |
snyaggarwal
left a comment
There was a problem hiding this comment.
Verdict: ready to merge once CI passes and #1029 has landed. One optional nit on 1992835.
All three fixes check out:
- Being built: an expansion being built is skipped and reported, whether it comes from
--allor a URI, so a stuck flag shows in the dry run. - Made current mid-run: with
--all, an expansion that a build made current after the run listed it is skipped, unless--forceis given. - Report: skips get their own
SKIPPEDlines, JSON lines and totals.
I went over the whole PR again: selection, the read-only dry run, --apply through update_health with the toggle guard, failures, resuming and the report. I found nothing else.
The production order still stands, as the PR body says: #1030's rebuild, then the toggle, then this dry run, then --apply with approval.
| mode = 'APPLY' if options['apply'] else 'DRY RUN' | ||
| self.stdout.write(f'{mode}. Rules version {RULES_VERSION}.') | ||
| for index, expansion_id in enumerate(self.get_expansion_ids()): | ||
| if index and options['pause']: |
There was a problem hiding this comment.
Nit (optional): --pause also waits before expansions that turn out to be skipped or gone. The sleep is in the loop, before backfill() decides to skip. A resumed run over many expansions made current since then waits for no work. Sleeping only after an expansion whose health was actually computed would avoid that.
…tween expansions whose health it computes
|
The |
snyaggarwal
left a comment
There was a problem hiding this comment.
Verdict: ready to merge once CI passes and #1029 has landed. No findings on ae9b874.
- The
--pausefix checks out: the wait now sits right before a computation and only after an earlier one, so skipped or missing expansions cost nothing. The new test runs one computed, one skipped and one computed expansion, and checks for exactly one wait. - The rest of the PR is unchanged since the last review, which found nothing else.
Still open, and not part of the code:
paynejd
left a comment
There was a problem hiding this comment.
Review at ae9b874. An independent defect pass (Codex, high effort), with every finding checked against the code. Nobody had read this PR before today's pass.
Verdict: approve. The dry run writes nothing but the --output file. --apply writes only health and health_is_current, through .update(), so members can't change. A plain rerun of --all --apply picks up failures, because failed rows are left not current. Nothing here blocks the merge or the staging run.
Worth fixing before the production run
- An interrupted
--applyleaves one row current but stale.update_healthwriteshealth_is_current=Truebefore computing. Ctrl-C or SIGTERM isn't caught, so that expansion keeps its old health marked current, and later runs skip it. It's the same root as #1026's point 3. Until that's fixed, add a runbook line: after an interrupted run, rerun--forcefrom the last completed id with--limit 1. - Pause before reading, not after.
--pausesleeps between loading the expansion and computing (~75-91), so a rebuild that finishes in that window gets overwritten. Suggestion inline. --limit 0means no limit (~62). Suggestion inline.
Minor
4. Print each expansion's id on its stdout line, and exit non-zero when any failed. Today the id that --start-after-id needs is only in the --output JSON.
5. The tests use only empty expansions. Please add one dry-run and one apply test on an expansion with a concept and a mapping, asserting that member ids are unchanged and that a dry run leaves health null.
| expansions = expansions.filter( | ||
| Q(health__isnull=True) | ~Q(health_is_current=True) | ~Q(health__rules_version=RULES_VERSION)) | ||
| ids = expansions.order_by('id').values_list('id', flat=True) | ||
| return list(ids[:self.options['limit']] if self.options['limit'] else ids) |
There was a problem hiding this comment.
Point 3: --limit 0 runs nothing instead of everything.
| return list(ids[:self.options['limit']] if self.options['limit'] else ids) | |
| return list(ids[:self.options['limit']] if self.options['limit'] is not None else ids) |
| def backfill(self, expansion_id): | ||
| expansion = Expansion.objects.filter(id=expansion_id).select_related('collection_version').first() | ||
| if not expansion: | ||
| return | ||
| skipped = self.get_skip_reason(expansion) | ||
| if skipped: | ||
| self.totals[f'skipped_{skipped.replace(" ", "_")}'] += 1 | ||
| self.write({'expansion': expansion.uri, 'id': expansion.id, 'skipped': skipped}) | ||
| return | ||
| # waits only between computations: a skip costs nothing | ||
| if self.has_computed and self.options['pause']: | ||
| time.sleep(self.options['pause']) | ||
| self.has_computed = True |
There was a problem hiding this comment.
Point 2: waits before reading the next expansion, not between reading and computing, so a build that ends during the wait isn't overwritten.
| def backfill(self, expansion_id): | |
| expansion = Expansion.objects.filter(id=expansion_id).select_related('collection_version').first() | |
| if not expansion: | |
| return | |
| skipped = self.get_skip_reason(expansion) | |
| if skipped: | |
| self.totals[f'skipped_{skipped.replace(" ", "_")}'] += 1 | |
| self.write({'expansion': expansion.uri, 'id': expansion.id, 'skipped': skipped}) | |
| return | |
| # waits only between computations: a skip costs nothing | |
| if self.has_computed and self.options['pause']: | |
| time.sleep(self.options['pause']) | |
| self.has_computed = True | |
| def backfill(self, expansion_id): | |
| # after a computation, waits before reading the next expansion: a build that ends meanwhile isn't overwritten | |
| if self.has_computed and self.options['pause']: | |
| time.sleep(self.options['pause']) | |
| self.has_computed = False | |
| expansion = Expansion.objects.filter(id=expansion_id).select_related('collection_version').first() | |
| if not expansion: | |
| return | |
| skipped = self.get_skip_reason(expansion) | |
| if skipped: | |
| self.totals[f'skipped_{skipped.replace(" ", "_")}'] += 1 | |
| self.write({'expansion': expansion.uri, 'id': expansion.id, 'skipped': skipped}) | |
| return | |
| self.has_computed = True |
…s only, waits before reading, honours --limit 0, prints ids and exits non-zero on a failure
|
Thanks, Jon. All five points are addressed in the latest commit, on a merge of the API branch (0f61439).
Also from #1025, point 1: health is kept for each version's default expansion only. The local Elasticsearch container is down, so CI is the first test run; pylint is clean. |
paynejd
left a comment
There was a problem hiding this comment.
Thanks, Sunny. All five points are met:
- An interrupted
--applyleaves the row not current, through #1026's revision check. - The command pauses before reading the next expansion.
--limit 0runs nothing.- Every line starts with the id, and a failure exits non-zero after the totals.
- The tests with members show the members unchanged.
Taking default expansions only with --all is right. My approval stands.
Two notes:
- CI: two of this PR's own tests fail (
test_all_takes_only_expansions_that_need_it, and an error intest_all_skips_an_expansion_a_build_made_current_since_the_run_listed_it). An expansion that should be current reads None, so this is the same setUp order as #1026's five failures: the default is set after the expansion is built. - A misleading message:
get_apply_errorsays "computing health failed; see the log" when the store lost to a repository mark. That mark sets None, not False, so the message names a failure that was never logged. Nothing is lost: it counts as failed, and a rerun picks it up.
… before seeding, so a just-built expansion is current
|
CI fix (6eb76f7): |
paynejd
left a comment
There was a problem hiding this comment.
Review lead (Claude, for Jon), round 3
Thanks, Sunny. The backfill tests now claim the default before seeding, so a just-built expansion is current. CI is green at 9b2fd6b. Every round-2 point is met. Approved for this PR's own changes; it merges after #1026.
The get_apply_error wording note from round 2 still applies; fix it or leave it as you prefer.
… to a change by the revision, whatever the change left
|
The
New test: a repository-style mark that sets None during compute is reported as changed, not failed. Merged #1029 (9a91614). Local Elasticsearch is down, so CI is the first run. |
PR 4 of 4 for OpenConceptLab/ocl_issues#3003 (epic OpenConceptLab/ocl_issues#2942): the backfill, decision 8. It's stacked on #1029. Expansions built from here on store their health at build; this command computes it for the ones built before.
What it does
--alltakes every active expansion of an active collection version that has no health yet, whose health isn't current, or whose health was computed with older rules (rules_version).--forcetakes the rest too.--allor passed as URIs, because their build stores health when it ends. A build that died with the flag still set shows up here.--all, expansions that a build made current after the run listed them.--apply: stores it throughExpansion.update_health, the same path builds use, so a change while it computes still marks the expansion out of date. It refuses to run whileEXPANSION_HEALTH_TOGGLEis off, because the stored health wouldn't be kept current.--start-after-idand--limitresume a long run;--pausewaits between expansions to keep production load down.The report
--output, each line holds the stored state before, the full health summary and the seconds it took.Order on production
rebuild_expansion_version_lists(OpenConceptLab/ocl_issues#3005 | rebuild_expansion_version_lists rebuilds expansions' explicit and evaluated version lists, dry run by default #1030) runs first, because health reads the lists it rebuilds.EXPANSION_HEALTH_TOGGLEgoes on in production.--applywith approval.The staging run comes first, once PR 3 is on staging.
Tests
core/collections/tests/tests_health_backfill.pyhas 14 tests:--applystores current health;--applyis refused with the toggle off;--alltakes, and--force;--alland by URI;--pausewaits only between computations;They pass locally, and
pylint -j0 core/exits 0.🤖 Generated with Claude Code