mastra-ai/mastra · error
Failed to rename session (${res.status})
Error message
Failed to rename session (${res.status}) What it means
regenerateSessionTitle in mastracode/factory-ui/src/ui/domains/workspaces/services/user-sessions.ts throws this when the POST to `${baseUrl}/web/user-sessions/${sessionId}/title` either returns non-OK or returns OK but the JSON body lacks a `title` field. The server can supply a specific `error` string in the body, which takes precedence over the generic message; the fallback embeds the HTTP status.
Source
Thrown at mastracode/factory-ui/src/ui/domains/workspaces/services/user-sessions.ts:97
return normalizeUserSession(body.session);
}
export async function deleteUserSession(baseUrl: string, sessionId: string): Promise<void> {
const res = await fetch(`${baseUrl}/web/user-sessions/${encodeURIComponent(sessionId)}`, {
method: 'DELETE',
credentials: 'include',
});
if (!res.ok && res.status !== 404) throw new Error(`Failed to delete session (${res.status})`);
}
/** Ask the title model to re-name a session's conversation. Resolves to the new title. */
export async function regenerateSessionTitle(baseUrl: string, sessionId: string): Promise<string> {
const res = await fetch(`${baseUrl}/web/user-sessions/${encodeURIComponent(sessionId)}/title`, {
method: 'POST',
credentials: 'include',
});
const body: { title?: string; error?: string } = await res.json().catch(() => ({}));
if (!res.ok || !body.title) throw new Error(body.error ?? `Failed to rename session (${res.status})`);
return body.title;
}
View on GitHub (pinned to 75dd419e61)
Solutions
- Check the `error` field the server returned — the thrown message already prefers it; use it to pick the fix.
- On 404, refresh the session list — the session no longer exists.
- On 429, wait/back off before retrying; debounce the regenerate button.
- On 401/403, re-authenticate; the credentials: 'include' cookie has expired or lacks scope.
- If status is OK but title is missing, inspect the endpoint response shape — likely a server regression.
Example fix
// before: throws on empty body with generic message
const body: { title?: string; error?: string } = await res.json().catch(() => ({}));
if (!res.ok || !body.title) throw new Error(body.error ?? `Failed to rename session (${res.status})`);
// after: retry once on 429/5xx before failing
if ((res.status === 429 || res.status >= 500) && attempt === 0) return regenerateSessionTitle(baseUrl, sessionId);
if (!res.ok || !body.title) throw new Error(body.error ?? `Failed to rename session (${res.status})`); Defensive patterns
Strategy: try-catch
Validate before calling
const sessions = await fetchUserSessions(baseUrl);
if (!sessions.some(s => s.id === sessionId)) throw new Error('Session not found; refresh the list'); Type guard
function hasTitle(v: unknown): v is { title: string } {
return typeof v === 'object' && v !== null && typeof (v as { title?: unknown }).title === 'string' && (v as { title: string }).title.length > 0;
} Try / catch
try {
const title = await regenerateSessionTitle(baseUrl, sessionId);
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
if (msg.includes('(429)')) await backoff(() => regenerateSessionTitle(baseUrl, sessionId));
else if (msg.includes('(404)')) invalidateSessionList();
else showToast(`Rename failed: ${msg}`);
} Prevention
- Debounce/disable the regenerate button to avoid 429 rate limits from rapid clicks.
- Validate the session still exists before renaming.
- Handle empty-body 200 responses defensively — check the returned title before using it.
When it happens
Trigger: POST returns 401/403 (bad or expired session cookie), 404 (sessionId no longer exists), 429 (title-model rate limit), 500 while invoking the rename model, or 200 with a malformed/empty body (no title, no error) due to a server/serialization bug.
Common situations: User clicks 'regenerate title' on a session that was deleted in another tab (404); the LLM-backed rename endpoint rate-limits rapid clicks (429); the backend model call times out and returns 500; a proxy strips the JSON body so body.title is undefined even on 200.
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
- Failed to load repository settings (${res.status})
- Failed to delete session (${res.status})
- Agent Learning request failed (${response.status})
- Failed to get file content type
- Slack OAuth HTTP error: ${tokenResponse.status} ${tokenRespo
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/f378acc825cc2168.
Report an issue: GitHub.