Skip to content

Indexer skips archived realms; archive cancels in-flight indexing (CS-11668)#5361

Draft
lukemelia wants to merge 2 commits into
mainfrom
cs-11668-indexer-skip-archived-realms-in-the-full-index-sweep-stop
Draft

Indexer skips archived realms; archive cancels in-flight indexing (CS-11668)#5361
lukemelia wants to merge 2 commits into
mainfrom
cs-11668-indexer-skip-archived-realms-in-the-full-index-sweep-stop

Conversation

@lukemelia

Copy link
Copy Markdown
Contributor

Summary

Archived realms shouldn't consume indexing. Two changes:

  • Full-index sweep: getFullReindexRealmUrls excludes realms with realm_metadata.archived_at IS NOT NULL, so the Grafana /_full-reindex endpoint and the post-deployment hook never enqueue from-scratch jobs for archived realms.
  • Archive endpoint: after archiveRealm writes the flag, handle-archive-realm calls cancelAllJobsInConcurrencyGroup(dbAdapter, 'indexing:' + realmURL). In-flight and pending from-scratch-index / incremental-index jobs are marked rejected, reservations are released, and a NOTIFY jobs_finished fans out to peer replicas. Mirrors the realm-level cancel-jobs endpoint (Realm.handleCancelJobsRequest). Partial work left behind by an in-flight cancellation is discarded by the unarchive-side full reindex.

What this PR doesn't change:

  • fetchAllRealmsWithOwnersfull-reindex.ts uses it as a lookup (URL → username), not as a source. The source list comes from getFullReindexRealmUrls (system sweep) or from the unarchive handler (which legitimately needs to reach a just-archived row).
  • The unarchive → full reindex enqueue — already in place from the unarchive handler.
  • Public / catalog realms — the archive endpoint rejects them with 422, so they never carry archived_at and the filter is a no-op for them.

Tests

  • full-reindex-test: getFullReindexRealmUrls returns only active realms across two registered realms with one archived; an unarchived realm reappears on the next call.
  • archive-realm-test: a pending from-scratch-index job for the realm is marked rejected once the archive endpoint runs.

Test plan

  • pnpm test in packages/realm-server (full-reindex-test, server-endpoints/archive-realm-test) — requires Docker for the test PG; will verify in CI.

The full-reindex sweep source (getFullReindexRealmUrls) excludes any
realm with realm_metadata.archived_at IS NOT NULL, so the Grafana
/_full-reindex endpoint and the post-deployment hook never enqueue
from-scratch-index jobs for archived realms. fetchAllRealmsWithOwners
stays unchanged: full-reindex uses it as a lookup (URL → username), not
as a source, and the unarchive handler legitimately needs to reach a
just-archived row to enqueue its restore reindex.

handle-archive-realm calls cancelAllJobsInConcurrencyGroup on
`indexing:${realmURL}` after archiveRealm. This mirrors the realm-level
cancel-jobs endpoint (Realm.handleCancelJobsRequest): in-flight
from-scratch / incremental-index jobs are marked rejected, the pending
queue is dropped, reservations are released, and a NOTIFY jobs_finished
fans out to peer replicas. The unarchive flow rebuilds boxel_index from
disk via the existing full-reindex enqueue, so any partial work left
behind by an in-flight cancellation is discarded on restore.

Catalog / public realms are unaffected because the archive endpoint
rejects them with 422 — they can never carry archived_at.

Tests:
- full-reindex-test: getFullReindexRealmUrls returns only active realms
  across two registered realms with one archived; an unarchived realm
  reappears on the next call.
- archive-realm-test: a pending from-scratch-index job for the realm is
  marked rejected once the archive endpoint runs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Host Test Results

    1 files      1 suites   2h 13m 55s ⏱️
3 320 tests 3 305 ✅ 15 💤 0 ❌
3 339 runs  3 324 ✅ 15 💤 0 ❌

Results for commit 7951fbf.

Realm Server Test Results

    1 files  ±0      1 suites  ±0   10m 51s ⏱️ +27s
1 682 tests +6  1 682 ✅ +7  0 💤 ±0  0 ❌  - 1 
1 761 runs  +6  1 761 ✅ +7  0 💤 ±0  0 ❌  - 1 

Results for commit 7951fbf. ± Comparison against earlier commit c95faa9.

@lukemelia lukemelia changed the base branch from cs-11665-enumeration-omits-archived-realms-from-_realm-auth-realm to main June 30, 2026 02:09
…-archived-realms-in-the-full-index-sweep-stop

# Conflicts:
#	packages/realm-server/tests/server-endpoints/archive-realm-test.ts
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.

1 participant