Cortex source replacement and index cleanup
Status: Ready
Truth label: Current
Audience: Fleet operator
Reader outcome: Use cortex source replacement and index cleanup in Cortex, with every control, its verification, and its limits stated.
Last verified: 2026-09-13
Open Sources, review a source, then choose Replace source or clean index. These controls keep publication, source identity and retained evidence separate. New original bytes keep their own source ID. Replacement records a relationship between the two IDs; it does not rewrite the old original or pretend two editions are identical.
Replace and reconcile
Upload, extract, review and publish the replacement first. Choose it in the source lifecycle editor. Load more candidates for a catalog beyond 200 entries. The preview shows both source identities, current revisions, group IDs, the replacement publication, and every affected saved source selection.
Optionally migrate saved selections. Both included and excluded source IDs move to the new identity, preserving exclusion precedence. Applying the exact preview retires the old source and updates both source histories in one SQLite transaction. Changed revisions or selection impact require another preview. Existing tasks and current conversation choices keep their original snapshots and IDs. The source/lens controls remain available to change the current conversation explicitly.
Undo restores the earlier relationship state and, by default, migrated saved selections as new revisions. It stops if a migrated selection has since changed. Disable selection restoration to keep those operator edits while undoing the relationship. Undo a later link in a replacement chain first. A replaced source cannot be separately restored through the retirement control. If its index has been removed, undo does not mark it published; extraction review and publication remain explicit.
Clean indexed copies
Choose old index generations, or every indexed passage of a retired source. Preview shows the affected count, retained index count, text bytes and exact passage manifest. Export the preview if useful, then apply it. The operation refuses a changed source or changed indexed content. It is bounded to 20,000 source passages and 80 MiB of passage text per cleanup.
Cleanup archives exact passage text and provenance in compressed SQLite records before the first deletion. It removes only the previewed index copies. Old-generation cleanup preserves the active publication. Full cleanup requires retirement and clears publication readiness before deletion. Restoring that source requires publishing its retained extraction again. Legacy indexed sources can also have their indexed copies removed; their external originals are never touched.
Interrupted cleanup retains already archived evidence and reports the error and removal count. Preview again before retrying. Source operations are serialized; cancellation or expiration clears the operation claim while preserving the prior retired/active state. An index row changed under a previously archived ID stops cleanup rather than overwriting its earlier citation.
Earlier citations remain inspectable through the library passage endpoint and Cortex's historical passage view. They report archived: true and are ineligible for new retrieval. Cleanup reduces index clutter; it does not erase the text from the retained citation archive. Original files and extraction histories are retained. Physical source-file erasure and archive retention policies remain separate storage work.
Storage and verification
Replacement relationships and migration snapshots live in source revision history. Archived passage content, hashes and compressed payloads live in library_archived_passages inside Brain's sources.sqlite3. Runtime backups now include those historical passage texts; external original/extraction backups remain separately required.
Tests cover explicit replacement and undo, saved-selection edits, publication state, stale index previews, archive-before-delete failure, partial deletion/retry, and historical citation integrity. Browser checks cover the real Cortex preview/export, stale cleanup, citation lookup, replacement/migration/undo, full index removal and restoration workflow. Tests use private source fixtures. No live source was replaced, retired or removed.