mastra-ai/mastra · error · Error

Linked Studio project ${linkedProjectId} was not found in th

Error message

Linked Studio project ${linkedProjectId} was not found in this organization. Re-link your project or pass a deploy ID explicitly.

What it means

Thrown by getLatestProjectDeploy when the Studio config references a linked project ID that does not exist among the projects fetched for the current organization. The CLI cannot resolve a latest deploy because the configured project is no longer visible — it advises re-linking or passing a deploy ID explicitly.

Source

Thrown at packages/cli/src/commands/studio/deploy-suggestions.ts:23

import { pollForDiagnosis, printDeploySuggestions } from '../deploy-suggestions.js';
import { fetchDeployDiagnosis, fetchProjects, startDeployDiagnosis } from './platform-api.js';
import type { Project } from './platform-api.js';
import { loadProjectConfig } from './project-config.js';

function getLatestProjectDeploy(projects: Project[], linkedProjectId?: string) {
  const linkedProject = linkedProjectId ? projects.find(project => project.id === linkedProjectId) : null;
  if (linkedProject) {
    if (linkedProject.latestDeployId) {
      return { deployId: linkedProject.latestDeployId, projectId: linkedProject.id, projectName: linkedProject.name };
    }

    throw new Error(
      `No deploys found for linked Studio project ${linkedProject.name}. The suggestions command helps debug failed deployments, and you can run it after a deployment fails with \`mastra studio deploy suggestions <deploy-id>\` or \`mastra studio deploy suggestions\`.`,
    );
  }

  if (linkedProjectId) {
    throw new Error(
      `Linked Studio project ${linkedProjectId} was not found in this organization. Re-link your project or pass a deploy ID explicitly.`,
    );
  }

  const latestProject = projects
    .filter(project => project.latestDeployId)
    .sort((left, right) => {
      const leftTime = left.latestDeployCreatedAt ? Date.parse(left.latestDeployCreatedAt) : 0;
      const rightTime = right.latestDeployCreatedAt ? Date.parse(right.latestDeployCreatedAt) : 0;
      return rightTime - leftTime;
    })[0];

  if (!latestProject?.latestDeployId) {
    return null;
  }

  return { deployId: latestProject.latestDeployId, projectId: latestProject.id, projectName: latestProject.name };
}

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Re-link your Studio project (`mastra studio link` or equivalent) so the config points to an existing project in your current organization.
  2. Pass the deploy ID explicitly: `mastra studio deploy suggestions <deploy-id>` to bypass project resolution.
  3. Verify the projectId in your local Studio/project config matches a project in the organization you're authenticated against.
  4. Check you're logged into the correct organization/account.

Example fix

// before (stale config)
{ "projectId": "proj_old_deleted" }
// after
mastra studio link  # re-link to an existing project
Defensive patterns

Strategy: validation

Validate before calling

const projects = await fetchProjects(token, orgId);
const pid = projectConfig?.projectId;
if (pid && !projects.some(p => p.id === pid)) {
  console.error(`Linked project ${pid} not in org ${orgId}; re-link with 'mastra studio link'.`);
}

Try / catch

try {
  const dep = await resolveDeployId(args, ctx);
} catch (err) {
  if ((err as Error).message.includes('was not found in this organization')) {
    console.error('Re-link the project (`mastra studio link`) or pass a deploy ID explicitly.');
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: Running a deploy-suggestions/logs command while projectConfig.projectId refers to a project deleted from the organization, belonging to a different organization than the one being queried (organizationId mismatch), or typed/stale in the local Studio config.

Common situations: Project was deleted or transferred to another org after linking; developer switched organizations or accounts in the CLI; team members checked out a repo whose Studio config contains someone else's project ID.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/a6b21211ce5a717e. Report an issue: GitHub.