CherryHQ/cherry-studio · error · Error

Agent storage path parent is not a directory: ${current}

Error message

Agent storage path parent is not a directory: ${current}

What it means

Thrown by assertAgentStoragePath during the segment walk when an intermediate component (not the final target) exists but is not a directory — e.g. a file sits where a directory is expected on the path to the target. This blocks creating a directory path through a file (which would fail anyway) and catches corrupted/misstructured agent data trees.

Source

Thrown at src/main/ai/agents/agentDataDirectory.ts:67

    throw new Error(`Agent storage path escapes its root: ${target}`)
  }

  const rootStat = await lstatIfExists(root)
  if (!rootStat?.isDirectory || rootStat.isSymbolicLink) {
    throw new Error(`Agent storage root must be a real directory: ${root}`)
  }

  let current = root
  const relative = path.relative(root, target)
  for (const segment of relative ? relative.split(path.sep) : []) {
    current = asAbsolutePath(path.join(current, segment))
    const currentStat = await lstatIfExists(current)
    if (!currentStat) break
    if (currentStat.isSymbolicLink) {
      throw new Error(`Agent storage path contains a symbolic link: ${current}`)
    }
    if (current !== target && !currentStat.isDirectory) {
      throw new Error(`Agent storage path parent is not a directory: ${current}`)
    }
  }

  const [realRoot, realTarget] = await Promise.all([
    resolveRealOrNearestExistingPath(root),
    resolveRealOrNearestExistingPath(target)
  ])
  if (realTarget !== realRoot && !isPathInside(realTarget, realRoot)) {
    throw new Error(`Agent storage path resolves outside its root: ${target}`)
  }
}

/** Ensure a Data/Agents path is a real directory contained by the Agent storage root. */
export async function ensureAgentStorageDirectory(agentsDataRoot: string, targetPath: string): Promise<void> {
  await ensureDir(asAbsolutePath(path.resolve(agentsDataRoot)))
  await assertAgentStoragePath(agentsDataRoot, targetPath)
  await ensureDir(asAbsolutePath(path.resolve(targetPath)))
  await assertAgentStoragePath(agentsDataRoot, targetPath)

View on GitHub (pinned to 726446b54c)

Solutions

  1. Inspect the named path and remove or relocate the file blocking the directory path.
  2. Re-create the expected directory structure via ensureAgentDataDirectory (after cleaning the obstruction).
  3. Determine what wrote the file at a directory path to prevent recurrence.
  4. Restore the agent data directory from a known-good backup if the structure is badly corrupted.
Defensive patterns

Strategy: validation

Validate before calling

import { lstatIfExists } from './agentDataDirectory'
// Reject an intermediate segment that is a file
for (const seg of path.relative(root, target).split(path.sep)) {
  current = path.join(current, seg)
  const st = await lstatIfExists(current)
  if (current !== target && st && !st.isDirectory) {
    throw new Error(`Refusing: '${current}' is not a directory`)
  }
}

Prevention

When it happens

Trigger: A file occupies a path segment that should be a directory: e.g. Data/Agents/<agentId> is a file (not a directory) while the target is Data/Agents/<agentId>/memory/file. The check is current !== target && !currentStat.isDirectory.

Common situations: Corrupted agent data where a directory was replaced by a file; a buggy write created a file at a directory path; partial migration leaving a file where a folder is expected; manual tampering with the data folder.

Related errors


AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12). Data as JSON: /api/errors/ff76e4221c8a9082. Report an issue: GitHub.