Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(#6712 PR 4b gate E1): the pass leaves Windows-unstorable colon paths out of the level with discovery's named per-file refusal (fileRefusals), and refuses both sides of a rename touching one, so the page keeps its identity (#5032)

garrytan189055f4e019
diff --git a/src/core/persistence/sync-discovery.ts b/src/core/persistence/sync-discovery.ts
index 7f495b67a7..2eb8441740 100644
--- a/src/core/persistence/sync-discovery.ts
+++ b/src/core/persistence/sync-discovery.ts
@@ -74,8 +74,15 @@ export interface SyncDiscovery { binding: WorktreeBinding; root: string; gitRoot
/** #6729: inexact Git renames split into a delete plus an add (origin form); recorded after the run commits. */
identityDowngrades?: DowngradedRename[]; }
/** #5032: the per-file refusal text for a Windows-unstorable ':' path, by the side sync skipped. */
-const COLON_REFUSAL_MESSAGES = { import: (path: string) => `${path} has a ':' in its name, which Windows cannot store; sync skipped it.`,
- delete: (path: string) => `${path} has a ':' in its name, which Windows cannot reconcile; sync skipped its deletion and its page stays live.` };
+export const COLON_REFUSAL_MESSAGES = { import: (path: string) => `${path} has a ':' in its name, which Windows cannot store; sync skipped it.`,
+ delete: (path: string) => `${path} has a ':' in its name, which Windows cannot reconcile; sync skipped its deletion and its page stays live.`,
+ rename: (path: string, from: string, to: string) => `${path} is one side of the rename ${from} -> ${to}, which Windows cannot reconcile; sync skipped both sides so the page keeps its identity.` };
+/** #5032: the named refusal of one Windows-unstorable ':' path (discovery and the pass, sync-pass.ts). */
+export function colonFileRefusal(sourceId: string, path: string, message: string): SyncFileRefusal {
+ return { path, code: 'colon_slug_windows_write_through', message,
+ suggestion: `Rename it without ':' on a macOS or Linux checkout and commit, then run gbrain sync --source ${sourceId} --no-pull.`,
+ docs: ERROR_CATALOGUE.colon_slug_windows_write_through.docs };
+}
export interface ManagedSyncContext { binding: WorktreeBinding; root: string; gitRoot: string; sourceId: string; incarnation: string;
source: { last_commit: string | null; config: Record<string, unknown> }; }
/** The persisted `sync.exclude` globs (plus a run's `--exclude`), as discovery matches them against a path relative to the source root. */
@@ -323,9 +330,7 @@ export async function discoverManagedSync(engine: BrainEngine, opts: SyncOpts, c
// keeps its identity until the change is synced from macOS or Linux.
const refused = new Map<string, SyncFileRefusal>();
const record = (path: string, message: string) => {
- if (eligible(path)) refused.set(path, { path, code: 'colon_slug_windows_write_through', message,
- suggestion: `Rename it without ':' on a macOS or Linux checkout and commit, then run gbrain sync --source ${sourceId} --no-pull.`,
- docs: ERROR_CATALOGUE.colon_slug_windows_write_through.docs });
+ if (eligible(path)) refused.set(path, colonFileRefusal(sourceId, path, message));
};
const refuse = (path: string, action: SyncEntry['action'] = 'import') => {
if (!isWindowsColonTarget(path)) return false;
@@ -342,7 +347,7 @@ export async function discoverManagedSync(engine: BrainEngine, opts: SyncOpts, c
const putRename = (rename: SyncManifest['renamed'][number], working = false) => {
if (isWindowsColonTarget(rename.from) || isWindowsColonTarget(rename.to)) {
for (const path of [rename.from, rename.to]) {
- record(path, `${path} is one side of the rename ${rename.from} -> ${rename.to}, which Windows cannot reconcile; sync skipped both sides so the page keeps its identity.`);
+ record(path, COLON_REFUSAL_MESSAGES.rename(path, rename.from, rename.to));
}
return;
}
diff --git a/src/core/persistence/sync-pass-run.ts b/src/core/persistence/sync-pass-run.ts
index ab2f69160c..b20efd55e2 100644
--- a/src/core/persistence/sync-pass-run.ts
+++ b/src/core/persistence/sync-pass-run.ts
@@ -24,7 +24,7 @@ import { getWriteRequestById } from './journal.ts';
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 SyncSlugCollision } from './sync-discovery.ts';
+import { adoptLegacyPage, 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 { OPEN_AT_STAMP_CAP, passFingerprint, readPassRow, SYNC_ORIGIN_DELETED_OP, writePassRow, type ManagedSyncPassValue, type PassEpisode,
@@ -414,10 +414,11 @@ export async function runSyncPass(engine: BrainEngine, input: SyncPassInput): Pr
await engine.transaction(async tx => { await assertDrainLease(tx, sourceId); await writePassRow(tx, value, { pin }); });
};
const identityDowngrades: DowngradedRename[] = [];
+ const fileRefusals = new Map<string, SyncFileRefusal>();
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 } : {}), ...(identityDowngrades.length ? { identityDowngrades } : {}), ...(inherited.length ? { inherited_options: inherited } : {}), ...(reason ? { reason } : {}),
+ ...(collisions.length ? { slugCollisions: collisions } : {}), ...(fileRefusals.size ? { fileRefusals: [...fileRefusals.values()] } : {}), ...(identityDowngrades.length ? { identityDowngrades } : {}), ...(inherited.length ? { inherited_options: inherited } : {}), ...(reason ? { reason } : {}),
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 {
@@ -503,6 +504,7 @@ export async function runSyncPass(engine: BrainEngine, input: SyncPassInput): Pr
head = value.telemetry.target = level.head;
levelSlugMode = level.slugMode;
lastLevel = level;
+ for (const refusal of level.fileRefusals ?? []) fileRefusals.set(refusal.path, refusal);
value.telemetry.timings_ms = level.timings_ms;
// Design §2.7 (b1): until the incarnation's markers are written (an aborted or failed first pass wrote none), not only on its first row.
if (markersOwed() && !remote) {
diff --git a/src/core/persistence/sync-pass.ts b/src/core/persistence/sync-pass.ts
index 77cda2e1cf..9548c90e18 100644
--- a/src/core/persistence/sync-pass.ts
+++ b/src/core/persistence/sync-pass.ts
@@ -28,7 +28,9 @@ import { loadActivePackForEngine } from '../schema-pack/engine-resolution.ts';
import { currentCompanyBrainSync, getCompanyBrainProfile } from '../company-brain/profile.ts';
import { sha256 } from './digest.ts';
import { sourceMirrorReadOnly } from './mirror-read-only.ts';
-import { readSyncFile, resolveManagedSyncContext, syncExcludePatterns, syncGit, type ManagedSyncContext } from './sync-discovery.ts';
+import { colonFileRefusal, COLON_REFUSAL_MESSAGES, readSyncFile, resolveManagedSyncContext, syncExcludePatterns, syncGit, type ManagedSyncContext, type SyncFileRefusal } from './sync-discovery.ts';
+import { isWindowsColonTarget } from './native-file-target.ts';
+import { confirmedSyncDelta } from '../sync-rename-identity.ts';
import { holdBasisMoved, holdRescreenDue, readGitHoldRetryPaths, readGitSourceHolds, SYNC_IMPORT_PROVENANCE_OP, syncImportParserFor,
type GitHoldRecord, type SyncImportProvenance } from './sync-holds.ts';
import { movedDriftHolds, sameParser } from './sync-prescreen.ts';
@@ -88,6 +90,8 @@ export interface ShadowLevel {
workingCache: WorkingStatCache | null;
/** Live file-backed pages whose origin is eligible: the mass-delete valve's denominator (#2828). */
reconcilable: number;
+ /** #5032: Windows-unstorable ':' paths this level left out, each with its named refusal (`SyncResult.fileRefusals`). */
+ fileRefusals?: SyncFileRefusal[];
timings_ms: Record<string, number>;
statements: number;
}
@@ -181,8 +185,8 @@ async function readOpenWork(exec: Exec, sourceId: string, incarnation: string, w
WHERE r.worktree_id=$1 AND r.source_id=$2 AND e.kind='git' AND e.state IN ('queued','running')`, [worktreeId, sourceId])]);
const pageIds = new Set<number>(), origins = new Set<string>();
for (const row of [...requests, ...effects]) if (row.page_id != null) pageIds.add(Number(row.page_id));
- for (const row of requests) for (const origin of [row.source_path, row.path]) if (origin) origins.add(syncOriginPath(origin));
- for (const row of effects) if (row.path) origins.add(syncOriginPath(row.path));
+ for (const row of requests) for (const origin of [row.source_path, row.path]) if (origin && !isWindowsColonTarget(origin)) origins.add(syncOriginPath(origin));
+ for (const row of effects) if (row.path && !isWindowsColonTarget(row.path)) origins.add(syncOriginPath(row.path));
return { pageIds, origins, statements: 2 };
}
@@ -193,7 +197,7 @@ async function readMarkers(exec: Exec, sourceId: string, incarnation: string): P
const rows = await exec.executeRaw<{ fingerprint: string; value: { kind?: string; blob_oids?: unknown; deletion?: unknown } | null }>(
'SELECT fingerprint, completed_keys->0 AS value FROM op_checkpoints WHERE op=$1 AND starts_with(fingerprint, $2)',
[SYNC_ORIGIN_DELETED_OP, prefix]);
- return new Map(rows.map(row => [syncOriginPath(row.fingerprint.slice(prefix.length)), {
+ return new Map(rows.filter(row => !isWindowsColonTarget(row.fingerprint.slice(prefix.length))).map(row => [syncOriginPath(row.fingerprint.slice(prefix.length)), {
kind: row.value?.kind === 'legacy' ? 'legacy' as const : 'deleted' as const,
blobOids: Array.isArray(row.value?.blob_oids) ? (row.value!.blob_oids as unknown[]).filter((oid): oid is string => typeof oid === 'string') : [],
deletion: typeof row.value?.deletion === 'string' ? row.value.deletion : null }]));
@@ -284,8 +288,11 @@ export async function readShadowLevel(engine: BrainEngine, input: { sourceId: st
const sourceRelative = (gitPath: string) => (scope ? gitPath.slice(scope.length + 1) : gitPath);
// Pure per path and asked several times per path in a round, so each is computed once.
const memo = <T>(fn: (path: string) => T) => { const seen = new Map<string, T>(); return (path: string): T => { let value = seen.get(path); if (value === undefined && !seen.has(path)) seen.set(path, value = fn(path)); return value as T; }; };
- const eligible = memo((gitPath: string) => (!scope || gitPath.startsWith(`${scope}/`)) && !matchesAnyGlob(sourceRelative(gitPath), exclude)
+ const selected = memo((gitPath: string) => (!scope || gitPath.startsWith(`${scope}/`)) && !matchesAnyGlob(sourceRelative(gitPath), exclude)
&& !isReservedSkillBundlePath(slugMode === 'source-root' ? sourceRelative(gitPath) : gitPath) && isSyncable(gitPath, { strategy: strategy as 'markdown', includeHidden }));
+ // #5032: a Windows-unstorable ':' path, and the other side of a rename touching one, take no part in the level.
+ let colonRefused = new Set<string>();
+ const eligible = (gitPath: string) => selected(gitPath) && !isWindowsColonTarget(gitPath) && !colonRefused.has(gitPath);
const originPath = memo((path: string) => syncOriginPath(path));
const originOf = memo((gitPath: string) => originPath(slugMode === 'source-root' && scope ? sourceRelative(gitPath) : gitPath));
const gitPathOf = memo((origin: string) => { const o = originPath(origin); return slugMode === 'source-root' && scope ? `${scope}/${o}` : o; });
@@ -332,6 +339,9 @@ export async function readShadowLevel(engine: BrainEngine, input: { sourceId: st
]);
timings.reads = t();
const [treeAll, index, untrackedPaths] = gitLevel;
+ const colon = await windowsColonRefusals(engine, { sourceId, gitRoot, from: context.source.last_commit, head, tree: treeAll, pages: snapshot.pages, selected,
+ gitPathOf: origin => slugMode === 'source-root' && scope ? `${scope}/${origin}` : origin, sourcePathOf: gitPath => (slugMode === 'source-root' ? sourceRelative(gitPath) : gitPath) });
+ colonRefused = colon.paths;
const tree = new Map<string, GitTreeEntry>([...treeAll].filter(([path]) => eligible(path)));
const untracked = new Set(untrackedPaths);
const { pages, open, markers, passRow, statements } = snapshot;
@@ -344,6 +354,7 @@ export async function readShadowLevel(engine: BrainEngine, input: { sourceId: st
t = timer();
const byOrigin = new Map<string, PageRow>();
for (const row of pages) {
+ if (isWindowsColonTarget(row.source_path)) continue;
const key = gitPathOf(pageOrigin(row));
const prior = byOrigin.get(key);
if (!prior || (prior.deleted && !row.deleted) || (prior.deleted === row.deleted && Number(row.id) > Number(prior.id))) byOrigin.set(key, row);
@@ -508,11 +519,34 @@ export async function readShadowLevel(engine: BrainEngine, input: { sourceId: st
return { sourceId, incarnation, root, gitRoot, scope, slugMode, mode, head, baselineCommit, full: input.full === true, kind: kind.kind, kindBlockers: kind.blockers,
heldRenames: holds.flatMap(hold => hold.meta.rename_from ? [{ path: toGit(hold.path), rename: hold.meta.rename_from }] : []),
releasableHolds: holds.filter(hold => !domain.has(toGit(hold.path))).map(hold => hold.path),
- paths, reconcilable, timings_ms: timings, statements: statements + attestationStatements + 3, pack: pack?.identity ?? null,
+ paths, reconcilable, ...(colon.refusals.size ? { fileRefusals: [...colon.refusals.values()] } : {}), timings_ms: timings, statements: statements + attestationStatements + 3, pack: pack?.identity ?? null,
selection: { exclude: [...exclude].sort(), includeHidden: [...includeHidden].sort(), strategy, srcSubpath: scope || null, mode },
rescreenDue: holds.filter(hold => holdRescreenDue(hold, retry.has(hold.path))).map(hold => toGit(hold.path)), workingCache: hashed?.cache ?? null };
}
+/**
+ * #5032, as discovery refuses them: on Windows a ':' path has no file. Each selected one gets a named refusal and leaves
+ * the level: a file at the target is skipped, a live page whose file left keeps its page, and a Git rename (last_commit to
+ * HEAD) touching one is refused on both sides, so the page keeps its identity until the change syncs from macOS or Linux.
+ * Off Windows, or with no ':' path, nothing is read.
+ */
+async function windowsColonRefusals(engine: BrainEngine, input: { sourceId: string; gitRoot: string; from: string | null; head: string; tree: Map<string, GitTreeEntry>;
+ pages: PageRow[]; selected: (gitPath: string) => boolean; gitPathOf: (origin: string) => string; sourcePathOf: (gitPath: string) => string }): Promise<{ refusals: Map<string, SyncFileRefusal>; paths: Set<string> }> {
+ const refusals = new Map<string, SyncFileRefusal>(), paths = new Set<string>();
+ const colonTree = [...input.tree.keys()].filter(path => isWindowsColonTarget(path));
+ const colonPages = input.pages.filter(row => !row.deleted && isWindowsColonTarget(row.source_path)).map(row => input.gitPathOf(row.source_path.replaceAll('\\', '/')));
+ if (!colonTree.length && !colonPages.length) return { refusals, paths };
+ const refuse = (path: string, message: string) => { paths.add(path); if (input.selected(path)) refusals.set(path, colonFileRefusal(input.sourceId, path, message)); };
+ const delta = input.from && input.from !== input.head ? await confirmedSyncDelta(engine, input.gitRoot, input.from, input.head, { sourceId: input.sourceId, sourcePathOf: input.sourcePathOf }) : null;
+ for (const rename of delta?.status === 'ok' ? delta.manifest.renamed : []) {
+ if (!isWindowsColonTarget(rename.from) && !isWindowsColonTarget(rename.to)) continue;
+ for (const path of [rename.from, rename.to]) refuse(path, COLON_REFUSAL_MESSAGES.rename(path, rename.from, rename.to));
+ }
+ for (const path of colonTree) if (!paths.has(path)) refuse(path, COLON_REFUSAL_MESSAGES.import(path));
+ for (const path of colonPages) if (!paths.has(path)) refuse(path, COLON_REFUSAL_MESSAGES.delete(path));
+ return { refusals, paths };
+}
+
/** `workingTreeFilePresent` (sync-discovery.ts) for a Git-root path: a file that exists, or one that cannot be read (fail closed). */
function readPresent(root: string, gitPath: string, scope: string): boolean {
const path = scope ? gitPath.slice(scope.length + 1) : gitPath;