{"record":{"id":"3ef1e48cda9b8b92","repo":"vercel/next.js","slug":"unsupported-ai-upgrade-type-json-stringify-upgradetype","errorCode":null,"errorMessage":"Unsupported AI upgrade type ${JSON.stringify(upgradeType)}. Expected \"security\", \"latest\", or \"future\".","messagePattern":"Unsupported AI upgrade type (.+?)\\. Expected \"security\", \"latest\", or \"future\"\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/cli/next-upgrade.ts","lineNumber":197,"sourceCode":"        })\n        return\n      }\n\n      // A workspace root must not launch an upgrade for an unspecified app.\n      if (!findDir(baseDir, 'app') && !findDir(baseDir, 'pages')) {\n        throw new Error(\n          'No Next.js app found in this directory. Run the command from an app directory or pass its path.'\n        )\n      }\n\n      const upgradeType = await resolveAIUpgradeType(baseDir, options.ai)\n\n      if (\n        upgradeType !== 'security' &&\n        upgradeType !== 'latest' &&\n        upgradeType !== 'future'\n      ) {\n        throw new Error(\n          `Unsupported AI upgrade type ${JSON.stringify(upgradeType)}. Expected \"security\", \"latest\", or \"future\".`\n        )\n      }\n\n      // Resolve the requested target before preparing an agent session.\n      const { prepareUpgrade } =\n        require('../lib/upgrade/prepare-upgrade') as typeof import('../lib/upgrade/prepare-upgrade')\n      const assessmentSpinner = createSpinner('Preparing upgrade')\n      const result = await prepareUpgrade(baseDir, upgradeType).finally(() =>\n        assessmentSpinner?.stop()\n      )\n\n      if (result.status !== 'ready') {\n        Log.info(result.reason)\n        return\n      }\n\n      const needsVersionMigration =","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/vercel/next.js/blob/34433fd12ee8074ea3f47af9f36255c7390d0301/packages/next/src/cli/next-upgrade.ts#L179-L215","documentation":"spawnNextUpgrade validates the resolved AI upgrade type before preparing the session. The type comes either from the --ai flag string or from experimental.agenticAutoUpgrade in next.config. Only 'security', 'latest', and 'future' are allowed; anything else is rejected defensively even though resolveAIUpgradeType normally normalizes to 'security'.","triggerScenarios":"`next upgrade --ai=<value>` with a value other than security/latest/future (e.g. --ai=canary), or a config value that bypasses normalization.","commonSituations":"Typo like --ai=secuirty; guessing flag values like --ai=codemap; older docs referencing removed policy names.","solutions":["Use one of --ai, --ai=security, --ai=latest, or --ai=future","Check next.config: experimental.agenticAutoUpgrade must be 'security' | 'latest' | 'future' if set","Run `next upgrade --help` to see accepted values"],"exampleFix":"// before\nnext upgrade --ai=canary\n// after\nnext upgrade --ai=latest","handlingStrategy":"validation","validationCode":"const AI_TYPES = ['security','latest','future']\nif (!AI_TYPES.includes(aiOption)) {\n  throw new Error(`--ai must be one of ${AI_TYPES.join(', ')}`)\n}","typeGuard":"function isAiUpgradeType(v: unknown): v is 'security'|'latest'|'future' {\n  return v === 'security' || v === 'latest' || v === 'future'\n}","tryCatchPattern":"try {\n  await spawnNextUpgrade(dir, { ai: opts.ai })\n} catch (e) {\n  if (String(e.message).includes('Unsupported AI upgrade type')) {\n    console.error('Use --ai, --ai=security, --ai=latest, or --ai=future')\n  }\n}","preventionTips":["Only pass --ai, --ai=security, --ai=latest, or --ai=future","Validate experimental.agenticAutoUpgrade values against the enum in next.config","Normalize unknown config values to 'security' before invoking"],"tags":["nextjs","cli","upgrade","invalid-value"],"backgroundTag":"invalid-enum-value","analyzedSha":"34433fd12ee8074ea3f47af9f36255c7390d0301","analyzedAt":"2026-09-20T18:20:20.576Z","contentChangedAt":"2026-09-20T18:20:20.576Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}