{"record":{"id":"906bdefc68dcd451","repo":"github/copilot-sdk","slug":"invalid-auto-mode-switch-request-payload-906bde","errorCode":null,"errorMessage":"invalid auto mode switch request payload","messagePattern":"invalid auto mode switch request payload","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/copilot/client.py","lineNumber":4978,"sourceCode":"        recommended_action = params.get(\"recommendedAction\")\n\n        if not session_id or not isinstance(summary, str):\n            raise ValueError(\"invalid exit plan mode request payload\")\n        if not isinstance(actions, list) or not isinstance(recommended_action, str):\n            raise ValueError(\"invalid exit plan mode request payload\")\n\n        with self._sessions_lock:\n            session = self._sessions.get(session_id)\n        if not session:\n            raise ValueError(f\"unknown session {session_id}\")\n\n        return dict(await session._handle_exit_plan_mode_request(params))\n\n    async def _handle_auto_mode_switch_request(self, params: dict) -> dict:\n        \"\"\"Handle an autoModeSwitch.request callback from the CLI server.\"\"\"\n        session_id = params.get(\"sessionId\")\n        if not session_id:\n            raise ValueError(\"invalid auto mode switch request payload\")\n\n        with self._sessions_lock:\n            session = self._sessions.get(session_id)\n        if not session:\n            raise ValueError(f\"unknown session {session_id}\")\n\n        response = await session._handle_auto_mode_switch_request(params)\n        return {\"response\": response}\n\n    async def _handle_system_message_transform(self, params: dict) -> dict:\n        \"\"\"Handle a systemMessage.transform request from the CLI server.\"\"\"\n        session_id = params.get(\"sessionId\")\n        sections = params.get(\"sections\")\n\n        if not session_id or not sections:\n            raise ValueError(\"invalid systemMessage.transform payload\")\n\n        with self._sessions_lock:","sourceCodeStart":4960,"sourceCodeEnd":4996,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/python/copilot/client.py#L4960-L4996","documentation":"Raised by the auto-mode-switch callback handler when params contain no 'sessionId'. Without a session id the request cannot be routed to any session, so the payload is considered invalid and a ValueError is thrown.","triggerScenarios":"The CLI server sends an autoModeSwitch.request callback whose params dict is empty or lacks the 'sessionId' key (or it is falsy, e.g. None or empty string).","commonSituations":"CLI/SDK version skew where the server uses a different params schema, a misbehaving CLI build, or a synthesized event dict missing 'sessionId'.","solutions":["Upgrade CLI and SDK to compatible versions so autoModeSwitch.request includes sessionId","Log params before the raise to confirm which key is absent","If emitting the request yourself, always set params['sessionId'] to the active session id","Catch ValueError in the dispatch layer and reply with an error response rather than propagating"],"exampleFix":"// before\nawait client._handle_auto_mode_switch_request({})\n// after\nawait client._handle_auto_mode_switch_request({\"sessionId\": sid})","handlingStrategy":"validation","validationCode":"def valid_auto_mode_params(p):\n    return isinstance(p, dict) and bool(p.get(\"sessionId\"))","typeGuard":"def has_session_id(p) -> bool:\n    return isinstance(p, dict) and isinstance(p.get(\"sessionId\"), str) and bool(p[\"sessionId\"])","tryCatchPattern":"try:\n    await client._handle_auto_mode_switch_request(params)\nexcept ValueError as e:\n    logger.error(\"bad auto-mode-switch payload: %s | params=%r\", e, params)","preventionTips":["Always include sessionId in autoModeSwitch.request params","Assert payload schema at the CLI/server boundary in tests","Pin CLI and SDK versions together","Log params before dispatch to catch schema drift early"],"tags":["validation","payload","auto-mode","rpc"],"backgroundTag":"missing-required-argument","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}