Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(write-through): re-check expected file bytes right before the rename; connector content holds for file_database_drift

garrytan0a97942f59b8
diff --git a/src/core/connectors/item-holds.ts b/src/core/connectors/item-holds.ts
index d8318a49e2..5a2a08c98e 100644
--- a/src/core/connectors/item-holds.ts
+++ b/src/core/connectors/item-holds.ts
@@ -103,7 +103,7 @@ const SOURCE_CODES = new Set([
]);
const CONTENT_CODES = new Set([
'invalid_params', 'invalid_connector_text', 'request_too_large', 'page_identity_changed', 'take_row_collision',
- 'connector_fence_below_timeline', 'malformed', 'http_4xx',
+ 'connector_fence_below_timeline', 'malformed', 'http_4xx', 'file_database_drift', 'page_body_segmented',
]);
const POSTGRES_SOURCE_CODES: Record<string, string> = {
'57014': 'statement_timeout', '55P03': 'lock_timeout', '40001': 'database_contention', '40P01': 'database_contention',
diff --git a/src/core/write-through.ts b/src/core/write-through.ts
index d647b3b70b..e2265256cb 100644
--- a/src/core/write-through.ts
+++ b/src/core/write-through.ts
@@ -475,15 +475,15 @@ export async function writePageThrough(
// EEXIST when the directory already exists (POSIX no-ops it). That aborts
// the put_page / enrich / capture write-through whenever the prefix dir
// already exists, silently leaving the DB and the .md file plane out of sync.
- if (opts.expectedFileBytes !== undefined
- && (existsSync(filePath) ? readFileSync(filePath, 'utf-8') : null) !== opts.expectedFileBytes) {
- return { written: false, skipped: 'file_changed' };
- }
+ const fileChanged = () => opts.expectedFileBytes !== undefined
+ && (existsSync(filePath) ? readFileSync(filePath, 'utf-8') : null) !== opts.expectedFileBytes;
+ if (fileChanged()) return { written: false, skipped: 'file_changed' };
await engine.transaction(tx => bindOrigin(tx, { sourceId, slug, sourcePath: sourcePathToBind, onlyIfUnset: true, liveOnly: true }));
assertSourceFilesystemActive();
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
assertSourceFilesystemActive();
+ if (fileChanged()) return { written: false, skipped: 'file_changed' };
atomicWriteFileSync(filePath, md, { verify: () => assertSourceFilesystemActive() });
// #2426: on a durability-hardened repo (user ran `gbrain sources harden`),