Skip to content

OpenConceptLab/ocl_online#740 | Deleting a collection, or one of its versions, reindexes its former members - #1046

Merged
snyaggarwal merged 6 commits into
masterfrom
search-740-delete-reindex
Nov 24, 2026
Merged

snyaggarwal merged 6 commits into
masterfrom
search-740-delete-reindex

Conversation

@paynejd

@paynejd paynejd commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Closes OpenConceptLab/ocl_online#740.

What changes

Deleting a collection, or one of its versions, reindexes the concepts and mappings it held, so search stops naming it on them. Until now their documents kept the deleted collection's name and URLs until something else reindexed them. That affected the collection, collection_url and collection_owner_url filters and facets, and a collection later created under the same name and URL matched the old members.

  • Collection.delete (new override, like Source.delete since OpenConceptLab/ocl_online#744 | A seeding import reindexes the rows it supersedes, and deleting a source version reindexes its rows #1038) reads the ids of the concepts and mappings in the expansions of the version being deleted, or of every version when HEAD is. Once the delete commits (transaction.on_commit, robust=True), it queues their reindex. The callback is registered in a finally, so a failure after the rows are deleted (queueing the export cleanup) still reindexes them; a rollback drops it. The Tasks belong to HEAD's last editor, as Source.delete's do. Source.delete gets the same robust=True and finally.
  • The chunked queueing moves from Source.queue_reindex to ConceptContainerModel.queue_children_reindex, unchanged: 5,000 ids a Task on the indexing queue, arguments saved so it can be rerun, and a chunk that can't be queued left as a failed Task. Source.queue_reindex keeps its latest-release step and its signature. Five test patch targets move from core.sources.models.batch_index_resources to core.common.models.batch_index_resources.
  • delete_collection no longer deletes a version's expansions before calling collection.delete, which would hide their members from it. The delete's cascade removes them, as it already did for the other versions when HEAD is deleted. References still go first.
  • Export cleanup: with the expansions still there, a version's export prefixes name its default expansion. The delete now clears the prefixes both with and without the default expansion, in the current and the old format, so an export made before the version had one is cleared too. An old-format prefix is cleared only when no other version builds it, with or without that version's own default expansion. Versions deleted in the same call (a HEAD's) don't count. The same, more cautious ownership check decides whether an old-format export is served.
  • The chunk size is REINDEX_CHUNK_SIZE in core.common.constants; DROPPED_CHILDREN_CHUNK_SIZE is that value.

This covers the HEAD and version DELETE routes (both use delete_collection) and an organization's delete. Not covered: a user's hard delete cascades in the database without calling Collection.delete, and deleting a non-default expansion leaves its name on its members.

Cost

One query on each expansion link table for each deleted collection row. The reindex runs on the indexing workers, never in the request.

Tests

  • core.collections.tests test_deleting_a_collection_indexes_its_former_members_again: deleting a version reindexes only its members (both expansions'), after commit. delete_collection on HEAD reindexes HEAD's and the remaining versions' members. A failing export-cleanup publish still reindexes them.
  • test_deleting_an_organization_indexes_its_collections_former_members_again: an organization's delete queues nothing until its transaction commits, then reindexes both collection rows' members.
  • Export cleanup: test_delete_version_clears_its_exports_with_and_without_its_default_expansion, test_delete_head_clears_an_old_format_export_prefix_only_its_versions_build, test_delete_version_leaves_an_old_format_export_prefix_another_version_builds, and tests_sources test_legacy_export_of_a_lookalike_made_before_its_expansion_is_not_owned.
  • core.sources.tests test_deleting_a_version_indexes_its_former_members_again also covers a failing export-cleanup publish.
  • QueryCollectionAccessTest.test_deleting_a_collection_indexes_its_members_again (ES): staff's collection_url search no longer finds a deleted version's members. After a collection is deleted and a public one is created under its name and URL, nobody's collection or collection_url search finds the old members.
  • The existing Source reindex and importer tests pass with the moved patch targets.

Local runs on 8c8c3d5 (oclapi2-local image with pylint 4.0.9, fresh test databases): pylint -j0 core/ clean; ES-tagged suite 698 tests OK; TEST_ES=off --exclude-tag es --parallel=4 3,653 tests OK.

Review

Codex: 3 defect passes and 2 checks of later commits, 12 P2s, no P0 or P1. Fixed: F1.1, F2.1, F3.1, F3.2, and FC.1 from the first check. Accepted, with reasons in each pass comment: F1.2-F1.4, F2.2, F3.3 (filed as OpenConceptLab/ocl_online#754), and the second check's two. The simplification review's three cuts were declined.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qTpN4J5JFjNSmhYF49
https://claude.ai/code/session_01AaZ4qTz8ve2veELx7gFNaJ

…versions, reindexes its former members

A concept's or mapping's search document names every collection version holding it, read from the expansions.
Deleting a collection removed the rows but left its members' documents as they were, so search kept the deleted
collection's name and URLs on them until something else reindexed them: in the collection filters and facets, and
for a collection later created under the same name and URL.

Collection.delete now reads the ids of the concepts and mappings in the expansions of the version being deleted (of
every version, when HEAD is), and once the delete commits it queues their reindex, as Source.delete does since
OpenConceptLab/ocl_online#744. The chunked queueing moves from Source.queue_reindex to
ConceptContainerModel.queue_children_reindex, unchanged: 5,000 ids a Task on the indexing queue, with its arguments
saved so it can be rerun, and a chunk that can't be queued left as a failed Task. Source.queue_reindex keeps its
latest-release step.

delete_collection no longer deletes a version's expansions before the version: that would hide their members from
Collection.delete. The delete's cascade removes them, as it already did for the other versions when HEAD is deleted.
This covers the HEAD and version DELETE routes and an organization's delete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qTpN4J5JFjNSmhYF49
@paynejd
paynejd requested a review from snyaggarwal November 24, 2026 04:46

@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.

Reviewed the diff and the paths it touches: delete_collection, Organization.delete, ConceptContainerModel.delete cascading to versions and expansions, and ConceptDocument reading collection_url from expansion_set. The approach looks right. Reading the ids before super().delete() and queueing after commit matches what Source.delete does. Dropping the explicit expansions.all().delete() is needed so the ids are still there to read, and the cascade removes the expansions anyway.

No blocking issues. Five nits are inline. The most useful is robust=True on the on_commit callback.

The gaps listed in the description, a user's hard delete and deleting a non-default expansion, are confirmed. I have nothing to add to them.

Comment thread core/collections/models.py Outdated
field, flat=True)) for relation, field in ((Expansion.concepts, 'concept_id'),
(Expansion.mappings, 'mapping_id')))
super().delete(using=using, keep_parents=keep_parents, force=force, sync=sync)
transaction.on_commit(lambda: self.queue_children_reindex(concept_ids, mapping_ids))

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.

Nit (optional): this on_commit callback isn't robust. delete_collection runs in autocommit, so the callback fires right away inside collection.delete. If queue_children_reindex raises (for example Task.new hits a DB error), the exception reaches delete_collection's except, which logs "Collection delete failed" and returns False for a delete that already committed. Inside Organization.delete's atomic block, it propagates after the commit. queue_count_task already uses robust=True for this reason. Source.delete has the same pattern, so it could be fixed there too.

Suggested change
transaction.on_commit(lambda: self.queue_children_reindex(concept_ids, mapping_ids))
transaction.on_commit(lambda: self.queue_children_reindex(concept_ids, mapping_ids), robust=True)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in e068a8c: the callback is robust=True, and Source.delete's too. It's also registered in a finally (Codex F1.1), so a failure after the rows are deleted still queues the reindex.

Comment thread core/collections/models.py Outdated
Comment on lines +334 to +337
concept_ids, mapping_ids = (set(
relation.through.objects.filter(expansion__collection_version_id__in=version_ids).values_list(
field, flat=True)) for relation, field in ((Expansion.concepts, 'concept_id'),
(Expansion.mappings, 'mapping_id')))

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.

Nit (optional): the tuple-unpacked generator is hard to read for just two queries. Two explicit lines say the same thing:

Suggested change
concept_ids, mapping_ids = (set(
relation.through.objects.filter(expansion__collection_version_id__in=version_ids).values_list(
field, flat=True)) for relation, field in ((Expansion.concepts, 'concept_id'),
(Expansion.mappings, 'mapping_id')))
expansions = dict(expansion__collection_version_id__in=version_ids)
concept_ids = set(Expansion.concepts.through.objects.filter(**expansions).values_list('concept_id', flat=True))
mapping_ids = set(Expansion.mappings.through.objects.filter(**expansions).values_list('mapping_id', flat=True))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in e068a8c, with your two explicit lines.

Comment thread core/common/models.py
"""
from core.sources.constants import DROPPED_CHILDREN_CHUNK_SIZE
from core.tasks.models import Task
user = user or self.updated_by

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.

Nit (optional): when a collection version is deleted, self is the version, so the reindex Tasks belong to that version's last editor. That may be neither the person deleting it nor HEAD's editor. Source.delete calls this on head (head.queue_reindex), so the two repo types now differ. To match Source, Collection.delete could pass user=self.head.updated_by, or call it on the head, when self isn't HEAD.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in e068a8c: a version's reindex Tasks belong to HEAD's last editor (get(self, 'head.updated_by'), read before the delete), as Source.delete's do.

Comment thread core/common/models.py Outdated
indexing queue, with its arguments saved so it can be rerun; a chunk that can't be queued is left as a failed
Task. user: who the Tasks belong to (and can cancel them), by default this repository's last editor.
"""
from core.sources.constants import DROPPED_CHILDREN_CHUNK_SIZE

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.

Nit (optional): this helper is now shared by collections, but its chunk size still comes from core.sources.constants through a lazy import. Moving DROPPED_CHILDREN_CHUNK_SIZE, or a neutral alias for it, to core.common.constants would let this module import it at the top and drop the dependency on sources.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in e068a8c: REINDEX_CHUNK_SIZE in core.common.constants, imported at the top of core.common.models. DROPPED_CHILDREN_CHUNK_SIZE is now that value, so its existing uses and test patches are unchanged.


@patch('core.common.models.delete_s3_objects', Mock())
@patch('core.common.models.batch_index_resources')
def test_deleting_a_collection_indexes_its_former_members_again(self, batch_index_resources_mock):

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.

Nit (optional): the description says an organization's delete is covered, but only Collection.delete and delete_collection are tested. Organization.delete runs everything in one transaction.atomic() and iterates collection_set (HEAD and versions, in any order), so its reindexes queue only after the outer commit. A short test that deletes an org with a collection HEAD and a version, then checks the reindex calls after commit, would keep that path from regressing silently.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added in e068a8c: test_deleting_an_organization_indexes_its_collections_former_members_again deletes an org holding a collection HEAD and a version with another owner's concept. Nothing is queued until the outer commit, and then both rows' ids are.

… failure and doesn't fail the delete; it belongs to HEAD's last editor

Review on oclapi2#1046 (Codex pass 1 F1.1, and Sunny's nits):

- Collection.delete registers the reindex in a `finally`, so a failure after the rows are deleted (queueing the
  export cleanup) still reindexes the former members. A rollback drops it.
- The callback is `robust`: in autocommit it runs inside the delete, and a failure there (Task.new on a DB error)
  no longer makes delete_collection report a committed delete as failed. Source.delete's callback is robust too.
- A version's reindex Tasks belong to HEAD's last editor, as Source.delete's do.
- The chunk size is REINDEX_CHUNK_SIZE in core.common.constants; DROPPED_CHILDREN_CHUNK_SIZE is that value.
- Two explicit queries read the ids. A test covers an organization's delete: one transaction, reindexed after it
  commits.

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

paynejd commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

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

Verdict: findings: 4 P2, no P0 or P1. One fixed in e068a8c; three accepted.

Detailed scenarios are on the tracking ticket.

…port made before it had a default expansion

The delete now runs with the version's expansions still in place, so its export prefix names its default expansion.
An export made while the version had none sits under the prefix without it, which the delete cleared before. Both are
cleared now.

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

paynejd commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

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

Verdict: findings: 2 new P2s, no P0 or P1. Pass 1's F1.1 is confirmed fixed; F1.2-F1.4 stay accepted as before. One new finding fixed in 424bbe4, one accepted.

  • F2.1 (P2), fixed in 424bbe4: the delete now runs with the version's expansions still in place, so the export cleanup used only the prefix that names its default expansion. An export made before the version had a default expansion sits under the prefix without it, which the old order (expansions deleted first) did clear. The delete now clears both. Tested on a version that gained a default expansion after its first export.
  • F2.2 (P2), accepted: if saving a reindex Task fails after the delete commits (for example a dropped database connection), that chunk and the ones after it aren't queued, and the ids can't be read again. Source.delete (OpenConceptLab/ocl_online#744 | A seeding import reindexes the rows it supersedes, and deleting a source version reindexes its rows #1038) works the same way. Closing it means saving the reindex work in the delete's own transaction and publishing it afterwards, which is wider than this change. A full reindex still corrects the documents.

Detailed scenarios are on the tracking ticket.

@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.

Re-review of e068a8c and 424bbe4.

All five earlier nits are fixed as described in the thread replies:

  • robust=True on both on_commit calls
  • the two explicit id queries
  • HEAD's last editor owns the Tasks
  • REINDEX_CHUNK_SIZE in core.common.constants
  • the organization delete test

The Codex passes check out too. The F1.1 finally works: inside a transaction a rollback drops the callback, and in autocommit it runs at once with the rows already gone. The F2.1 fix and its test cover the current key format. I agree with accepting F1.2-F1.4 and F2.2. They're the same races and gaps Source.delete has, and a full reindex corrects them.

New in this pass:

  • Important (inline): the legacy export prefix needs the same bare-prefix treatment as F2.1, with its own ownership check.
  • Pre-existing (inline): Source.delete lacks the F1.1 finally.
  • Nit, no change needed: the finally also registers the reindex when super().delete() raises before deleting anything, for example a ValidationError when deleting the only version without force. The extra reindex rewrites unchanged documents and does no harm.

Comment thread core/common/models.py Outdated
Comment on lines +1085 to +1087
bare = self.get_version_export_path(suffix=None, with_expansion=False)
if bare != prefixes[0][0]:
prefixes.append((bare, get_export_key_pattern(bare)))

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.

Important: this restores the bare prefix for the current key format, but the legacy prefix loses its bare form in the same way, as in F2.1. Before this PR, delete_collection deleted the expansions first, so get_export_key_prefixes built both the current and the legacy prefix without the expansion. Now the legacy entry carries the expansion (orgs/O/O_C_v1_exp.). A legacy export taken before the version had a default expansion (orgs/O/O_C_v1.) is no longer cleared.

It can't be a one-line append like the current-format bare prefix. owns_legacy_export_path checks the legacy path with the expansion, and a sibling with the same legacy name (a source C with version v1, or version 1 against v1) builds the same bare legacy prefix. So the bare legacy prefix needs its own ownership check before it's added. If you'd rather accept the gap, note it with F2.1 on the ticket.

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.

Fixed in a546ff6 (Codex F3.1/F3.2), and I checked the fix: the bare legacy prefix is cleared only when this version owns it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for checking. 463dcc8 adds your example as a test: collection C v1's old-format prefix without its expansion stays when source C v1 builds it. The same commit fixes what the Codex check of a546ff6 found: on a HEAD delete, versions deleted in the same call no longer count as other owners, so a prefix that only they build (version a with expansion b, and version a_b) is cleared.

Comment thread core/sources/models.py Outdated
@@ -1090,30 +1089,17 @@ def delete(self, using=None, keep_parents=False, force=False, sync=False):
concept_ids = list(self.concepts.values_list('id', flat=True))
mapping_ids = list(self.mappings.values_list('id', flat=True))
super().delete(using=using, keep_parents=keep_parents, force=force, sync=sync)

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.

Pre-existing (not from this change, not blocking): Source.delete now has robust=True, but not the try/finally from F1.1. If the export cleanup raises after the rows are deleted (for example delete_s3_objects.apply_async can't reach the broker), the reindex is never registered. In autocommit the rows stay deleted and the members keep the version's name. This came in with #1038. The same finally would fix it here, or it can wait for a follow-up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in 8c8c3d5: Source.delete registers the reindex in the same finally. test_deleting_a_version_indexes_its_former_members_again now also covers a failing export-cleanup publish.

…fore its default expansion is cleared on delete, and isn't taken for another's

Deleting a version also clears its old-format export prefix without the default expansion, when no other version
builds it. A version's old-format prefix is now someone else's if another version builds it with or without that
version's own default expansion, so a version that gained an expansion after an export keeps that export.

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

paynejd commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

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

Verdict: findings: 3 P2s, no P0 or P1. Two fixed in a546ff6, one accepted. This was the last defect pass; earlier accepted findings are unchanged.

  • F3.1 (P2), fixed in a546ff6: 424bbe4 cleared the current-format export prefix without the default expansion, but not the old-format one. The delete now clears that too, when no other version builds it.
  • F3.2 (P2), fixed in a546ff6: a version's old-format prefix could match another version's prefix from before that version had its own default expansion, and the ownership check compared only the other version's prefix with its current expansion. It now compares both, so an export whose owner is ambiguous is kept. The same check also decides which old-format export is served, so that's now as cautious as the delete. Test added next to the existing lookalike test.
  • F3.3 (P2), accepted: batch_index_full pages by offset, so a row hard-deleted from an earlier page while a reindex runs can make it skip a later row. That's in the shared batch indexer, used by every queued reindex (this PR's and Source.queue_reindex's alike), and needs its own change.

Full suites on 424bbe4: ES 698 OK, non-ES 3,650 OK. Detailed scenarios are on the tracking ticket.

@paynejd

paynejd commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Simplification review (Claude subagent, commit a546ff6)

Verdict: 3 suggested cuts, all low confidence. None applied, so the head stays a546ff6.

  • S1 (yagni), declined: dropping DROPPED_CHILDREN_CHUNK_SIZE for REINDEX_CHUNK_SIZE would change six uses in the source drop and seed code and a test patch, none of which this PR otherwise touches. The alias is what the review nit settled on.
  • S2 (shrink), declined: without the guard, every deleted version without a default expansion would queue one more S3 deletion task and run the old-format ownership queries twice. A HEAD delete does that for every version.
  • S3 (dup-test), declined: the id set alone doesn't show which resource the ids were queued as. That line checks they were queued as concepts.

@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.

Re-review of a546ff6.

My legacy bare-prefix finding is fixed. Codex pass 3 found the same problem as F3.1, and a546ff6 fixes it. When the default-expansion prefix differs from the bare one, get_export_paths_to_delete now adds the bare current-format prefix and the bare legacy one. The legacy one is added only when this version owns it. The F3.2 change to owns_legacy_export_path is right: a legacy prefix that matches another version's bare or current-expansion prefix isn't owned, so it's kept. test_legacy_export_of_a_lookalike_made_before_its_expansion_is_not_owned covers the collision.

Two side effects of the stricter ownership check, both deliberate and cautious:

  • Serving. A version whose legacy prefix matches a lookalike's bare prefix no longer has its legacy export served. Jon's comment says so.
  • migrate_export_keys. It calls the same check, so those prefixes are now listed as "Shared, skipped" instead of being moved, and --assign can still move them. If the migration has already run in production, this makes no difference.

Still open: my pre-existing note on Source.delete lacking the F1.1 finally hasn't had a reply. It's fine as a follow-up, but please reply on that thread either way.

New, inline: a pre-existing ownership gap for a candidate's former default expansion. It only risks losing an export file nothing can reach.

I agree with accepting F3.3 (batch_index_full paging by offset). It sits in the shared indexer, not in this change. Nothing here blocks merging.

Comment thread core/common/models.py
base = candidate.get_legacy_version_export_path(suffix=None, with_expansion=False).rstrip('.')
same_path = candidate.get_legacy_version_export_path(suffix=None) == legacy_path
if legacy_path.startswith(base) and same_path:
if legacy_path in (candidate.get_legacy_version_export_path(suffix=None, with_expansion=False),

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.

Pre-existing (not from this change, not blocking): this check covers a candidate's prefix without an expansion and with its current default expansion. It doesn't cover a default expansion the candidate used to have. Take candidate version a, exported when its default expansion was b and since moved to c. Its old export sits under O_coll_va_b.. Version a_b with no expansion builds that same bare prefix and passes this check, so deleting a_b clears a's old export. Version a can't reach that export any more, so the only harm is a lost orphan file. Comparing against all of the candidate's expansion mnemonics would close it, but that can be a follow-up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed: it predates this PR, so I've left it for a follow-up. Comparing all of a candidate's expansions would narrow it but not close it, because a deleted expansion leaves no record of having been the default. As you say, the only harm is an orphan export that version a can't reach any more.

paynejd and others added 2 commits November 24, 2026 00:33
…port prefix that only its own versions build

A version's old-format prefix counts as another version's only if that version outlives the delete. When HEAD goes, its
versions go too, so a prefix two of them build (version a with expansion b, and version a_b) is cleared. Tests also pin
that a version's old-format prefix without its expansion stays when a source of the same name and version builds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qTz8ve2veELx7gFNaJ
…reindex even if a later step fails

As Collection.delete does: registered in a finally, so a failure after the rows are deleted (export cleanup) still
reindexes the version's former members, and a rollback drops it.

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

paynejd commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits 424bbe4..a546ff6 (codex-cli 0.169.0)

Verdict: one P2, fixed in 463dcc8.

  • FC.1 (P2), fixed in 463dcc8: a546ff6's stricter ownership check kept an old-format export prefix that two versions of the same collection build (version a with expansion b, and version a_b), even when deleting HEAD removes both. A version deleted in the same call no longer counts as another owner, so a HEAD delete clears it. Tested.

8c8c3d5 also folds in the review's pre-existing point: Source.delete registers its reindex in the same finally. A Codex check of a546ff6..8c8c3d5 is running.

@paynejd

paynejd commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits a546ff6..8c8c3d5 (codex-cli 0.169.0)

Verdict: the previous check's FC.1 is confirmed fixed. Two new P2s, both accepted; no change.

  • FC.1 of this check (P2), accepted: a synchronous delete inside a transaction (an organization purge) clears exports before the transaction commits, so a rollback can't restore them. The prefix two of HEAD's own versions build is now one of those exports. That's how every export a synchronous delete clears already behaves, and an export can be generated again. Deferring S3 cleanup to after commit would be a change to export cleanup as a whole.
  • FC.2 (P2), accepted: Source.delete's finally also queues the reindex when the delete fails before removing any rows. That's the same as the review's note on Collection.delete: the extra reindex rewrites unchanged documents. Checking inside the finally whether the rows are gone would itself fail inside a transaction that's already broken, and hide the original error.

No commits after 8c8c3d5. Detailed scenarios are on the tracking ticket.

@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.

Re-review of 463dcc8 and 8c8c3d5. Everything from my earlier reviews is resolved, and I have no new findings.

  • Source.delete now has the F1.1 finally (8c8c3d5), with a test that fails the export-cleanup publish. Thanks for picking up the pre-existing note.
  • Lookalike prefix on a HEAD delete (FC.1, 463dcc8): deleting is skipped only when isinstance(self, model), so a source and a collection whose ids happen to match can't hide each other. On a HEAD delete, the prefix that only HEAD's own versions build is cleared, and a prefix that another repo also builds is kept. Both tests cover those cases. I also traced an organization purge. Sources go first, so a source's old-format prefix that its same-named collection also builds is kept, and then cleared when the collection is deleted, because by then the source rows are gone inside the same transaction. Nothing is left orphaned.
  • Former default expansions in the ownership check: I agree with leaving it for a follow-up, for the reason you give.
  • The two accepted Codex points (FC.1 and FC.2): I agree with both. The second is the same harmless extra reindex I noted on Collection.delete.

From my side this is ready to merge.

@snyaggarwal
snyaggarwal merged commit 17c9eda into master Nov 24, 2026
2 of 3 checks passed
@snyaggarwal
snyaggarwal deleted the search-740-delete-reindex branch November 24, 2026 05:46
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