Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

chore: register file_database_drift, name the next step on new refusals, and update the page-body-reader baseline

garrytande00a845e820
diff --git a/docs/guides/error-codes.md b/docs/guides/error-codes.md
index 7f254ec688..e3f245c0a9 100644
--- a/docs/guides/error-codes.md
+++ b/docs/guides/error-codes.md
@@ -1346,6 +1346,16 @@ More: [docs/guides/write-refusals.md#fence_unrenderable](../../docs/guides/write
More: [docs/guides/write-refusals.md#fetch_failed](../../docs/guides/write-refusals.md#fetch_failed)
+### file_database_drift
+
+<a id="file_database_drift"></a>
+
+| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable |
+|---|---|---|---|---|---|---|
+| A page's checkout file and its database copy differ, so the writer left both as they are instead of replacing one with the other; the item is held and the rest of the batch continues. | Replacing the file with the database copy (or the database copy with the file) would destroy an edit only the replaced copy holds: a hand edit sync has not imported, an unindexed file at the page's path, or a database edit the file never received (#6982). The file is replaceable only when it equals the live page or one of its recent page_versions rows. | If the file holds the newer edit, run gbrain sync --source <source> to import it; if the database copy is newer, re-save the page with write-through on; when both changed, ask the user which version to keep before retrying. | agent | `repeat the read that failed` | 1 | no |
+
+More: [docs/guides/write-refusals.md](../../docs/guides/write-refusals.md)
+
### file_drift
<a id="file_drift"></a>
diff --git a/scripts/page-body-readers-baseline.tsv b/scripts/page-body-readers-baseline.tsv
index 1233f44a72..90342063b5 100644
--- a/scripts/page-body-readers-baseline.tsv
+++ b/scripts/page-body-readers-baseline.tsv
@@ -113,6 +113,7 @@ src/core/cycle/concept-publication.ts publishClassicConcept call:serializeMarkdo
src/core/cycle/concept-publication.ts publishClassicConcept field INLINE
src/core/cycle/concept-publication.ts publishManagedConcept call:serializeMarkdown INLINE
src/core/cycle/dream-taint.ts putDerivedPage call:putPage SEGW
+src/core/cycle/dream-taint.ts putDerivedPage field SEGW compares the prior body from readStoredBody; a segmented prior reads NULL, so it is versioned before the putPage
src/core/cycle/drift.ts runPhaseDrift call:putPage INLINE
src/core/cycle/drift.ts runPhaseDrift call:serializeMarkdown INLINE
src/core/cycle/edge-contradictions.ts removeTimelineLine call:serializeMarkdown SEGW
@@ -144,9 +145,10 @@ src/core/cycle/phantom-redirect-managed.ts redirectManagedPhantom field SEGW seg
src/core/cycle/phantom-redirect.ts fenceDbDrift field SEGW segmented page: getter throws page_body_segmented
src/core/cycle/phantom-redirect.ts materializeCanonicalToDisk call:serializeMarkdown SEGW canonical asserted inline by the caller
src/core/cycle/phantom-redirect.ts materializeCanonicalToDisk field SEGW canonical asserted inline by the caller
+src/core/cycle/phantom-redirect.ts mergeIntoCanonicalBody field SEGW canonical asserted inline by tryRedirectPhantom before the merge
+src/core/cycle/phantom-redirect.ts mergeIntoCanonicalFile call:contentHash META hash of the reparsed inline file
+src/core/cycle/phantom-redirect.ts mergeIntoCanonicalFile field SEGW canonical asserted inline by tryRedirectPhantom before the merge
src/core/cycle/phantom-redirect.ts phantomHasResidue field SEGW phantom stubs are small; segmented page: getter throws page_body_segmented
-src/core/cycle/phantom-redirect.ts tryRedirectPhantom call:contentHash META hash of the reparsed inline file
-src/core/cycle/phantom-redirect.ts tryRedirectPhantom call:refreshPageBody SEGW assertInlineBody on the canonical first
src/core/cycle/phantom-redirect.ts tryRedirectPhantom field SEGW canonical target asserted inline before the disk fence append; per-phantom throw is logged and the walk continues
src/core/cycle/propose-takes.ts listCandidatePages sql STREAM
src/core/cycle/propose-takes.ts ProposeTakesPhase.process call:contentHash META
@@ -212,9 +214,13 @@ src/core/facts/backstop.ts runFactsBackstop field STREAM
src/core/facts/backstop.ts runPipeline field STREAM
src/core/facts/drain.ts estimateBacklogUsd sql META
src/core/facts/eligibility.ts isFactsBackstopEligible field LEAD
-src/core/facts/fence-write.ts writeFactsToFence call:contentHash META
-src/core/facts/fence-write.ts writeFactsToFence call:refreshPageBody SEGW
-src/core/facts/fence-write.ts writeFactsToFence field SEGW
+src/core/facts/file-body-guard.ts fileBodyMatchesStored field SEGW a segmented page reads NULL inline columns, never matches, and the caller holds it (nothing written)
+src/core/facts/file-body-guard.ts mirroredBody field NONE the parsed checkout file body, not a page row
+src/core/facts/file-body-guard.ts readStoredBody sql SEGW reads the inline columns only; a segmented page reads NULL and every caller holds it
+src/core/facts/file-body-guard.ts replaceStoredBody call:contentHash META hash of the inline file body being mirrored
+src/core/facts/file-body-guard.ts replaceStoredBody call:refreshPageBody SEGW runs only after fileBodyMatchesStored matched the inline row under the lock, so never on a segmented page
+src/core/facts/file-body-guard.ts replaceStoredBody field SEGW runs only after fileBodyMatchesStored matched the inline row under the lock, so never on a segmented page
+src/core/facts/file-body-guard.ts replaceableFile sql SEGW a segmented page reads NULL inline columns, so its file is never replaceable and the caller holds it
src/core/facts/forget.ts forgetFactInFence call:contentHash META inline pages only
src/core/facts/forget.ts forgetFactInFence call:refreshPageBody SEGW assertInlineBody first
src/core/facts/forget.ts forgetFactInFence field SEGW assertInlineBody before the DB strike/mirror (best-effort: the withdrawal record stays authoritative)
@@ -239,9 +245,6 @@ src/core/facts/relink-publish.ts prepareRelinkMutation field SEGW
src/core/facts/subject-infer-write.ts linkAllowed field STREAM
src/core/facts/unfenced-facts.ts auditUnadoptableFacts call:serializePageToMarkdown SEGW
src/core/facts/unfenced-facts.ts fenceDatabaseOnlyPage call:serializePageToMarkdown SEGW
-src/core/facts/unfenced-facts.ts fenceFilePage call:contentHash META
-src/core/facts/unfenced-facts.ts fenceFilePage call:refreshPageBody SEGW
-src/core/facts/unfenced-facts.ts fenceFilePage field SEGW
src/core/facts/unfenced-facts.ts planManagedPage call:serializePageToMarkdown SEGW
src/core/facts/withdrawal-discovery.ts discoverWithdrawalTargets field STREAM inline rows only
src/core/facts/withdrawal-discovery.ts discoverWithdrawalTargets sql STREAM page scan reads inline bodies (NULL never matches); segmented pages are found by the chunk scan and their mirror writers refuse or skip (per-segment discovery, PR 2)
diff --git a/src/commands/sync/full.ts b/src/commands/sync/full.ts
index 29f4255aa8..328b7321b0 100644
--- a/src/commands/sync/full.ts
+++ b/src/commands/sync/full.ts
@@ -482,13 +482,13 @@ async function reconcileFullSyncDeletes(
const { writePageThrough } = await import('../../core/write-through.ts');
for (const slug of dbOnlySlugs) {
try {
- if (segmentedSlugs.has(slug)) throw new OperationError('page_body_segmented', 'Re-export cannot render a segmented page; read it with gbrain get --body auto.');
+ if (segmentedSlugs.has(slug)) throw new OperationError('page_body_segmented', 'Re-export cannot render a segmented page.', 'Read it with gbrain get --body auto; the page stays in the database.');
const r = await writePageThrough(engine, slug, { sourceId: sid, expectedFileBytes: null });
if (r.written) { reExported++; continue; }
if (r.skipped === 'disabled_by_config' || r.skipped === 'url_clone') continue;
- if (r.skipped === 'file_changed') throw new OperationError('file_database_drift', 'The checkout file exists; re-export only restores absent files.');
+ if (r.skipped === 'file_changed') throw new OperationError('file_database_drift', 'The checkout file exists; re-export only restores absent files.', `If the file holds the newer edit, run gbrain sync --source ${sid} to import it; otherwise ask the user which version to keep.`);
if (r.error) throw new Error(r.error);
- throw new OperationError('storage_error', `The page was not re-exported (${r.skipped}).`);
+ throw new OperationError('storage_error', `The page was not re-exported (${r.skipped}).`, 'Run gbrain doctor --json for the write-through target, then sync again.');
} catch (error) {
const failure = classifyItemFailure(error);
if (failure.scope === 'run') throw error;
diff --git a/src/core/error-registry.ts b/src/core/error-registry.ts
index 1cc0ae33bb..0965e9c818 100644
--- a/src/core/error-registry.ts
+++ b/src/core/error-registry.ts
@@ -270,6 +270,7 @@ export const CODES = {
feedback_disabled: { class: 'host_only', summary: "Retrieval feedback is off (or not learning) on this brain, so ratings are not recorded.", docs: 'docs/guides/retrieval-feedback.md#feedback_disabled' },
feedback_not_authorized: { class: 'host_only', summary: "This caller may not change the brain's shared ranking for that source.", docs: 'docs/guides/retrieval-feedback.md#feedback_not_authorized' },
fetch_failed: { class: 'retryable', summary: "Fetching the upstream failed." },
+ file_database_drift: { class: 'caller', summary: "A page's checkout file and its database copy differ, so the writer left both as they are instead of replacing one with the other; the item is held and the rest of the batch continues.", why: "Replacing the file with the database copy (or the database copy with the file) would destroy an edit only the replaced copy holds: a hand edit sync has not imported, an unindexed file at the page's path, or a database edit the file never received (#6982). The file is replaceable only when it equals the live page or one of its recent page_versions rows.", docs: 'docs/guides/write-refusals.md', suggestion: 'If the file holds the newer edit, run gbrain sync --source <source> to import it; if the database copy is newer, re-save the page with write-through on; when both changed, ask the user which version to keep before retrying.' },
fix_not_writable: { class: 'host_only', summary: "A gbrain lint fix was not applied because the file refused the write (EACCES, EPERM or EROFS); the file was left unchanged.", why: "Lint repairs files in place, and this file's permissions or a read-only mount stopped the write; lint reports it and continues with the remaining files.", docs: 'docs/guides/repair.md#fix-not-writable', suggestion: "Make the file writable by the user running gbrain, or pass its directory or file name to gbrain lint --exclude, then lint again." },
file_drift: { class: 'caller', summary: "A managed sync import would have overwritten a database version of the page that sync never saw (the page changed since its file was last imported), so the file is held and the page keeps the database version.", why: "Sync imports a file only when the page is still at the revision its last recorded import wrote, or when the import changes nothing. Here the page moved (a database-only write, or no import record to compare on an upgraded brain) and the file's content differs, so importing would silently replace the newer database copy. Pages under storage.keep_db prefixes are never held: the keep_db worker reconciles them from the database.", docs: 'docs/guides/write-refusals.md#file_drift', suggestion: 'Preview with gbrain repair file-drift --source <source> --slug <slug> --prefer database (keep the database copy and rewrite the file) or --prefer file (import the file), decide with the user, then apply it with the plan hash; the next gbrain sync --source <source> --no-pull re-screens the hold.' },
file_removed_during_scan: { class: 'retryable', summary: "A file lint listed was removed before lint read it, so it was not linted.", why: "Another process deleted or renamed the file during the run; lint reports it and continues with the remaining files.", docs: 'docs/guides/repair.md#file-removed-during-scan', suggestion: "Re-run gbrain lint on the same target; it lints the files present now." },
diff --git a/src/core/github-source.ts b/src/core/github-source.ts
index c4ea03a5d9..20b476321f 100644
--- a/src/core/github-source.ts
+++ b/src/core/github-source.ts
@@ -976,7 +976,8 @@ async function materializePage(deps: GitHubSyncDeps, filePath: string, content:
if (databaseOnly) return { ...await importPage(deps, filePath, activePack, rel, content), created: !existing };
const guard = await replaceableFile(deps.engine, deps.sourceId, slug, filePath);
const drift = () => new OperationError('file_database_drift',
- `${slug}: the checkout file has an edit not retained in the database, or changed during import. The file was not replaced. If the file is newer, run gbrain sync --source ${deps.sourceId}; if the database is newer, re-save its page with write-through on; if both changed, ask the user which version to keep before retrying.`);
+ `${slug}: the checkout file has an edit not retained in the database, or changed during import. The file was not replaced. If the file is newer, run gbrain sync --source ${deps.sourceId}; if the database is newer, re-save its page with write-through on; if both changed, ask the user which version to keep before retrying.`,
+ 'Import the newer file with gbrain sync, or ask the user which version to keep; the item is held until then.');
if (!guard.ok) throw drift();
const created = guard.expectedFileBytes === null;
mkdirSync(dirname(filePath), { recursive: true });
diff --git a/src/core/google/sweep-shared.ts b/src/core/google/sweep-shared.ts
index 9305ac048a..13025e4a67 100644
--- a/src/core/google/sweep-shared.ts
+++ b/src/core/google/sweep-shared.ts
@@ -146,7 +146,8 @@ export async function importRendered(
const databaseOnly = await isWriteThroughDisabled(deps.engine);
const guard = databaseOnly ? null : await replaceableFile(deps.engine, deps.sourceId, slug, filePath);
const drift = () => new OperationError('file_database_drift',
- `${slug}: the checkout file has an edit not retained in the database, or changed during import. The file was not replaced. If the file is newer, run gbrain sync --source ${deps.sourceId}; if the database is newer, re-save its page with write-through on; if both changed, ask the user which version to keep before retrying.`);
+ `${slug}: the checkout file has an edit not retained in the database, or changed during import. The file was not replaced. If the file is newer, run gbrain sync --source ${deps.sourceId}; if the database is newer, re-save its page with write-through on; if both changed, ask the user which version to keep before retrying.`,
+ 'Import the newer file with gbrain sync, or ask the user which version to keep; the item is held until then.');
if (guard && !guard.ok) throw drift();
const before = databaseOnly ? !!existing : existsSync(filePath);
// Temp-write → import → rename: a failed import never destroys the