Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge remote-tracking branch 'origin/capy/6712-pr4b-gate-e2' into capy/6712-pr4b-gate-e

garrytan609e6e5c93f2
diff --cc src/core/persistence/sync-pass-run.ts
index 7cefc7edd3,595a93ad10..b1e55f1145
--- a/src/core/persistence/sync-pass-run.ts
+++ b/src/core/persistence/sync-pass-run.ts
@@@ -24,9 -25,9 +25,9 @@@ import { getWriteRequestById } from './
import type { WriteRequest } from './model.ts';
import { managedSyncWriteDiagnostic } from './sync-write-diagnostic.ts';
import { recordedStop, replaysUnchangedRefusal } from './sync-stop-class.ts';
- import { adoptLegacyPage, syncExcludePatterns, syncGit, type LegacyIdentity, type ManagedSyncContext, type SyncDiscovery, type SyncEntry, type SyncFileRefusal, type SyncSlugCollision } from './sync-discovery.ts';
-import { adoptLegacyPage, assertTakeoverIdentity, incomingId, syncExcludePatterns, syncGit, type LegacyIdentity, type ManagedSyncContext, type SyncDiscovery, type SyncEntry, type SyncSlugCollision } from './sync-discovery.ts';
++import { adoptLegacyPage, assertTakeoverIdentity, incomingId, syncExcludePatterns, syncGit, type LegacyIdentity, type ManagedSyncContext, type SyncDiscovery, type SyncEntry, type SyncFileRefusal, type SyncSlugCollision } from './sync-discovery.ts';
import { assertSyncDispatchActive, type SyncAuthority, type SyncProcessingOptions } from './sync-authority.ts';
-import type { PassStamp, SyncCursorOptions, SyncIntent } from './sync-prepare.ts';
+import { recordPassFenceTrend, type PassStamp, type SyncCursorOptions, type SyncIntent } from './sync-prepare.ts';
import { OPEN_AT_STAMP_CAP, passFingerprint, readPassRow, SYNC_ORIGIN_DELETED_OP, writePassRow, type ManagedSyncPassValue, type PassEpisode,
type PassKind, type PassOutcome, type SyncSelection } from './sync-pass-row.ts';
import { readSyncAdmission, type SyncAdmission } from './sync-admission.ts';
@@@ -162,8 -162,8 +164,8 @@@ async function batchEntries(engine: Bra
}
}
const slugs = [...new Set([...slugOf.values()].filter(Boolean))];
- const holders = new Map((slugs.length ? await engine.executeRaw<{ id: number | string; slug: string; source_path: string | null; revision: string; deleted: boolean; unbound: boolean }>(
- `SELECT id, slug, source_path, knowledge_revision::text AS revision, deleted_at IS NOT NULL AS deleted, ${databaseOnlyPageSql('pages')} AS unbound FROM pages WHERE source_id=$1 AND slug=ANY($2::text[])`, [level.sourceId, slugs]) : [])
- const holders = new Map((slugs.length ? await engine.executeRaw<{ id: number | string; slug: string; source_path: string | null; revision: string; deleted: boolean; fm_id: string | null }>(
- "SELECT id, slug, source_path, knowledge_revision::text AS revision, deleted_at IS NOT NULL AS deleted, frontmatter->>'id' AS fm_id FROM pages WHERE source_id=$1 AND slug=ANY($2::text[])", [level.sourceId, slugs]) : [])
++ const holders = new Map((slugs.length ? await engine.executeRaw<{ id: number | string; slug: string; source_path: string | null; revision: string; deleted: boolean; unbound: boolean; fm_id: string | null }>(
++ `SELECT id, slug, source_path, knowledge_revision::text AS revision, deleted_at IS NOT NULL AS deleted, ${databaseOnlyPageSql('pages')} AS unbound, frontmatter->>'id' AS fm_id FROM pages WHERE source_id=$1 AND slug=ANY($2::text[])`, [level.sourceId, slugs]) : [])
.map(page => [page.slug, page]));
const gitPathOfOrigin = (origin: string) => level.slugMode === 'source-root' && level.scope ? `${level.scope}/${syncOriginPath(origin)}` : syncOriginPath(origin);
// #6887: a both-moved import imports when the page still holds what its recorded disk blob imports (sync-screen.ts driftBaselineContent).
@@@ -202,13 -211,14 +213,15 @@@
const paths = entryPaths(level, winner.path);
const base = { ...paths, action: 'import' as const, working: working(winner), level: winner.state.level, slug, ...legacySlugs.get(winner.path) };
if (holder) {
+ // #6729: a file whose frontmatter id differs from the page's is another document; it inherits nothing (refused before any write).
+ assertTakeoverIdentity(discovery, named(winner), holder);
// A live page at the slug with no recorded origin (written straight to the database, or by an older gbrain) attests
// neither side: the import is guarded as drift of unknown side, so the freeze imports it only as a proven no-op and
- // otherwise holds file_drift (as discovery's tree walk guards it, sync-prescreen.ts).
+ // otherwise holds file_drift (as discovery's tree walk guards it, sync-prescreen.ts). A page written while the source was
+ // unbound (#5254) is not guarded: its preparation refuses the file that now occupies its path (source_changed).
entries.push({ ...base, pageId: Number(holder.id), revision: holder.revision,
...(holder.source_path !== null ? { renameFrom: { sourcePath: holder.source_path, slug, pageId: Number(holder.id), revision: holder.revision } } : {}),
- ...(holder.source_path === null && !holder.deleted ? { drift: 'unknown' as const } : {}) });
+ ...(holder.source_path === null && !holder.deleted && !holder.unbound ? { drift: 'unknown' as const } : {}) });
if (holderPath !== null && deleteEntries.delete(holderPath)) renamed.add(holderPath);
continue;
}