Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

sync: hold an unread origin as origin_unknown instead of never_committed

garrytanfab662d4ab40
diff --git a/docs/guides/repair.md b/docs/guides/repair.md
index eaaaa76f0e..a812e103c6 100644
--- a/docs/guides/repair.md
+++ b/docs/guides/repair.md
@@ -2202,7 +2202,9 @@ A `file_gone` hold whose `meta.reason` is `never_committed` or `ignored`
(#7130) is a page whose file is missing although Git never committed it: the
sync could not tell a deletion from a file that never reached the repository,
so the page may hold the only copy. `--prefer file` deletes it after review;
-committing the file again clears the hold.
+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.
<a id="file-drift-provenance"></a>**Provenance: who deleted each gone file.** Every page of a
`--held --side deleted --state file_gone` preview names where its file went
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 969d97eb7d..8dd4f39014 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -1138,6 +1138,8 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.380.0', text: '`gbrain extract --stale` no longer exits 1 when one page holds a line or fence longer than the block bound (`page_body_segmented`). The link phase and the mention pass report that page by code, leave it stale and due, and finish every other page; before, the mention pass threw, and the unmanaged sweep stopped at that page.' },
// GBRA-133: a page written after its file is never soft-deleted for the file's deletion
{ since: '0.60.381.0', text: '`gbrain repair file-drift --held --side deleted --state file_gone --prefer file` (including `--provenance deleted_by_commit`) and `gbrain repair ghost-pages` no longer soft-delete a page whose revision was written in the database after its file last held it (neither the revision sync last imported from the file nor one a committed sync or Git-published write produced; for a page no import record covers, written after the commit that deleted its file): the preview lists it apart as `database_ahead_of_file` with how to recreate its file (`--slug <slug> --prefer database`), and the apply refuses it (`refused`, `database_ahead_of_file`), also for an approval saved before this release. Before, a commit that deleted the file was taken as the page\'s deletion, so content no commit held was soft-deleted.' },
+ // GBRA-133 (soak: an unread origin was reported as never committed). `since` is restamped at the merge slot.
+ { since: '0.60.381.0', text: 'A `file_drift` hold (side `deleted`, state `file_gone`) for a missing file whose Git history read did not finish now carries `meta.reason` `origin_unknown` and says Git could not show whether a commit held the file, instead of `never_committed` and "Git never committed it". The page is still kept, and the `--held` preview still reads the whole history and names the provenance.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/persistence/sync-classify.ts b/src/core/persistence/sync-classify.ts
index 3a46907def..067d0779a6 100644
--- a/src/core/persistence/sync-classify.ts
+++ b/src/core/persistence/sync-classify.ts
@@ -88,8 +88,8 @@ export interface SyncClassified {
/** `drift` and `delete_drift`: the hold's side. `deleted_edited`: its state. */
side?: 'both' | 'unknown' | 'deleted';
state?: 'tombstone_edited' | 'purged_differs' | 'file_gone';
- /** #7130: a `delete_drift` whose file Git never committed (`never_committed`, also when that could not be read) or `.gitignore` excludes. */
- uncommitted?: 'never_committed' | 'ignored';
+ /** #7130: a `delete_drift` whose file Git never committed (`never_committed`), `.gitignore` excludes, or whose history read did not answer (`origin_unknown`). */
+ uncommitted?: 'never_committed' | 'ignored' | 'origin_unknown';
/** `db_ahead` `db_only` under keep_db: also gets the DB-wins write. */
keepDbWrite?: true;
/** `db_ahead` `db_only`/`unproven` under an open full obligation: excluded and counted (`full_skipped_db_ahead`). */
@@ -148,7 +148,7 @@ function afterHold(s: SyncPathState): Matched {
if (s.mode === 'committed' && s.present) return { cls: 'kept', settled: true, action: 'none' };
if (!s.present) {
if (s.originEvidence && s.originEvidence !== 'committed') return { cls: 'delete_drift', settled: false, action: 'hold', side: 'deleted', state: 'file_gone',
- uncommitted: s.originEvidence === 'ignored' ? 'ignored' : 'never_committed' };
+ uncommitted: s.originEvidence === 'unknown' ? 'origin_unknown' : s.originEvidence };
return proof ? { cls: 'delete', settled: false, action: 'delete' } : { cls: 'delete_drift', settled: false, action: 'hold', side: 'deleted', state: 'file_gone' };
}
}
diff --git a/src/core/persistence/sync-holds.ts b/src/core/persistence/sync-holds.ts
index 45a911db03..9217d05f37 100644
--- a/src/core/persistence/sync-holds.ts
+++ b/src/core/persistence/sync-holds.ts
@@ -117,7 +117,7 @@ export interface PreparationStallMeta {
}
export type GitHoldReason = InvalidFrontmatterReason | 'rename_source_changed' | 'explicit_id_conflict' | FenceReason | OriginConflictReason | PageIdentityHoldReason
| 'symlink_in_repo' | 'symlink_outside_root' | 'symlink_dangling' | 'symlink_loop' | 'permission_denied' | 'not_regular_file' | 'skip_worktree' | 'deleted_locally'
- | 'not_utf8' | 'control_character' | 'never_committed' | 'ignored';
+ | 'not_utf8' | 'control_character' | 'never_committed' | 'ignored' | 'origin_unknown';
/** GBRA-130: why a `page_identity_changed` hold's path has no page sync may write (A-17, B-3, B-4). */
export type PageIdentityHoldReason = 'several_tombstones' | 'spelling' | 'identity_differs';
/** #6712 PR 4b: the sides a `file_drift` Decision can be about, and the states of a deleted side (design v3.2 §4). */
@@ -681,7 +681,8 @@ function deletedDriftFix(record: Pick<GitHoldRecord, 'source_id' | 'path' | 'met
const preview = (prefer: 'database' | 'file') => heldDriftPreviewArgv(source, 'deleted', state, prefer, record.path);
const verify = { argv: ['gbrain', 'sources', 'status', source, '--json'] };
const uncommitted = state === 'file_gone' && (record.meta.reason === 'never_committed' || record.meta.reason === 'ignored');
- const what = uncommitted ? `${record.path} is gone, but Git never committed it${record.meta.reason === 'ignored' ? ' (.gitignore excludes it)' : ''}, so its absence is no evidence of a deletion and sync kept page ${slug} instead of deleting it (#7130). Put the file back and commit it (un-ignore it first) to keep the page file-backed. `
+ const what = state === 'file_gone' && record.meta.reason === 'origin_unknown' ? `${record.path} is gone, and Git could not show whether a commit held it (its history read did not finish), so sync kept page ${slug} instead of deleting it (#7130). The --held preview reads the whole history and names the file's provenance. `
+ : uncommitted ? `${record.path} is gone, but Git never committed it${record.meta.reason === 'ignored' ? ' (.gitignore excludes it)' : ''}, so its absence is no evidence of a deletion and sync kept page ${slug} instead of deleting it (#7130). Put the file back and commit it (un-ignore it first) to keep the page file-backed. `
: state === 'tombstone_edited' ? `Page ${slug} was deleted${revision} and ${record.path} then changed, so sync held the file instead of restoring the page or dropping the edit. `
: state === 'purged_differs' ? `The page of ${record.path} was purged and the file differs from what the brain held, so sync held the file instead of importing it as a new page. `
: `${record.path} is gone from the last commit but page ${slug} changed${revision}, so sync held the deletion instead of removing a page that changed. `;
diff --git a/src/core/persistence/sync-pass-apply.ts b/src/core/persistence/sync-pass-apply.ts
index cb4604a622..268634cc59 100644
--- a/src/core/persistence/sync-pass-apply.ts
+++ b/src/core/persistence/sync-pass-apply.ts
@@ -304,7 +304,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) {
- const why = r.uncommitted === 'ignored' ? '.gitignore excludes it, so Git never kept it' : 'no commit in its history holds it (or Git could not show one)';
+ 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 } : {}) },
message: `${path}: the file is gone, but ${why}, so its absence is no evidence that page ${entry.slug} was deleted; sync held it and kept the page instead of deleting it (#7130); the rest of the source synced.` });
} else if (r.cls === 'delete_drift') {
diff --git a/test/sync-origin-unknown-hold-gbra133.test.ts b/test/sync-origin-unknown-hold-gbra133.test.ts
new file mode 100644
index 0000000000..5a46d8d78a
--- /dev/null
+++ b/test/sync-origin-unknown-hold-gbra133.test.ts
@@ -0,0 +1,32 @@
+/**
+ * GBRA-133 (600k soak): a missing file whose Git history read did not answer (`unknown` origin evidence) was held as
+ * `never_committed`, and its hold said "Git never committed it", so thousands of files the history did hold read as files
+ * Git never saw. The hold now carries `origin_unknown` and says Git could not show whether a commit held the file; the page
+ * is still kept.
+ */
+import { describe, expect, test } from 'bun:test';
+import { createHash } from 'node:crypto';
+import { classifySyncPath, type SyncPathState } from '../src/core/persistence/sync-classify.ts';
+import { gitHoldFix } from '../src/core/persistence/sync-holds.ts';
+
+const sha = (s: string) => createHash('sha256').update(s).digest('hex');
+const gone: SyncPathState = { mode: 'committed', tree: null, level: null, present: false, dirty: null, diskOid: null,
+ page: { live: true, revision: 'R1', originMatches: true }, record: { blobOids: ['A'], revision: 'R1', parserSame: true },
+ attested: null, levelSha256: sha('A'), published: false, hold: null, marker: null, baseline: 'A', spelling: false, episodeUnsatisfied: false, keepDb: false, openWork: false };
+
+describe('GBRA-133: an unread origin is not reported as never committed', () => {
+ test('the classifier holds the page with the evidence it read', () => {
+ expect(classifySyncPath({ ...gone, originEvidence: 'unknown' })).toMatchObject({ cls: 'delete_drift', action: 'hold', state: 'file_gone', uncommitted: 'origin_unknown' });
+ expect(classifySyncPath({ ...gone, originEvidence: 'never_committed' })).toMatchObject({ cls: 'delete_drift', uncommitted: 'never_committed' });
+ expect(classifySyncPath({ ...gone, originEvidence: 'ignored' })).toMatchObject({ cls: 'delete_drift', uncommitted: 'ignored' });
+ expect(classifySyncPath({ ...gone, originEvidence: 'committed' })).toMatchObject({ cls: 'delete', action: 'delete' });
+ });
+
+ test("the hold's next step says the history read did not answer", () => {
+ const fix = (reason: 'origin_unknown' | 'never_committed') => gitHoldFix({ source_id: 'source-a', path: 'notes/a.md', slug: 'notes/a', code: 'file_drift',
+ meta: { side: 'deleted', state: 'file_gone', reason } } as Parameters<typeof gitHoldFix>[0]).why;
+ expect(fix('origin_unknown')).toContain('Git could not show whether a commit held it');
+ expect(fix('origin_unknown')).not.toContain('never committed');
+ expect(fix('never_committed')).toContain('Git never committed it');
+ });
+});