{"record":{"id":"71089937ae0e09cc","repo":"can1357/oh-my-pi","slug":"unsupported-pi-tiny-device-json-stringify-value","errorCode":null,"errorMessage":"Unsupported PI_TINY_DEVICE=${JSON.stringify(value)}. Use cpu, gpu, metal, webgpu, auto, cuda, dml, coreml, wasm, webnn, webnn-gpu, webnn-cpu, or webnn-npu.","messagePattern":"Unsupported PI_TINY_DEVICE=(.+?)\\. Use cpu, gpu, metal, webgpu, auto, cuda, dml, coreml, wasm, webnn, webnn-gpu, webnn-cpu, or webnn-npu\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tiny/device.ts","lineNumber":39,"sourceCode":"\tcuda: true,\n\tdml: true,\n\tcoreml: true,\n\twebnn: true,\n\t\"webnn-npu\": true,\n\t\"webnn-gpu\": true,\n\t\"webnn-cpu\": true,\n};\n\nfunction usesDarwinWorkerWebGpu(device: TinyModelDevice): boolean {\n\treturn process.platform === \"darwin\" && (device === \"gpu\" || device === \"webgpu\" || device === \"auto\");\n}\n\nexport function normalizeTinyModelDevice(value: string | undefined): TinyModelDevice | undefined {\n\tconst raw = value?.trim().toLowerCase();\n\tif (!raw) return undefined;\n\tif (raw === \"metal\") return \"webgpu\";\n\tif (raw in DEVICE_VALUES) return raw as TinyModelDevice;\n\tthrow new Error(\n\t\t`Unsupported PI_TINY_DEVICE=${JSON.stringify(value)}. Use cpu, gpu, metal, webgpu, auto, cuda, dml, coreml, wasm, webnn, webnn-gpu, webnn-cpu, or webnn-npu.`,\n\t);\n}\n\nexport function resolveTinyModelDevicePreference(\n\tvalue: string | undefined = $env.PI_TINY_DEVICE,\n): TinyModelDevicePreference {\n\treturn {\n\t\tdevice: normalizeTinyModelDevice(value) ?? CPU_DEVICE,\n\t\traw: value,\n\t};\n}\n\nexport function tinyModelDeviceLoadOrder(preference: TinyModelDevicePreference): readonly TinyModelDevice[] {\n\tif (preference.device === CPU_DEVICE) return CPU_ONLY_ORDER;\n\tif (usesDarwinWorkerWebGpu(preference.device)) return DARWIN_WEBGPU_UNSAFE_ORDER;\n\treturn [preference.device, CPU_DEVICE];\n}","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tiny/device.ts#L21-L57","documentation":"normalizeTinyModelDevice validates the PI_TINY_DEVICE environment variable against the known device-value set (mapping `metal` -> `webgpu` as an alias). Any non-empty value not in the set throws immediately rather than silently falling back, since a wrong device choice would silently degrade tiny-model inference.","triggerScenarios":"Setting PI_TINY_DEVICE to a typo'd or unsupported value (e.g. `GPU0`, `vulkan`, `Metal ` with trailing chars handled, `cpu,gpu`) and then resolving the tiny model device preference.","commonSituations":"Copying device names from ONNX Runtime docs that omp doesn't expose (vulkan, coreml variants); casing/typo mistakes like `CUDA` vs `cuda` (case is normalized, but spelling must match); stale values from another tool's env.","solutions":["Set PI_TINY_DEVICE to one of: cpu, gpu, metal, webgpu, auto, cuda, dml, coreml, wasm, webnn, webnn-gpu, webnn-cpu, webnn-npu","Use `auto` to let the runtime pick the best device","Unset PI_TINY_DEVICE entirely to use the per-model default"],"exampleFix":"// before\nexport PI_TINY_DEVICE=vulkan\n// after\nexport PI_TINY_DEVICE=cuda","handlingStrategy":"validation","validationCode":"const DEVICES = [\"cpu\",\"gpu\",\"metal\",\"webgpu\",\"auto\",\"cuda\",\"dml\",\"coreml\",\"wasm\",\"webnn\",\"webnn-gpu\",\"webnn-cpu\",\"webnn-npu\"];\nconst v = process.env.PI_TINY_DEVICE?.trim().toLowerCase();\nif (v && !DEVICES.includes(v)) throw new Error(`PI_TINY_DEVICE must be one of ${DEVICES.join(\", \")}`);","typeGuard":null,"tryCatchPattern":"try {\n\tconst device = normalizeTinyModelDevice(process.env.PI_TINY_DEVICE);\n} catch (err) {\n\tlogger.warn(\"Invalid PI_TINY_DEVICE, falling back to auto\", { value: process.env.PI_TINY_DEVICE });\n\treturn \"auto\";\n}","preventionTips":["Only use documented values; remember `metal` maps to webgpu","Prefer `auto` unless you have a specific device requirement","Validate env vars at startup rather than at first inference"],"tags":["configuration","environment-variable","tiny-model","device"],"backgroundTag":"unsupported-env-var-value","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}