Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
fix(config): stat and read config and lock files through one descriptor
KageBinarybcdeb72679a3
diff --git a/ix-cli/src/cli/config-lock.ts b/ix-cli/src/cli/config-lock.tsindex 3aea0411..39df585a 100644--- a/ix-cli/src/cli/config-lock.ts+++ b/ix-cli/src/cli/config-lock.ts@@ -1,6 +1,6 @@// Copyright 2026 Ix Infrastructure Inc.-import { closeSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, statSync, writeSync } from "node:fs";+import { closeSync, fstatSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeSync } from "node:fs";import { dirname } from "node:path";import { hostname } from "node:os";import { randomBytes } from "node:crypto";@@ -95,15 +95,23 @@ interface Observed {}function observe(path: string): Observed | null {- let st;- try { st = statSync(path); } catch { return null; }- let meta: LockMeta | null = null;+ // One descriptor for both the stat and the read, so they describe the same file.+ let fd: number;+ try { fd = openSync(path, "r"); } catch { return null; }try {- const parsed = JSON.parse(readFileSync(path, "utf-8"));- // An older Ix wrote this lock without a token; its pid still tells.- if (parsed && typeof parsed === "object" && typeof parsed.pid === "number") meta = parsed as LockMeta;- } catch { /* being written, or not ours */ }- return { meta, id: `${meta?.token ?? ""}:${st.ino}:${st.mtimeMs}:${st.size}`, mtimeMs: st.mtimeMs };+ const st = fstatSync(fd);+ let meta: LockMeta | null = null;+ try {+ const parsed = JSON.parse(readFileSync(fd, "utf-8"));+ // An older Ix wrote this lock without a token; its pid still tells.+ if (parsed && typeof parsed === "object" && typeof parsed.pid === "number") meta = parsed as LockMeta;+ } catch { /* being written, or not ours */ }+ return { meta, id: `${meta?.token ?? ""}:${st.ino}:${st.mtimeMs}:${st.size}`, mtimeMs: st.mtimeMs };+ } catch {+ return null;+ } finally {+ closeSync(fd);+ }}/** Why the observed holder is gone, or undefined while it may still be working. */diff --git a/ix-cli/src/cli/config.ts b/ix-cli/src/cli/config.tsindex ea3976e3..5a5722ee 100644--- a/ix-cli/src/cli/config.ts+++ b/ix-cli/src/cli/config.ts@@ -1,6 +1,6 @@// Copyright 2026 Ix Infrastructure Inc.-import { readFileSync, writeFileSync, existsSync, rmSync, chmodSync, realpathSync, mkdirSync, statSync } from "node:fs";+import { readFileSync, writeFileSync, existsSync, rmSync, chmodSync, realpathSync, mkdirSync, statSync, openSync, fstatSync, closeSync } from "node:fs";import { dirname, isAbsolute, join, relative, resolve as resolvePath, sep } from "node:path";import { createHash, randomBytes } from "node:crypto";import { execFileSync } from "node:child_process";@@ -187,20 +187,26 @@ export function loadConfig(): IxConfig {// workspace into it, so every later load in the process that found no// config file -- a fresh IX_HOME, a deleted file -- inherited workspaces// that were never in either.- let stat: { mtimeMs: number; size: number };+ // One descriptor for the stat and the read, so the memo's key always+ // describes the bytes it was parsed from.+ let fd: number;try {- stat = statSync(configPath);+ fd = openSync(configPath, "r");} catch {return { ...defaultConfig };}- if (configMemo && configMemo.path === configPath && configMemo.mtimeMs === stat.mtimeMs && configMemo.size === stat.size) {- return structuredClone(configMemo.config);- }+ let stat: { mtimeMs: number; size: number };let raw: string;try {- raw = readFileSync(configPath, "utf-8");+ stat = fstatSync(fd);+ if (configMemo && configMemo.path === configPath && configMemo.mtimeMs === stat.mtimeMs && configMemo.size === stat.size) {+ return structuredClone(configMemo.config);+ }+ raw = readFileSync(fd, "utf-8");} catch {return { ...defaultConfig };+ } finally {+ closeSync(fd);}let parsed: Partial<IxConfig> | null;try {