Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(persistence): the withhold stamp compares the page revision in its own transaction; file_absent stamps in groups (#7618)

garrytana65597bede83
diff --git a/src/core/persistence/git-conversion.ts b/src/core/persistence/git-conversion.ts
index 03af8610bb..1d9ff3c090 100644
--- a/src/core/persistence/git-conversion.ts
+++ b/src/core/persistence/git-conversion.ts
@@ -630,8 +630,9 @@ async function withholdGroups(engine: BrainEngine, plan: GitConversionPlan, prev
const stamp = (items: WithholdItem[]) => engine.transaction(async tx => {
await declarePersistenceProtocol(tx);
for (const item of items) {
- await tx.executeRaw(`UPDATE pages SET database_only_reason=$2, withheld_source_path=COALESCE(NULLIF(source_path,''), withheld_source_path),
- source_path=NULL, source_uri=NULL WHERE id=$1::bigint`, [item.id, item.declared]);
+ const [stamped] = await tx.executeRaw<{ id: string }>(`UPDATE pages SET database_only_reason=$2, withheld_source_path=COALESCE(NULLIF(source_path,''), withheld_source_path),
+ source_path=NULL, source_uri=NULL WHERE id=$1::bigint AND deleted_at IS NULL AND knowledge_revision::text IS NOT DISTINCT FROM $3 RETURNING id`, [item.id, item.declared, item.revision]);
+ if (!stamped) throw previewChangedError(plan.preview.preview_hash, previewCommand);
}
});
const committed = plan.withhold.filter(item => item.kind === 'file_committed');
@@ -655,8 +656,11 @@ async function withholdGroups(engine: BrainEngine, plan: GitConversionPlan, prev
onGroup({ pages: group.length, commits: commits.length });
}
const absent = plan.withhold.filter(item => item.kind === 'file_absent');
- for (const item of absent) await assertUnchanged(item);
- if (absent.length) { await stamp(absent); onGroup({ pages: absent.length, commits: commits.length }); }
+ for (let start = 0; start < absent.length; start += CONVERSION_GROUP_MAX) {
+ const group = absent.slice(start, start + CONVERSION_GROUP_MAX);
+ await stamp(group);
+ onGroup({ pages: group.length, commits: commits.length });
+ }
return { pages: plan.withhold.length, commits };
}
diff --git a/test/git-canonical-conversion-g8a.test.ts b/test/git-canonical-conversion-g8a.test.ts
index 346ac0e56f..471b61a31f 100644
--- a/test/git-canonical-conversion-g8a.test.ts
+++ b/test/git-canonical-conversion-g8a.test.ts
@@ -618,6 +618,21 @@ for (const backend of testBackends()) describe(`[${backend}] G8a: sources canoni
expect((await revisions(engine))['notes/untracked']).toBe(before['notes/untracked']);
}, { databaseUrl, setup }), 180_000);
+ test('#7618: a private page whose committed file was deleted from the working tree only withholds it: the removal is committed', () => managedBrain(async brain => {
+ const { engine, root } = brain;
+ await committedPrivatePage(brain);
+ await databaseOnlyEdit(engine, 'notes/private', 'A private note, edited in the database.');
+ rmSync(join(root, 'notes/private.md'));
+ const before = await pageRow(engine, 'notes/private'), base = git(root, 'rev-parse', 'HEAD');
+ const { preview } = await planGitConversion(engine, 'default');
+ expect(preview).toMatchObject({ withhold: { count: 1, by: { file_committed: 1, file_absent: 0 } }, discard: { count: 0 } });
+ expect(await applyGitConversion(engine, 'default', preview.preview_hash, PROCESSING)).toMatchObject({ status: 'converted', withheld: { pages: 1 }, after: { remaining: 0 } });
+ expect(conversionCommits(root, base)).toEqual([{ subject: expect.any(String), paths: ['notes/private.md'] }]);
+ expect(atHead(root, 'notes/private.md')).toBe('');
+ expect(git(root, 'status', '--porcelain')).toBe('');
+ expect(await pageRow(engine, 'notes/private')).toEqual({ body: before.body, deleted: false, source_path: null, withheld: 'notes/private.md', reason: 'private' });
+ }, { databaseUrl, setup }), 180_000);
+
test('#7618: a file_absent withhold refuses preview_changed when the private page moved after the preview, and stamps nothing', () => managedBrain(async brain => {
const { engine, root } = brain;
await privateRemovedByHand(brain);