{"record":{"id":"0f2f138e2a9cc300","repo":"mastra-ai/mastra","slug":"session-configuration-is-not-ready-try-again","errorCode":null,"errorMessage":"Session configuration is not ready. Try again.","messagePattern":"Session configuration is not ready\\. Try again\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mastracode/factory-ui/src/ui/domains/chat/hooks/useCreateUserSessionFromDraft.ts","lineNumber":29,"sourceCode":"import { AGENT_CONTROLLER_ID } from '../services/constants';\nimport { promptHandoffState } from './useHandoffPrompt';\n\nexport function useCreateUserSessionFromDraft() {\n  const { baseUrl, factorySessionState } = useChatSessionContext();\n  const { activeModeId } = useChatModes();\n  const { activeModelId, draftModelPackId, modelPacks } = useChatModels();\n  const { factoryId, draftSessionId } = useParams<{ factoryId: string; draftSessionId: string }>();\n  const queryClient = useQueryClient();\n  const navigate = useNavigate();\n\n  return useMutation({\n    mutationFn: async (prompt: string) => {\n      const projectRepositoryId = factorySessionState?.projectRepositoryId;\n      if (!draftSessionId || !factoryId || !projectRepositoryId) {\n        throw new Error('Could not create the session. Reload the page and try again.');\n      }\n      if (!activeModeId || !activeModelId) {\n        throw new Error('Session configuration is not ready. Try again.');\n      }\n\n      // Activating the pack applies its models server-side, so only hand off a\n      // model when the draft explicitly deviated from the selected pack.\n      const modeKey =\n        activeModeId === 'build' || activeModeId === 'plan' || activeModeId === 'fast' ? activeModeId : undefined;\n      const packModelId =\n        draftModelPackId && modeKey\n          ? modelPacks.find(pack => pack.id === draftModelPackId)?.models[modeKey]\n          : undefined;\n      const handoffModelId = activeModelId === packModelId ? undefined : activeModelId;\n\n      try {\n        const session = await createUserSession(baseUrl, projectRepositoryId, {\n          sessionId: draftSessionId,\n          title: prompt,\n        });\n        return { session, prompt, factoryId, projectRepositoryId, activeModeId, handoffModelId, draftModelPackId };","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory-ui/src/ui/domains/chat/hooks/useCreateUserSessionFromDraft.ts#L11-L47","documentation":"Thrown inside useCreateUserSessionFromDraft's createDraftSessionMutation when the draft session is submitted but the UI has not yet resolved an active mode or active model. The mutation requires both activeModeId and activeModelId to hand off configuration to the server, so it aborts early with a retry-oriented message. It is a transient readiness guard, not a server failure.","triggerScenarios":"Calling createDraftSessionMutation.mutateAsync(prompt) while activeModeId or activeModelId is still undefined/null — typically submitting before mode/model selection hydrates from the draft session, pack activation, or model policy fetch.","commonSituations":"Rapid double-submit on mount before React Query resolves mode/model state; a draft whose model pack failed to activate server-side leaving no activeModelId; a model policy that filters out all models so no model becomes active.","solutions":["Wait until activeModeId and activeModelId are defined before enabling the submit control (disable the composer button when either is missing).","Verify the model pack / mode state that should populate activeModelId actually loaded (check the pack activation response and model policy allowlist).","Retry the mutation after the configuration state settles, per the error message.","If persistent, confirm factorySessionState provides projectRepositoryId and that draftSessionId was created (the sibling error covers missing ids)."],"exampleFix":"// before\nif (!activeModeId || !activeModelId) {\n  throw new Error('Session configuration is not ready. Try again.');\n}\n// after\nif (!activeModeId || !activeModelId) {\n  if (!submitEnabled) return; // gate the button instead of throwing\n  throw new Error('Session configuration is not ready. Try again.');\n}","handlingStrategy":"validation","validationCode":"const canSubmit = Boolean(draftSessionId && factoryId && factorySessionState?.projectRepositoryId && activeModeId && activeModelId);\nif (!canSubmit) disableSubmit(); // only call mutateAsync when canSubmit is true","typeGuard":"function hasSessionConfig(s: { activeModeId?: string | null; activeModelId?: string | null }): s is { activeModeId: string; activeModelId: string } {\n  return typeof s.activeModeId === 'string' && s.activeModeId.length > 0 && typeof s.activeModelId === 'string' && s.activeModelId.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Disable the submit button until mode and model are resolved.","Surface a loading state while mode/model hydration is pending.","Alert on model packs that activate with zero active models."],"tags":["react-query","state-readiness","mutation","ui"],"backgroundTag":"state-not-ready","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}