{"record":{"id":"69be605785109bfe","repo":"mastra-ai/mastra","slug":"found-existing-length-existing-project-s-in-th","errorCode":null,"errorMessage":"Found ${existing.length} existing project(s) in this organization. Pass --project <id-or-slug> to select one, or re-run without --yes to choose interactively.","messagePattern":"Found (.+?) existing project\\(s\\) in this organization\\. Pass --project <id-or-slug> to select one, or re-run without --yes to choose interactively\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/server/deploy.ts","lineNumber":301,"sourceCode":"    };\n  }\n\n  const name = defaultName;\n  if (!name) {\n    throw new Error('Could not determine project name from package.json. Use --project to specify one.');\n  }\n\n  const existing = await fetchServerProjects(token, orgId);\n  const nameMatches = existing.filter(proj => proj.name === name || proj.slug === name);\n\n  if (existing.length > 0) {\n    if (autoAccept) {\n      // Non-interactive: only safe to auto-pick when exactly one project matches by name/slug.\n      if (nameMatches.length === 1) {\n        const m = nameMatches[0]!;\n        return { projectId: m.id, projectName: m.name, projectSlug: m.slug ?? m.name };\n      }\n      throw new Error(\n        `Found ${existing.length} existing project(s) in this organization. Pass --project <id-or-slug> to select one, or re-run without --yes to choose interactively.`,\n      );\n    }\n\n    const CREATE_NEW = '__create_new__';\n    const initialValue = nameMatches.length === 1 ? nameMatches[0]!.id : existing[0]!.id;\n    const selected = await p.select({\n      message: 'Select a project to deploy to',\n      initialValue,\n      options: [\n        ...existing.map(proj => ({ value: proj.id, label: `${proj.name} (${proj.id})` })),\n        { value: CREATE_NEW, label: `＋ Create new project \"${name}\"` },\n      ],\n    });\n\n    if (p.isCancel(selected)) {\n      p.cancel('Deploy cancelled.');\n      process.exit(0);","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/server/deploy.ts#L283-L319","documentation":"In non-interactive (--yes) deploys, resolveProject will only auto-pick a project when exactly one existing project in the organization matches the derived name/slug. If any projects exist but none (or more than one) match the name, it refuses to guess and throws, telling you to select explicitly.","triggerScenarios":"Running `mastra server deploy --yes` when the org already contains projects and either (a) no project's name or slug equals the default name from package.json, or (b) multiple projects share that name. With zero existing projects this error is not thrown (it creates a new one).","commonSituations":"CI pipelines with --yes on a fresh checkout where package.json name differs from the deployed project's name; renamed package in package.json so the slug no longer matches; organizations with several similarly named projects causing ambiguous matches.","solutions":["Pass the target explicitly: `mastra server deploy --yes --project <id-or-slug>`","Re-run interactively without --yes and pick the project from the prompt","Set MASTRA_PROJECT_ID to the project id in CI secrets","Align package.json \"name\" (or the project slug) with exactly one existing project"],"exampleFix":"// before (CI script)\nmastra server deploy --yes\n// after\nmastra server deploy --yes --project \"$MASTRA_PROJECT_ID\"","handlingStrategy":"validation","validationCode":"// CI guard: fail fast unless exactly one project target is pinned\nif (process.env.CI && !process.env.MASTRA_PROJECT_ID) {\n  throw new Error('CI deploys must set MASTRA_PROJECT_ID (or pass --project).');\n}","typeGuard":"function isPinnedTarget(opts: { project?: string }): boolean {\n  return typeof opts.project === 'string' && opts.project.length > 0 ||\n    typeof process.env.MASTRA_PROJECT_ID === 'string' && process.env.MASTRA_PROJECT_ID.length > 0;\n}","tryCatchPattern":"try {\n  await exec('mastra server deploy --yes');\n} catch (err) {\n  if (err instanceof Error && /existing project\\(s\\) in this organization/.test(err.message)) {\n    await exec(`mastra server deploy --yes --project ${REQUIRED_PROJECT_ID}`);\n  } else throw err;\n}","preventionTips":["Pin --project (or MASTRA_PROJECT_ID) in all non-interactive/CI deploys","Keep package.json name in sync with the deployed project's slug","Avoid duplicate project names in one organization","Do a first deploy interactively to establish .mastra-project.json"],"tags":["cli","ci","ambiguous-selection"],"backgroundTag":"ambiguous-project-selection","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}