mastra-ai/mastra · error

Agent Learning request failed (${response.status})

Error message

Agent Learning request failed (${response.status})

What it means

defaultRequest is the fetch wrapper used by the Agent Learning / Trace Intelligence context in the playground UI. It calls fetch with credentials included and throws this error whenever the HTTP response status is not ok (e.g. 404, 401, 500), since the API endpoint did not return a usable response. The thrown Error discards the response body, so only the numeric status is reported.

Source

Thrown at packages/playground-ui/src/ee/signals/trace-intelligence-context.ts:10

import { createContext } from 'react';

import type { LinkComponent } from '@/ds/types/link-component';

export type TraceIntelligenceRequest = <Response>(path: string) => Promise<Response>;

async function defaultRequest<Response>(path: string): Promise<Response> {
  const response = await fetch(path, { credentials: 'include' });
  if (!response.ok) {
    throw new Error(`Agent Learning request failed (${response.status})`);
  }
  return response.json() as Promise<Response>;
}

export interface TraceIntelligenceContextValue {
  cacheScope: string;
  request: TraceIntelligenceRequest;
  LinkComponent: LinkComponent;
  getTraceHref: (traceId: string) => string;
}

export const defaultTraceIntelligenceContextValue: TraceIntelligenceContextValue = {
  cacheScope: 'oss-studio',
  request: defaultRequest,
  LinkComponent: 'a',
  getTraceHref: traceId => `/traces?traceId=${encodeURIComponent(traceId)}`,
};

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Check the reported HTTP status in the message and inspect the corresponding server logs for the failing endpoint.
  2. Verify the playground and server versions match so the Agent Learning API routes exist (404).
  3. Confirm you are logged in / session cookie is valid (401/403); re-authenticate.
  4. Retry the request if the status is 5xx, as it may be a transient backend failure.

Example fix

// before
const data = await request('/api/agent-learning/summary');

// after
try {
  const data = await request('/api/agent-learning/summary');
} catch (e) {
  if (e instanceof Error && e.message.startsWith('Agent Learning request failed')) {
    showAgentLearningUnavailableNotice();
  } else {
    throw e;
  }
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const data = await request<Response>(path);
} catch (e) {
  const status = e instanceof Error ? /\((\d+)\)$/.exec(e.message)?.[1] : undefined;
  if (status === '401' || status === '403') redirectToLogin();
  else showFallbackUi();
}

Prevention

When it happens

Trigger: Any call to the TraceIntelligenceRequest function where fetch(path, { credentials: 'include' }) resolves with response.ok === false — e.g. the Agent Learning API route is missing, the server returns 401/403 because the user is not authenticated, or a 500 from a backend failure.

Common situations: Running the playground against a server that does not have the Agent Learning routes registered (older server version), an expired or missing session cookie causing 401, or a transient server error (500/502) behind a proxy.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


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