{"record":{"id":"8a811b91d43092fb","repo":"github/copilot-sdk","slug":"user-input-requested-but-no-handler-registered-8a811b","errorCode":null,"errorMessage":"User input requested but no handler registered","messagePattern":"User input requested but no handler registered","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/copilot/session.py","lineNumber":2829,"sourceCode":"\n    async def _handle_user_input_request(self, request: dict) -> UserInputResponse:\n        \"\"\"\n        Handle a user input request from the Copilot CLI.\n\n        Note:\n            This method is internal and should not be called directly.\n\n        Args:\n            request: The user input request data from the CLI.\n\n        Returns:\n            A dictionary containing the user's response.\n        \"\"\"\n        with self._user_input_handler_lock:\n            handler = self._user_input_handler\n\n        if not handler:\n            raise RuntimeError(\"User input requested but no handler registered\")\n\n        try:\n            handler_start = time.perf_counter()\n            result = handler(\n                UserInputRequest(\n                    question=request.get(\"question\", \"\"),\n                    choices=request.get(\"choices\") or [],\n                    allowFreeform=request.get(\"allowFreeform\", True),\n                ),\n                {\"session_id\": self.session_id},\n            )\n            if inspect.isawaitable(result):\n                result = await result\n            log_timing(\n                logger,\n                logging.DEBUG,\n                \"CopilotSession._handle_user_input_request dispatch\",\n                handler_start,","sourceCodeStart":2811,"sourceCodeEnd":2847,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/python/copilot/session.py#L2811-L2847","documentation":"Raised by CopilotSession's user-input request dispatcher in python/copilot/session.py when the host sends a user-input request but no user-input handler was registered on the session (self._user_input_handler is None). The SDK cannot prompt the user, so it fails the request immediately with a RuntimeError.","triggerScenarios":"The agent issues a user-input request during a turn while the application never called the session's register/set user-input handler (or explicitly cleared it by passing None).","commonSituations":"Headless/embedded integrations that don't wire a user-input callback; registering handlers after the first prompt already triggered a request; accidentally passing None to clear handlers while the agent still asks questions.","solutions":["Register a user-input handler on the session (the callback receiving UserInputRequest) before sending any prompt.","Re-register the handler after resume_session — registrations are per-session and not persisted.","If prompting is impossible in your environment, configure the session/agent to run without user questions (e.g. non-interactive mode) so no user-input request is issued.","Inspect the request's question field in your handler and return a structured response dict; wrap handler code in try/except so handler bugs don't masquerade as missing-handler errors."],"exampleFix":"# before\nsession = await client.create_session()\nawait session.send_and_wait(\"Deploy to prod?\")  # RuntimeError: no user-input handler\n\n# after\nsession = await client.create_session()\nsession.register_user_input_handler(lambda req: {\"answer\": input(req.question)})\nawait session.send_and_wait(\"Deploy to prod?\")","handlingStrategy":"validation","validationCode":"if getattr(session, \"_user_input_handler\", None) is None:\n    raise ValueError(\"register a user-input handler before sending prompts that may ask questions\")","typeGuard":"def has_user_input_handler(session) -> bool:\n    return callable(getattr(session, \"_user_input_handler\", None))","tryCatchPattern":"try:\n    message = await session.send_and_wait(prompt)\nexcept RuntimeError as e:\n    if \"no handler registered\" in str(e):\n        session.register_user_input_handler(default_console_handler)\n        message = await session.send_and_wait(prompt)\n    else:\n        raise","preventionTips":["Register the user-input handler immediately after session creation, before any send.","Re-register handlers after resume_session.","Never pass None to clear the handler while the agent can still emit user-input requests.","In non-interactive environments, configure the agent to avoid user questions instead of leaving the handler unset."],"tags":["user-input","handler","session","registration"],"backgroundTag":"missing-required-config","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"}