{"record":{"id":"fef69576604c2f64","repo":"moeru-ai/airi","slug":"extension-package-changed-during-inspection-select-the","errorCode":null,"errorMessage":"Extension package changed during inspection. Select the folder again.","messagePattern":"Extension package changed during inspection\\. Select the folder again\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/stage-tamagotchi/src/main/services/airi/plugins/host/directory-import.ts","lineNumber":142,"sourceCode":"    // One extra byte distinguishes the maximum valid manifest from a file\n    // that grew past the limit after the directory walk.\n    const buffer = Buffer.allocUnsafe(extensionPackageLimits.manifestBytes + 1)\n    let bytesRead = 0\n    while (bytesRead < buffer.byteLength) {\n      const result = await handle.read(buffer, bytesRead, buffer.byteLength - bytesRead, bytesRead)\n      if (result.bytesRead === 0) {\n        break\n      }\n      bytesRead += result.bytesRead\n    }\n\n    if (bytesRead > extensionPackageLimits.manifestBytes) {\n      throw new Error('Extension manifest exceeds the 1 MiB size limit.')\n    }\n\n    const finalStats = await handle.stat()\n    if (!finalStats.isFile() || finalStats.size !== expectedSize || bytesRead !== expectedSize) {\n      throw new Error('Extension package changed during inspection. Select the folder again.')\n    }\n\n    return buffer.subarray(0, bytesRead)\n  }\n  finally {\n    await handle.close()\n  }\n}\n\nasync function inspectExtensionDirectory(sourcePath: string): Promise<InspectedExtensionDirectory> {\n  const sourceStats = await lstat(sourcePath)\n  if (sourceStats.isSymbolicLink() || !sourceStats.isDirectory()) {\n    throw new Error(`Extension source must be a regular directory: ${sourcePath}`)\n  }\n\n  const sourceRealPath = await realpath(sourcePath)\n  const manifestPath = join(sourceRealPath, extensionManifestFileName)\n  await assertRegularFile(manifestPath, 'Extension manifest')","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/moeru-ai/airi/blob/438a067dde47aa0bdb46c2323d1fe293dc805218/apps/stage-tamagotchi/src/main/services/airi/plugins/host/directory-import.ts#L124-L160","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-select the extension folder so inspection restarts from a stable snapshot (as the message instructs).","Close editors, watchers, build processes, or file-sync clients that write to the folder, then retry the import.","Copy the extension folder to a stable location and import the copy instead.","Verify the manifest is not being generated on the fly; run the build first, then import the finished output."],"exampleFix":"// before: importing a folder being actively written by a watcher\nawait staged('/home/dev/my-extension') // manifest rewritten mid-scan -> throws\n// after: quiesce the source first\nawait runBuild('/home/dev/my-extension') // finish all writes\nawait staged('/home/dev/my-extension/dist') // import a stable output folder","handlingStrategy":"retry","validationCode":"import { stat } from 'node:fs/promises'\nconst before = await stat(join(folder, 'manifest.json'))\nawait new Promise(r => setTimeout(r, 250))\nconst after = await stat(join(folder, 'manifest.json'))\nif (before.size !== after.size || before.mtimeMs !== after.mtimeMs)\n  throw new Error('Manifest is still being modified; wait and retry.')","typeGuard":null,"tryCatchPattern":"try {\n  await staged(folder)\n} catch (error) {\n  if (error instanceof Error && error.message.includes('changed during inspection')) {\n    // surface 'please re-select the folder' and retry once after a delay\n    await sleep(500)\n    return staged(folder)\n  }\n  throw error\n}","preventionTips":["Import only quiescent folders — stop watchers, builds, and sync clients first.","Import a committed copy (dist output or a copied folder), not a live working tree.","Avoid importing folders under active Dropbox/OneDrive/IDE sync."],"tags":["filesystem","race-condition","extensions","electron"],"backgroundTag":"file-read-failed","analyzedSha":"438a067dde47aa0bdb46c2323d1fe293dc805218","analyzedAt":"2026-09-17T01:14:42.644Z","contentChangedAt":"2026-09-17T01:14:42.644Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}