Never fail a release because Codex refuses thread/unsubscribe

Unloading the replaced thread is cleanup; a thread the App Server no
longer holds must not block /new or closing the chat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 18:13:32 +00:00
parent ce5e744419
commit 1535d20ca8
2 changed files with 21 additions and 7 deletions
+10 -7
View File
@@ -13,6 +13,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"net"
"net/http"
"net/url"
@@ -568,14 +569,16 @@ func (c *Chat) ReleaseSession(ctx context.Context, id string) error {
return err
}
}
_, err := c.call(ctx, "thread/unsubscribe", map[string]any{"threadId": id})
var refused *rpcCallError
if errors.As(err, &refused) && refused.Code == -32601 {
// An App Server without thread/unsubscribe keeps the thread loaded;
// the interrupt above already stopped its work.
return nil
// Unloading is cleanup: a thread the App Server no longer holds, or a
// server without thread/unsubscribe (-32601), must not make the close or
// /new fail; the interrupt above already stopped its work.
if _, err := c.call(ctx, "thread/unsubscribe", map[string]any{"threadId": id}); err != nil {
var refused *rpcCallError
if !errors.As(err, &refused) || refused.Code != -32601 {
log.Printf("codex release session=%s: unsubscribe: %v", id, err)
}
}
return err
return nil
}
// Create starts one Codex thread in directory.
+11
View File
@@ -102,3 +102,14 @@ func TestReleaseSessionUnloadsIdleThreadAndToleratesOldServers(t *testing.T) {
t.Fatalf("an idle release must only unsubscribe: %v", methods)
}
}
// Unloading is cleanup: a thread the App Server no longer holds must not make
// a close or /new fail.
func TestReleaseSessionToleratesAnUnsubscribeRefusal(t *testing.T) {
c := modelTestChat(t, func(string, json.RawMessage) any {
return &rpcError{Code: -32600, Message: "thread not found"}
})
if err := c.ReleaseSession(context.Background(), fixtureThread); err != nil {
t.Fatalf("a refused unsubscribe must not fail the release: %v", err)
}
}