microsoft/autogen · error · Error
Failed to fetch sessions
Error message
Failed to fetch sessions
What it means
Thrown by SessionAPI.listSessions when GET /sessions/?user_id=... returns a body with a falsy status field. Note the check is on data.status (the application-level envelope), not response.ok — so this fires even on HTTP 200 whenever the backend marks the operation failed. It also throws on non-JSON error bodies only indirectly (json() would throw first).
Source
Thrown at python/packages/autogen-studio/frontend/src/components/views/playground/api.ts:14
import { Session, SessionRuns } from "../../types/datamodel";
import { BaseAPI } from "../../utils/baseapi";
export class SessionAPI extends BaseAPI {
async listSessions(userId: string): Promise<Session[]> {
const response = await fetch(
`${this.getBaseUrl()}/sessions/?user_id=${userId}`,
{
headers: this.getHeaders(),
}
);
const data = await response.json();
if (!data.status)
throw new Error(data.message || "Failed to fetch sessions");
return data.data;
}
async getSession(sessionId: number, userId: string): Promise<Session> {
const response = await fetch(
`${this.getBaseUrl()}/sessions/${sessionId}?user_id=${userId}`,
{
headers: this.getHeaders(),
}
);
const data = await response.json();
if (!data.status)
throw new Error(data.message || "Failed to fetch session");
return data.data;
}
async createSession(
sessionData: Partial<Session>,View on GitHub (pinned to 027ecf0a37)
Solutions
- Log the full response body — data.message identifies which envelope failure it is
- Ensure userId is a real non-empty value before calling (guard against undefined during initial load)
- Verify the auth token matches the user_id being queried
- Hit GET /sessions/?user_id=... directly with curl to see the raw envelope
- If data is undefined because the body was an HTML error page, harden the json parse (see exampleFix)
Example fix
// before
const response = await fetch(`${this.getBaseUrl()}/sessions/?user_id=${userId}`, { headers: this.getHeaders() });
const data = await response.json();
if (!data.status) throw new Error(data.message || "Failed to fetch sessions");
// after
const response = await fetch(`${this.getBaseUrl()}/sessions/?user_id=${encodeURIComponent(userId)}`, { headers: this.getHeaders() });
if (!response.ok) throw new Error(`Failed to fetch sessions (HTTP ${response.status})`);
const data = await response.json();
if (!data.status) throw new Error(data.message || "Failed to fetch sessions"); Defensive patterns
Strategy: validation
Validate before calling
function isValidUserId(u: string | undefined | null): u is string {
return typeof u === "string" && u.length > 0;
}
// gate the call
if (!isValidUserId(userId)) throw new Error("userId not loaded yet"); Type guard
function isSessionListEnvelope(x: unknown): x is { status: true; data: Session[] } {
return !!x && typeof x === "object" && (x as any).status === true && Array.isArray((x as any).data);
} Try / catch
try {
setSessions(await sessionAPI.listSessions(userId));
} catch (e) {
setSessions([]);
notify(e instanceof Error ? e.message : "Failed to fetch sessions");
} Prevention
- Never fire session calls before the user context is loaded
- Check both response.ok and data.status in wrappers so 401 JSON envelopes don't masquerade as generic failures
- Use encodeURIComponent on user_id query params
When it happens
Trigger: GET {base}/sessions/?user_id=X returning {status:false,...}: invalid/empty user_id, user not found in the backend DB, auth token rejected (backend answers 200/401 with status:false envelope), or backend DB unavailable.
Common situations: user_id not yet loaded (empty string) when the call fires on mount, user deleted/recreated while token stale, fresh database with no migrations, auth mismatch between token subject and user_id param.
Related errors
- Failed to fetch session
- Failed to list MCP tools
- Failed to call MCP tool
- MCP health check failed
- HTTP ${response.status}: ${errorText || "Failed to create We
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/16a5a9f94d9b960c.
Report an issue: GitHub.