multica-ai/multica · error

stat opened codex home %s: %w

Error message

stat opened codex home %s: %w

What it means

verifyCodexHomeRoot calls root.Stat(".") on the just-opened os.Root to capture the identity of the directory the handle refers to. Failure here means the opened handle could not be stat'ed, which is nearly impossible unless the filesystem errors after a successful open (e.g. NFS, FUSE weirdness) — it is the first half of the symlink/replacement identity check.

Source

Thrown at server/internal/daemon/execenv/codex_home.go:984

	root, err := os.OpenRoot(codexHome)
	if err != nil {
		return nil, fmt.Errorf("open codex home %s: %w", codexHome, err)
	}
	if err := verifyCodexHomeRoot(root, codexHome, key); err != nil {
		root.Close()
		return nil, err
	}
	return root, nil
}

// verifyCodexHomeRoot proves that root is the directory codexHome names right
// now: not reached through a symlink, and the same directory os.Lstat sees at
// that path. It is separate from openVerifiedCodexHomeRoot so the swap case can
// be tested deterministically instead of by racing.
func verifyCodexHomeRoot(root *os.Root, codexHome, key string) error {
	opened, err := root.Stat(".")
	if err != nil {
		return fmt.Errorf("stat opened codex home %s: %w", codexHome, err)
	}
	current, err := os.Lstat(codexHome)
	if err != nil {
		return fmt.Errorf("stat codex home %s: %w", codexHome, err)
	}
	if current.Mode()&os.ModeSymlink != 0 {
		return fmt.Errorf("codex home %s is a symlink; refusing to write %s through it", codexHome, key)
	}
	if !os.SameFile(opened, current) {
		return fmt.Errorf("codex home %s was replaced while opening it; refusing to write %s through it", codexHome, key)
	}
	return nil
}

// materialiseInCodexHome writes src to relPath inside codexHome using
// root-scoped operations, so no symlink below the task home can redirect the
// daemon's mkdir, remove, or write outside it.
//

View on GitHub (pinned to 2c0912b6ec)

Solutions

  1. Retry the task prepare once — transient FS errors usually clear
  2. Move the task home off the network/exotic filesystem to local disk
  3. Check dmesg / volume health if the error persists
Defensive patterns

Strategy: retry

Try / catch

if err := prepareCodexHome(...); err != nil {
	if strings.Contains(err.Error(), "stat opened codex home") {
		// transient fstat failure; one retry on local disk is safe
		err = prepareCodexHome(...)
	}
}

Prevention

When it happens

Trigger: Underlying filesystem returns an error for fstat on an open directory handle (network filesystem, failing disk, FUSE mount); handle already closed by another goroutine.

Common situations: Task home on NFS or a container overlay that fails fstat; flaky cloud volume during task start.

Related errors


AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15). Data as JSON: /api/errors/a489a56d944353db. Report an issue: GitHub.