Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(chat-catalog): stat the open handle (no check-then-read race); fixed PATH in the real-sh test

review9c38f2feb92a
diff --git a/src/core/chat-catalog.test.ts b/src/core/chat-catalog.test.ts
index 6ec6b97e2..aa173d2a3 100644
--- a/src/core/chat-catalog.test.ts
+++ b/src/core/chat-catalog.test.ts
@@ -195,7 +195,7 @@ describe('remote (one ssh round trip)', () => {
write(path.join(cwd, '.claude/commands/a/b.md'), 'nested')
write(path.join(cwd, '.claude/commands/it\'s.md'), 'quote')
const roots = catalogRoots({ agentId: 'claude', accountId: undefined, cwd }, { remote: true })
- const out = execFileSync('/bin/sh', ['-c', remoteCatalogCommand(roots)], { env: { PATH: process.env.PATH, HOME: host }, encoding: 'utf8' })
+ const out = execFileSync('/bin/sh', ['-c', remoteCatalogCommand(roots)], { env: { PATH: '/usr/local/bin:/usr/bin:/bin', HOME: host }, encoding: 'utf8' })
const { perRoot, partial } = parseRemoteCatalog(out, roots)
const all = perRoot.flat()
const n = all.map((e) => e.name)
diff --git a/src/core/chat-catalog.ts b/src/core/chat-catalog.ts
index 6f14f9aea..29fbedcc7 100644
--- a/src/core/chat-catalog.ts
+++ b/src/core/chat-catalog.ts
@@ -223,12 +223,14 @@ async function listLocalDir(dir: string): Promise<{ name: string; dir: boolean }
async function readLocalHead(file: string): Promise<string | null> {
try {
- const st = await fsp.stat(file)
- if (!st.isFile()) return null
- const hit = headCache.get(file)
- if (hit && hit.mtimeMs === st.mtimeMs && hit.size === st.size) return hit.text
+ // Open FIRST and stat the handle: the (mtime, size) the cache is keyed on then describes the very
+ // bytes read, never a file swapped in between a path stat and the open.
const fh = await fsp.open(file, 'r')
try {
+ const st = await fh.stat()
+ if (!st.isFile()) return null
+ const hit = headCache.get(file)
+ if (hit && hit.mtimeMs === st.mtimeMs && hit.size === st.size) return hit.text
const buf = Buffer.alloc(Math.min(CATALOG_HEAD_BYTES, st.size))
const { bytesRead } = await fh.read(buf, 0, buf.length, 0)
const text = buf.subarray(0, bytesRead).toString('utf8')