mastra-ai/mastra · error · HTTPException

Favorites storage domain is not available

Error message

Favorites storage domain is not available

What it means

When listing with ?favoritedOnly=true, the handler additionally needs the 'favorites' domain store to resolve the caller's starred agent IDs; if storage.getStore('favorites') returns undefined it throws HTTP 500. Only triggered on the favorites-filtered list path, after agents store resolution succeeds.

Source

Thrown at packages/server/src/server/handlers/stored-agents.ts:289

      });

      const scope = await getStoredResourceScope(mastra, requestContext);
      const scopedMetadata = scopeStoredResourceMetadata(metadata, scope);

      const callerId = getCallerAuthorId(requestContext);
      const favoritesEnabled = await isBuilderFeatureEnabled(mastra, 'favorites');
      const honoredStarredOnly = favoritesEnabled && favoritedOnly === true;
      const favoriteSubjectId = pinFavoritedFor ?? callerId;

      // `?favoritedOnly=true`: fetch caller's favorited IDs, then refilter + recompute total.
      if (honoredStarredOnly) {
        const effectivePerPage: number = perPage ?? 100;
        if (!favoriteSubjectId) {
          return { agents: [], total: 0, page, perPage: effectivePerPage, hasMore: false };
        }
        const favoritesStore = await storage.getStore('favorites');
        if (!favoritesStore) {
          throw new HTTPException(500, { message: 'Favorites storage domain is not available' });
        }
        const starredIds = await favoritesStore.listFavoritedIds({ userId: favoriteSubjectId, entityType: 'agent' });
        if (starredIds.length === 0) {
          return { agents: [], total: 0, page, perPage: effectivePerPage, hasMore: false };
        }
        const allMatching = await agentsStore.listResolved({
          perPage: false,
          orderBy,
          status,
          authorId: filter.kind === 'exact' ? filter.authorId : undefined,
          metadata: scopedMetadata,
          entityIds: starredIds,
        });
        const visible = allMatching.agents.filter(record => matchesAuthorFilter(record, filter));
        const total = visible.length;
        const startIdx = effectivePerPage === 0 ? 0 : page * effectivePerPage;
        const endIdx = effectivePerPage === 0 ? 0 : startIdx + effectivePerPage;
        const sliced = effectivePerPage === 0 ? [] : visible.slice(startIdx, endIdx);

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Upgrade the storage adapter to a version implementing the favorites domain store
  2. Run the adapter's schema/migration step so the favorites table/domain exists
  3. Use an official adapter that supports favorites (@mastra/pg, @mastra/libsql current versions)
  4. Disable the favorites builder feature if the backend cannot support it

Example fix

// before
pnpm add @mastra/pg@1.2.0 // no favorites domain
// after
pnpm add @mastra/pg@latest && pnpm mastra db migrate
Defensive patterns

Strategy: fallback

Validate before calling

const fav = await mastra.getStorage()?.getStore('favorites');
if (!fav) console.warn('favorites domain unavailable; favoritedOnly queries will fail');

Type guard

function supportsFavorites(s: { getStore(d: string): Promise<unknown> }): Promise<boolean> {
  return s.getStore('favorites').then(Boolean);
}

Try / catch

try {
  return await get('/stored/agents?favoritedOnly=true');
} catch (e) {
  if ((e as any).status === 500 && /Favorites storage domain/.test((e as any).message)) {
    // degrade gracefully: fetch unfiltered list instead
    return get('/stored/agents');
  }
  throw e;
}

Prevention

When it happens

Trigger: GET /stored/agents?favoritedOnly=true (or pinFavoritedFor set) where the favorites feature flag is enabled but the storage adapter lacks a favorites domain store; adapter older than the favorites domain.

Common situations: Upgraded server enables favorites by default but the storage backend/adapter predates the favorites domain; custom adapter implements agents but not favorites; favorites feature flag turned on in config without migrating storage schema.

Related errors


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