Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(sync): #6712 PR 4b restore the pass's unchanged-refusal replay helpers

garrytan2e6f806e6325
diff --git a/src/core/persistence/sync-stop-class.ts b/src/core/persistence/sync-stop-class.ts
index 994dd91381..a3117dd17f 100644
--- a/src/core/persistence/sync-stop-class.ts
+++ b/src/core/persistence/sync-stop-class.ts
@@ -9,7 +9,10 @@ import type { WriteRequest } from './model.ts';
import { classifyTerminal } from './terminal-classify.ts';
import { classifySyncFault } from './sync-fault-class.ts';
import { isContentRefusal } from '../import-screen.ts';
+import { sha256 } from './digest.ts';
+import { readSyncFile } from './sync-discovery.ts';
import { VERSION } from '../../version.ts';
+import { pinnedWorktreeConflict } from './sync-page-fault.ts';
/**
* #6712 (#6565): how the run treats a receipt that did not commit, from the terminal classifier: `transport` (a dropped
@@ -59,3 +62,29 @@ export interface RecordedStop { gbrain_version: string | null }
export function replaysContentRefusal(failed: WriteRequest, recorded: { gbrain_version: string | null }, unchanged: () => boolean): boolean {
return isContentRefusal(failed.error_code, failed.error_message) && recorded.gbrain_version === VERSION && unchanged();
}
+
+/**
+ * #6712 PR 3 (L7): whether the next sync replays a page's recorded refusal instead of retrying it, because what decides it
+ * has not changed since this gbrain version recorded it: a content refusal while the file has its frozen bytes, and a pinned
+ * import refused for newer working-tree bytes (`source_changed`) while HEAD is still the run's target and the file still
+ * holds the working-tree bytes that refused (the frozen `rawHash`). Bytes decide, never the
+ * file's mtime against the stop's database timestamp: those are two clocks, and a correction written within their skew
+ * (a filesystem timestamp lags the wall clock by up to a scheduler tick) read as unwritten and replayed the refusal.
+ * Committing the file, editing it or upgrading gbrain retries it. #6712 PR 4b: the pass replays what its last blocked pass
+ * stopped on (sync-pass-run.ts, under sync.holds=fail).
+ */
+export function replaysUnchangedRefusal(failed: WriteRequest, recorded: RecordedStop,
+ entry: { root: string; intent: { path?: string | null; rawHash?: string | null }; target: string; head: () => string }): boolean {
+ if (replaysContentRefusal(failed, recorded, () => fileUnchangedSinceFreeze(entry.root, entry.intent))) return true;
+ if (!pinnedWorktreeConflict(failed) || recorded.gbrain_version !== VERSION || !entry.intent.path || entry.head() !== entry.target) return false;
+ return fileUnchangedSinceFreeze(entry.root, entry.intent);
+}
+
+/** Whether the entry's file still has the bytes its frozen request carried (a missing file, for a deletion). */
+export function fileUnchangedSinceFreeze(root: string, intent: { path?: string | null; rawHash?: string | null }): boolean {
+ if (!intent.path) return true;
+ try {
+ const bytes = readSyncFile(root, intent.path);
+ return (bytes === null ? null : sha256(bytes)) === (intent.rawHash ?? null);
+ } catch { return false; }
+}