Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(sync): #8007 review: ignored supabase_only, file-drift --prefer file and held deletions fail closed; quote-aware flow lists; behavior notes

garrytan70fb8e22070c
diff --git a/docs/guides/repair.md b/docs/guides/repair.md
index 0bf0e13518..8e8f24ab93 100644
--- a/docs/guides/repair.md
+++ b/docs/guides/repair.md
@@ -2561,7 +2561,8 @@ committing the file again clears the hold. Reason `origin_unknown` means the
sync's history read did not finish, so it could not tell whether a commit held
the file and kept the page; the provenance below reads the whole history.
Reason `storage_invalid` (#8007) means `gbrain.yml`'s storage section did not
-load, or declared `db_only` in a form that resolved no directory, so the sync
+load, declared `db_only` in a form that resolved no directory, or listed a
+deprecated `supabase_only` next to canonical keys (ignored), so the sync
could not tell whether the page is database-only and kept it: run
`gbrain storage status`, fix `gbrain.yml`, commit it and sync again; the hold
clears and the page is decided under the fixed config.
diff --git a/docs/storage-tiering.md b/docs/storage-tiering.md
index e6379d5ada..fed3ed6b4a 100644
--- a/docs/storage-tiering.md
+++ b/docs/storage-tiering.md
@@ -35,7 +35,7 @@ storage:
Path requirements:
- Each directory must end with `/` for canonical form. The validator auto-normalizes missing trailing slashes (one-time info note shows what changed).
-- A tier may also be a one-line flow list, `db_only: [media/x/, 'media/articles/']`. A flow list split over several lines, or a `db_only` key outside `storage:`, resolves no directory: `gbrain storage status` names it, and until it is fixed a managed sync keeps every live page whose file is gone (held as `file_drift` with reason `storage_invalid`) instead of deleting it, because it cannot tell which pages are database-only (#8007). A tier overlap holds them the same way. Fix `gbrain.yml`, commit it and sync again; the holds clear and each page is decided under the fixed config.
+- A tier may also be a one-line flow list, `db_only: [media/x/, 'media/articles/']`. A flow list split over several lines, or a `db_only` key outside `storage:`, resolves no directory: `gbrain storage status` names it, and until it is fixed a managed sync keeps every live page whose file is gone (held as `file_drift` with reason `storage_invalid`) instead of deleting it, because it cannot tell which pages are database-only (#8007). A tier overlap holds them the same way, and so does a deprecated `supabase_only` list next to canonical keys, which canonical keys make gbrain ignore. `gbrain repair file-drift --prefer file` and `sync.apply_held_deletions` skip these pages while the config stays invalid. Fix `gbrain.yml`, commit it and sync again; the holds clear and each page is decided under the fixed config.
- A directory cannot appear in both tiers — that's a tier-overlap error and `loadStorageConfig` throws `StorageConfigError`. Edit `gbrain.yml` to remove the overlap and try again.
- Any other key under `storage:` is ignored with a warning naming it (a typo such as `kep_db` used to be ignored silently).
diff --git a/src/commands/sync-diagnostics.ts b/src/commands/sync-diagnostics.ts
index d1b8cbdf6c..f986075e85 100644
--- a/src/commands/sync-diagnostics.ts
+++ b/src/commands/sync-diagnostics.ts
@@ -71,7 +71,7 @@ export function printManagedSyncNotes(result: SyncResult, write: (line: string)
for (const refusal of result.fileRefusals ?? []) {
write(` Refused ${refusal.code}: ${refusal.message} ${refusal.suggestion} (${refusal.docs})`);
}
- if (result.storage_invalid_kept) write(` ${result.storage_invalid_kept} page(s) whose file is gone were kept, not deleted: gbrain.yml's storage section is invalid or declares db_only in a form that resolved no directory, so sync cannot tell which are database-only. Run \`gbrain storage status\`, fix gbrain.yml, then sync again.`);
+ if (result.storage_invalid_kept) write(` ${result.storage_invalid_kept} page(s) whose file is gone were kept, not deleted: gbrain.yml's storage section is invalid or ambiguous about db_only (it does not load, declares db_only in a form that resolved no directory, or lists a deprecated supabase_only next to canonical keys), so sync cannot tell which are database-only. Run \`gbrain storage status\`, fix gbrain.yml, then sync again.`);
if (result.working_tree_kept) write(` ${result.working_tree_kept} page(s) whose file is in the working tree but not in Git were kept (imported from the working tree, or import provenance unknown); delete the file, or commit it, to change that.`);
const skips = result.legacySkips;
if (skips?.contextualMode) write(` ${skips.contextualMode} legacy file(s) skipped because they parse to the same page but have no contextual retrieval mode, which a skipped import cannot stamp; to stamp it: gbrain repair contextual-mode`);
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 4150de8f58..27a4a3f2c3 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -1366,6 +1366,8 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.506.0', id: 'sources_add_next_gbra156', text: '`gbrain sources add` without `--federated` or `--no-federated`, on a brain that is not managed where connections with no source grant read no page, now prints `next: gbrain sources federate <id>` on stdout. `--json` prints `{id, name, local_path, remote_url, federated, next?}` on stdout and moves the human lines to stderr. A managed brain prints its lifecycle receipt as before.' },
// GBRA-156 #7601 quoted transcript rows. since is stamped at the merge slot.
{ since: '0.60.507.0', id: 'search_quotes_transcript_rows', text: '`search`, `query` and `assemble_evidence` now return a row from a conversation page (type `conversation`, what transcript imports write) with `quoted: "transcript"` and its text wrapped as a quoted excerpt: a line naming the page as source material, then a code fence. Tool-call and function-call JSON inside (Gemini `functionCall` included), and XML-style `function_calls`, `invoke`, `tool_use` and `tool_call` blocks, become `[tool call: <name>, arguments omitted]`. Under `return_unit: auto` an explicit `token_budget` pays for the fence, so a conversation-heavy result can return fewer or shorter rows. Stored pages, ranking, scores and other page types are unchanged; read `quoted` to tell these rows apart, and `get_page` for the text as stored.' },
+ { since: 'TBD', id: 'storage_invalid_holds_8007', text: 'A managed sync no longer deletes a live page whose file is gone while gbrain.yml\'s storage section is invalid (tiers that overlap), declares `db_only` in a form that resolves no directory (a flow list split over lines, a key outside `storage:`), or lists a deprecated `supabase_only` next to canonical keys (which ignores it): it cannot tell which pages are database-only, so it keeps each such page and holds its path as `file_drift` with `meta.reason` `storage_invalid`. Run `gbrain storage status`, fix gbrain.yml, commit it and sync again; the holds clear and each page is decided under the fixed config. `gbrain repair file-drift --prefer file` and `sync.apply_held_deletions` skip these pages too.' },
+ { since: 'TBD', id: 'storage_flow_lists_8007', text: 'gbrain.yml storage tiers written as a one-line flow list (`db_only: [media/x/, \'archive/\']`, likewise `db_tracked` and `keep_db`) now take effect; they used to resolve nothing. After upgrading, directories declared that way are treated as declared: sync adds `db_only` ones to .gitignore and publishes new pages there database-only, and `keep_db` ones get database-wins writes. An explicit `db_only: []` declares no directory and no longer makes the sync baseline commit refuse.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/persistence/source-storage.ts b/src/core/persistence/source-storage.ts
index d8112125f6..0872f47980 100644
--- a/src/core/persistence/source-storage.ts
+++ b/src/core/persistence/source-storage.ts
@@ -39,21 +39,15 @@ function load(root: string): StorageConfig | null {
return entry.config;
}
-/**
- * Whether a page slug falls under a `storage.db_only` dir declared in the
- * gbrain.yml at this source root. A gbrain.yml that cannot be read, whose
- * tiers overlap, or that declares db_only in syntax resolving nothing is
- * logged once per version; `refuse` then throws `storage_error`, while
- * `not_db_only` answers false so the caller keeps its non-db_only behavior.
- */
/**
* #8007: whether a page slug is database-only at this source root, or `unknown` when gbrain.yml cannot be read, its tiers
- * overlap or it declares db_only in syntax resolving nothing. A caller deciding whether a missing file deletes its page
+ * overlap, it declares db_only in syntax resolving nothing, or a deprecated `supabase_only` list was ignored next to canonical keys. A caller deciding whether a missing file deletes its page
* holds the page on `unknown` instead of guessing.
*/
export function sourceDbOnlyVerdict(root: string, slug: string): boolean | 'unknown' {
try {
- return isDeclaredDbOnlySlug(slug, load(root));
+ const config = load(root);
+ return isDeclaredDbOnlySlug(slug, config) || (config?.deprecated_db_only_ignored ? 'unknown' : false);
} catch {
return 'unknown';
}
@@ -65,6 +59,13 @@ export function sourceDbOnlyDir(root: string, slug: string): string | null {
return config?.db_only.find(dir => isDeclaredDbOnlySlug(slug, { ...config, db_only: [dir] })) ?? null;
}
+/**
+ * Whether a page slug falls under a `storage.db_only` dir declared in the
+ * gbrain.yml at this source root. A gbrain.yml that cannot be read, whose
+ * tiers overlap, or that declares db_only in syntax resolving nothing is
+ * logged once per version; `refuse` then throws `storage_error`, while
+ * `not_db_only` answers false so the caller keeps its non-db_only behavior.
+ */
export function isSourceDbOnlySlug(root: string, slug: string, onInvalid: 'refuse' | 'not_db_only'): boolean {
try {
return isDeclaredDbOnlySlug(slug, load(root));
diff --git a/src/core/persistence/sync-held-deletions.ts b/src/core/persistence/sync-held-deletions.ts
index 7816fa9068..6ec896bfd5 100644
--- a/src/core/persistence/sync-held-deletions.ts
+++ b/src/core/persistence/sync-held-deletions.ts
@@ -27,6 +27,7 @@ import { fileMatchesSnapshot } from './page-prepare.ts';
import type { ManagedSyncContext } from './sync-discovery.ts';
import { readBlobs } from './sync-git-stream.ts';
import { readGitSourceHolds } from './sync-holds.ts';
+import { sourceDbOnlyVerdict } from './source-storage.ts';
import { readDeletionProvenance } from './sync-origin-evidence.ts';
import { levelReuseAllowed, SYNC_LEVEL_REUSE_KEY } from './sync-tree-reuse.ts';
import type { ShadowLevel, ShadowPath } from './sync-pass.ts';
@@ -76,7 +77,7 @@ export async function applyHeldDeletions(engine: BrainEngine, level: ShadowLevel
return hold?.code === 'file_drift' && hold.meta.state === 'file_gone' && !hold.meta.reason && hold.meta.held_deletion?.page_revision !== entry.revision;
});
}
- const batch = [...fresh, ...held].filter(entry => !state.screened.has(entry.path)).slice(0, Math.max(0, PASS_HELD_DELETION_MAX - state.screened.size));
+ const batch = [...fresh, ...held].filter(entry => !state.screened.has(entry.path) && sourceDbOnlyVerdict(level.root, entry.slug!) === false).slice(0, Math.max(0, PASS_HELD_DELETION_MAX - state.screened.size));
if (!batch.length) return;
for (const entry of batch) state.screened.add(entry.path);
const verdicts = await proveHeldDeletions(engine, level, context, batch, holdPath);
diff --git a/src/core/persistence/sync-holds.ts b/src/core/persistence/sync-holds.ts
index 8bd0343df4..523f8a8ca4 100644
--- a/src/core/persistence/sync-holds.ts
+++ b/src/core/persistence/sync-holds.ts
@@ -720,7 +720,7 @@ function deletedDriftFix(record: Pick<GitHoldRecord, 'source_id' | 'path' | 'met
const verify = { argv: ['gbrain', 'sources', 'status', source, '--json'] };
if (state === 'file_gone' && record.meta.reason === 'storage_invalid') {
return { argv: ['gbrain', 'storage', 'status'], consent: [], actor: 'agent', requires_exclusive: false, docs: 'docs/storage-tiering.md',
- why: `${record.path} is gone, but gbrain.yml's storage section is invalid or declares db_only in a form that resolved no directory, so sync cannot tell whether page ${slug} is database-only and kept it instead of deleting it (#8007). This read-only check names the problem; fix gbrain.yml at the source root (list db_only directories in block style or as a one-line [a/, b/] list), commit it, then sync again.`,
+ why: `${record.path} is gone, but gbrain.yml's storage section is invalid or ambiguous about db_only (it does not load, declares db_only in a form that resolved no directory, or lists a deprecated supabase_only next to canonical keys), so sync cannot tell whether page ${slug} is database-only and kept it instead of deleting it (#8007). This read-only check names the problem; fix gbrain.yml at the source root (list db_only directories in block style or as a one-line [a/, b/] list), commit it, then sync again.`,
then: { argv: ['gbrain', 'sync', '--source', source, '--no-pull'], consent: [], actor: 'agent', requires_exclusive: false, verify,
why: `Decides ${record.path} again under the fixed gbrain.yml: a database-only page is kept, any other deletion follows its usual proof.` },
verify };
diff --git a/src/core/persistence/sync-pass-apply.ts b/src/core/persistence/sync-pass-apply.ts
index 3c73efee51..a50ba39cd2 100644
--- a/src/core/persistence/sync-pass-apply.ts
+++ b/src/core/persistence/sync-pass-apply.ts
@@ -311,7 +311,7 @@ async function writePassHolds(engine: BrainEngine, level: ShadowLevel, input: Pa
if (r.cls === 'delete_drift' && heldRenameOrigins.has(syncOriginPath(passEntryPaths(level, entry.path).sourcePath))) continue;
if (r.cls === 'delete_drift' && r.uncommitted === 'storage_invalid') {
pending.push({ entry, code: 'file_drift', slug: entry.slug, kind: 'uncommitted', meta: { side: 'deleted', state: 'file_gone', reason: 'storage_invalid', ...(entry.revision ? { page_revision: entry.revision } : {}) },
- message: `${path}: the file is gone, but gbrain.yml's storage section is invalid or declares db_only in a form that resolved no directory, so sync cannot tell whether page ${entry.slug} is database-only; it held the path and kept the page instead of deleting it (#8007); the rest of the source synced.` });
+ message: `${path}: the file is gone, but gbrain.yml's storage section is invalid or ambiguous about db_only (it does not load, declares db_only in a form that resolved no directory, or lists a deprecated supabase_only next to canonical keys), so sync cannot tell whether page ${entry.slug} is database-only; it held the path and kept the page instead of deleting it (#8007); the rest of the source synced.` });
} else if (r.cls === 'delete_drift' && r.uncommitted) {
const why = r.uncommitted === 'ignored' ? '.gitignore excludes it, so Git never kept it' : r.uncommitted === 'origin_unknown' ? 'Git could not show whether a commit held it (its history read did not finish)' : 'no commit in its history holds it';
pending.push({ entry, code: 'file_drift', slug: entry.slug, kind: 'uncommitted', meta: { side: 'deleted', state: 'file_gone', reason: r.uncommitted, ...(entry.revision ? { page_revision: entry.revision } : {}) },
diff --git a/src/core/persistence/sync-pass.ts b/src/core/persistence/sync-pass.ts
index 4397eac77e..9e24a660b3 100644
--- a/src/core/persistence/sync-pass.ts
+++ b/src/core/persistence/sync-pass.ts
@@ -810,7 +810,7 @@ export async function readShadowLevel(engine: BrainEngine, input: { sourceId: st
episodeUnsatisfied: input.pass ? !!input.pass.episodeFullId && live && (record ? pages.fullEpisode[at!] : undefined) !== input.pass.episodeFullId
: input.full === true && live,
derivedCurrent: live && pages.derivedCurrent(at!), fullObligation: input.pass ? !!input.pass.episodeFullId : input.full === true,
- keepDb: !mirror && keepDbPrefixes.length > 0 && row && isKeepDbSlug(pages.slug[at!]!, keepDbPrefixes), dbOnly: row && (dbOnlyUnknown ? 'unknown' : isDeclaredDbOnlySlug(pages.slug[at!]!, storage)),
+ keepDb: !mirror && keepDbPrefixes.length > 0 && row && isKeepDbSlug(pages.slug[at!]!, keepDbPrefixes), dbOnly: row && (isDeclaredDbOnlySlug(pages.slug[at!]!, storage) || (dbOnlyUnknown ? 'unknown' : false)),
openWork: row && open.pageIds.has(Number(pages.id[at!])) || open.origins.has(origin),
};
return { state, ...(row ? { at } : {}), ...(legacyPageless ? { legacyPageless } : {}) };
@@ -968,7 +968,7 @@ async function readLevelSettings(engine: BrainEngine, context: ManagedSyncContex
return { slugMode: settled(slugModeRead), exclude: settled(excludeRead), pack: settled(packRead), mirror: settled(mirrorRead), workingConfig: settled(workingRead),
metafilePages: settled(metafilePagesRead), strict: context.source.config?.canonical === 'git', strategy: input.pass?.strategy ?? (context.source.config?.strategy as string | undefined) ?? 'markdown',
includeHidden: [...new Set([...input.pass?.includeHidden ?? [], ...(settled(includeHiddenRead) ?? '').split(/[\n,]/).map(v => v.trim()).filter(Boolean)].map(v => v.endsWith('/') ? `${v}**` : v))],
- keepDbPrefixes: storage?.keep_db ?? [], storage, dbOnlyUnknown: storageInvalid || hasUnresolvedDbOnlyDeclaration(root, storage) };
+ keepDbPrefixes: storage?.keep_db ?? [], storage, dbOnlyUnknown: storageInvalid || storage?.deprecated_db_only_ignored === true || hasUnresolvedDbOnlyDeclaration(root, storage) };
}
/** A failed mark, proof or delta read: the round reads again without them (it aborted a Postgres snapshot). */
diff --git a/src/core/repair/file-drift.ts b/src/core/repair/file-drift.ts
index c02c054daf..4723bd4bcb 100644
--- a/src/core/repair/file-drift.ts
+++ b/src/core/repair/file-drift.ts
@@ -73,6 +73,7 @@ import { auditDriftConflicts, DRIFT_CLASSES, driftClass, liveFileDrift, type Dri
import { protectedReconcileKey, reconcileCanonical, RECONCILE_SCAN_KEYS, type ReconcileDecision } from '../persistence/reconcile-merge.ts';
import { fileWinsContent } from '../persistence/file-wins-content.ts';
import { ABSENT_FILE_HASH, canonicalDeletionState, missingFileRoute, readCanonicalFileText, readDeletedDriftTarget, readReconcileState, type DeletedDriftChange, type DeletedDriftTarget, type ReconcileArtifact } from '../persistence/reconcile-state.ts';
+import { sourceDbOnlyVerdict } from '../persistence/source-storage.ts';
import { clearGitHold, fileDriftActionVerb, fileDriftSide, FILE_DRIFT_DELETED_STATES, FILE_DRIFT_SIDES, GIT_HOLD_OP, heldDriftPreviewArgv, requestGitHoldRetry, type FileDriftDeletedState, type FileDriftSide, type GitHoldRecord } from '../persistence/sync-holds.ts';
import { prepareRepairPublication, repairScreenConfig, submitManagedFileRepair } from '../persistence/file-repair.ts';
import { maintenancePreflight, submitDatabaseMaintenanceIntent, submitMaintenanceIntent } from '../persistence/prepared-maintenance.ts';
@@ -524,6 +525,8 @@ async function fileGonePage(engine: BrainEngine, sourceId: string, slug: string,
const root = join(binding!.local_path!, binding!.relative_path);
const deletion = canonicalDeletionState(root, join(root, ...now.ghost.path.split('/')));
if (deletion !== 'gone') return { skip: deletion === 'in_head' ? 'deletion_uncommitted' : 'unknown_deletion_state', detail: missingFileRoute(sourceId, slug, now.ghost.path, deletion) };
+ if (opts.prefer === 'file' && sourceDbOnlyVerdict(root, slug) === 'unknown') return { skip: 'storage_invalid',
+ detail: `gbrain.yml's storage section is invalid or ambiguous about db_only, so whether ${slug} is database-only is unknown and --prefer file would delete it (#8007): run gbrain storage status, fix gbrain.yml, commit it, then gbrain sync --source ${sourceId} --no-pull` };
if (opts.provenance === 'never_committed' && target?.provenance?.kind === 'never_committed') {
return { page: { slug, prefer: 'database', exceptions: [], detach_page: { path: now.ghost.path, page_id: now.ghost.page_id, revision: now.ghost.revision, observed_at: target.hold.observed_at } },
detail: `keeps the page database-only: no commit ever held ${now.ghost.path}, so the page holds the only copy; no file is written and the page forgets that path` };
diff --git a/src/core/storage-config.ts b/src/core/storage-config.ts
index 86d2fa56eb..5e3e5d8f1a 100644
--- a/src/core/storage-config.ts
+++ b/src/core/storage-config.ts
@@ -17,6 +17,11 @@ export interface StorageConfig {
* the database copy by the trusted local maintenance worker on the canonical owner host (repair/keep-db-policy.ts).
*/
keep_db?: string[];
+ /**
+ * #8007: a deprecated `supabase_only` list sat next to canonical keys and was ignored (canonical wins), so which pages
+ * are database-only is ambiguous; a caller deciding whether a missing file deletes its page holds it instead.
+ */
+ deprecated_db_only_ignored?: true;
}
export type StorageTier = 'db_tracked' | 'db_only' | 'unspecified';
@@ -107,8 +112,8 @@ function parseStorageYaml(content: string, unknown: string[] = []): RawStorage |
currentList = key as keyof RawStorage;
// Inline flow list on one line: `db_only: []` or `db_only: [dir/, 'other/']`.
const flow = /^\[(.*)\]$/.exec(indented.slice(colon + 1).trim());
- if (flow) {
- const values = flow[1]!.split(',').map((value) => value.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
+ if (flow && !/[[\]]/.test(flow[1]!)) {
+ const values = [...flow[1]!.matchAll(/\s*("[^"]*"|'[^']*'|[^,]*)\s*(?:,|$)/g)].map((m) => m[1]!.replace(/^["']|["']$/g, '').trim()).filter(Boolean);
raw[currentList] = [...(raw[currentList] ?? []), ...values];
}
continue;
@@ -168,6 +173,7 @@ function normalizeStorageConfig(raw: RawStorage): StorageConfig {
db_tracked: raw.db_tracked ?? [],
db_only: raw.db_only ?? [],
...keep,
+ ...(raw.supabase_only?.length ? { deprecated_db_only_ignored: true as const } : {}),
};
}
@@ -348,7 +354,8 @@ export function normalizeAndValidateStorageConfig(input: StorageConfig): Storage
}
}
- return { db_tracked: tracked.normalized, db_only: dbonly.normalized, ...(keep ? { keep_db: keep.normalized } : {}) };
+ return { db_tracked: tracked.normalized, db_only: dbonly.normalized, ...(keep ? { keep_db: keep.normalized } : {}),
+ ...(input.deprecated_db_only_ignored ? { deprecated_db_only_ignored: true as const } : {}) };
}
/**
diff --git a/test/storage-config.test.ts b/test/storage-config.test.ts
index 47d245073b..38cde61933 100644
--- a/test/storage-config.test.ts
+++ b/test/storage-config.test.ts
@@ -180,7 +180,7 @@ describe('loadStorageConfig — real-disk loader', () => {
}
});
-test('#8007: a one-line flow list resolves its directories, quoted or not', () => {
+ test('#8007: a one-line flow list resolves its directories, quoted or not', () => {
try {
writeFileSync(join(tmp, 'gbrain.yml'), "storage:\n db_only: [conversations/, 'media/x/', \"notes/\"]\n db_tracked: [people/]\n");
expect(loadStorageConfig(tmp)).toMatchObject({ db_only: ['conversations/', 'media/x/', 'notes/'], db_tracked: ['people/'] });
@@ -189,6 +189,31 @@ test('#8007: a one-line flow list resolves its directories, quoted or not', () =
}
});
+ test('#8007: a comma inside a quoted flow value stays in that value; a nested list resolves nothing', () => {
+ try {
+ writeFileSync(join(tmp, 'gbrain.yml'), "storage:\n db_only: ['a, b/', c/]\n");
+ expect(loadStorageConfig(tmp)!.db_only).toEqual(['a, b/', 'c/']);
+ writeFileSync(join(tmp, 'gbrain.yml'), 'storage:\n db_only: [[a/]]\n');
+ expect(loadStorageConfig(tmp)?.db_only ?? []).toEqual([]);
+ expect(hasUnresolvedDbOnlyDeclaration(tmp, loadStorageConfig(tmp))).toBe(true);
+ } finally {
+ cleanup();
+ }
+ });
+
+ test('#8007: a deprecated supabase_only list ignored next to canonical keys is flagged, so delete decisions treat db_only as unknown', () => {
+ try {
+ writeFileSync(join(tmp, 'gbrain.yml'), 'storage:\n db_only: [private/]\n supabase_only:\n - archive/\n');
+ expect(loadStorageConfig(tmp)).toEqual({ db_tracked: [], db_only: ['private/'], deprecated_db_only_ignored: true });
+ writeFileSync(join(tmp, 'gbrain.yml'), 'storage:\n db_only: [private/]\n');
+ expect(loadStorageConfig(tmp)).toEqual({ db_tracked: [], db_only: ['private/'] });
+ writeFileSync(join(tmp, 'gbrain.yml'), 'storage:\n supabase_only:\n - archive/\n');
+ expect(loadStorageConfig(tmp)).toEqual({ db_tracked: [], db_only: ['archive/'] });
+ } finally {
+ cleanup();
+ }
+ });
+
test('returns null when repoPath is missing', () => {
try {
expect(loadStorageConfig(undefined)).toBeNull();
diff --git a/test/sync-storage-invalid-8007.test.ts b/test/sync-storage-invalid-8007.test.ts
index f3580d5a6a..e4aa3fedf0 100644
--- a/test/sync-storage-invalid-8007.test.ts
+++ b/test/sync-storage-invalid-8007.test.ts
@@ -1,11 +1,13 @@
/**
* #8007: a managed sync decides whether a page whose file is gone is deleted. A page under a declared storage.db_only dir
- * is kept (#7324), so when gbrain.yml's storage section cannot be read (tiers that overlap) or declares db_only in a form
- * that resolves no directory (a flow list split over lines), sync cannot tell which pages are database-only. On a real
+ * is kept (#7324), so when gbrain.yml's storage section cannot be read (tiers that overlap), declares db_only in a form
+ * that resolves no directory (a flow list split over lines), or ignores a deprecated supabase_only list next to canonical keys, sync cannot tell which pages are database-only. On a real
* managed brain (PGLite, and Postgres through the E2E wrapper), this protects:
* - the frozen discovery manifest drops every deletion and names it in storageInvalidKept;
* - a managed sync, incremental and full, deletes nothing: each missing-file page is held (file_drift, reason
* storage_invalid, fix `gbrain storage status`) and stays live, and the retention purge removes none of them;
+ * - `gbrain repair file-drift --held --prefer file` previews none of these held pages as a soft delete;
+ * - `sync.apply_held_deletions` deletes none of them, even from a hold an older gbrain wrote with no reason;
* - the same holds on a strict (canonical: git) source, where Git's verdict would otherwise delete a committed-then-removed file;
* - once gbrain.yml is valid again (a one-line flow list, which the parser now reads), the next syncs keep the db_only
* pages, delete the removed page outside db_only, and release the storage_invalid holds.
@@ -19,6 +21,9 @@ import { discoverManagedSync } from '../src/core/persistence/sync-discovery.ts';
import { performManagedSync } from '../src/core/persistence/sync-run.ts';
import { purgeDeletedPagesCoordinated } from '../src/core/persistence/purge-deleted.ts';
import { readGitHoldListing } from '../src/core/persistence/sync-holds.ts';
+import { registerLocalWriter, withVerifiedLocalRegistration } from '../src/core/persistence/identity.ts';
+import { resolveRepairScope } from '../src/core/repair/core.ts';
+import { repairRunner } from '../src/core/repair/registry.ts';
import { managedBrain } from './helpers/managed-brain.ts';
import { requirePostgresTestDatabase, testBackends } from './helpers/test-backends.ts';
@@ -53,6 +58,7 @@ const storageHolds = async (engine: BrainEngine) => ((await readGitHoldListing(e
const INVALID = [
['tiers that overlap (the storage config cannot load)', 'storage:\n db_only:\n - library/\n db_tracked:\n - library/\n'],
['a db_only flow list split over lines (resolves no directory)', 'storage:\n db_only: [library/,\n archive/]\n'],
+ ['a deprecated supabase_only list next to a canonical key (ignored)', 'storage:\n db_only: [archive/]\n supabase_only:\n - library/\n'],
] as const;
for (const backend of testBackends()) describe(`[${backend}] #8007: an invalid gbrain.yml never turns a missing file into a deletion`, () => {
@@ -75,6 +81,12 @@ for (const backend of testBackends()) describe(`[${backend}] #8007: an invalid g
const hold = ((await readGitHoldListing(engine, ['default'], 100))[0]?.holds ?? []).find(h => h.path === 'notes/control.md')!;
expect(hold.meta).toMatchObject({ side: 'deleted', state: 'file_gone', reason: 'storage_invalid' });
+ const logger = { info() {}, warn() {}, error() {} };
+ const repair = await withVerifiedLocalRegistration(engine, await registerLocalWriter(engine, 'cli'), async () =>
+ (await repairRunner(engine, { apply: false, logger })).run('file-drift', await resolveRepairScope(engine, 'default'),
+ { explicit: true, sourceFlag: 'default', held: true, prefer: 'file', side: 'deleted', state: 'file_gone' }));
+ expect(repair.details!.pages).toEqual([]);
+ expect(repair.listing!.map(row => row.class).filter(cls => cls !== 'storage_invalid' && cls !== 'side_changed')).toEqual([]);
const purged = await purgeDeletedPagesCoordinated(engine, 0);
for (const slug of [...CARDS, 'notes/control']) expect(purged.slugs).not.toContain(slug);
for (const slug of [...CARDS, 'notes/control']) expect({ slug, live: await live(engine, slug) }).toEqual({ slug, live: true });
@@ -88,4 +100,17 @@ for (const backend of testBackends()) describe(`[${backend}] #8007: an invalid g
expect(await live(engine, 'notes/keep')).toBe(true);
expect(await storageHolds(engine)).toEqual([]);
}, { databaseUrl, setup }), 240_000);
+
+ test('sync.apply_held_deletions never deletes a held missing-file page while gbrain.yml is invalid, a hold with no reason included', () => managedBrain(async ({ engine, root }) => {
+ expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');
+ invalidateAndUntrack(root, INVALID[0][1]);
+ await performManagedSync(engine, OPTS);
+ expect(await storageHolds(engine)).toEqual(REMOVED);
+ // An older gbrain wrote file_gone holds with no reason, and those never re-screen.
+ await engine.executeRaw("UPDATE op_checkpoints SET completed_keys = jsonb_set(completed_keys, '{0,meta}', (completed_keys->0->'meta') - 'reason') WHERE op='sync-hold'");
+ await engine.setConfig('sync.apply_held_deletions', 'true');
+ await performManagedSync(engine, OPTS);
+ await performManagedSync(engine, { ...OPTS, full: true });
+ for (const slug of [...CARDS, 'notes/control']) expect({ slug, live: await live(engine, slug) }).toEqual({ slug, live: true });
+ }, { databaseUrl, setup }), 240_000);
});