mastra-ai/mastra · error
Could not create the session: ${message}. Try again.
Error message
Could not create the session: ${message}. Try again. What it means
Wrapping error thrown in createDraftSessionMutation's catch: any failure from the underlying session-creation call is re-thrown as 'Could not create the session: <cause message>. Try again.' with the original attached as cause. It exists to give users a single actionable message while preserving the root-cause error for developers.
Source
Thrown at mastracode/factory-ui/src/ui/domains/chat/hooks/useCreateUserSessionFromDraft.ts:50
// Activating the pack applies its models server-side, so only hand off a
// model when the draft explicitly deviated from the selected pack.
const modeKey =
activeModeId === 'build' || activeModeId === 'plan' || activeModeId === 'fast' ? activeModeId : undefined;
const packModelId =
draftModelPackId && modeKey
? modelPacks.find(pack => pack.id === draftModelPackId)?.models[modeKey]
: undefined;
const handoffModelId = activeModelId === packModelId ? undefined : activeModelId;
try {
const session = await createUserSession(baseUrl, projectRepositoryId, {
sessionId: draftSessionId,
title: prompt,
});
return { session, prompt, factoryId, projectRepositoryId, activeModeId, handoffModelId, draftModelPackId };
} catch (error) {
const message = error instanceof Error ? error.message : 'Session creation failed';
throw new Error(`Could not create the session: ${message}. Try again.`, { cause: error });
}
},
onSuccess: ({
session,
prompt,
factoryId,
projectRepositoryId,
activeModeId,
handoffModelId,
draftModelPackId,
}) => {
queryClient.setQueryData(queryKeys.userSession(session.sessionId), session);
addCachedSession(queryClient, projectRepositoryId, session);
queryClient.setQueryData<MastraDBMessage[]>(
queryKeys.agentControllerThreadMessages(
AGENT_CONTROLLER_ID,
session.sessionId,
session.sessionId,View on GitHub (pinned to 75dd419e61)
Solutions
- Read error.cause to see the underlying message and fix that root issue first.
- Retry the mutation as the message suggests; if it persists, check server logs for the create-session endpoint status.
- Confirm the user session is authenticated (cookies/credentials: include) and the factoryId/projectRepositoryId are valid.
- Verify handoffModelId (when set) is permitted by the active model pack/policy.
Example fix
// before
try {
session = await client.createSession({ ... });
} catch (error) {
const message = error instanceof Error ? error.message : 'Session creation failed';
throw new Error(`Could not create the session: ${message}. Try again.`, { cause: error });
}
// after
try {
session = await client.createSession({ ... });
} catch (error) {
console.error('session create root cause:', error); // inspect cause server/client side
throw new Error(`Could not create the session: ${error instanceof Error ? error.message : 'Session creation failed'}. Try again.`, { cause: error });
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!draftSessionId || !factoryId || !factorySessionState?.projectRepositoryId) throw new Error('Could not create the session. Reload the page and try again.'); Type guard
function hasCause(e: unknown): e is Error & { cause: unknown } {
return e instanceof Error && 'cause' in e;
} Try / catch
try {
await createDraftSessionMutation.mutateAsync(prompt);
} catch (error) {
const root = (error as { cause?: unknown })?.cause;
showToast(`Could not create the session: ${root instanceof Error ? root.message : String(error)}. Try again.`);
// optionally inspect root for status-specific handling (401 -> re-login)
} Prevention
- Always log error.cause to find the root failure.
- Ensure the user session is authenticated before entering the composer.
- Validate handoffModelId against the active model policy before submitting.
When it happens
Trigger: Any exception inside the mutation body after the readiness checks — server 4xx/5xx from the create-session request, network failure, or a thrown error from activating the pack / creating the session server-side.
Common situations: Expired or missing auth cookie causing 401 on session create; server rejecting a handoffModelId not allowed by policy; transient network drop mid-request; draft session already consumed.
Related errors
- Session configuration is not ready. Try again.
- Failed to load repository settings (${res.status})
- Token exchange failed: ${error}
- Failed to fetch user info from Auth0
- Token exchange failed: ${error}
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/da622c2374cdcc39.
Report an issue: GitHub.