{"record":{"id":"86094dd6316781e0","repo":"HKUDS/Vibe-Trading","slug":"the-originating-session-is-not-an-im-conversation","errorCode":null,"errorMessage":"the originating session is not an IM conversation","messagePattern":"the originating session is not an IM conversation","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"agent/src/scheduled_research/service.py","lineNumber":109,"sourceCode":"        raise ValueError(\"end_at must include an explicit timezone offset\")\n    return int(parsed.timestamp() * 1000)\n\n\ndef _origin_target(session_id: str | None) -> tuple[str, str, str | None, str]:\n    if not session_id:\n        raise ValueError(\"origin delivery requires the originating session\")\n    host = sys.modules.get(\"api_server\") or sys.modules.get(\"agent.api_server\")\n    service = (\n        host._get_session_service()\n        if host and hasattr(host, \"_get_session_service\")\n        else None\n    )\n    session = service.get_session(session_id) if service else None\n    config = getattr(session, \"config\", None) or {}\n    channel = config.get(\"channel\")\n    target = config.get(\"channel_chat_id\")\n    if not isinstance(channel, str) or not isinstance(target, str):\n        raise ValueError(\"the originating session is not an IM conversation\")\n    return channel, target, None, \"当前会话\"\n\n\ndef build_job_from_draft(\n    draft: Mapping[str, Any],\n    *,\n    session_id: str | None = None,\n    now_ms: int | None = None,\n) -> ScheduledResearchJob:\n    \"\"\"Validate the public draft and build a persisted-model job.\"\"\"\n    now = int(time.time() * 1000) if now_ms is None else now_ms\n    title = str(draft.get(\"title\") or \"\").strip()\n    if not title:\n        raise ValueError(\"title is required\")\n    source = draft.get(\"source\")\n    schedule_spec = draft.get(\"schedule\")\n    delivery_spec = draft.get(\"delivery\") or {\"mode\": \"in_app\"}\n    if not isinstance(source, Mapping) or not isinstance(schedule_spec, Mapping):","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/scheduled_research/service.py#L91-L127","documentation":"For origin delivery, the originating session's config must contain a string 'channel' and 'channel_chat_id'. The session exists but is not bound to an IM conversation (or the config keys are missing/wrong types), so there is nowhere to deliver results.","triggerScenarios":"Session created via web UI or API without channel binding; config['channel'] set but channel_chat_id missing or numeric; test stub sessions lacking channel fields.","commonSituations":"Users trying origin delivery from the web app instead of the IM bot; partial session migrations that dropped channel metadata; channels that don't persist chat ids.","solutions":["Create the job from within the IM conversation so the session has channel + channel_chat_id","Verify session.config contains both keys as strings (str() the chat id if numeric)","Use 'configured' delivery with an explicit target_ref if the session can't be IM-bound"],"exampleFix":"# before\nsession.config = {\"channel\": \"telegram\"}  # no chat id\n# after\nsession.config = {\"channel\": \"telegram\", \"channel_chat_id\": \"12345\"}","handlingStrategy":"type-guard","validationCode":"cfg = session.config or {}\nassert isinstance(cfg.get(\"channel\"), str) and isinstance(cfg.get(\"channel_chat_id\"), str), \"session not IM-bound\"","typeGuard":"def session_is_im_conversation(session) -> bool:\n    cfg = getattr(session, \"config\", None) or {}\n    return isinstance(cfg.get(\"channel\"), str) and isinstance(cfg.get(\"channel_chat_id\"), str)","tryCatchPattern":"try:\n    build_job_from_draft(draft, session_id=sid)\nexcept ValueError as e:\n    if \"not an IM conversation\" in str(e):\n        suggest_configured_delivery()","preventionTips":["Persist channel/channel_chat_id as strings at session creation","Coerce numeric chat ids with str() before storing"],"tags":["scheduled-research","delivery","im-channel","session-config"],"backgroundTag":"missing-channel-binding","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}