nanocoai/nanoclaw · warning

inbox-safety: failed to resolve inbox dir

Error message

inbox-safety: failed to resolve inbox dir

What it means

Resolving/realpath-ing an intended inbox directory threw — e.g. a parent disappeared mid-resolution (ENOENT on realpath), permission denied, or a symlink loop. The operation returns null and the caller treats the inbox path as unusable (attachment extraction is skipped).

Solutions

  1. Check the inboxDir in the log exists and all parents are traversable (x bit)
  2. Avoid symlinks in the data/ tree
  3. Retry the attachment send — transient races usually clear
Defensive patterns

Strategy: validation

Validate before calling

import fs from 'node:fs';
const p = fs.realpathSync(inboxDir); // pre-validate before extracting attachments
if (!p.startsWith(realInboxRoot)) abort();

Type guard

function isSafeInboxDir(dir: string, root: string): boolean {
  try { return fs.realpathSync(dir).startsWith(fs.realpathSync(root) + '/'); } catch { return false; }
}

Try / catch

const safe = ensureContainedInboxDir(dir); if (!safe) skipAttachmentExtraction();

Prevention

When it happens

Trigger: ensureContainedInboxDir's fs.realpath calls throw on a missing/renamed session dir, an unreadable parent, or a symlinked path segment.

Common situations: Session directory recreated concurrently (container restart race), permission changes on data/v2-sessions, or symlinked data dirs.

Related errors


AI-assisted analysis of nanocoai/nanoclaw@294ef2aee8 (2026-08-28). Data as JSON: /api/errors/3c4d4b1d014bc1e1. Report an issue: GitHub.

Appendix: source

Thrown at src/inbox-safety.ts:80

        return null;
      }
    } catch {
      // Does not exist yet — fine, mkdir below creates it.
    }
  }

  fs.mkdirSync(inboxDir, { recursive: true });

  try {
    const realInboxDir = fs.realpathSync(inboxDir);
    const realInboxRoot = fs.realpathSync(inboxRoot);
    if (!isPathInside(realInboxRoot, realInboxDir)) {
      log.warn('inbox-safety: inbox dir escaped inbox root', { ...context, inboxDir });
      return null;
    }
    return realInboxDir;
  } catch (err) {
    log.warn('inbox-safety: failed to resolve inbox dir', { ...context, inboxDir, err });
    return null;
  }
}

View on GitHub (pinned to 294ef2aee8)