{"record":{"id":"cfe19244613c453c","repo":"github/copilot-sdk","slug":"no-user-input-handler-registered","errorCode":null,"errorMessage":"No user input handler registered","messagePattern":"No user input handler registered","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Session.cs","lineNumber":1682,"sourceCode":"            if (result.Action == UIElicitationResponseAction.Accept\n                && result.Content != null\n                && result.Content.TryGetValue(\"value\", out var val))\n            {\n                return val.ValueKind == JsonValueKind.String ? val.GetString() : val.ToString();\n            }\n\n            return null;\n        }\n    }\n\n    /// <summary>\n    /// Handles a user input request from the Copilot CLI.\n    /// </summary>\n    /// <param name=\"request\">The user input request from the CLI.</param>\n    /// <returns>A task that resolves with the user's response.</returns>\n    internal async Task<UserInputResponse> HandleUserInputRequestAsync(UserInputRequest request)\n    {\n        var handler = _userInputHandler ?? throw new InvalidOperationException(\"No user input handler registered\");\n        var invocation = new UserInputInvocation\n        {\n            SessionId = SessionId\n        };\n\n        var userInputTimestamp = Stopwatch.GetTimestamp();\n        var response = await handler(request, invocation);\n        LoggingHelpers.LogTiming(_logger, LogLevel.Debug, null,\n            \"CopilotSession.HandleUserInputRequestAsync dispatch. Elapsed={Elapsed}, SessionId={SessionId}\",\n            userInputTimestamp,\n            SessionId);\n        return response;\n    }\n\n    /// <summary>\n    /// Handles an exit-plan-mode request from the Copilot CLI.\n    /// </summary>\n    /// <param name=\"request\">The exit-plan-mode request from the CLI.</param>","sourceCodeStart":1664,"sourceCodeEnd":1700,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Session.cs#L1664-L1700","documentation":"HandleUserInputRequestAsync processes user-input requests sent by the Copilot CLI. It requires an application-registered user input handler (_userInputHandler); if none was registered when the CLI asks for user input, the SDK throws InvalidOperationException rather than silently returning an empty answer.","triggerScenarios":"The host sends a UserInputRequest (e.g. the agent needs user confirmation/input) while the app never called the registration API that sets _userInputHandler, or the handler was registered on a different session instance.","commonSituations":"Running the SDK without wiring the user-input callback while the agent task requires interaction; forgetting to register handlers after recreating the session; interactive flows exercised in headless test runs.","solutions":["Register a user input handler on the session (the API that assigns _userInputHandler) before starting/continuing tasks.","Implement the handler to surface the prompt to your UI/CLI and return a UserInputResponse.","If interaction is impossible, ensure the agent flow avoids user-input-requiring tools, or catch the error and respond with a decline/failure to the request.","Confirm the handler is registered on the same session instance that is running the task."],"exampleFix":"// before\nvar session = new CopilotSession(...);\nawait session.SendAsync(\"deploy\"); // throws on user input request\n\n// after\nvar session = new CopilotSession(...);\nsession.RegisterUserInputHandler(async req => new UserInputResponse { Answer = Console.ReadLine() });\nawait session.SendAsync(\"deploy\");","handlingStrategy":"validation","validationCode":"if (!session.HasUserInputHandler)\n    session.RegisterUserInputHandler(req => Task.FromResult(new UserInputResponse { Answer = AskUser(req) }));","typeGuard":"bool ready = session is { _userInputHandler: not null }; // prefer a public HasUserInputHandler check","tryCatchPattern":"try { var resp = await session.HandleUserInputRequestAsync(request); }\ncatch (InvalidOperationException ex) when (ex.Message == \"No user input handler registered\")\n{ return UserInputResponse.Decline(\"Interactive input unavailable\"); }","preventionTips":["Register the user input handler before starting agent tasks","Re-register handlers when recreating sessions","Provide a headless default handler for test/CI runs"],"tags":["user-input","handler-registration","configuration","dotnet"],"backgroundTag":"missing-required-config-field","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}