{"record":{"id":"c461d76c81275470","repo":"microsoft/autogen","slug":"kernel-is-not-running","errorCode":null,"errorMessage":"Kernel is not running","messagePattern":"Kernel is not running","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs","lineNumber":62,"sourceCode":"\n    public Kernel? Kernel => this.kernel;\n\n    public async Task<bool> StartAsync(string workingDirectory, CancellationToken ct = default)\n    {\n        if (this.kernel != null)\n        {\n            return true;\n        }\n\n        this.kernel = await this.CreateKernelAsync(workingDirectory, true, ct);\n        return true;\n    }\n\n    public async Task<string?> SubmitCommandAsync(SubmitCode cmd, CancellationToken ct)\n    {\n        if (this.kernel == null)\n        {\n            throw new ArgumentException(\"Kernel is not running\");\n        }\n\n        return await this.kernel.RunSubmitCodeCommandAsync(cmd.Code, cmd.TargetKernelName, ct);\n    }\n\n    public async Task<string?> SubmitPowershellCodeAsync(string code, CancellationToken ct)\n    {\n        var command = new SubmitCode(code, targetKernelName: \"pwsh\");\n        return await this.SubmitCommandAsync(command, ct);\n    }\n\n    public async Task<string?> SubmitCSharpCodeAsync(string code, CancellationToken ct)\n    {\n        var command = new SubmitCode(code, targetKernelName: \"csharp\");\n        return await this.SubmitCommandAsync(command, ct);\n    }\n\n    public bool RestoreDotnetInteractive()","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs#L44-L80","documentation":"Thrown by InteractiveService.SubmitCommandAsync when the internal kernel field is null — the interactive kernel process has not been started (or the service was never given one). All Submit*CodeAsync helpers route through this guard, so any code submission before startup fails with ArgumentException('Kernel is not running').","triggerScenarios":"Creating InteractiveService with the directory constructor (kernel starts as null) and calling SubmitCSharpCodeAsync/SubmitPowershellCodeAsync/SubmitCommandAsync before awaiting StartAsync, or after a kernel crash/dispose left kernel null.","commonSituations":"Forgetting the awaited StartAsync call, calling submit from a thread that races ahead of startup, using the service after Dispose, or the kernel process dying mid-session (then a subsequent submit throws).","solutions":["Await service.StartAsync(workingDirectory) once before any submit call","Check service.Kernel is not null before submitting (it is exposed as a public property) as a cheap pre-condition","If the kernel died, recreate the InteractiveService and StartAsync again rather than reusing it","Avoid calling submit after DisposeAsync/Dispose"],"exampleFix":"// before:\nvar service = new InteractiveService(dir);\nawait service.SubmitCSharpCodeAsync(\"1+1\", ct); // throws: kernel null\n// after:\nvar service = new InteractiveService(dir);\nawait service.StartAsync(workingDirectory);\nawait service.SubmitCSharpCodeAsync(\"1+1\", ct);","handlingStrategy":"validation","validationCode":"// Guard before submitting\nif (service.Kernel is null)\n{\n    var ok = await service.StartAsync(workingDirectory, ct);\n    if (!ok) throw new InvalidOperationException(\"Failed to start interactive kernel\");\n}\nvar result = await service.SubmitCSharpCodeAsync(code, ct);","typeGuard":"static bool IsKernelRunning(InteractiveService s) => s.Kernel is not null;","tryCatchPattern":"try { await service.SubmitCSharpCodeAsync(code, ct); }\ncatch (ArgumentException e) when (e.Message == \"Kernel is not running\")\n{ /* kernel not started or died: recreate service, await StartAsync, retry once */ }","preventionTips":["Await StartAsync exactly once at startup before any submit","Check the public Kernel property as a cheap pre-condition"],"tags":["autogen","dotnet-interactive","lifecycle","initialization"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}