mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
fix(openclaw): don't let an unreadable, migrated legacy log block commits
Reading the legacy log through one handle meant opening it to learn its version, so a log already migrated that later became unreadable failed every commit, although its metadata alone shows it unchanged. When open() is refused, compare the path's metadata with the recorded version and skip the log if it matches. An unreadable log that was never migrated still fails loudly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
20b032d5cf
commit
a9e9ea6e8c
@@ -39,7 +39,7 @@
|
||||
*/
|
||||
|
||||
import { createHash } from "node:crypto";
|
||||
import { lstat, mkdir, open, readFile, rename, writeFile, type FileHandle } from "node:fs/promises";
|
||||
import { lstat, mkdir, open, readFile, rename, stat, writeFile, type FileHandle } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import * as os from "node:os";
|
||||
|
||||
@@ -174,6 +174,9 @@ export class DurableAdvancementKeyStore {
|
||||
if (code === "ENOENT" || code === "ENOTDIR") {
|
||||
return; // No legacy log. A blocked path fails loudly at the first commit.
|
||||
}
|
||||
if ((code === "EACCES" || code === "EPERM") && (await this.isMigratedLog())) {
|
||||
return; // Unreadable now, but every key it held has a marker, and it hasn't changed since.
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
let version: LegacyLogVersion;
|
||||
@@ -230,6 +233,17 @@ export class DurableAdvancementKeyStore {
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether the log's metadata alone identifies it as the version already migrated. */
|
||||
private async isMigratedLog(): Promise<boolean> {
|
||||
try {
|
||||
const { size, mtimeMs, ino } = await stat(this.path);
|
||||
this.migratedVersion ??= await this.readMigratedLogRecord();
|
||||
return sameVersion(this.migratedVersion, { size, mtimeMs, ino });
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async readMigratedLogRecord(): Promise<LegacyLogVersion | undefined> {
|
||||
try {
|
||||
return JSON.parse(await readFile(this.migratedLogRecordPath(), "utf8")) as LegacyLogVersion;
|
||||
|
||||
@@ -306,6 +306,10 @@ describe("DurableAdvancementKeyStore", () => {
|
||||
const restarted = new DurableAdvancementKeyStore(storePath);
|
||||
await expect(restarted.tryCommit("turn-next")).resolves.toBe("committed");
|
||||
|
||||
// Nor does a migrated log that can no longer be read block commits.
|
||||
await fs.chmod(storePath, 0o000);
|
||||
await expect(new DurableAdvancementKeyStore(storePath).tryCommit("turn-c")).resolves.toBe("committed");
|
||||
|
||||
// The directory becomes writable, and an older version that is still
|
||||
// running commits turn-b the way it always did (temp file + rename).
|
||||
// The running store migrates it before its next commit, and can now
|
||||
|
||||
Reference in New Issue
Block a user