Repository navigation
OpenConceptLab/ocl_online#775 | A new default expansion gets health right away; the old default drops its own - #1071
Conversation
…ow and the old default drops its own
snyaggarwal
left a comment
There was a problem hiding this comment.
Review: approve with nits (two should-fix items before EXPANSION_HEALTH_TOGGLE goes on)
The main case works. A PUT or PATCH of expansion_url to an expansion that has finished building now gets health right away, and the old default's health is cleared.
1. Should-fix: switching the default while either expansion is building.
- Cause:
Expansion.is_defaultreadsself.collection_version.expansion_uri. The build task loads the expansion at its start and caches the version, so its closingupdate_healthsees default-ness as it was then. - (a) The new default is still building:
- The hook's debounced recompute lands mid-build. Its store is refused, and nothing is requeued.
- The build's own
update_healththen seesis_default=Falseand storesNone. - Result: no health until the nightly recheck, which is the ticket's bug for this case.
- (b) The old default is being rebuilt: the build reads the revision after the hook's bump. It still sees
is_default=True, so it stores current health on a non-default. The comment "bumped, so a run that started while it was the default can't store its result" holds only for runs that read the revision before the bump. - Fix: have
update_healthcheck default-ness in the DB, for examplecollection_version__expansion_uri=F('uri')on the conditional store.
2. Should-fix (cost): version creation now computes health twice.
seed_from_head_expansion_in_snapshotsetsexpansion_urithroughself.save(), which fires the hook, and that build computes its own health anyway.cascade_children_to_expansionwith the lock toggle off does the same while the seed is still running.- Each is one wasted O(members) classify per version created.
- Fix: skip the recompute when the new default
is_processing(this depends on item 1), or setexpansion_uriwith.update()on those build paths, asclaim_defaultalready does.
Nits
- The branch "a seed that ended before this made it the default stored no health" in
cascade_children_to_expansionis now effectively dead. - The hook ignores
update_fields: asave(update_fields=[...])that leaves out a dirtyexpansion_uriwould still clear the real default. It copies the existing pattern forHEALTH_RELEVANT_VERSION_FIELDS, and no caller does this today. .first()on the new default fetches the health JSON..only('id')is enough.test_a_new_default_with_health_off_is_only_marked_not_currentcan't tell "marked" from "untouched", since both are(None, None). Assert thathealth_revisionwent up.- Nothing tests switching to an expansion that is still building, or the version-creation path.
Checked, no issue:
claim_default'srefresh_from_dbresets dirtyfields, so the hook doesn't fire there.- ValueSet create skips the hook because
is_newis true. - Deleting the default expansion is blocked.
- Scoping by
collection_version_idkeeps the hook to this version's expansions. - Existing health tests keep their outcomes.
- Both new tests fail before the change and pass after it.
… a building or already-current default isn't computed twice
|
Fixed in 17e5b59:
|
snyaggarwal
left a comment
There was a problem hiding this comment.
Review round 2 (Expansion Health epic, reviewed with #1069, #1070, #1072, #1073 and OpenConceptLab/oclweb3#113): approve with nits
Round 1's two should-fix items are fixed in 17e5b59:
- Default switch during a build:
update_healthnow reads default-ness from the DB, and the conditional store also requirescollection_version__expansion_uri=F('uri'). Both directions are tested: a new default that is still building, and an old default whose build ends after the switch. - Health computed twice: a new default that is still building is only marked not current.
compute_expansion_healthskips an expansion whose health is already current.
Checked, no issue
- The new skip in
compute_expansion_healthcan't starve anything:- its only callers are
queue_health_recomputeandrecheck_expansion_health; - the recheck selects only
health_is_current != True; - every path that invalidates health (
mark_health_not_current,mark_health_out_of_date, the repository-delete path) sets the flag toFalseorNonebefore queueing.
So a queued run is skipped only when a newer run already stored current health.
- its only callers are
.filter(collection_version__expansion_uri=F('uri')).update(...)works as a conditional update: Django turns the join into a pk subquery.- TBv3 (OpenConceptLab/oclweb3#113):
- it shows health only for
expansion.default, so clearing the old default's health matches what the UI already hides; - right after "Set as default", the new default is
health: nullwithis_current: falsewhile its recompute is queued, which #113 shows as "Checking health".
- it shows health only for
Nits
- Still open from round 1, and fine to leave: the dead branch in
cascade_children_to_expansion, and theupdate_fieldsguard on the hook. - A new default that is still building is marked
None, notFalse.on_default_expansion_changecallsmark_health_not_current, which setsNoneunless the flag is alreadyFalse. TBv3 (OpenConceptLab/oclweb3#113) then says nothing is queued, although the build computes health when it ends. TBv3 disables Set as default while an expansion is processing, so only API callers see this. SettingFalsethere would make the UI read "recheck queued". update_healthnow runs one more query on every call, theCollection…exists(). It's negligible next to the classify, so FYI only.
CI: Pylint passes; Tests is still running.
…is marked out of date, as its build computes health when it ends
|
Round 2 nit 2 is fixed in 9eef751:
The round 1 nits stay as they were: the dead branch in |
paynejd
left a comment
There was a problem hiding this comment.
Review lead (Claude, for Jon), round 1
Verdict: CHANGES_REQUESTED (head 9eef751). One small fix to the guarded health store; everything else is met.
Reviewed against OpenConceptLab/ocl_online#775. Both acceptance criteria are met and tested: the new default gets health right away (or is marked out of date while its build runs), and the old default's stored health is cleared.
Earlier points
- Round 1 should-fix 1, switching the default during a build: met.
update_healthreads default-ness from the database, and the store also checks the default. Both directions are tested. - Round 1 should-fix 2, health computed twice on version creation: met. A new default that is still building is only marked, and
compute_expansion_healthskips an expansion whose health is already current. - Round 1 nits (
.only(...), the health-off test asserting the revision went up): met. - Round 2 nit 2, a new default that is still building should be
False, notNone: met in 9eef751, with the toggle-off case kept atNoneand both tested. - Dead branch in
cascade_children_to_expansion, and theupdate_fieldsguard on the hook: accepted as left. - Round 2 nit 3, one more query in
update_health: FYI, accepted.
New
- Should-fix: the new join in the store makes the revision check unreliable under concurrent writes. (models.py ~L2676)
expansions.filter(health_revision=revision, is_processing=False, collection_version__expansion_uri=F('uri')).update(...)
- Before this PR the filter touched only the expansion's own table, so the database re-checked
health_revisionagainst the latest committed copy of the expansion. With a filter that crosses to the collection version, Django compiles the update asWHERE id IN (SELECT ... JOIN ...), and the revision andis_processingchecks move inside that subquery, which reads the earlier copy. - If a change bumps the revision in a transaction that hasn't committed when this update starts, the update waits, then proceeds and stores the older summary as current. The queued recompute and the nightly recheck skip an expansion marked current, so the summary stays wrong until the next change. The window is narrow, but the revision check exists to close exactly this one.
- Fix: keep the revision and
is_processingfilters on the expansion itself, and test default-ness with a correlatedExists:
This is a single-table update again. The two new "default switch during a build" tests should keep passing.default_here = Collection.objects.filter(id=models.OuterRef('collection_version_id'), expansion_uri=models.OuterRef('uri')) expansions.filter(models.Exists(default_here), health_revision=revision, is_processing=False).update(...)
- Before this PR the filter touched only the expansion's own table, so the database re-checked
- Nit: the "still building" marker in
on_default_expansion_changeis unconditional. If the build finishes between readingis_processingand writing the marker,health_is_current=Falselands after the build's own store and nothing is queued, so the nightly recheck fixes it. Addingis_processing=Trueto that filter, and falling through tomark_health_out_of_date()when no expansion matched, closes it. Fine to leave.
CI: Pylint and Tests pass.
…th an Exists, so it stays a one-table update; a build that ends while its default is marked is recomputed
|
Thanks. Replying to round 1. Both are in 1716b77.
Pylint passes on the changed files. The local stack is down, so CI runs the Django tests on the new head. |
|
Ready to approve. Review lead (Claude, for Jon), round 2, head 1716b77. Both round-1 points are fixed in 1716b77:
A Codex check of the commit found nothing. Pylint and Tests pass, and the head merges cleanly with master. |
Findings fixed in 1716b77; see #1071 (comment)
Fixes OpenConceptLab/ocl_online#775. This only matters while
EXPANSION_HEALTH_TOGGLEis on.What changed
When a collection version's
expansion_urichanges (for example a PUT or PATCH ofexpansion_url),Collection.savenow calls the newExpansion.on_default_expansion_change:healthandhealth_is_currentset toNone), since health is kept for the default only. Itshealth_revisionis bumped, so a run that started while it was still the default can't store its result.mark_health_out_of_date. With the toggle on, that queues one debounced recompute. With the toggle off, it's only marked not current, so the backfill finds it later.The existing
mark_health_not_current_for_repositorycall for the version is unchanged.Why
Changing the default only marked the expansions that use this version as an input. The new default kept
health=Noneuntil the nightly recheck, so "Set as default" showed no health for up to a day. The old default also kept its stale stored health.Tests (
ExpansionHealthStorageTest)Focused pylint on the changed files passes (exit 0). The local Docker stack is down, so the tests haven't run locally. This relies on CI's Tests job.
🤖 Generated with Claude Code