{"record":{"id":"6cb3519fb83bb88a","repo":"microsoft/semantic-kernel","slug":"this-thread-has-been-deleted-and-cannot-be-used-an-6cb351","errorCode":null,"errorMessage":"This thread has been deleted and cannot be used anymore.","messagePattern":"This thread has been deleted and cannot be used anymore\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/OpenAI/OpenAIResponseAgentThread.cs","lineNumber":95,"sourceCode":"\n        try\n        {\n            await this._client.DeleteResponseAsync(this.ResponseId, cancellationToken).ConfigureAwait(false);\n        }\n        catch (Exception ex)\n        {\n            throw new AgentThreadOperationException(\"The thread could not be deleted due to an error response from the service.\", ex);\n        }\n\n        this._isDeleted = true;\n    }\n\n    /// <inheritdoc/>\n    protected override Task OnNewMessageInternalAsync(ChatMessageContent newMessage, CancellationToken cancellationToken = default)\n    {\n        if (this._isDeleted)\n        {\n            throw new InvalidOperationException(\"This thread has been deleted and cannot be used anymore.\");\n        }\n\n        return Task.CompletedTask;\n    }\n\n    /// <inheritdoc />\n    public async IAsyncEnumerable<ChatMessageContent> GetMessagesAsync([EnumeratorCancellation] CancellationToken cancellationToken = default)\n    {\n        if (this._isDeleted)\n        {\n            throw new InvalidOperationException(\"This thread has been deleted and cannot be used anymore.\");\n        }\n\n        if (!string.IsNullOrEmpty(this.ResponseId))\n        {\n            var collectionResult = this._client.GetResponseInputItemsAsync(this.ResponseId, cancellationToken).ConfigureAwait(false);\n            await foreach (var responseItem in collectionResult)\n            {","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/OpenAI/OpenAIResponseAgentThread.cs#L77-L113","documentation":"Thrown by OnNewMessageInternalAsync on OpenAIResponseAgentThread when _isDeleted is true. Once deleted, the thread refuses any new message. This mirrors the deleted-thread guard on the other thread types (241/252).","triggerScenarios":"await thread.DeleteAsync(); then await agent.InvokeAsync(newMessage, thread); (or thread.OnNewMessageAsync) which routes through OnNewMessageInternalAsync.","commonSituations":"Conversation-end cleanup followed by a late inbound message; reusing a deleted Response thread.","solutions":["Check thread.IsDeleted before sending new messages.","Create a fresh OpenAIResponseAgentThread for a new conversation."],"exampleFix":"// before\nawait thread.DeleteAsync();\nawait agent.InvokeAsync(msg, thread); // throws\n\n// after\nif (thread.IsDeleted) thread = new OpenAIResponseAgentThread(client);\nawait agent.InvokeAsync(msg, thread);","handlingStrategy":"validation","validationCode":"if (!thread.IsDeleted)\n{\n    await agent.InvokeAsync(newMessage, thread);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check IsDeleted before sending new messages to a Response thread.","Replace deleted threads with fresh instances for new conversations."],"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"}