{"record":{"id":"bb8367c2000d9f2f","repo":"iOfficeAI/AionUi","slug":"assistant-id-is-required","errorCode":null,"errorMessage":"assistant_id is required","messagePattern":"assistant_id is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/desktop/src/renderer/pages/cron/ScheduledTasksPage/resolveCronAgentConfig.ts","lineNumber":49,"sourceCode":"\nexport function resolveCronAgentConfig(input: ResolveCronAgentConfigInput): ResolveCronAgentConfigResult {\n  const {\n    agentValue,\n    presetAssistants,\n    selectedAionrsProvider,\n    model_id,\n    config_options,\n    workspace,\n    localeKey = 'en-US',\n    getMode,\n    aionrsModelRequiredMessage,\n  } = input;\n\n  const colonIdx = agentValue.indexOf(':');\n  const prefixedId = colonIdx >= 0 ? agentValue.substring(colonIdx + 1) : agentValue;\n  const assistantSelection = presetAssistants.find((item) => item.id === prefixedId || item.id === agentValue);\n  if (!assistantSelection) {\n    throw new Error('assistant_id is required');\n  }\n\n  let agent_config: ICronAgentConfigWrite | undefined;\n\n  const assistant = assistantSelection;\n  const assistantName = resolveAssistantName(assistant, localeKey, assistant.name);\n  const mode = getMode(assistant);\n\n  if (isAionrsAssistant(assistant)) {\n    if (!selectedAionrsProvider?.id || !model_id) {\n      throw new Error(aionrsModelRequiredMessage);\n    }\n    agent_config = {\n      name: assistantName,\n      assistant_id: assistant.id,\n      mode,\n      model_id,\n      model: {","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/iOfficeAI/AionUi/blob/711aa0550ee183ea495dc33e2c05c7943b70a60a/packages/desktop/src/renderer/pages/cron/ScheduledTasksPage/resolveCronAgentConfig.ts#L31-L67","documentation":"While resolving the agent configuration for a scheduled (cron) task, the selected assistant could not be found among `presetAssistants` by either its prefixed (`provider:id`) or raw id. The code treats a missing assistant as an invalid configuration and refuses to build the cron agent config.","triggerScenarios":"Submitting or evaluating a scheduled task whose `agentValue` references an assistant id that is not present in the loaded preset assistants list — e.g. an assistant that was uninstalled, disabled, or whose provider-scoped id string was parsed incorrectly.","commonSituations":"User picks an assistant, then the assistant/plugin is removed before the task is saved; preset assistant list failed to load (empty array) so every lookup misses; agentValue format changed (missing or extra `provider:` prefix) so the substring extraction yields a stale id; stale form state restored from localStorage after a version change.","solutions":["Re-fetch/refresh the preset assistants list and confirm it is non-empty before rendering the picker","Verify the agentValue string format matches the provider-prefixed convention used when building the list","Clear stale form state and re-select the assistant from the current list","If the assistant was removed, prompt the user to choose a replacement before submitting"],"exampleFix":"// before\nconst assistantSelection = presetAssistants.find((item) => item.id === prefixedId || item.id === agentValue);\nif (!assistantSelection) {\n  throw new Error('assistant_id is required');\n}\n\n// after (validate before submit and show i18n message)\nconst assistantSelection = presetAssistants.find((item) => item.id === prefixedId || item.id === agentValue);\nif (!assistantSelection) {\n  return { error: 'assistant_unavailable' } as const; // handled by handleSubmit with a toast\n}","handlingStrategy":"validation","validationCode":"const valid = presetAssistants.some((a) => a.id === extractId(agentValue));\nif (!valid) { /* re-select assistant, do not submit */ }","typeGuard":"const isKnownAssistant = (list: Assistant[], value: string): boolean =>\n  list.some((a) => a.id === value || a.id === value.substring(value.indexOf(':') + 1));","tryCatchPattern":"catch (e) { if (e.message === 'assistant_id is required') { await reloadAssistants(); toast.warning(t('cron.assistantUnavailable')); } }","preventionTips":["Refresh the assistant list when the scheduled-task form opens","Disable submit when the selected id is not in the current list"],"tags":["cron","scheduled-tasks","assistant","validation","config"],"backgroundTag":"referenced-entity-not-found","analyzedSha":"711aa0550ee183ea495dc33e2c05c7943b70a60a","analyzedAt":"2026-08-28T07:56:06.558Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}