The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
fix: handle Windows settings file identity
Danted3af582bade7
diff --git a/scripts/lib/install/claude-settings-lock.js b/scripts/lib/install/claude-settings-lock.jsindex ae413fa01..75aa6a4f0 100644--- a/scripts/lib/install/claude-settings-lock.js+++ b/scripts/lib/install/claude-settings-lock.js@@ -7,7 +7,16 @@ const path = require('path');const INVALID_LOCK_STALE_MS = 5 * 60 * 1000;function sameFileIdentity(left, right) {- return left.dev === right.dev && left.ino === right.ino;+ if (left.ino !== right.ino) {+ return false;+ }+ // Node's path-based stats can omit the Windows volume serial (`dev = 0`)+ // while fstat() on the same file handle reports it. Preserve strict device+ // checks everywhere else, including when both Windows stats report a device.+ if (process.platform === 'win32' && (!left.dev || !right.dev)) {+ return true;+ }+ return left.dev === right.dev;}function createSettingsLock(lockPath) {@@ -167,4 +176,5 @@ function runWithSettingsLock(settingsPath, callback) {module.exports = {acquireSettingsLock,runWithSettingsLock,+ sameFileIdentity,};diff --git a/scripts/lib/install/claude-settings.js b/scripts/lib/install/claude-settings.jsindex 7075c5bd9..dba4a4a75 100644--- a/scripts/lib/install/claude-settings.js+++ b/scripts/lib/install/claude-settings.js@@ -4,7 +4,11 @@ const fs = require('fs');const path = require('path');const { isDeepStrictEqual } = require('util');const { writeFileAtomic } = require('../atomic-write');-const { acquireSettingsLock, runWithSettingsLock } = require('./claude-settings-lock');+const {+ acquireSettingsLock,+ runWithSettingsLock,+ sameFileIdentity,+} = require('./claude-settings-lock');const CLAUDE_SETTINGS_FILENAME = 'settings.json';const CLAUDE_HOOKS_CONFIG_PATH = 'hooks/hooks.json';@@ -340,10 +344,10 @@ function readSettingsSnapshot(settingsPath) {}try {- const descriptorStat = fs.fstatSync(descriptor);+ const descriptorStat = fs.fstatSync(descriptor, { bigint: true });let pathStat;try {- pathStat = fs.lstatSync(settingsPath);+ pathStat = fs.lstatSync(settingsPath, { bigint: true });} catch (error) {if (error && error.code === 'ENOENT') {error.code = 'ECC_SETTINGS_CHANGED';@@ -354,8 +358,7 @@ function readSettingsSnapshot(settingsPath) {!descriptorStat.isFile()|| !pathStat.isFile()|| pathStat.isSymbolicLink()- || descriptorStat.dev !== pathStat.dev- || descriptorStat.ino !== pathStat.ino+ || !sameFileIdentity(descriptorStat, pathStat)) {const error = new Error(`Refusing to read changed Claude settings at ${settingsPath}`);error.code = 'ECC_SETTINGS_CHANGED';@@ -366,7 +369,7 @@ function readSettingsSnapshot(settingsPath) {exists: true,raw,settings: parseSettings(raw, `Claude settings at ${settingsPath}`),- mode: descriptorStat.mode & 0o777,+ mode: Number(descriptorStat.mode & 0o777n),dev: descriptorStat.dev,ino: descriptorStat.ino,};diff --git a/tests/lib/claude-settings.test.js b/tests/lib/claude-settings.test.jsindex 53caaf4bb..2bfc17972 100644--- a/tests/lib/claude-settings.test.js+++ b/tests/lib/claude-settings.test.js@@ -22,6 +22,7 @@ const {updateSettingsAtomic,validateManagedHooks,} = require('../../scripts/lib/install/claude-settings');+const { sameFileIdentity } = require('../../scripts/lib/install/claude-settings-lock');function test(name, fn) {try {@@ -279,6 +280,80 @@ function runTests() {);})) passed++; else failed++;+ if (test('compares file identities strictly except for missing Windows device ids', () => {+ const originalPlatform = process.platform;+ try {+ Object.defineProperty(process, 'platform', { value: 'win32', configurable: true });+ assert.strictEqual(+ sameFileIdentity({ dev: 0, ino: 42 }, { dev: 2162558900, ino: 42 }),+ true+ );+ assert.strictEqual(+ sameFileIdentity(+ { dev: 0n, ino: 19421773395341796n },+ { dev: 2162558900n, ino: 19421773395341796n }+ ),+ true+ );+ assert.strictEqual(+ sameFileIdentity(+ { dev: 1n, ino: 9007199254740992n },+ { dev: 1n, ino: 9007199254740993n }+ ),+ false+ );+ assert.strictEqual(+ sameFileIdentity({ dev: 1n, ino: 42n }, { dev: 2n, ino: 42n }),+ false+ );++ Object.defineProperty(process, 'platform', { value: 'linux', configurable: true });+ assert.strictEqual(+ sameFileIdentity({ dev: 0n, ino: 42n }, { dev: 2n, ino: 42n }),+ false+ );+ } finally {+ Object.defineProperty(process, 'platform', {+ value: originalPlatform,+ configurable: true,+ });+ }+ })) passed++; else failed++;++ if (test('atomic settings updates accept Windows path stats with an omitted device id', () => {+ const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'claude-settings-win-dev-'));+ const settingsPath = path.join(tempDir, 'settings.json');+ const originalLstatSync = fs.lstatSync;+ const originalPlatform = process.platform;+ try {+ fs.writeFileSync(settingsPath, '{"theme":"dark"}\n');+ Object.defineProperty(process, 'platform', { value: 'win32', configurable: true });+ fs.lstatSync = function(...args) {+ const stats = originalLstatSync.apply(fs, args);+ stats.dev = typeof stats.dev === 'bigint' ? 0n : 0;+ return stats;+ };++ updateSettingsAtomic(+ settingsPath,+ settings => ({ settings: { ...settings, managed: true } })+ );++ assert.deepStrictEqual(JSON.parse(fs.readFileSync(settingsPath, 'utf8')), {+ theme: 'dark',+ managed: true,+ });+ assert.ok(!fs.existsSync(`${settingsPath}.ecc.lock`));+ } finally {+ fs.lstatSync = originalLstatSync;+ Object.defineProperty(process, 'platform', {+ value: originalPlatform,+ configurable: true,+ });+ fs.rmSync(tempDir, { recursive: true, force: true });+ }+ })) passed++; else failed++;+if (test('atomic settings updates retry after a concurrent change and preserve secure mode', () => {const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'claude-settings-atomic-'));const settingsPath = path.join(tempDir, 'settings.json');