{"record":{"id":"2b2fb5c1bdbaf24c","repo":"microsoft/semantic-kernel","slug":"this-thread-has-been-deleted-and-cannot-be-recreat-2b2fb5","errorCode":null,"errorMessage":"This thread has been deleted and cannot be recreated.","messagePattern":"This thread has been deleted and cannot be recreated\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/OpenAI/OpenAIResponseAgentThread.cs","lineNumber":58,"sourceCode":"\n        this._client = client;\n        this.ResponseId = responseId;\n    }\n\n    /// <summary>\n    /// The current response id.\n    /// </summary>\n    internal string? ResponseId { get; set; }\n\n    /// <inheritdoc />\n    public override string? Id => this.ResponseId;\n\n    /// <inheritdoc />\n    protected override Task<string?> CreateInternalAsync(CancellationToken cancellationToken = default)\n    {\n        if (this._isDeleted)\n        {\n            throw new InvalidOperationException(\"This thread has been deleted and cannot be recreated.\");\n        }\n\n        // Id will not be available until after a message is sent\n        return Task.FromResult<string?>(null);\n    }\n\n    /// <inheritdoc />\n    protected override async Task DeleteInternalAsync(CancellationToken cancellationToken = default)\n    {\n        if (this._isDeleted)\n        {\n            return;\n        }\n\n        if (this.ResponseId is null)\n        {\n            throw new InvalidOperationException(\"This thread cannot be deleted, since it has not been created.\");\n        }","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/OpenAI/OpenAIResponseAgentThread.cs#L40-L76","documentation":"Thrown by CreateInternalAsync on OpenAIResponseAgentThread when _isDeleted is true. OpenAIResponseAgentThread is lazily created (its id is the first response id), and after deletion it cannot be recreated — the guard makes that explicit. Normally CreateInternalAsync just returns null (id arrives after the first message).","triggerScenarios":"await thread.DeleteAsync(); then any later use of the thread that triggers internal creation (e.g. a new invoke that calls EnsureThreadExists → CreateAsync → CreateInternalAsync).","commonSituations":"Reusing a deleted thread object for a new turn instead of allocating a fresh one.","solutions":["After deleting, do not reuse the instance — create a new OpenAIResponseAgentThread.","Track deletion state in your application so a deleted thread is replaced, not reused."],"exampleFix":"// before\nawait thread.DeleteAsync();\nawait agent.InvokeAsync(messages, thread); // CreateInternalAsync throws\n\n// after\nawait thread.DeleteAsync();\nthread = new OpenAIResponseAgentThread(client);\nawait agent.InvokeAsync(messages, thread);","handlingStrategy":"validation","validationCode":"if (thread.IsDeleted)\n{\n    thread = new OpenAIResponseAgentThread(client);\n}\nawait agent.InvokeAsync(messages, thread);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat a deleted Response thread as terminal; allocate a new one for new conversations.","Track lifecycle state so deleted threads are replaced, not reused."],"tags":["thread","lifecycle","responses-api","agents","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}