Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(#6865): regressions for the review fixes (YAML comment, publication recheck, collisions and deleted pages never scheduled, moved scan restarts, deadline slices, judged holds left to the lane); docs

garrytan94988b0daebf
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 380a13a3f1..9035fd456d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,8 +31,8 @@ Hold messages now say what gbrain actually found: "decide which page keeps the s
### Things to watch
-- The sync edits at most 200 files and spends at most 60 seconds per run; the rest wait for the next sync. Nothing runs at upgrade.
-- To see what it would do first: `gbrain repair content --source <id> --no-llm` (read-only). To turn it off: `gbrain config set sync.slug_conflicts.auto_remove false` (or pause the whole content-repair lane with `fences.repair.enabled false`). To undo one edit: `git revert` its commit and sync, which holds the file again.
+- The sync looks at at most 200 held files and spends at most 60 seconds per run; the rest wait for the next sync. A hold the content-repair lane has already judged is left to the lane. Nothing runs at upgrade.
+- To see what it would do first: `gbrain repair content --source <id> --no-llm` (read-only). To turn it off: `gbrain config set sync.slug_conflicts.auto_remove false` (or pause the whole content-repair lane with `fences.repair.enabled false`). To undo one edit: `git revert` its commit and sync, which holds the file again; the alias stays, so the restored line then names the file's own page and needs a hand edit.
- Before you upgrade, `gbrain sync unblock --source <id> --apply` or `gbrain repair content --source <id>` removes the same lines by hand.
## To take advantage of v0.60.271.0
@@ -61,14 +61,16 @@ Hold messages now say what gbrain actually found: "decide which page keeps the s
#### Sync-time removal of stray `slug:` lines
-- `src/core/repair/slug-autoheal.ts` `healAfterManagedSync` runs once per managed sync from `commands/sync/perform.ts` `performManagedBranch`, after the drain lease is released. It applies only the content-repair lane's deterministic `absent_page` rule (`healAbsentSlugLine` in `repair/slug-conflicts.ts`), bound to the held bytes (`changed_since_hold`) and skipped for a busy path, through the same coordinated `submitManagedFileRepair` write the maintenance run uses.
+- `src/core/repair/slug-autoheal.ts` `healAfterManagedSync` runs once per managed sync from `commands/sync/perform.ts` `performManagedBranch`, after the drain lease is released. It applies only the content-repair lane's deterministic `absent_page` rule (`healAbsentSlugLine` in `repair/slug-conflicts.ts`), bound to the held bytes (`changed_since_hold`) and skipped for a busy path, through the same coordinated `submitManagedFileRepair` write the maintenance run uses. Inside that write the declared slug is checked again: a page, an alias of another page or a file at its path written since the heal read the source refuses it (`changed_since_preview`). Only holds without a current-lane verdict for their bytes are examined.
+- The declared slug is the YAML scalar the import reads (a trailing comment, quoting and escapes resolved), for the sync-time heal and the maintenance lane alike.
- The declared slug is recorded as a `slug_aliases` row inside that write (`recordSlugLineAlias`, `page-state/rename-alias.ts`); the receipt carries `declared_alias`.
- Skip reasons on `SyncResult.slug_lines_removed`: `disabled`, `lane_paused`, `remote_authority`, `sync_unfinished`, `not_writable`. Budget: `SLUG_HEAL_MAX_FILES` 200, `SLUG_HEAL_BUDGET_MS` 60 000.
- `sync.slug_conflicts.auto_remove` (default on) is registered in `KNOWN_CONFIG_KEYS`; `gbrain config set` rejects values other than true/false.
#### Unindexed files
-- `src/core/persistence/unindexed-files.ts` streams the last synced commit's tree (`git ls-tree`), filters it through discovery's own eligibility (`loadSyncEligibility`, now exported from `sync-discovery.ts`) and compares in batches against pages, holds and scheduled re-screens. Bounded by time and count with a resume cursor; an incomplete scan is never reported clean. Results live in `op_checkpoints` (op `unindexed-files`).
+- `src/core/persistence/unindexed-files.ts` streams the last synced commit's tree (`git ls-tree`), filters it through discovery's own eligibility (`loadSyncEligibility`, now exported from `sync-discovery.ts`) and compares in batches against pages, holds and scheduled re-screens. Bounded by time and count with a resume cursor (continued only while the target commit and eligibility are unchanged); blobs are screened in slices of at most 32 MiB with the deadline checked between them; an incomplete scan is never reported clean. Results live in `op_checkpoints` (op `unindexed-files`).
+- Files a re-screen cannot import are never scheduled: `slug_taken` (the path slug belongs to another page) and `deleted_page` (the page was deleted while the file stayed committed). Doctor names them read-only with a user fix (rename, delete or restore).
- The maintenance cycle phase `unindexed_files` runs one bounded pass per managed Git source and schedules found files with `requestGitHoldRetry`; doctor `unindexed_files` judges the stored result without scanning; `gbrain sources retry-held <id> --unindexed` runs a pass now (`--dry-run` lists only). The scan never runs on the per-sync path.
- `metafile_skipped` counts titled `isSyncMetafile` names (`index.md`, `README.md`, ...) that sync skips by design; read-only, never scheduled.
diff --git a/docs/guides/repair.md b/docs/guides/repair.md
index 41217b97b7..34ec221e36 100644
--- a/docs/guides/repair.md
+++ b/docs/guides/repair.md
@@ -1895,7 +1895,9 @@ hold; incremental sync never revisits it. The
maintenance phase `unindexed_files` finds such files (bounded, never
clean while incomplete) and schedules a re-screen; doctor
`unindexed_files` reports them. Run `gbrain sources retry-held <id> --unindexed`, then the sync it prints: each file imports or becomes a
-[hold](#held-files). `slug_taken` stays until one of the two files is renamed.
+[hold](#held-files). `slug_taken` (the path slug belongs to another page) and `deleted_page`
+(the page was deleted while the file stayed committed) are never scheduled:
+rename one of the two files, or delete the file or restore the page.
`metafile_skipped` (never scheduled) lists titled scaffolding files sync skips
on purpose (`index.md`, `README.md`, ...): rename one
(`investors/fund-a/index.md` to `investors/fund-a.md`), commit and sync.
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 1bdca8f286..28eb80c743 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -740,7 +740,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText }
{ since: '0.60.270.0', text: 'On a writer-claimed brain, background writes are refused before any receipt, so they spend no write-request id, when their source cannot publish: the worktree is in recovery, or the claim\'s owner verification fails on the owner host (a missing canonical or coordination path, or a physical root whose owner marker .gbrain-owner.json or reservation is gone or changed; a device-only change is still re-stamped by the write). The refusal is owner_unavailable with the fix `gbrain sources writer status --source <id> --json`, checked once per source per run. Background writes are every write not made from an interactive surface: the autopilot cycle and its maintenance phases (extraction, synthesis, patterns, consolidation, fence and content repair, lint fixes), Minion jobs (sync, extract and the other job handlers), connector syncs, delegated serve syncs started as background, the keep-DB reconcile, autopilot and job managed syncs, and the transcript stale-part delete. Interactive CLI, MCP and repair writes are unaffected; a paused (draining) owner still accepts and replays.' },
{ since: '0.60.270.0', text: 'The managed purge (autopilot purge phase, the purge job and `gbrain pages purge-deleted`) submits nothing for a source whose writer needs recovery (reported `writer_not_active` with its state and reason) and parks a page after five failed purges (doctor `purge_parked_pages`: actor agent on the CLI, host_admin remotely). The cycle purge phase reports warn, not fail, for either. `gbrain pages purge-deleted --retry-parked` retries parked pages once; it obeys `--older-than` (a parked page younger than the cutoff is not retried) and the rename-recovery hold, and its preview, its consent text (which names the parked count) and its run come from one selector.' },
{ since: '0.60.270.0', text: '`gbrain repair content` / `repair slug-conflicts` now clears a frontmatter_slug_conflict hold deterministically (remove_slug) when the only other change autoFixFrontmatter would make is a style-only NESTED_QUOTES re-quote of a valid JSON-style tag or alias array. Only the slug: line is removed; the array is left as written and listed as style_only in the preview, the run result and the content_repair receipt. Such holds used to stay still_invalid and needed `repair frontmatter --include-ambiguous`. When the lane still cannot clear a hold because the frontmatter needs other fixes, the still_invalid message now names those fix codes (for example NULL_BYTES).' },
- { since: '0.60.271.0', text: 'A managed `gbrain sync` now removes a stray frontmatter `slug:` line by itself when the slug it names has no page and no file (#6865, the content-repair lane\'s deterministic `absent_page` rule): right after the sync releases its drain lease, each such held file is rewritten without that one line, imported under the slug its path gives, its `frontmatter_slug_conflict` hold cleared and the edit committed as `gbrain: repair frontmatter slug in <path>` with the `gbrain-repair:` trailer, through the same coordinated repair write the maintenance run already used; the declared slug becomes an alias of the page so links written against it keep resolving. At most 200 files and 60 s per sync; the result\'s `slug_lines_removed` counts them and the rest. A line naming an existing page (with a file or database-only), a file edited since sync held it, a source with an unfinished sync, and a sync submitted by a remote job or agent are left held. Preview what the lane would do with `gbrain repair content --source <id> --no-llm`; opt out with `gbrain config set sync.slug_conflicts.auto_remove false` (or pause the whole lane with `fences.repair.enabled false`); undo one edit with `git revert` of its commit and a sync, which holds the file again. Nothing runs at upgrade. Slug-conflict hold status now follows what the lane found: "decide which page keeps the slug" appears only when the line names a live page, a hold with no verdict yet never escalates to a person, and a verdict an older gbrain recorded is rechecked once by the next sync or maintenance run instead of being listed for a person.' },
+ { since: '0.60.271.0', text: 'A managed `gbrain sync` now removes a stray frontmatter `slug:` line by itself when the slug it names has no page and no file (#6865, the content-repair lane\'s deterministic `absent_page` rule): right after the sync releases its drain lease, each such held file is rewritten without that one line, imported under the slug its path gives, its `frontmatter_slug_conflict` hold cleared and the edit committed as `gbrain: repair frontmatter slug in <path>` with the `gbrain-repair:` trailer, through the same coordinated repair write the maintenance run already used; the declared slug becomes an alias of the page so links written against it keep resolving. At most 200 files and 60 s per sync; the result\'s `slug_lines_removed` counts them and the rest. A line naming an existing page (with a file or database-only, checked again inside the write), a hold the lane already judged, a file edited since sync held it, a source with an unfinished sync, and a sync submitted by a remote job or agent are left held. Preview what the lane would do with `gbrain repair content --source <id> --no-llm`; opt out with `gbrain config set sync.slug_conflicts.auto_remove false` (or pause the whole lane with `fences.repair.enabled false`); undo one edit with `git revert` of its commit and a sync, which holds the file again (the alias stays, so the restored line then names the file\'s own page and needs a hand edit). Nothing runs at upgrade. Slug-conflict hold status now follows what the lane found: "decide which page keeps the slug" appears only when the line names a live page, a hold with no verdict yet never escalates to a person, and a verdict an older gbrain recorded is rechecked once by the next sync or maintenance run instead of being listed for a person.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/test/e2e/slug-autoheal-6865-postgres.test.ts b/test/e2e/slug-autoheal-6865-postgres.test.ts
index e6b6efe5ec..1c5989f283 100644
--- a/test/e2e/slug-autoheal-6865-postgres.test.ts
+++ b/test/e2e/slug-autoheal-6865-postgres.test.ts
@@ -1,6 +1,6 @@
/** Postgres arm of test/slug-autoheal-6865.test.ts (#6865). */
import { describe, test } from 'bun:test';
-import { existingPageStopsAndAsks, healNeverEditsInFlight, killSwitchKeepsHold, olderVerdictRecheckedAfterUpgrade, strayLineHealedBySync } from '../helpers/slug-autoheal-scenarios.ts';
+import { commentedLineNamingPageStays, declaredSlugRecheckedAtPublication, existingPageStopsAndAsks, healNeverEditsInFlight, killSwitchKeepsHold, olderVerdictRecheckedAfterUpgrade, strayLineHealedBySync } from '../helpers/slug-autoheal-scenarios.ts';
const url = process.env.DATABASE_URL;
describe.skipIf(!url)('Postgres stray frontmatter slug: lines (#6865)', () => {
@@ -9,4 +9,6 @@ describe.skipIf(!url)('Postgres stray frontmatter slug: lines (#6865)', () => {
test('a line naming an existing page (file-backed or database-only) stays held and the verdict names both pages', () => existingPageStopsAndAsks(url), 180_000);
test('no edit while the source syncs, the path is busy, the file changed since the hold, or under remote authority', () => healNeverEditsInFlight(url), 180_000);
test('a verdict an older gbrain recorded is rechecked, and the next sync heals the file', () => olderVerdictRecheckedAfterUpgrade(url), 180_000);
+ test('a slug: line with a trailing YAML comment naming an existing page stays held', () => commentedLineNamingPageStays(url), 180_000);
+ test('a file created at the declared slug after the heal read the checkout refuses the write', () => declaredSlugRecheckedAtPublication(url), 180_000);
});
diff --git a/test/helpers/slug-autoheal-scenarios.ts b/test/helpers/slug-autoheal-scenarios.ts
index d18f4111ea..4168549c5f 100644
--- a/test/helpers/slug-autoheal-scenarios.ts
+++ b/test/helpers/slug-autoheal-scenarios.ts
@@ -149,6 +149,8 @@ export async function existingPageStopsAndAsks(databaseUrl?: string) {
expect(verdict.human_reason).toContain('page `concepts/fund-c`');
expect(verdict.human_reason).toContain('decide which page keeps the slug');
for (const path of [DB_ONLY_HELD, FILE_HELD]) expect(read(root, path)).toBe(files[path]!);
+ const next = await sync(engine);
+ expect(next.slug_lines_removed).toMatchObject({ removed: 0, pending: 0, left_by_reason: { lane_verdict: 2 } });
}, { databaseUrl, setup: plant(files, true) });
}
@@ -202,3 +204,31 @@ export async function olderVerdictRecheckedAfterUpgrade(databaseUrl?: string) {
expect(read(root, STRAY)).not.toContain('slug: fund-a');
}, { databaseUrl, setup: plant({ [STRAY]: STRAY_BYTES }) });
}
+
+/** The declared slug is the YAML scalar: a trailing comment does not hide an existing page, so the line stays held. */
+export async function commentedLineNamingPageStays(databaseUrl?: string) {
+ const bytes = '---\ntitle: Fund B notes\ntype: company\nslug: fund-b # the existing page\n---\nMore on Fund B.\n';
+ await managedBrain(async ({ engine, root }) => {
+ const result = await sync(engine);
+ expect(result.slug_lines_removed).toMatchObject({ removed: 0, failed: 0 });
+ expect(read(root, DB_ONLY_HELD)).toBe(bytes);
+ expect((await holds(engine)).map(hold => hold.path)).toEqual([DB_ONLY_HELD]);
+ expect(await engine.readPageSnapshot('fund-b-the-existing-page', { sourceId: 'default' })).toBeNull();
+ }, { databaseUrl, setup: plant({ [DB_ONLY_HELD]: bytes }, true) });
+}
+
+/** A file created at the declared slug's path after the heal read the checkout refuses the publication: nothing is edited. */
+export async function declaredSlugRecheckedAtPublication(databaseUrl?: string) {
+ await managedBrain(async brain => {
+ const { engine, root, ctx } = brain;
+ await heldWithHealOff(brain);
+ const run = (await absentSlugHealRun(engine, 'default', { embed: false }))!;
+ expect(run.slugs().has('fund-a')).toBe(false);
+ writeFileSync(join(root, 'fund-a.md'), '---\ntitle: Fund A\ntype: company\n---\nWritten while the heal ran.\n');
+ const outcome = await healAbsentSlugLine(ctx, run, STRAY);
+ expect(outcome).toMatchObject({ applied: false, reason: 'changed_since_read' });
+ expect(read(root, STRAY)).toBe(STRAY_BYTES);
+ expect((await holds(engine)).map(hold => hold.path)).toEqual([STRAY]);
+ expect(await engine.executeRaw("SELECT 1 FROM slug_aliases WHERE source_id='default' AND alias_slug='fund-a'")).toEqual([]);
+ }, { databaseUrl, setup: plant({ [STRAY]: STRAY_BYTES }) });
+}
diff --git a/test/slug-autoheal-6865.test.ts b/test/slug-autoheal-6865.test.ts
index 0118209c58..8c9d6be66d 100644
--- a/test/slug-autoheal-6865.test.ts
+++ b/test/slug-autoheal-6865.test.ts
@@ -1,6 +1,6 @@
/** PGLite arm of the #6865 stray slug: line scenarios (test/helpers/slug-autoheal-scenarios.ts); Postgres: test/e2e/slug-autoheal-6865-postgres.test.ts. */
import { describe, test } from 'bun:test';
-import { existingPageStopsAndAsks, healNeverEditsInFlight, killSwitchKeepsHold, olderVerdictRecheckedAfterUpgrade, strayLineHealedBySync } from './helpers/slug-autoheal-scenarios.ts';
+import { commentedLineNamingPageStays, declaredSlugRecheckedAtPublication, existingPageStopsAndAsks, healNeverEditsInFlight, killSwitchKeepsHold, olderVerdictRecheckedAfterUpgrade, strayLineHealedBySync } from './helpers/slug-autoheal-scenarios.ts';
describe('PGLite stray frontmatter slug: lines (#6865)', () => {
test('the next sync removes a line naming no page and indexes the file under its path', () => strayLineHealedBySync(), 180_000);
@@ -8,4 +8,6 @@ describe('PGLite stray frontmatter slug: lines (#6865)', () => {
test('a line naming an existing page (file-backed or database-only) stays held and the verdict names both pages', () => existingPageStopsAndAsks(), 180_000);
test('no edit while the source syncs, the path is busy, the file changed since the hold, or under remote authority', () => healNeverEditsInFlight(), 180_000);
test('a verdict an older gbrain recorded is rechecked, and the next sync heals the file', () => olderVerdictRecheckedAfterUpgrade(), 180_000);
+ test('a slug: line with a trailing YAML comment naming an existing page stays held', () => commentedLineNamingPageStays(), 180_000);
+ test('a file created at the declared slug after the heal read the checkout refuses the write', () => declaredSlugRecheckedAtPublication(), 180_000);
});
diff --git a/test/unindexed-files.test.ts b/test/unindexed-files.test.ts
index 80bd128dcb..e1a7e4f907 100644
--- a/test/unindexed-files.test.ts
+++ b/test/unindexed-files.test.ts
@@ -206,6 +206,48 @@ test('a bounded scan that stops early is incomplete and never clean; later passe
expect((await s.doctor()).details).toMatchObject({ sources: [{ state: 'scheduled', waiting: 1 }] });
}), 240_000);
+test('slug collisions and deleted pages are reported for a person, never scheduled; syncs keep working and doctor does not warn', () => each(async engine => {
+ const s = await source(engine, { 'notes/a-b.md': note('AB'), 'notes/Case.md': note('Case'), 'notes/gone.md': note('Gone') });
+ await s.sync();
+ await unmanaged(engine, () => engine.executeRaw("UPDATE pages SET deleted_at=now() WHERE source_id=$1 AND slug='notes/gone'", [s.id]));
+ await s.legacy({ 'notes/a b.md': note('A space B'), 'notes/case.md': note('Lower case') });
+ const scan = await findUnindexedFiles(engine, s.id);
+ expect(scan).toMatchObject({ complete: true, unindexed: 3, slug_taken: 2, deleted_page: 1 });
+ const phase = await runUnindexedFilesPhase(engine, { dryRun: false });
+ expect(phase.details).toMatchObject({ scheduled_now: 0 });
+ expect(await readGitHoldRetryPaths(engine, s.id, await incarnationOf(engine, s.id))).toEqual([]);
+ expect((await retryUnindexed(engine, s.id)).scheduled).toBe(0);
+ writeFileSync(join(s.repo, 'notes/new.md'), note('New'));
+ commit(s.repo);
+ await s.sync();
+ expect(await engine.getPage('notes/new', { sourceId: s.id })).not.toBeNull();
+ const [gone] = await engine.executeRaw<{ deleted_at: string | null }>("SELECT deleted_at FROM pages WHERE source_id=$1 AND slug='notes/gone'", [s.id]);
+ expect(gone!.deleted_at).not.toBeNull();
+ const check = await s.doctor();
+ expect(check).toMatchObject({ status: 'ok', severity: 'info', details: { sources: [{ state: 'ok', slug_taken: 2, deleted_page: 1 }] } });
+ expect((check.fix as Action).actor).toBe('user');
+ expect(check.message).toContain('3 committed file(s) cannot be imported as they are');
+}), 240_000);
+
+test('a stored incomplete scan whose target commit moved starts over instead of continuing its cursor', () => each(async engine => {
+ const s = await source(engine, { 'notes/m.md': note('M'), 'notes/z.md': note('Z') });
+ await s.sync();
+ const first = await refreshUnindexedFiles(engine, s.id, { batch: 1, maxScanned: 1 });
+ expect(first.record).toMatchObject({ complete: false, cursor: 'notes/m.md' });
+ await s.legacy({ 'notes/a.md': note('A') });
+ const second = await refreshUnindexedFiles(engine, s.id);
+ expect(second.record).toMatchObject({ complete: true, scanned: 3, unindexed: 1, target: git(s.repo, 'rev-parse', 'HEAD') });
+ expect(second.record.pending).toEqual(['notes/a.md']);
+}), 240_000);
+
+test('a pass past its deadline reads no more blobs: found files count as unscreened and the scan is incomplete', () => each(async engine => {
+ const s = await source(engine, { 'notes/a.md': note('A') });
+ await s.sync();
+ await s.legacy({ 'notes/b.md': note('B') });
+ const scan = await findUnindexedFiles(engine, s.id, { deadlineAt: 0 });
+ expect(scan).toMatchObject({ complete: false, unindexed: 1, by_code: { unscreened: 1 } });
+}), 240_000);
+
for (const mode of ['git-root', 'source-root'] as const) {
test(`a subdirectory source in ${mode} mode: discovery and the detector share one eligibility, compared in source-path space`, () => each(async engine => {
const s = await source(engine, { 'brain/notes/a.md': note('A'), 'brain/notes/b.md': note('B'), 'brain/.hidden/h.md': note('H'), 'other/x.md': note('X') },