Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(#6712 PR 4b): the pass keeps working-tree imports by provenance (keptWorkingTreePages) and reports working_tree_kept; 5459 step 5 held per design §2.3 row 6

garrytan069bebb1614e
diff --git a/src/core/persistence/sync-classify.ts b/src/core/persistence/sync-classify.ts
index fb1d84f32b..115d026645 100644
--- a/src/core/persistence/sync-classify.ts
+++ b/src/core/persistence/sync-classify.ts
@@ -28,7 +28,7 @@ export interface SyncPathState {
tree: string | null;
/** `L(p)`: committed mode `T[p]`; working mode the physical bytes' blob id (CRLF-folded / LFS-resolved to `T[p]` when clean); null = absent. */
level: string | null;
- /** `workingTreeFilePresent`. */
+ /** `workingTreeFilePresent`; committed mode, `L = absent`: false for a page whose import provenance is the Git blob (`keptWorkingTreePages`). */
present: boolean;
/** Committed mode, `p ∈ T`: the candidate dirtiness; null when the pass did not probe it (only paths settled without it). */
dirty: SyncDirtiness | null;
diff --git a/src/core/persistence/sync-pass-run.ts b/src/core/persistence/sync-pass-run.ts
index b1e55f1145..eba8ae35ea 100644
--- a/src/core/persistence/sync-pass-run.ts
+++ b/src/core/persistence/sync-pass-run.ts
@@ -457,11 +457,12 @@ export async function runSyncPass(engine: BrainEngine, input: SyncPassInput): Pr
};
const identityDowngrades: DowngradedRename[] = [];
const fileRefusals = new Map<string, SyncFileRefusal>();
+ const keptCount = () => lastLevel?.paths.filter(entry => entry.result.cls === 'kept').length ?? 0;
const result = (status: SyncResult['status'], reason?: SyncResult['reason']): SyncResult => ({ status, fromCommit: remote ? null : context.source.last_commit, toCommit: remote ? '' : head,
added: counts.added, modified: counts.modified, deleted: counts.deleted, renamed: counts.renamed, chunksCreated: counts.chunks, embedded: 0, pagesAffected: [],
filesImported: sliceBase.pages, bankedFiles: sliceBase.pages, waived: { imports: counts.waivedImports, deletes: counts.waivedDeletes }, prescreened: 0,
...(collisions.length ? { slugCollisions: collisions } : {}), ...(fileRefusals.size ? { fileRefusals: [...fileRefusals.values()] } : {}), ...(identityDowngrades.length ? { identityDowngrades } : {}), ...(inherited.length ? { inherited_options: inherited } : {}), ...(reason ? { reason } : {}),
- ...(sizeStates ? { size_states: sizeStates } : {}), ...(legacySkips.contextualMode || legacySkips.canonicalBytes ? { legacySkips: { ...legacySkips } } : {}),
+ ...(sizeStates ? { size_states: sizeStates } : {}), ...(keptCount() ? { working_tree_kept: keptCount() } : {}), ...(legacySkips.contextualMode || legacySkips.canonicalBytes ? { legacySkips: { ...legacySkips } } : {}),
pass: { pass_id: passId, kind, round: value.telemetry.round, outcome: value.telemetry.outcome, stop_reason: value.telemetry.stop_reason, candidates: candidatesFirst,
settled: S.size + yieldSettled, remaining: value.telemetry.remaining, not_converged_streak: value.obligations.not_converged_streak } });
try {
diff --git a/src/core/persistence/sync-pass.ts b/src/core/persistence/sync-pass.ts
index a4a9c5fecc..c457fe2759 100644
--- a/src/core/persistence/sync-pass.ts
+++ b/src/core/persistence/sync-pass.ts
@@ -98,7 +98,7 @@ export interface ShadowLevel {
/** A page of the source with the import-record fields the classifier reads; `arm1` / `attested_hash` (`A`) are filled for the pages that need a proof. */
interface PageRow { id: number | string; slug: string; source_path: string; revision: string; deleted: boolean; request_id: string | null;
- record: (Pick<SyncImportProvenance, 'origin' | 'blob_oid' | 'disk_blob_oid' | 'revision' | 'parser'> & { full_episode?: string | null }) | null; arm1: boolean | null; attested_hash: string | null }
+ record: (Pick<SyncImportProvenance, 'origin' | 'blob_oid' | 'disk_blob_oid' | 'revision' | 'parser' | 'working'> & { full_episode?: string | null }) | null; arm1: boolean | null; attested_hash: string | null }
const recordOids = (record: PageRow['record']): string[] =>
record ? [record.blob_oid, record.disk_blob_oid].filter((oid): oid is string => typeof oid === 'string' && oid.length > 0) : [];
@@ -128,16 +128,16 @@ async function readPages(exec: Exec, kind: 'postgres' | 'pglite', sourceId: stri
p.revision_write_request_id::text AS request_id,
c.completed_keys IS NOT NULL AS has_record, c.completed_keys->0->>'origin' AS rec_origin, c.completed_keys->0->>'blob_oid' AS rec_blob_oid,
c.completed_keys->0->>'disk_blob_oid' AS rec_disk_blob_oid, c.completed_keys->0->>'revision' AS rec_revision, c.completed_keys->0->'parser' AS rec_parser,
- c.completed_keys->0->>'full_episode' AS rec_full_episode
+ c.completed_keys->0->>'full_episode' AS rec_full_episode, (c.completed_keys->0->'working')::text AS rec_working
FROM pages p LEFT JOIN op_checkpoints c ON c.op=$2 AND c.fingerprint=$3||p.id::text
WHERE p.source_id=$1 AND p.source_path IS NOT NULL`;
const params = [sourceId, SYNC_IMPORT_PROVENANCE_OP, `${sourceId}:${incarnation}:`];
type Raw = Omit<PageRow, 'record' | 'arm1' | 'attested_hash'> & { has_record: boolean; rec_origin: string | null; rec_blob_oid: string | null;
- rec_disk_blob_oid: string | null; rec_revision: string | null; rec_parser: SyncImportProvenance['parser'] | null; rec_full_episode: string | null };
+ rec_disk_blob_oid: string | null; rec_revision: string | null; rec_parser: SyncImportProvenance['parser'] | null; rec_full_episode: string | null; rec_working: string | null };
const rows: PageRow[] = [];
- const take = (page: Raw[]) => { for (const { has_record, rec_origin, rec_blob_oid, rec_disk_blob_oid, rec_revision, rec_parser, rec_full_episode, ...row } of page) rows.push({ ...row, arm1: null, attested_hash: null,
+ const take = (page: Raw[]) => { for (const { has_record, rec_origin, rec_blob_oid, rec_disk_blob_oid, rec_revision, rec_parser, rec_full_episode, rec_working, ...row } of page) rows.push({ ...row, arm1: null, attested_hash: null,
record: has_record ? { origin: rec_origin ?? '', blob_oid: rec_blob_oid ?? undefined, disk_blob_oid: rec_disk_blob_oid, revision: rec_revision ?? undefined, parser: rec_parser ?? undefined,
- full_episode: rec_full_episode } : null }); };
+ full_episode: rec_full_episode, ...(rec_working === 'true' || rec_working === 'false' ? { working: rec_working === 'true' } : {}) } : null }); };
if (kind === 'postgres') { take(await exec.executeRaw<Raw>(select, params)); return { rows, statements: 1 }; }
let after = 0, statements = 0;
for (;;) {
@@ -439,8 +439,11 @@ export async function readShadowLevel(engine: BrainEngine, input: { sourceId: st
const row = byOrigin.get(path);
const level = levelOf(path, probe);
// Presence decides only rows 4-6 (a level of absent); a committed path in T is not read here (Dp covers it).
- const presentNow = mode === 'working' ? level !== null : level === null ? readPresent(root, path, scope) : true;
const record = row?.record ?? null;
+ // #5459 (`keptWorkingTreePages`): a page whose import provenance is the pinned Git blob follows Git, so a lingering
+ // untracked copy of its file does not keep it.
+ const fromGit = record?.working === false || (record?.working === undefined && !!record?.blob_oid);
+ const presentNow = mode === 'working' ? level !== null : level === null ? !fromGit && readPresent(root, path, scope) : true;
const recordBlobOids = recordOids(record);
const attested = row && (row.arm1 || row.attested_hash) ? { hash: row.attested_hash ?? null, arm1: row.arm1 === true } : null;
const hold = holdByGitPath.get(path);
diff --git a/test/sync-full-untracked-import-5459.test.ts b/test/sync-full-untracked-import-5459.test.ts
index 51f5bad415..f30ae49ce5 100644
--- a/test/sync-full-untracked-import-5459.test.ts
+++ b/test/sync-full-untracked-import-5459.test.ts
@@ -105,11 +105,13 @@ describe('--full tree walk keeps pages imported from untracked working-tree file
expect(await live()).toEqual(['notes/base', 'notes/scratch']);
expect(result.working_tree_kept).toBe(1);
- // 5. The untracked file is gone: nothing backs the page any more, so the walk deletes it, and the counter is absent.
+ // 5. The untracked file is gone: nothing backs the page any more, and the counter is absent. #6712 PR 4b (design v3.2
+ // §2.3 row 6, `delete_drift`): step 3's maintenance write moved the page with no proof, so the deletion is held
+ // file_drift (side deleted, state file_gone) for a person's Decision instead of soft-deleting a page that changed.
r.remove('scratch');
result = await full();
- expect(await live()).toEqual(['notes/base']);
- expect((await page('notes/scratch'))!.deleted_at).not.toBeNull();
+ expect(await live()).toEqual(['notes/base', 'notes/scratch']);
+ expect((result.held ?? []).map(item => [item.path, item.code, item.side, item.state, item.slug])).toEqual([['notes/scratch.md', 'file_drift', 'deleted', 'file_gone', 'notes/scratch']]);
expect(result.working_tree_kept).toBeUndefined();
}
}), 300_000);