moeru-ai/airi · error · Error

Extension package changed during inspection. Select the…

Error message

Extension package changed during inspection. Select the folder again.

What it means

readManifestSnapshot reads the manifest through a stable file handle and re-stats the file afterwards. This error is thrown when the final stat no longer matches the size that was measured during directory inspection (finalStats.size !== expectedSize or bytesRead !== expectedSize), meaning the manifest file changed between inspection and snapshot read. The library refuses to proceed because the preview and fingerprint must describe identical manifest contents.

Solutions

  1. Re-select the extension folder so inspection restarts from a stable snapshot (as the message instructs).
  2. Close editors, watchers, build processes, or file-sync clients that write to the folder, then retry the import.
  3. Copy the extension folder to a stable location and import the copy instead.
  4. Verify the manifest is not being generated on the fly; run the build first, then import the finished output.

Example fix

// before: importing a folder being actively written by a watcher
await staged('/home/dev/my-extension') // manifest rewritten mid-scan -> throws
// after: quiesce the source first
await runBuild('/home/dev/my-extension') // finish all writes
await staged('/home/dev/my-extension/dist') // import a stable output folder
Defensive patterns

Strategy: retry

Validate before calling

import { stat } from 'node:fs/promises'
const before = await stat(join(folder, 'manifest.json'))
await new Promise(r => setTimeout(r, 250))
const after = await stat(join(folder, 'manifest.json'))
if (before.size !== after.size || before.mtimeMs !== after.mtimeMs)
  throw new Error('Manifest is still being modified; wait and retry.')

Try / catch

try {
  await staged(folder)
} catch (error) {
  if (error instanceof Error && error.message.includes('changed during inspection')) {
    // surface 'please re-select the folder' and retry once after a delay
    await sleep(500)
    return staged(folder)
  }
  throw error
}

Prevention

When it happens

Trigger: Calling inspectExtensionDirectory (via `inspected` or `staged`) while the manifest file inside the selected extension folder is modified, truncated, grown, or replaced between the initial lstat-based scan and the readManifestSnapshot read of the same file.

Common situations: An editor, build tool, package manager, or sync client (Dropbox/OneDrive/rsync) is writing to the extension folder while the user selects it in the import dialog; a dev server regenerating manifest.json during import; the user edits the manifest in another window mid-import.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of moeru-ai/airi@438a067dde (2026-09-17). Data as JSON: /api/errors/fef69576604c2f64. Report an issue: GitHub.

Appendix: source

Thrown at apps/stage-tamagotchi/src/main/services/airi/plugins/host/directory-import.ts:142

    // One extra byte distinguishes the maximum valid manifest from a file
    // that grew past the limit after the directory walk.
    const buffer = Buffer.allocUnsafe(extensionPackageLimits.manifestBytes + 1)
    let bytesRead = 0
    while (bytesRead < buffer.byteLength) {
      const result = await handle.read(buffer, bytesRead, buffer.byteLength - bytesRead, bytesRead)
      if (result.bytesRead === 0) {
        break
      }
      bytesRead += result.bytesRead
    }

    if (bytesRead > extensionPackageLimits.manifestBytes) {
      throw new Error('Extension manifest exceeds the 1 MiB size limit.')
    }

    const finalStats = await handle.stat()
    if (!finalStats.isFile() || finalStats.size !== expectedSize || bytesRead !== expectedSize) {
      throw new Error('Extension package changed during inspection. Select the folder again.')
    }

    return buffer.subarray(0, bytesRead)
  }
  finally {
    await handle.close()
  }
}

async function inspectExtensionDirectory(sourcePath: string): Promise<InspectedExtensionDirectory> {
  const sourceStats = await lstat(sourcePath)
  if (sourceStats.isSymbolicLink() || !sourceStats.isDirectory()) {
    throw new Error(`Extension source must be a regular directory: ${sourcePath}`)
  }

  const sourceRealPath = await realpath(sourcePath)
  const manifestPath = join(sourceRealPath, extensionManifestFileName)
  await assertRegularFile(manifestPath, 'Extension manifest')

View on GitHub (pinned to 438a067dde)