Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

refactor(#6712 PR 4b lane C): delete resumableSliceStage and readSyncSlice (only a non-company cursor run resumed a path-slice record; the dry run never did)

garrytanc16b8bd00f38
diff --git a/src/core/persistence/sync-discovery.ts b/src/core/persistence/sync-discovery.ts
index 60a4d17b8c..7f495b67a7 100644
--- a/src/core/persistence/sync-discovery.ts
+++ b/src/core/persistence/sync-discovery.ts
@@ -30,7 +30,7 @@ import { holdBasisMoved, holdRescreenDue, readGitHoldRetryPaths, readGitSourceHo
import { readBlobContents, readTreeBlobs, SYNC_READ_BOUND } from './sync-blobs.ts';
import { gitChildEnv } from '../git-env.ts';
import { movedDriftHolds, prescreenSyncEntries, type SyncDriftSide } from './sync-prescreen.ts';
-import { readSyncSlice, sliceEntries, syncCursorOptions, type SyncSliceCursor, type SyncSliceState } from './sync-slices.ts';
+import { sliceEntries, type SyncSliceCursor, type SyncSliceState } from './sync-slices.ts';
/** The page an import takes over from its previous origin: a Git rename, or a file that replaced a vanished origin at the same slug. */
export interface SyncRename { sourcePath: string; slug: string; pageId: number; revision: string; }
@@ -83,10 +83,6 @@ export async function syncExcludePatterns(engine: Pick<BrainEngine, 'getConfig'>
return [...extra, ...(await engine.getConfig('sync.exclude') ?? '').split(/[\n,]/).map(v => v.trim()).filter(Boolean)]
.map(v => v.endsWith('/') ? `${v}**` : v);
}
-/** Whether `commit` is still reachable in the checkout (a sliced target pinned before a history rewrite is not). */
-function commitExists(gitRoot: string, commit: string): boolean {
- try { syncGit(gitRoot, ['cat-file', '-e', `${commit}^{commit}`]); return true; } catch { return false; }
-}
export function syncGit(root: string, args: string[]): string {
return execFileSync('git', ['-c', 'core.quotepath=false', '-C', root, ...args],
{ env: gitChildEnv(), encoding: 'utf8', timeout: 30_000, maxBuffer: 32 * 1024 ** 2, stdio: ['ignore', 'pipe', 'pipe'] });
@@ -268,16 +264,6 @@ export function stagedSyncTarget(gitRoot: string, from: string, target: string,
return good < 0 ? { oversized: commits[0] ?? target } : { commit: commits[good]!, first: commits[0]! };
}
-/**
- * #6349 (P4.4): an unfinished path-sliced target of this source under these exact options continues where its last
- * slice checkpointed, pinned at the same target; a target history no longer holds starts over from HEAD.
- */
-async function resumableSliceStage(engine: BrainEngine, opts: SyncOpts, gitRoot: string, sourceId: string, incarnation: string):
- Promise<{ target: string; head: string; slice: Pick<SyncSliceCursor, 'phase' | 'after'> } | null> {
- const resume = await readSyncSlice(engine, sourceId, incarnation, syncCursorOptions(opts));
- if (!resume || !commitExists(gitRoot, resume.target)) return null;
- return { target: resume.target, head: syncGit(gitRoot, ['rev-parse', 'HEAD']).trim(), slice: { phase: resume.phase, after: resume.after } };
-}
/**
* #5459 (P4.5): "not in the Git tree" is not "deleted" for a page imported from the working tree. The durable import
* provenance (not the request intent, which compaction nulls) says where the bytes came from; a working-tree import
@@ -308,10 +294,6 @@ export async function discoverManagedSync(engine: BrainEngine, opts: SyncOpts, c
stage?: { target: string; head: string; slice?: Pick<SyncSliceCursor, 'phase' | 'after'> }, walk = false): Promise<SyncDiscovery> {
const { binding, root, gitRoot, sourceId, incarnation, source } = context ?? await resolveManagedSyncContext(engine, opts);
const company = currentCompanyBrainSync(sourceId);
- if (!company && !stage && !opts.dryRun) {
- const resume = await resumableSliceStage(engine, opts, gitRoot, sourceId, incarnation);
- if (resume) return discoverManagedSync(engine, opts, context ?? { binding, root, gitRoot, sourceId, incarnation, source }, resume, walk);
- }
const { scope, slugMode, nativeRoot, nativeGitRoot, eligible, sourcePath } = await loadSyncEligibility(engine, { root, gitRoot, sourceId, source }, opts, !!company);
const originScope: SyncOriginScope = { sourceId, root, scope, slugMode };
const target = stage?.target ?? company?.plan.revision?.commit ?? syncGit(gitRoot, ['rev-parse', 'HEAD']).trim();
diff --git a/src/core/persistence/sync-slices.ts b/src/core/persistence/sync-slices.ts
index 9b7ebe66ad..f70e16c9d5 100644
--- a/src/core/persistence/sync-slices.ts
+++ b/src/core/persistence/sync-slices.ts
@@ -29,13 +29,6 @@ export function syncCursorOptions(opts: SyncOpts): SyncCursorOptions {
}
const sliceFingerprint = (sourceId: string, incarnation: string, options: SyncCursorOptions) => `${sourceId}:${incarnation}:${digest(options)}`;
-export async function readSyncSlice(engine: Exec, sourceId: string, incarnation: string, options: SyncCursorOptions): Promise<SyncSliceCursor | null> {
- const [row] = await engine.executeRaw<{ record: SyncSliceCursor }>('SELECT completed_keys->0 AS record FROM op_checkpoints WHERE op=$1 AND fingerprint=$2',
- [SYNC_SLICE_OP, sliceFingerprint(sourceId, incarnation, options)]);
- const record = row?.record;
- if (!record || (record.phase !== 'import' && record.phase !== 'delete') || typeof record.target !== 'string' || typeof record.head !== 'string') return null;
- return { phase: record.phase, after: typeof record.after === 'string' ? record.after : null, head: record.head, target: record.target };
-}
export async function writeSyncSlice(tx: Exec, sourceId: string, incarnation: string, options: SyncCursorOptions, slice: SyncSliceCursor): Promise<void> {
await tx.executeRaw(`INSERT INTO op_checkpoints(op,fingerprint,completed_keys) VALUES($1,$2,$3::text::jsonb)
ON CONFLICT(op,fingerprint) DO UPDATE SET completed_keys=EXCLUDED.completed_keys,updated_at=now()`,