Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(mcp-host): release a held charge whose path is no longer a directory

Alfredo Lopeza12a1eeeeaaa
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 821971cb5..1df010922 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.540",
+ "version": "0.1.541",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.540",
+ "version": "0.1.541",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 7198f029a..490042602 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.540",
+ "version": "0.1.541",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/internalTools/gfsDownloadStore.ts b/mcp-host/src/internalTools/gfsDownloadStore.ts
index 5d85d8b36..2463de13f 100644
--- a/mcp-host/src/internalTools/gfsDownloadStore.ts
+++ b/mcp-host/src/internalTools/gfsDownloadStore.ts
@@ -1084,13 +1084,16 @@ export class GfsDownloadStore {
if (entry.provenance === 'adopted') totals.adopted += 1
}
// A held directory this sweep never reached (its listing failed, or it is
- // no longer a duplicate) keeps its charge until lstat proves it gone.
+ // no longer a duplicate) keeps its charge until lstat proves it gone:
+ // ENOENT, ENOTDIR (a parent is no longer a directory) or a path that is
+ // no longer a directory. Any other answer keeps the charge.
for (const [directory, copy] of previousHeld) {
if (settled.has(directory)) continue
try {
- await fs.lstat(directory)
+ if (!(await fs.lstat(directory)).isDirectory()) continue
} catch (error) {
- if (errorCode(error) === 'ENOENT') continue
+ const code = errorCode(error)
+ if (code === 'ENOENT' || code === 'ENOTDIR') continue
}
held.set(directory, copy)
}
diff --git a/mcp-host/src/internalTools/gfsDownloadStoreHeldCharges.test.ts b/mcp-host/src/internalTools/gfsDownloadStoreHeldCharges.test.ts
index 43d3be5bb..e539d80a9 100644
--- a/mcp-host/src/internalTools/gfsDownloadStoreHeldCharges.test.ts
+++ b/mcp-host/src/internalTools/gfsDownloadStoreHeldCharges.test.ts
@@ -200,7 +200,7 @@ describe('GFS download store: held duplicate charges survive transient failures
await store.fail(admitted.transfer.id, PLANTER)
})
- it('a carried charge whose lstat fails with anything but ENOENT is kept', async () => {
+ it('a carried charge whose lstat fails with anything but ENOENT or ENOTDIR is kept', async () => {
const { store, planter, ids } = await heldDuplicates()
const listings = failWithEio('readdir', target => target.endsWith(DOWNLOADS))
const probes = failWithEio('lstat', target =>
@@ -220,6 +220,44 @@ describe('GFS download store: held duplicate charges survive transient failures
await store.fail(admitted.transfer.id, PLANTER)
})
+ // R3-F2, ported from the round-3 review's SOL-R3-HELD-ENOTDIR repro. The
+ // owner's 40 bytes are adopted and evictable; an admission of 40 fits the
+ // 80-byte budget beside them only if no phantom charge remains. A phantom
+ // 40 bytes would make the admission evict every one of the owner's copies.
+ it('SOL-R3-HELD-ENOTDIR: a carried charge below a caller root that became a file is dropped', async () => {
+ const { store, owner, planter, ids } = await heldDuplicates()
+ faults.clear()
+ syncFs.rmSync(planter, { recursive: true, force: true })
+ syncFs.writeFileSync(planter, '', { mode: 0o600 })
+ // Witness: the held paths now answer ENOTDIR, not ENOENT.
+ await expect(fs.lstat(downloadDirectory(planter, ids[0]!))).rejects.toMatchObject({
+ code: 'ENOTDIR',
+ })
+ for (let sweep = 0; sweep < 3; sweep += 1) await store.cleanupExpired()
+
+ const admitted = await startTransfer(store, owner, OWNER, 101, 40)
+ for (const id of ids) expect(exists(downloadDirectory(owner, id))).toBe(true)
+ await store.fail(admitted.transfer.id, OWNER)
+ })
+
+ it('a carried path that is no longer a directory is dropped while its parent cannot be listed', async () => {
+ const { store, owner, planter, ids } = await heldDuplicates()
+ faults.clear()
+ const listings = failWithEio('readdir', target => target.endsWith(DOWNLOADS))
+ for (const id of ids) {
+ const target = downloadDirectory(planter, id)
+ syncFs.rmSync(target, { recursive: true, force: true })
+ syncFs.writeFileSync(target, '', { mode: 0o600 })
+ }
+
+ const admitted = await startTransfer(store, owner, OWNER, 101, 40)
+ // Witness: the duplicates were unreachable, so only the lstat re-check
+ // can have released their charge; no owner copy had to be evicted.
+ expect(listings.length).toBeGreaterThan(0)
+ for (const id of ids) expect(exists(downloadDirectory(owner, id))).toBe(true)
+ await store.fail(admitted.transfer.id, OWNER)
+ })
+
it('a carried directory that is now indexed is charged once, not twice', async () => {
const owner = callerDirectory(hostRoot, OWNER)
const planter = callerDirectory(hostRoot, PLANTER)
diff --git a/scripts/ci/pinned-vitest-cases/mcp-host.json b/scripts/ci/pinned-vitest-cases/mcp-host.json
index 58bb874fc..6aff524b3 100644
--- a/scripts/ci/pinned-vitest-cases/mcp-host.json
+++ b/scripts/ci/pinned-vitest-cases/mcp-host.json
@@ -889,7 +889,15 @@
},
{
"suite": "gfsDownloadStoreHeldCharges.test.ts",
- "fullName": "GFS download store: held duplicate charges survive transient failures (R2-F2) a carried charge whose lstat fails with anything but ENOENT is kept"
+ "fullName": "GFS download store: held duplicate charges survive transient failures (R2-F2) a carried charge whose lstat fails with anything but ENOENT or ENOTDIR is kept"
+ },
+ {
+ "suite": "gfsDownloadStoreHeldCharges.test.ts",
+ "fullName": "GFS download store: held duplicate charges survive transient failures (R2-F2) SOL-R3-HELD-ENOTDIR: a carried charge below a caller root that became a file is dropped"
+ },
+ {
+ "suite": "gfsDownloadStoreHeldCharges.test.ts",
+ "fullName": "GFS download store: held duplicate charges survive transient failures (R2-F2) a carried path that is no longer a directory is dropped while its parent cannot be listed"
},
{
"suite": "gfsDownloadStoreHeldCharges.test.ts",