Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

atoms-restore: set-based restore rule (linear in atoms), GIN-scoped per-atom recheck; regenerate pages SQL-text golden (#7013)

garrytand5bba3d89c1e
diff --git a/docs/architecture/key-files/commands-2.md b/docs/architecture/key-files/commands-2.md
index 601620e1cc..0a0b5a031c 100644
--- a/docs/architecture/key-files/commands-2.md
+++ b/docs/architecture/key-files/commands-2.md
@@ -14,7 +14,7 @@ Doctor's embedding-dimension warning treats existing chunks as existing data eve
- `src/commands/doctor/checks/unbound-source.ts` — `unbound_source` (#5254) counts live pages with `pages.database_only_reason='unbound_source'` and no recorded origin (blank `source_path` and `source_uri`) per source, via `databaseOnlyPageSql` (`persistence/unbound-pages.ts`), the SQL form of `isDatabaseOnlyPage` (#6536). A managed sync that records a page's origin, and a reconcile apply, clear the marker. While the source is unbound the count is ok and the message carries the filled `sources writer status`/`writer claim` bind command (database-only is the chosen mode); once the source has a binding it warns, because binding never materializes those pages into canonical files. Unreadable state warns. Registered on the `persistence_capacity` line in `doctor.ts`. Tests: `e2e/unbound-source-postgres`, `unbound-source-6536`.
- `src/commands/doctor/checks/revision-backfill.ts` — `revision_backfill` (#5216, META, registered before `search_mode`): reads `readRevisionBackfillStatus` (column state, pages still without `knowledge_revision`, failed rows still pending with their page). ok when the column is NOT NULL; warn with the pending count and `gbrain apply-migrations --force-schema` as `fix` while any row is resumable (or only the NOT NULL step remains); failed rows are listed by page id, `source:slug`, attempt and error, and when only rows with spent attempts remain the `fix` is the read-only `gbrain repair orphan-children` preview. Tests: `test/doctor-revision-backfill.test.ts`.
- `src/commands/doctor/checks/extractor-facts.ts` — `extractor_facts_expired` (#5731): counts conversation-extractor facts the pre-v0.60.11.0 projection expired, by class (`evidenced`, `ambiguous`; `excluded` reported but never a finding) through `classifyExtractorFacts`, and names `gbrain repair extractor-facts` (explicit-only, so the remediation plan and banner list it with its preview). Read-only; health unknown when the query fails.
-- `src/commands/doctor/checks/atom-retirements.ts` — `atom_retirements_restorable` (#7013, BRAIN, a `WAVE_CHECKS` entry with `resolution: 'repair'`, host-only, cleared by the explicit-only `atoms-restore`, so remediation classifies it `explicit_kind_required`): counts atoms `restorableAtomRetirementSql` selects per source; `warn` names the count, origins, oldest and newest `retired_at`, the end of the earliest purge hold (`hold_until`) and the read-only preview `gbrain repair atoms-restore --source <id> --json` as an agent `fix`; the apply is the user's call.
+- `src/commands/doctor/checks/atom-retirements.ts` — `atom_retirements_restorable` (#7013, BRAIN, a `WAVE_CHECKS` entry with `resolution: 'repair'`, host-only, cleared by the explicit-only `atoms-restore`, so remediation classifies it `explicit_kind_required`): counts the `restorable` rows of `atomRetirementsSql` per source; `warn` names the count, origins, oldest and newest `retired_at`, the end of the earliest purge hold (`hold_until`) and the read-only preview `gbrain repair atoms-restore --source <id> --json` as an agent `fix`; the apply is the user's call.
- `src/commands/doctor/checks/conversation-outcomes.ts` — `conversation_label_facts` (wave check, host-only, resolution `repair`): bounded count (capped at 1000, reported as at least N) of the default set `gbrain repair conversation-labels` would retire; names the preview, never the apply. `conversation_outcomes_stale` (wave check, host-only, resolution `operator`): counts active conversation extraction outcomes stamped with an older `extractor_version` than `CONVERSATION_EXTRACTOR_VERSION` (outcomes are never reopened automatically) and names the `--force --dry-run` re-extract preview; outcomes older than the stamp are counted as `unstamped` and never warn. Bounded scan of the extractor rows, capped at 5000 (reported as at least N). Read-only.
- `src/commands/doctor/checks/captured-facts.ts` — `captured_facts_active` (wave check, host-only): counts active capture-lane facts (`hook:writeback`, `hook:compact`, `sweep:corpus`) that `classifyCapturedFacts` classes as self-capture (`evidenced`) or paste candidates (`ambiguous`); `excluded` and `unclassifiable` are reported, never a finding. Names `gbrain repair captured-facts` (explicit-only) and says it counts facts while `self_capture` counts corpus files. Read-only; health unknown when the scan fails.
- `src/commands/doctor/checks/loop-facts.ts` — `loop_facts_drift` (#5869): counts closed commitment loops whose fact is still active and retirable (`loopFactDrift`) and names `gbrain repair loop-facts` (explicit-only). Read-only; health unknown when the query fails.
diff --git a/docs/architecture/key-files/memory-purge.md b/docs/architecture/key-files/memory-purge.md
index a9b711f0b4..092ef427b3 100644
--- a/docs/architecture/key-files/memory-purge.md
+++ b/docs/architecture/key-files/memory-purge.md
@@ -22,7 +22,7 @@ User-facing contract: [expire versus purge](../../guides/memory-boundaries.md#pu
- Withdrawn-claim refusal on `remember` (`persistence/memory-mutations.ts`, `memory-prepare.ts`) — admission refuses a withdrawn claim (`fact_withdrawn`, `FACT_WITHDRAWN_MESSAGE`/`_SUGGESTION` in `src/core/facts/withdrawal.ts`) before a request exists, and preparation re-checks it; `writeFailureDiagnostic` allowlists that prefix, so a failed receipt and `get_write_request` name it. `replaces` accepts a target saved without an entity (links it by supersession). Test: `test/remember-withdrawn-claim.test.ts`. (R1, Cat 40 Hard.) The refusal carries an additive `withdrawn` object (`factWithdrawnRefusal` in `facts/single-prepare.ts`, from `fact_withdrawals` only: the named entity's row over `all_entities`, then the newest, omitted when the caller cannot read the forgotten rows); `withdrawalFailureDetail`/`withdrawnFromDetail` in `facts/withdrawal.ts` keep it in the failed receipt's `error_detail` for `get_write_request` and replay. Tests: `test/withdrawn-detail.test.ts`, `test/e2e/withdrawn-detail-postgres.test.ts`.
- `src/core/persistence/purge-deleted.ts` — `purgeDeletedPagesCoordinated` backs the cycle `purge` phase, the purge job, `purge_deleted_pages` and `gbrain pages purge-deleted`. Unmanaged brains keep the engine bulk delete, after the belief-ledger expiry of recorded sources' tombstones: each is its own transaction and item (ItemRun site `purge.recorded_tombstones`), a run-scoped failure or a systemic run stops the purge, and any other failure lists the tombstone in `blocked` with its classified code, counts it in `failed` (no `error`, so the phase warns) and keeps it out of the bulk delete (`purgeDeletedPages` `excludeIds`); a content failure counts toward the same park as the managed purge, a transient one is retried next run, and parked tombstones are skipped as `purge_parked` unless `retryParked` (the unmanaged preview excludes them too). A managed brain purges each tombstone older than the window (skipping archived sources, which the source lifecycle purges) through `delete_page` with `purge: true` and the internal `retention: true` bound to its revision (retention is not an owner purge; see [belief ledger](belief-ledger.md)). Writer state is read once per run (`writerOnboardingPreflight`): a source whose writer is `recovery_required` submits nothing and its tombstones are listed in `blocked` as `writer_not_active` (counted in `inactive`). Revision races are deferred to the next run; a parked tombstone (`purge-parks.ts`) is skipped as `purge_parked` (counted in `parked`) unless `retryParked`, and any other failure is listed in `blocked` and sets `error`. `selectPurgeCandidates` is the one eligibility selector (preview, consent, `purge_deleted_pages` op, run); #6884: the run submits only while the writer has outstanding-request room (`readOutstandingRoom` in `journal.ts`, at `persistence.capacity.background_pause_pct` of the cap for a background run); the rest, and the rest after a `queue_capacity` refusal, is `blocked` as `write_capacity_deferred` and counted in `capacity_deferred`, never a failure or a park. `purgePhaseStatus`/`purgePhaseNote` shape the cycle purge phase (fail on `error`; warn on `writer_not_active`, parked, capacity-deferred or an unmanaged `failed` tombstone). The engine bulk delete (`engine-sql/pages.ts` `purgeDeletedPages`) also deletes, in its transaction, the purged pages' stagings (by source and slug) and the segment texts only their manifests referenced. Tests: `test/managed-writers-w3.test.ts`, `test/purge-deleted-parks.test.ts`, `test/purge-deleted-capacity-6884.test.ts`, `test/pathological/a49-unmanaged-purge-tombstones.test.ts`.
-- `src/core/persistence/atom-retirement-hold.ts` — #7013: the one SQL rule for atoms `gbrain repair atoms-restore` restores (`restorableAtomRetirementSql`: a non-imported atom soft-deleted with `retired_by: managed-reextract`, whose origin is a live page of its source or a transcript, that no live atom of the same origin with another stripped source hash replaced, and whose hash is the hash of the origin's latest `managed-reextract` retirement), its parts (used for the preview residuals) and `atomRetirementPurgeHold`, which keeps such an atom out of every batch purge selection (engine `purgeDeletedPages` preview and delete, the belief-ledger expiry, `selectPurgeCandidates`) for `ATOM_RESTORE_HOLD_DAYS` (30) after `deleted_at`, next to the #6729 `identityDowngradePurgeHold`. An explicit `delete --purge` is not held. Static strings only, so `engine-sql/pages.ts` imports it.
-- `src/core/repair/atoms-restore.ts` — `gbrain repair atoms-restore` (#7013), explicit-only and preview-bound: lists atoms an empty managed re-extraction retired (`retired_by: managed-reextract`) that `restorableAtomRetirementSql` (`persistence/atom-retirement-hold.ts`) selects, each with origin, stripped source hash and `retired_at`, and residuals `restorable`, `origins`, `origin_gone`, `replaced`, `older_generation`; `--apply --expect <hash>` restores the approved set, rechecking each atom (id, incarnation, revision, origin, hash, `retired_at`, rule match) and reporting `changed_since_preview` otherwise. Managed: one `managed_maintenance_restore_reextract_atom` request per atom (`deleted_page: true`, bound to the deleted revision, request id in the outcome detail); `prepareAtomRestore` (dispatched from `prepared-maintenance.ts`) rechecks the rule under the atom and origin page locks and publishes a revision-bound `revert_version` to `version_id`, the newest live version of the atom at its source hash without `retired_by` (the one the coordinated delete archived; file written back, `allowMissingFile`); none is `no_version`, lowered to the `derive:atoms` tier of its origin with taint edges. Unmanaged: `createVersion`, `restorePage` and the two keys dropped in one `maintenanceTransaction`. Extraction state is not touched. Test: `test/pathological/d24-atoms-restore.test.ts`.
+- `src/core/persistence/atom-retirement-hold.ts` — #7013: the one SQL rule for atoms `gbrain repair atoms-restore` restores. `atomRetirementsSql(scope)` is set-based (CTEs over `pages` joined on source and origin key, linear in the atoms in scope) and returns every non-imported atom soft-deleted with `retired_by: managed-reextract` with `origin_live` (a live page origin in its source, or a transcript), `replaced` (a live atom of the same origin carries another stripped source hash), `latest` (its hash is the hash of the origin's latest `managed-reextract` retirement) and `restorable` (all three right); `atomOriginScopeSql` narrows it to one atom's source and origin through the frontmatter GIN index for the apply recheck; `atomRetirementPurgeHold`, which keeps such an atom out of every batch purge selection (engine `purgeDeletedPages` preview and delete, the belief-ledger expiry, `selectPurgeCandidates`) for `ATOM_RESTORE_HOLD_DAYS` (30) after `deleted_at`, next to the #6729 `identityDowngradePurgeHold`. An explicit `delete --purge` is not held. Static strings only, so `engine-sql/pages.ts` imports it.
+- `src/core/repair/atoms-restore.ts` — `gbrain repair atoms-restore` (#7013), explicit-only and preview-bound: lists atoms an empty managed re-extraction retired (`retired_by: managed-reextract`) that `atomRetirementsSql` (`persistence/atom-retirement-hold.ts`) marks `restorable`, each with origin, stripped source hash and `retired_at`, and residuals `restorable`, `origins`, `origin_gone`, `replaced`, `older_generation`; `--apply --expect <hash>` restores the approved set, rechecking each atom (id, incarnation, revision, origin, hash, `retired_at`, rule match) and reporting `changed_since_preview` otherwise. Managed: one `managed_maintenance_restore_reextract_atom` request per atom (`deleted_page: true`, bound to the deleted revision, request id in the outcome detail); `prepareAtomRestore` (dispatched from `prepared-maintenance.ts`) rechecks the rule under the atom and origin page locks and publishes a revision-bound `revert_version` to `version_id`, the newest live version of the atom at its source hash without `retired_by` (the one the coordinated delete archived; file written back, `allowMissingFile`); none is `no_version`, lowered to the `derive:atoms` tier of its origin with taint edges. Unmanaged: `createVersion`, `restorePage` and the two keys dropped in one `maintenanceTransaction`. Extraction state is not touched. Test: `test/pathological/d24-atoms-restore.test.ts`.
- `src/core/persistence/purge-parks.ts` — #6741 C: per-tombstone purge parks in op_checkpoints (op `purge-deleted-park`, key source+slug+deleted_at, so a re-deleted page starts fresh); park at `PURGE_PARK_LIMIT` (5) non-deferral failures, a success clears it, and parks of a source seen inactive rearm the first run its writer is active again (`notePurgeSourceWriter`). `purgeStaleCheckpoints` exempts the op; `prunePurgeParks` drops parks whose tombstone is gone. Tests: `test/purge-deleted-parks.test.ts`.
diff --git a/src/commands/doctor/checks/atom-retirements.ts b/src/commands/doctor/checks/atom-retirements.ts
index d402659c51..180b71862b 100644
--- a/src/commands/doctor/checks/atom-retirements.ts
+++ b/src/commands/doctor/checks/atom-retirements.ts
@@ -1,14 +1,14 @@
/**
* #7013 `atom_retirements_restorable`: atoms a managed re-extraction retired (`retired_by: managed-reextract`) that
* `gbrain repair atoms-restore` can bring back, by the one rule the repair and the purge hold share
- * (`restorableAtomRetirementSql`). A `WAVE_CHECKS` entry: `ok` when none; `warn` with the count, the origins, the
+ * (`atomRetirementsSql`). A `WAVE_CHECKS` entry: `ok` when none; `warn` with the count, the origins, the
* oldest and newest retirement, the date the purge hold of the earliest one ends, and the read-only preview as fix.
* The apply needs the user's agreement on the previewed set. Read-only.
*/
import type { BrainEngine } from '../../../core/engine.ts';
import type { Check } from '../../doctor.ts';
import { agentFix } from '../check-fix.ts';
-import { ATOM_RESTORE_HOLD_DAYS, restorableAtomRetirementSql } from '../../../core/persistence/atom-retirement-hold.ts';
+import { ATOM_RESTORE_HOLD_DAYS, atomRetirementsSql } from '../../../core/persistence/atom-retirement-hold.ts';
const DOCS = 'docs/guides/repair.md#atoms-restore';
@@ -17,11 +17,10 @@ export async function atomRetirementsRestorableCheck(engine: BrainEngine, source
const sources = sourceIds ?? (await engine.executeRaw<{ id: string }>('SELECT id FROM sources WHERE archived IS NOT TRUE ORDER BY id')).map(row => row.id);
const rows = await engine.executeRaw<{ source_id: string; count: number; origins: number; oldest: string | null; newest: string | null; hold_until: string }>(`
SELECT p.source_id, count(*)::int AS count,
- count(DISTINCT COALESCE(NULLIF(p.frontmatter->>'source_slug',''), 'path:'||(p.frontmatter->>'source_path')))::int AS origins,
- min(p.frontmatter->>'retired_at') AS oldest, max(p.frontmatter->>'retired_at') AS newest,
+ count(DISTINCT c.origin_kind||':'||c.origin)::int AS origins, min(c.retired_at) AS oldest, max(c.retired_at) AS newest,
to_char((min(p.deleted_at) + interval '${ATOM_RESTORE_HOLD_DAYS} days') AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS"Z"') AS hold_until
- FROM pages p WHERE p.source_id=ANY($1::text[]) AND ${restorableAtomRetirementSql('p')}
- GROUP BY p.source_id ORDER BY p.source_id`, [sources]);
+ FROM (${atomRetirementsSql('p.source_id=ANY($1::text[])')}) c JOIN pages p ON p.id=c.id
+ WHERE c.restorable GROUP BY p.source_id ORDER BY p.source_id`, [sources]);
const bySource = rows.map(row => ({ ...row, count: Number(row.count), origins: Number(row.origins) }));
const count = bySource.reduce((sum, row) => sum + row.count, 0);
const details = { count, origins: bySource.reduce((sum, row) => sum + row.origins, 0),
diff --git a/src/core/persistence/atom-retirement-hold.ts b/src/core/persistence/atom-retirement-hold.ts
index 108fdc9a02..dcecc104c5 100644
--- a/src/core/persistence/atom-retirement-hold.ts
+++ b/src/core/persistence/atom-retirement-hold.ts
@@ -1,20 +1,22 @@
/**
- * #7013: atoms a managed re-extraction retired that `gbrain repair atoms-restore` can bring back, as one SQL
- * predicate shared by the repair (preview, apply recheck and coordinated preparer), the
- * `atom_retirements_restorable` doctor check and the purge hold. Static strings over a `pages` alias only, so
- * `engine-sql/pages.ts` may import it.
+ * #7013: atoms a managed re-extraction retired that `gbrain repair atoms-restore` can bring back, as one SQL rule
+ * shared by the repair (preview, apply recheck and coordinated preparer), the `atom_retirements_restorable` doctor
+ * check and the purge hold. Static strings only, so `engine-sql/pages.ts` may import it.
*
- * A page `a` is restorable when every part holds:
- * - `reextractRetiredAtomSql`: a soft-deleted, non-imported atom stamped `retired_by: managed-reextract`;
- * - `atomOriginLiveSql`: its origin is a live page of the same source (`source_slug`), or a transcript
- * (`source_path`, whose file SQL cannot check);
- * - `atomReplacedSql` is false: no live, non-imported atom of the same source and origin carries a different
- * source hash (a `pending:` prefix stripped), so no later generation replaced it;
- * - `atomLatestGenerationSql`: its hash is the hash of the origin's most recently retired `managed-reextract`
- * atom, so an older generation that a later extraction replaced is never revived.
+ * `atomRetirementsSql(scope)` returns one row per re-extraction retirement in scope: a soft-deleted, non-imported
+ * atom stamped `retired_by: managed-reextract`, with its origin (`source_slug` page, else `source_path` transcript),
+ * stripped source hash (a `pending:` prefix removed) and three verdicts:
+ * - `origin_live`: a page origin is a live page of the same source (a transcript cannot be checked in SQL);
+ * - `replaced`: a live, non-imported atom of the same source and origin carries a different hash, so a later
+ * generation replaced it;
+ * - `latest`: its hash is the hash of the origin's most recently retired `managed-reextract` atom, so an older
+ * generation that a later extraction replaced is never revived.
+ * `restorable` is `origin_live AND NOT replaced AND latest`. The query is set-based (each CTE reads `pages` once,
+ * joined on source and origin), so its cost grows linearly with the atoms in scope.
*
* The purge (engine bulk delete and preview, the belief-ledger expiry, the managed selection) holds a restorable
- * atom for `ATOM_RESTORE_HOLD_DAYS` after its `deleted_at`; an explicit `gbrain delete --purge` is not held.
+ * atom for `ATOM_RESTORE_HOLD_DAYS` after its `deleted_at` (`atomRetirementPurgeHold`); an explicit
+ * `gbrain delete --purge` is not held.
*/
/** The stamp `prepareManagedAtomMutation` writes on a re-extraction retirement (`ATOM_RETIRED_BY_REEXTRACT`). */
@@ -24,44 +26,55 @@ export const ATOM_REEXTRACT_RETIRED_BY = 'managed-reextract';
export const ATOM_RESTORE_HOLD_DAYS = 30;
const strippedHash = (alias: string) => `regexp_replace(COALESCE(${alias}.frontmatter->>'source_hash',''),'^pending:','')`;
+const originKey = (alias: string) => `CASE WHEN NULLIF(${alias}.frontmatter->>'source_slug','') IS NOT NULL THEN 'slug:'||(${alias}.frontmatter->>'source_slug')
+ WHEN NULLIF(${alias}.frontmatter->>'source_path','') IS NOT NULL THEN 'path:'||(${alias}.frontmatter->>'source_path') END`;
+const notImported = (alias: string) => `NULLIF(${alias}.frontmatter->>'imported_from','') IS NULL`;
-/** `other` is bound to the same origin as `alias`: the same `source_slug`, or for a transcript atom the same `source_path`. */
-const sameOrigin = (other: string, alias: string) => `((NULLIF(${alias}.frontmatter->>'source_slug','') IS NOT NULL
- AND ${other}.frontmatter @> jsonb_build_object('source_slug',${alias}.frontmatter->'source_slug'))
- OR (NULLIF(${alias}.frontmatter->>'source_slug','') IS NULL
- AND ${other}.frontmatter @> jsonb_build_object('source_path',${alias}.frontmatter->'source_path')))`;
-
-export function reextractRetiredAtomSql(alias: string): string {
- return `(${alias}.type='atom' AND ${alias}.deleted_at IS NOT NULL
- AND ${alias}.frontmatter->>'retired_by'='${ATOM_REEXTRACT_RETIRED_BY}'
- AND NULLIF(${alias}.frontmatter->>'imported_from','') IS NULL)`;
-}
-
-export function atomOriginLiveSql(alias: string): string {
- return `((NULLIF(${alias}.frontmatter->>'source_slug','') IS NOT NULL AND EXISTS (SELECT 1 FROM pages ao
- WHERE ao.source_id=${alias}.source_id AND ao.slug=${alias}.frontmatter->>'source_slug' AND ao.deleted_at IS NULL))
- OR (NULLIF(${alias}.frontmatter->>'source_slug','') IS NULL AND NULLIF(${alias}.frontmatter->>'source_path','') IS NOT NULL))`;
-}
-
-export function atomReplacedSql(alias: string): string {
- return `EXISTS (SELECT 1 FROM pages ar WHERE ar.source_id=${alias}.source_id AND ar.type='atom' AND ar.deleted_at IS NULL
- AND NULLIF(ar.frontmatter->>'imported_from','') IS NULL AND ${sameOrigin('ar', alias)}
- AND ${strippedHash('ar')}<>${strippedHash(alias)})`;
-}
-
-export function atomLatestGenerationSql(alias: string): string {
- return `${strippedHash(alias)}=(SELECT ${strippedHash('ag')} FROM pages ag WHERE ag.source_id=${alias}.source_id AND ag.type='atom'
- AND ag.deleted_at IS NOT NULL AND ag.frontmatter @> jsonb_build_object('retired_by','${ATOM_REEXTRACT_RETIRED_BY}')
- AND NULLIF(ag.frontmatter->>'imported_from','') IS NULL AND ${sameOrigin('ag', alias)}
- ORDER BY ag.frontmatter->>'retired_at' DESC NULLS LAST, ag.id DESC LIMIT 1)`;
+/**
+ * SQL: every re-extraction retirement whose page `p` satisfies `scope` (a predicate over the `pages` alias `p`; it
+ * also narrows the live atoms the replacement check reads, so scope by source or by origin, never by atom), with
+ * columns id, source_id, slug, origin_kind, origin, origin_page_id, hash, retired_at, origin_live, replaced, latest
+ * and restorable.
+ */
+export function atomRetirementsSql(scope = 'true'): string {
+ return `WITH retired AS (
+ SELECT p.id, p.source_id, p.slug, ${originKey('p')} AS okey, NULLIF(p.frontmatter->>'source_slug','') AS origin_slug,
+ COALESCE(NULLIF(p.frontmatter->>'source_slug',''), p.frontmatter->>'source_path') AS origin,
+ ${strippedHash('p')} AS hash, p.frontmatter->>'retired_at' AS retired_at
+ FROM pages p
+ WHERE p.type='atom' AND p.deleted_at IS NOT NULL AND p.frontmatter->>'retired_by'='${ATOM_REEXTRACT_RETIRED_BY}' AND ${notImported('p')}
+ AND (${scope})
+ ), latest AS (
+ SELECT DISTINCT ON (source_id, okey) source_id, okey, hash FROM retired WHERE okey IS NOT NULL
+ ORDER BY source_id, okey, retired_at DESC NULLS LAST, id DESC
+ ), live AS (
+ SELECT p.source_id, ${originKey('p')} AS okey, array_agg(DISTINCT ${strippedHash('p')}) AS hashes
+ FROM pages p WHERE p.type='atom' AND p.deleted_at IS NULL AND ${notImported('p')} AND (${scope})
+ GROUP BY 1, 2
+ )
+ SELECT r.id, r.source_id, r.slug, CASE WHEN r.origin_slug IS NOT NULL THEN 'page' ELSE 'transcript' END AS origin_kind, r.origin,
+ o.id AS origin_page_id, r.hash, r.retired_at,
+ (r.okey IS NOT NULL AND (r.origin_slug IS NULL OR o.id IS NOT NULL)) AS origin_live,
+ (lv.hashes IS NOT NULL AND NOT (lv.hashes <@ ARRAY[r.hash])) AS replaced,
+ COALESCE(l.hash = r.hash, false) AS latest,
+ (r.okey IS NOT NULL AND (r.origin_slug IS NULL OR o.id IS NOT NULL) AND NOT COALESCE(lv.hashes IS NOT NULL AND NOT (lv.hashes <@ ARRAY[r.hash]), false)
+ AND COALESCE(l.hash = r.hash, false)) AS restorable
+ FROM retired r
+ LEFT JOIN pages o ON o.source_id=r.source_id AND o.slug=r.origin_slug AND o.deleted_at IS NULL
+ LEFT JOIN live lv ON lv.source_id=r.source_id AND lv.okey=r.okey
+ LEFT JOIN latest l ON l.source_id=r.source_id AND l.okey=r.okey`;
}
-/** SQL: the page aliased `alias` is an atom `gbrain repair atoms-restore` restores. */
-export function restorableAtomRetirementSql(alias: string): string {
- return `(${reextractRetiredAtomSql(alias)} AND ${atomOriginLiveSql(alias)} AND NOT ${atomReplacedSql(alias)} AND ${atomLatestGenerationSql(alias)})`;
+/** SQL predicate over `pages` aliased `p`: the page shares its source and origin with the page whose id is `atomIdSql`. */
+export function atomOriginScopeSql(atomIdSql: string): string {
+ return `p.source_id=(SELECT x.source_id FROM pages x WHERE x.id=${atomIdSql}) AND p.frontmatter @> (SELECT CASE
+ WHEN NULLIF(x.frontmatter->>'source_slug','') IS NOT NULL THEN jsonb_build_object('source_slug',x.frontmatter->'source_slug')
+ ELSE jsonb_build_object('source_path',x.frontmatter->'source_path') END FROM pages x WHERE x.id=${atomIdSql})`;
}
/** SQL predicate for a purge scan over `pages` aliased `alias`: the page is not a restorable atom inside its hold. */
export function atomRetirementPurgeHold(alias: string): string {
- return `NOT (${alias}.deleted_at > now() - interval '${ATOM_RESTORE_HOLD_DAYS} days' AND ${restorableAtomRetirementSql(alias)})`;
+ return `NOT (${alias}.type='atom' AND ${alias}.frontmatter->>'retired_by'='${ATOM_REEXTRACT_RETIRED_BY}'
+ AND ${alias}.deleted_at > now() - interval '${ATOM_RESTORE_HOLD_DAYS} days'
+ AND ${alias}.id IN (SELECT held.id FROM (${atomRetirementsSql()}) held WHERE held.restorable))`;
}
diff --git a/src/core/repair/atoms-restore.ts b/src/core/repair/atoms-restore.ts
index 0150b3f96c..df22002719 100644
--- a/src/core/repair/atoms-restore.ts
+++ b/src/core/repair/atoms-restore.ts
@@ -3,7 +3,7 @@
* returned no atoms for their origin. An empty extraction retired every earlier atom of the origin by soft delete
* stamped `retired_by: managed-reextract`, and the purge then removed them for good.
*
- * The candidate rule is one SQL predicate (`restorableAtomRetirementSql`, persistence/atom-retirement-hold.ts):
+ * The candidate rule is one SQL query (`atomRetirementsSql`, persistence/atom-retirement-hold.ts, column `restorable`):
* the latest retired generation of a live origin (a page in the same source, or a transcript) that no later
* generation replaced. Imported atoms, `stale-atoms` retirements and older generations are never listed; the
* preview counts what it keeps (`origin_gone`, `replaced`, `older_generation`).
@@ -29,8 +29,7 @@ import { managedPersistenceEnabled } from '../persistence/ownership.ts';
import { maintenanceTransaction } from '../persistence/attribution.ts';
import { preparePageMutation } from '../persistence/page-prepare.ts';
import { maintenancePreflight, submitMaintenanceIntent } from '../persistence/prepared-maintenance.ts';
-import { atomLatestGenerationSql, atomOriginLiveSql, atomReplacedSql, reextractRetiredAtomSql, restorableAtomRetirementSql,
- ATOM_REEXTRACT_RETIRED_BY } from '../persistence/atom-retirement-hold.ts';
+import { atomOriginScopeSql, atomRetirementsSql, ATOM_REEXTRACT_RETIRED_BY } from '../persistence/atom-retirement-hold.ts';
import { clearApprovedSet, loadApprovedSet, previewChangedError, previewHash, saveApprovedSet } from '../persistence/preview-approval.ts';
import { declareDerivation, deriveTrust, lowerToDerivedTier, recordTaintEdges } from '../trust/taint.ts';
import { afterCursor, repairRequestId, type RepairHandler, type RepairItem, type RepairItemOutcome, type RepairPlan, type RepairScope } from './core.ts';
@@ -62,22 +61,18 @@ interface RestoreItem extends RepairItem { atom: RestorableAtom; hash: string; l
/** An approved atom carries the preview's source selection, so an apply under another `--source` refuses. */
interface ApprovedAtom extends RestorableAtom { selection: string[] }
-/** Restorable atoms of these sources in id order; `atomId` narrows to one atom for the apply recheck. */
+/** Restorable atoms of these sources in id order; `atomId` narrows to one atom (and its origin) for the apply recheck. */
async function restorableAtoms(db: BrainEngine, sourceIds: string[], atomId?: number): Promise<RestorableAtom[]> {
+ const scope = atomId === undefined ? 'p.source_id=ANY($1::text[])' : `p.source_id=ANY($1::text[]) AND ${atomOriginScopeSql('$2::bigint')}`;
const rows = await db.executeRaw<RestorableAtom>(`
- SELECT a.id, a.source_id, (SELECT s.incarnation::text FROM sources s WHERE s.id=a.source_id) AS incarnation,
- a.slug, a.knowledge_revision::text AS revision,
- CASE WHEN NULLIF(a.frontmatter->>'source_slug','') IS NOT NULL THEN 'page' ELSE 'transcript' END AS origin_kind,
- COALESCE(NULLIF(a.frontmatter->>'source_slug',''), a.frontmatter->>'source_path') AS origin,
- (SELECT o.id FROM pages o WHERE o.source_id=a.source_id AND o.slug=a.frontmatter->>'source_slug' AND o.deleted_at IS NULL) AS origin_page_id,
- regexp_replace(COALESCE(a.frontmatter->>'source_hash',''),'^pending:','') AS hash,
- a.frontmatter->>'retired_at' AS retired_at,
+ SELECT c.id, c.source_id, (SELECT s.incarnation::text FROM sources s WHERE s.id=c.source_id) AS incarnation,
+ a.slug, a.knowledge_revision::text AS revision, c.origin_kind, c.origin, c.origin_page_id, c.hash, c.retired_at,
(SELECT v.id FROM page_versions v WHERE v.page_id=a.id AND v.is_deleted=false AND v.frontmatter->>'retired_by' IS NULL
- AND regexp_replace(COALESCE(v.frontmatter->>'source_hash',''),'^pending:','')=regexp_replace(COALESCE(a.frontmatter->>'source_hash',''),'^pending:','')
+ AND regexp_replace(COALESCE(v.frontmatter->>'source_hash',''),'^pending:','')=c.hash
ORDER BY v.id DESC LIMIT 1) AS version_id
- FROM pages a
- WHERE a.source_id=ANY($1::text[]) AND ($2::int IS NULL OR a.id=$2::int) AND ${restorableAtomRetirementSql('a')}
- ORDER BY a.id`, [sourceIds, atomId ?? null]);
+ FROM (${atomRetirementsSql(scope)}) c JOIN pages a ON a.id=c.id
+ WHERE c.restorable${atomId === undefined ? '' : ' AND c.id=$2::bigint'}
+ ORDER BY c.id`, atomId === undefined ? [sourceIds] : [sourceIds, atomId]);
return rows.map(row => ({ ...row, id: Number(row.id), origin_page_id: row.origin_page_id === null ? null : Number(row.origin_page_id),
version_id: row.version_id === null ? null : Number(row.version_id) }));
}
@@ -85,12 +80,10 @@ async function restorableAtoms(db: BrainEngine, sourceIds: string[], atomId?: nu
/** The re-extraction retirements of these sources the rule keeps, by reason. */
async function keptCounts(db: BrainEngine, sourceIds: string[]): Promise<{ origin_gone: number; replaced: number; older_generation: number }> {
const [row] = await db.executeRaw<{ origin_gone: number; replaced: number; older_generation: number }>(`
- SELECT count(*) FILTER (WHERE NOT live)::int AS origin_gone,
- count(*) FILTER (WHERE live AND replaced)::int AS replaced,
- count(*) FILTER (WHERE live AND NOT replaced AND NOT latest)::int AS older_generation
- FROM (SELECT ${atomOriginLiveSql('a')} AS live, ${atomReplacedSql('a')} AS replaced,
- COALESCE(${atomLatestGenerationSql('a')}, false) AS latest
- FROM pages a WHERE a.source_id=ANY($1::text[]) AND ${reextractRetiredAtomSql('a')}) kept`, [sourceIds]);
+ SELECT count(*) FILTER (WHERE NOT origin_live)::int AS origin_gone,
+ count(*) FILTER (WHERE origin_live AND replaced)::int AS replaced,
+ count(*) FILTER (WHERE origin_live AND NOT replaced AND NOT latest)::int AS older_generation
+ FROM (${atomRetirementsSql('p.source_id=ANY($1::text[])')}) kept`, [sourceIds]);
return { origin_gone: Number(row?.origin_gone ?? 0), replaced: Number(row?.replaced ?? 0), older_generation: Number(row?.older_generation ?? 0) };
}
diff --git a/test/fixtures/goldens/sql-text/pages.json b/test/fixtures/goldens/sql-text/pages.json
index 58b5ab6767..2bd763e822 100644
--- a/test/fixtures/goldens/sql-text/pages.json
+++ b/test/fixtures/goldens/sql-text/pages.json
@@ -789,8 +789,8 @@
"params": [
"number"
],
- "sql": "DELETE FROM pages WHERE deleted_at IS NOT NULL AND deleted_at < now() - ($1 || ' hours')::interval -- #6729: the old page of an open rename-identity downgrade waits for its disposition (identityDowngradePurgeHold). AND NOT EXISTS (SELECT 1 FROM op_checkpoints dg WHERE dg.op = 'sync-identity-downgrade' AND dg.fingerprint = pages.id::text AND dg.completed_keys->0->>'disposition' IS NULL AND pages.deleted_at = (dg.completed_keys->0->>'old_deleted_at')::timestamptz) -- #7013: a restorable re-extraction retirement waits out its hold (atomRetirementPurgeHold). AND NOT (pages.deleted_at > now() - interval '30 days' AND ((pages.type='atom' AND pages.deleted_at IS NOT NULL AND pages.frontmatter->>'retired_by'='managed-reextract' AND NULLIF(pages.frontmatter->>'imported_from','') IS NULL) AND ((NULLIF(pages.frontmatter->>'source_slug','') IS NOT NULL AND EXISTS (SELECT 1 FROM pages ao WHERE ao.source_id=pages.source_id AND ao.slug=pages.frontmatter->>'source_slug' AND ao.deleted_at IS NULL)) OR (NULLIF(pages.frontmatter->>'source_slug','') IS NULL AND NULLIF(pages.frontmatter->>'source_path','') IS NOT NULL)) AND NOT EXISTS (SELECT 1 FROM pages ar WHERE ar.source_id=pages.source_id AND ar.type='atom' AND ar.deleted_at IS NULL AND NULLIF(ar.frontmatter->>'imported_from','') IS NULL AND ((NULLIF(pages.frontmatter->>'source_slug','') IS NOT NULL AND ar.frontmatter @> jsonb_build_object('source_slug',pages.frontmatter->'source_slug')) OR (NULLIF(pages.frontmatter->>'source_slug','') IS NULL AND ar.frontmatter @> jsonb_build_object('source_path',pages.frontmatter->'source_path'))) AND regexp_replace(COALESCE(ar.frontmatter->>'source_hash',''),'^pending:','')<>regexp_replace(COALESCE(pages.frontmatter->>'source_hash',''),'^pending:','')) AND regexp_replace(COALESCE(pages.frontmatter->>'source_hash',''),'^pending:','')=(SELECT regexp_replace(COALESCE(ag.frontmatter->>'source_hash',''),'^pending:','') FROM pages ag WHERE ag.source_id=pages.source_id AND ag.type='atom' AND ag.deleted_at IS NOT NULL AND ag.frontmatter @> jsonb_build_object('retired_by','managed-reextract') AND NULLIF(ag.frontmatter->>'imported_from','') IS NULL AND ((NULLIF(pages.frontmatter->>'source_slug','') IS NOT NULL AND ag.frontmatter @> jsonb_build_object('source_slug',pages.frontmatter->'source_slug')) OR (NULLIF(pages.frontmatter->>'source_slug','') IS NULL AND ag.frontmatter @> jsonb_build_object('source_path',pages.frontmatter->'source_path'))) ORDER BY ag.frontmatter->>'retired_at' DESC NULLS LAST, ag.id DESC LIMIT 1))) RETURNING slug, source_id",
- "textSha256": "0d8c2215c423232c2e41fa9ef0e32071bf140e85591d43f6a824de834ec9c504"
+ "sql": "DELETE FROM pages WHERE deleted_at IS NOT NULL AND deleted_at < now() - ($1 || ' hours')::interval -- #6729: the old page of an open rename-identity downgrade waits for its disposition (identityDowngradePurgeHold). AND NOT EXISTS (SELECT 1 FROM op_checkpoints dg WHERE dg.op = 'sync-identity-downgrade' AND dg.fingerprint = pages.id::text AND dg.completed_keys->0->>'disposition' IS NULL AND pages.deleted_at = (dg.completed_keys->0->>'old_deleted_at')::timestamptz) -- #7013: a restorable re-extraction retirement waits out its hold (atomRetirementPurgeHold). AND NOT (pages.type='atom' AND pages.frontmatter->>'retired_by'='managed-reextract' AND pages.deleted_at > now() - interval '30 days' AND pages.id IN (SELECT held.id FROM (WITH retired AS ( SELECT p.id, p.source_id, p.slug, CASE WHEN NULLIF(p.frontmatter->>'source_slug','') IS NOT NULL THEN 'slug:'||(p.frontmatter->>'source_slug') WHEN NULLIF(p.frontmatter->>'source_path','') IS NOT NULL THEN 'path:'||(p.frontmatter->>'source_path') END AS okey, NULLIF(p.frontmatter->>'source_slug','') AS origin_slug, COALESCE(NULLIF(p.frontmatter->>'source_slug',''), p.frontmatter->>'source_path') AS origin, regexp_replace(COALESCE(p.frontmatter->>'source_hash',''),'^pending:','') AS hash, p.frontmatter->>'retired_at' AS retired_at FROM pages p WHERE p.type='atom' AND p.deleted_at IS NOT NULL AND p.frontmatter->>'retired_by'='managed-reextract' AND NULLIF(p.frontmatter->>'imported_from','') IS NULL AND (true) ), latest AS ( SELECT DISTINCT ON (source_id, okey) source_id, okey, hash FROM retired WHERE okey IS NOT NULL ORDER BY source_id, okey, retired_at DESC NULLS LAST, id DESC ), live AS ( SELECT p.source_id, CASE WHEN NULLIF(p.frontmatter->>'source_slug','') IS NOT NULL THEN 'slug:'||(p.frontmatter->>'source_slug') WHEN NULLIF(p.frontmatter->>'source_path','') IS NOT NULL THEN 'path:'||(p.frontmatter->>'source_path') END AS okey, array_agg(DISTINCT regexp_replace(COALESCE(p.frontmatter->>'source_hash',''),'^pending:','')) AS hashes FROM pages p WHERE p.type='atom' AND p.deleted_at IS NULL AND NULLIF(p.frontmatter->>'imported_from','') IS NULL AND (true) GROUP BY 1, 2 ) SELECT r.id, r.source_id, r.slug, CASE WHEN r.origin_slug IS NOT NULL THEN 'page' ELSE 'transcript' END AS origin_kind, r.origin, o.id AS origin_page_id, r.hash, r.retired_at, (r.okey IS NOT NULL AND (r.origin_slug IS NULL OR o.id IS NOT NULL)) AS origin_live, (lv.hashes IS NOT NULL AND NOT (lv.hashes <@ ARRAY[r.hash])) AS replaced, COALESCE(l.hash = r.hash, false) AS latest, (r.okey IS NOT NULL AND (r.origin_slug IS NULL OR o.id IS NOT NULL) AND NOT COALESCE(lv.hashes IS NOT NULL AND NOT (lv.hashes <@ ARRAY[r.hash]), false) AND COALESCE(l.hash = r.hash, false)) AS restorable FROM retired r LEFT JOIN pages o ON o.source_id=r.source_id AND o.slug=r.origin_slug AND o.deleted_at IS NULL LEFT JOIN live lv ON lv.source_id=r.source_id AND lv.okey=r.okey LEFT JOIN latest l ON l.source_id=r.source_id AND l.okey=r.okey) held WHERE held.restorable)) RETURNING slug, source_id",
+ "textSha256": "f862c722576ff2336a3952630456e751b0308cde53c669ef2e0d4a36ab354fa6"
},
{
"event": "commit",
@@ -803,8 +803,8 @@
"params": [
"number"
],
- "sql": "SELECT slug, deleted_at FROM pages WHERE deleted_at IS NOT NULL AND deleted_at < now() - ($1 || ' hours')::interval AND NOT EXISTS (SELECT 1 FROM op_checkpoints dg WHERE dg.op = 'sync-identity-downgrade' AND dg.fingerprint = pages.id::text AND dg.completed_keys->0->>'disposition' IS NULL AND pages.deleted_at = (dg.completed_keys->0->>'old_deleted_at')::timestamptz) AND NOT (pages.deleted_at > now() - interval '30 days' AND ((pages.type='atom' AND pages.deleted_at IS NOT NULL AND pages.frontmatter->>'retired_by'='managed-reextract' AND NULLIF(pages.frontmatter->>'imported_from','') IS NULL) AND ((NULLIF(pages.frontmatter->>'source_slug','') IS NOT NULL AND EXISTS (SELECT 1 FROM pages ao WHERE ao.source_id=pages.source_id AND ao.slug=pages.frontmatter->>'source_slug' AND ao.deleted_at IS NULL)) OR (NULLIF(pages.frontmatter->>'source_slug','') IS NULL AND NULLIF(pages.frontmatter->>'source_path','') IS NOT NULL)) AND NOT EXISTS (SELECT 1 FROM pages ar WHERE ar.source_id=pages.source_id AND ar.type='atom' AND ar.deleted_at IS NULL AND NULLIF(ar.frontmatter->>'imported_from','') IS NULL AND ((NULLIF(pages.frontmatter->>'source_slug','') IS NOT NULL AND ar.frontmatter @> jsonb_build_object('source_slug',pages.frontmatter->'source_slug')) OR (NULLIF(pages.frontmatter->>'source_slug','') IS NULL AND ar.frontmatter @> jsonb_build_object('source_path',pages.frontmatter->'source_path'))) AND regexp_replace(COALESCE(ar.frontmatter->>'source_hash',''),'^pending:','')<>regexp_replace(COALESCE(pages.frontmatter->>'source_hash',''),'^pending:','')) AND regexp_replace(COALESCE(pages.frontmatter->>'source_hash',''),'^pending:','')=(SELECT regexp_replace(COALESCE(ag.frontmatter->>'source_hash',''),'^pending:','') FROM pages ag WHERE ag.source_id=pages.source_id AND ag.type='atom' AND ag.deleted_at IS NOT NULL AND ag.frontmatter @> jsonb_build_object('retired_by','managed-reextract') AND NULLIF(ag.frontmatter->>'imported_from','') IS NULL AND ((NULLIF(pages.frontmatter->>'source_slug','') IS NOT NULL AND ag.frontmatter @> jsonb_build_object('source_slug',pages.frontmatter->'source_slug')) OR (NULLIF(pages.frontmatter->>'source_slug','') IS NULL AND ag.frontmatter @> jsonb_build_object('source_path',pages.frontmatter->'source_path'))) ORDER BY ag.frontmatter->>'retired_at' DESC NULLS LAST, ag.id DESC LIMIT 1))) ORDER BY deleted_at ASC, slug ASC",
- "textSha256": "cc27694a76f120933c3771d45f1d6b506bdc58a9a1644db9c560fc27d4cdc55b"
+ "sql": "SELECT slug, deleted_at FROM pages WHERE deleted_at IS NOT NULL AND deleted_at < now() - ($1 || ' hours')::interval AND NOT EXISTS (SELECT 1 FROM op_checkpoints dg WHERE dg.op = 'sync-identity-downgrade' AND dg.fingerprint = pages.id::text AND dg.completed_keys->0->>'disposition' IS NULL AND pages.deleted_at = (dg.completed_keys->0->>'old_deleted_at')::timestamptz) AND NOT (pages.type='atom' AND pages.frontmatter->>'retired_by'='managed-reextract' AND pages.deleted_at > now() - interval '30 days' AND pages.id IN (SELECT held.id FROM (WITH retired AS ( SELECT p.id, p.source_id, p.slug, CASE WHEN NULLIF(p.frontmatter->>'source_slug','') IS NOT NULL THEN 'slug:'||(p.frontmatter->>'source_slug') WHEN NULLIF(p.frontmatter->>'source_path','') IS NOT NULL THEN 'path:'||(p.frontmatter->>'source_path') END AS okey, NULLIF(p.frontmatter->>'source_slug','') AS origin_slug, COALESCE(NULLIF(p.frontmatter->>'source_slug',''), p.frontmatter->>'source_path') AS origin, regexp_replace(COALESCE(p.frontmatter->>'source_hash',''),'^pending:','') AS hash, p.frontmatter->>'retired_at' AS retired_at FROM pages p WHERE p.type='atom' AND p.deleted_at IS NOT NULL AND p.frontmatter->>'retired_by'='managed-reextract' AND NULLIF(p.frontmatter->>'imported_from','') IS NULL AND (true) ), latest AS ( SELECT DISTINCT ON (source_id, okey) source_id, okey, hash FROM retired WHERE okey IS NOT NULL ORDER BY source_id, okey, retired_at DESC NULLS LAST, id DESC ), live AS ( SELECT p.source_id, CASE WHEN NULLIF(p.frontmatter->>'source_slug','') IS NOT NULL THEN 'slug:'||(p.frontmatter->>'source_slug') WHEN NULLIF(p.frontmatter->>'source_path','') IS NOT NULL THEN 'path:'||(p.frontmatter->>'source_path') END AS okey, array_agg(DISTINCT regexp_replace(COALESCE(p.frontmatter->>'source_hash',''),'^pending:','')) AS hashes FROM pages p WHERE p.type='atom' AND p.deleted_at IS NULL AND NULLIF(p.frontmatter->>'imported_from','') IS NULL AND (true) GROUP BY 1, 2 ) SELECT r.id, r.source_id, r.slug, CASE WHEN r.origin_slug IS NOT NULL THEN 'page' ELSE 'transcript' END AS origin_kind, r.origin, o.id AS origin_page_id, r.hash, r.retired_at, (r.okey IS NOT NULL AND (r.origin_slug IS NULL OR o.id IS NOT NULL)) AS origin_live, (lv.hashes IS NOT NULL AND NOT (lv.hashes <@ ARRAY[r.hash])) AS replaced, COALESCE(l.hash = r.hash, false) AS latest, (r.okey IS NOT NULL AND (r.origin_slug IS NULL OR o.id IS NOT NULL) AND NOT COALESCE(lv.hashes IS NOT NULL AND NOT (lv.hashes <@ ARRAY[r.hash]), false) AND COALESCE(l.hash = r.hash, false)) AS restorable FROM retired r LEFT JOIN pages o ON o.source_id=r.source_id AND o.slug=r.origin_slug AND o.deleted_at IS NULL LEFT JOIN live lv ON lv.source_id=r.source_id AND lv.okey=r.okey LEFT JOIN latest l ON l.source_id=r.source_id AND l.okey=r.okey) held WHERE held.restorable)) ORDER BY deleted_at ASC, slug ASC",
+ "textSha256": "1465c25692e36ffd111d5d84cf1ba8e6039a2af4a4bb06fa5a341d3db4aa21ce"
}
]
},