{"record":{"id":"10d34e2367dd225a","repo":"coleam00/Archon","slug":"pi-shim-setup-failed-at-shimdir-err-message","errorCode":null,"errorMessage":"Pi shim setup failed at ${shimDir}: ${err.message}","messagePattern":"Pi shim setup failed at (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/providers/src/community/pi/provider.ts","lineNumber":116,"sourceCode":"  const shimPkgJson = join(shimDir, 'package.json');\n  if (!existsSync(shimPkgJson)) {\n    // `piConfig: {}` is explicit so Pi's defaults (`name: 'pi'`,\n    // `configDir: '.pi'`) kick in — matches Pi's standalone behavior.\n    try {\n      mkdirSync(shimDir, { recursive: true });\n      writeFileSync(\n        shimPkgJson,\n        JSON.stringify({\n          name: 'archon-pi-shim',\n          version: '0.0.0',\n          piConfig: {},\n        })\n      );\n    } catch (error) {\n      // Surface as a classified error so the executor's catch sees a known\n      // shape instead of a raw EACCES/ENOSPC from node:fs.\n      const err = error as NodeJS.ErrnoException;\n      throw new Error(`Pi shim setup failed at ${shimDir}: ${err.message}`);\n    }\n  }\n  process.env.PI_PACKAGE_DIR = shimDir;\n}\n\n// ─── Bedrock backend registration (compiled-binary parity) ───────────────────\n\n/**\n * Registrar for Pi's Bedrock backend module. Split out from\n * `ensureBedrockProviderRegistered` so tests can inject a spy without touching\n * the real SDK (Bun's `mock.module` is process-global and irreversible).\n */\nexport type BedrockRegistrar = () => Promise<void>;\n\n/**\n * The default registrar: dynamically import the Pi SDK's Bedrock override hook\n * and the statically-bundled Bedrock module, then wire them together.\n *","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/providers/src/community/pi/provider.ts#L98-L134","documentation":"ensurePiPackageDirShim sets up a Pi package-directory shim on the filesystem (env PI_PACKAGE_DIR points at it). Any fs failure (permission, disk space, etc.) is caught and rethrown as a classified error so the executor's catch sees a known shape instead of a raw errno error.","triggerScenarios":"listPiModels or sendQuery invoking ensurePiPackageDirShim when the shim directory cannot be created/written: EACCES (read-only or non-owned path), ENOSPC (full disk), ENOENT on a parent path, or EEXIST with conflicting file type.","commonSituations":"Running the engine as a different user than a previous run (root-owned ~/.pi or cache dir), read-only containers, full disks in CI, or a file existing where the shim dir is expected.","solutions":["Check permissions on the shim path (the path is in the message) and chown/chmod it","Free disk space if ENOSPC","Remove the stale/corrupt shim directory and re-run","Run under a user that owns the Pi agent directory (~/.pi)"],"exampleFix":"// before (run as unrelated user, dir owned by root)\n$ archon run workflow\n// after\n$ sudo chown -R $(whoami) ~/.pi\n$ archon run workflow","handlingStrategy":"try-catch","validationCode":"import { accessSync, constants } from 'node:fs';\ntry {\n  accessSync(shimParent, constants.W_OK);\n} catch {\n  throw new Error(`Cannot write Pi shim dir at ${shimParent}: check permissions/disk space`);\n}","typeGuard":"function isFsErrnoException(e: unknown): e is NodeJS.ErrnoException {\n  return e instanceof Error && typeof (e as NodeJS.ErrnoException).code === 'string';\n}","tryCatchPattern":"try {\n  await sendQuery(req);\n} catch (err) {\n  if (err.message.startsWith('Pi shim setup failed')) {\n    const m = err.message.match(/: (\\w+):/); // extract errno e.g. EACCES/ENOSPC\n    console.error(`Fix filesystem at shim path (${m?.[1]}), then retry`);\n  }\n  throw err;\n}","preventionTips":["Run the engine as a user that owns ~/.pi and the configured workspace dirs","Monitor disk space in CI runners","Never run one install as multiple system users against the same home dir without chowning first","Prefer pre-warming the shim at startup so failures surface before runs start"],"tags":["filesystem","permissions","setup"],"backgroundTag":"filesystem-permission-denied","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}