Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(GST-1209): the segmented-tiling preview lists nothing on a source with no damaged page, repo-less included (remediation-plan preview commands run as pasted)

garrytanec9e391cc2bf
diff --git a/docs/guides/repair.md b/docs/guides/repair.md
index e7611e42cd..c334b52dd2 100644
--- a/docs/guides/repair.md
+++ b/docs/guides/repair.md
@@ -173,7 +173,7 @@ work behind exits 0, so scripts should also check `results[].complete`.
| `missing-tables` | `schema_missing_tables` | Explicit-only, preview-bound. Recreates, empty, a rebuildable cache table (`query_cache`, `code_traversal_cache`) that the applied migrations created but the brain no longer has, on a brain whose schema version already covers its creating migration, so `apply-migrations` never recreates it (#6911). DDL only (`IF NOT EXISTS`), no journal admission, brain-wide. See [missing tables](#missing-tables). | `user_data_tables`: a missing table that holds user data; this repair never recreates it, so restore its rows from a backup first. `other_tables`: a missing table that holds no user data; `gbrain init --migrate-only` recreates it if the base schema defines it. |
| `url-clone-fences` | none (`gbrain sync --source <id>` stops at the pull with `pull_blocked_local_changes`) | Explicit-only, preview-bound, destructive consent. Clears the `## Facts` fence rows an older gbrain appended to files of a clone it owns (`gbrain sources add --url`), which block every `git pull --ff-only` that touches those files (#6946). The preview proves each changed file differs from HEAD only by appended fence rows; `--apply --expect <hash> --yes` backs each file up, keeps its rows database-only and restores the file from HEAD. Unmanaged brains only. See [URL clone fences](#url-clone-fences). | `non_fence_edit`, `unparsed_fence`, `staged_change`, `deleted`, `not_in_head`, `unreadable_checkout`: a file with any other difference from HEAD, named with why; a file whose HEAD would not import as its page (`visibility_noncanonical` and the other import holds): apply keeps its rows database-only and restores the file so the clone can pull, but does not import HEAD and reports `held`; files that changed after the preview (`changed_since_preview`). |
| `segmented-mirror` | none (doctor does not read segmented files; run the preview once if the brain ran a version before v0.60.299.0) | Explicit-only, preview-bound, destructive consent. Rewrites the canonical file of a page stored in segments that an older binary's withdrawal mirror passed by (`page_body_segmented`), so the file still holds a row `forget`, `forget_fact` or `purge_fact` removed from the database. The file becomes the page's canonical render (`gbrain export`'s bytes), written by the withdrawal mirror and committed by its Git effect. See [segmented mirror](#segmented-mirror). | `file_database_drift`: the file also differs from the database for another reason; it is listed held and never rewritten. `not_owner_host`: the preview ran off the source's owner host and read none of its files. |
-| `segmented-tiling` | `segmented_tiling` | Explicit-only, preview-bound, trusted local CLI on the owner host. Republishes, from the file Git holds at HEAD, each live page stored in segments whose live generation's rows do not cover its body (every read of it refuses `page_body_rows_unreadable` and a managed sync holds its file). `--source <id>` (`--slug <slug>` narrows), then `--apply --expect <hash>`. See [segmented tiling](#segmented-tiling). | Pages with no file, a file HEAD does not hold or one over `pages.max_bytes`, a file another sync hold withholds or one the next sync's import screen would hold (listed `held`); pages that changed after the preview (`changed_since_preview`). A source with no Git checkout, a repo-less brain included, refuses (`not_a_git_repo`). |
+| `segmented-tiling` | `segmented_tiling` | Explicit-only, preview-bound, trusted local CLI on the owner host. Republishes, from the file Git holds at HEAD, each live page stored in segments whose live generation's rows do not cover its body (every read of it refuses `page_body_rows_unreadable` and a managed sync holds its file). `--source <id>` (`--slug <slug>` narrows), then `--apply --expect <hash>`. See [segmented tiling](#segmented-tiling). | Pages with no file, a file HEAD does not hold or one over `pages.max_bytes`, a file another sync hold withholds or one the next sync's import screen would hold (listed `held`); pages that changed after the preview (`changed_since_preview`). A source with no Git checkout, a repo-less brain included, refuses (`not_a_git_repo`) once it holds a damaged page; with none the preview lists nothing. |
| `secret-spans` | none (the operator names the pages) | Explicit-only, preview-bound, trusted local CLI. Replaces the credentials the secret scanner finds in the database copies of the named pages with `<REDACTED:rule>` markers and changes nothing else: title, frontmatter values (never keys), the body (inline or segmented), timeline, fact, take and link rows, raw data; chunks holding a value are rebuilt. Database only: no file write, no Git commit, and a sync hold stays. `--source <id> --slug <slug>... [--rules <list>]`, then `--apply --expect <hash>`. See [secret spans](#secret-spans). | `clean` (no match), `refused` (`page_not_found`, `page_kind_unsupported`, `page_too_large`, `proof_failed`, `fact_value_unsupported`, `timeline_rows_collide`); pages that moved after the preview (`preview_changed`, `changed_since_preview`). |
Timeline rows that an earlier version of a page produced and its current text
@@ -454,10 +454,11 @@ file that changes who can read the page is held too (`visibility`,
type that is private by default), as is one the next sync's content gate
would quarantine, flag or stop embedding when the stored page carries no
such marker. So is a file over 24 MiB, the most the import screen reads
-whole. A source without a Git checkout, a
-repo-less brain included, refuses with `not_a_git_repo`: this repair
-republishes the copy Git holds, and there the database has no other copy.
-On such a brain, rewrite the page from a copy you hold (`put_page`).
+whole. A source without a Git checkout, a repo-less brain included, previews
+nothing while no page is damaged and refuses with `not_a_git_repo` once one
+is: this repair republishes the copy Git holds, and there the database has no
+other copy. On such a brain, rewrite the page from a copy you hold
+(`put_page`).
The apply needs the preview's hash. It checks each page again (revision,
generation and blob) and refuses `preview_changed` when one moved. Then, per
diff --git a/src/core/repair/segmented-tiling.ts b/src/core/repair/segmented-tiling.ts
index 8dc08c6c37..5333319b61 100644
--- a/src/core/repair/segmented-tiling.ts
+++ b/src/core/repair/segmented-tiling.ts
@@ -13,7 +13,8 @@
* (purged page content, the write gate, private visibility, a fence it refuses), one that changes who can read the page
* or one the next sync's content gate would quarantine, flag or skip embedding (the apply keeps the stored frontmatter),
* or one over the 24 MiB the screen reads whole. A source without a Git
- * checkout (a repo-less brain) refuses: this repair republishes the copy Git holds, and the database has no other.
+ * checkout (a repo-less brain) that holds a damaged page refuses: this repair republishes the copy Git holds, and the
+ * database has no other; with no damaged page the preview lists nothing.
*
* `--apply --expect <hash>` re-checks every page (`preview_changed`), then per page, in one transaction under the page's
* key lock (a coordinated maintenance write on a managed brain; refused while a sync or write in flight names the file):
@@ -168,12 +169,14 @@ async function stageable(engine: BrainEngine, page: { source_id: string; slug: s
/** Every damaged page of the selection, as the preview lists it (republishable pages and held ones). */
async function survey(engine: BrainEngine, selection: Selection): Promise<{ pages: HealPage[]; listing: RepairListing[]; held: number }> {
+ const damaged = await untiledSegmentedPages(engine, { sourceIds: [selection.source_id], ...(selection.slugs.length ? { slugs: selection.slugs } : {}) });
+ if (!damaged.length) return { pages: [], listing: [], held: 0 };
const checkout = await sourceCheckout(engine, selection.source_id);
const { maxBytes } = await readPageBodyPolicy(engine);
const pages: HealPage[] = [];
const listing: RepairListing[] = [];
let held = 0;
- for (const page of await untiledSegmentedPages(engine, { sourceIds: [selection.source_id], ...(selection.slugs.length ? { slugs: selection.slugs } : {}) })) {
+ for (const page of damaged) {
const label = `${page.source_id}:${page.slug} (revision ${page.revision})`;
const blob = page.source_path ? headBlob(checkout.root, page.source_path, maxBytes) : { held: 'the page has no file, so Git holds no copy of it' };
if ('held' in blob) { held++; listing.push({ item: label, class: 'held', detail: blob.held }); continue; }
diff --git a/test/large-pages/segmented-tiling-repair.test.ts b/test/large-pages/segmented-tiling-repair.test.ts
index 9b09961b31..44ccd320ed 100644
--- a/test/large-pages/segmented-tiling-repair.test.ts
+++ b/test/large-pages/segmented-tiling-repair.test.ts
@@ -5,7 +5,8 @@
* preview names the page, its file and HEAD's blob under a hash; `--apply` refuses without that hash; the apply
* republishes the page from the blob at HEAD as a new generation that tiles, keeps the damaged generation as a
* version by reference, writes a receipt, clears the sync hold, and the next managed sync completes with no hold.
- * A source with no Git checkout refuses the preview (not_a_git_repo); a remote caller is refused.
+ * A source with no Git checkout previews nothing while no page is damaged and refuses once one is (not_a_git_repo);
+ * a remote caller is refused.
* 2. Fails when: doctor misses the page or writes, an apply runs without the previewed hash or against a changed page,
* the republished generation does not tile, the hold survives, a repo-less source reads as republishable, or a file
* that narrows who can read the page or that the content gate would quarantine is republished under the stored frontmatter.
@@ -223,7 +224,7 @@ test('a claim the owner purged stays out: the apply republishes the file through
expect(await engine.executeRaw('SELECT count(*)::int AS n FROM content_chunks WHERE page_id=$1 AND chunk_text LIKE $2', [f.pageId, `%${PURGED}%`])).toEqual([{ n: 0 }]);
}), 300_000);
-test('a source without a Git checkout refuses the preview: Git is the only copy it republishes', async () => withEnv(env, async () => {
+test('a source without a Git checkout previews nothing while no page is damaged, then refuses: Git is the only copy it republishes', async () => withEnv(env, async () => {
await disposePersistenceConsumer(engine);
await engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1');
const sourceId = `repoless-${randomUUID().slice(0, 8)}`;
@@ -231,9 +232,10 @@ test('a source without a Git checkout refuses the preview: Git is the only copy
await engine.setConfig('pages.segmented_storage', 'on');
await importFromContent(engine, 'notes/repoless-example', person(1260 * 1024), { sourceId, noEmbed: true });
const [row] = await engine.executeRaw<{ id: number }>('SELECT id FROM pages WHERE source_id=$1 AND slug=$2', [sourceId, 'notes/repoless-example']);
+ const scope = await resolveRepairScope(engine, sourceId);
+ expect((await repairRunner(engine, { apply: false, logger }).then(runner => runner.run('segmented-tiling', scope, { explicit: true, sourceFlag: sourceId }))).listing ?? []).toEqual([]);
await engine.executeRaw('DELETE FROM page_body_manifest WHERE page_id=$1 AND staging_id IS NULL AND seq=(SELECT max(seq) FROM page_body_manifest WHERE page_id=$1 AND staging_id IS NULL)', [row!.id]);
expect((await segmentedTilingCheck(engine, [sourceId])).status).toBe('fail');
- const scope = await resolveRepairScope(engine, sourceId);
await expect(repairRunner(engine, { apply: false, logger }).then(runner => runner.run('segmented-tiling', scope, { explicit: true, sourceFlag: sourceId })))
.rejects.toMatchObject({ code: 'not_a_git_repo' });
await engine.executeRaw('UPDATE persistence_brain SET enabled=true WHERE singleton=1');