{"record":{"id":"7c77cf4739c52f2a","repo":"chenhg5/cc-connect","slug":"copilot-session-delete-s","errorCode":null,"errorMessage":"copilot: session.delete: %s","messagePattern":"copilot: session\\.delete: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/copilot/copilot.go","lineNumber":399,"sourceCode":"\tdefer probe.close()\n\n\tpingResp, err := probe.call(probeCtx, \"ping\", nil)\n\tif err != nil || pingResp.Error != nil {\n\t\tslog.Debug(\"copilot: DeleteSession ping failed\", \"error\", err)\n\t\treturn nil\n\t}\n\n\tdelResp, err := probe.call(probeCtx, \"session.delete\", map[string]any{\"sessionId\": sessionID})\n\tif err != nil {\n\t\treturn nil\n\t}\n\n\tif delResp.Error != nil {\n\t\t// method-not-found or invalid-request means unsupported\n\t\tif delResp.Error.Code == -32601 || delResp.Error.Code == -32600 {\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"copilot: session.delete: %s\", delResp.Error.Message)\n\t}\n\n\tvar result copilotDeleteSessionResponse\n\tif err := json.Unmarshal(delResp.Result, &result); err != nil {\n\t\t// Ignore parse errors - treat as success\n\t\treturn nil\n\t}\n\tif !result.Success {\n\t\tif result.Error != nil {\n\t\t\treturn fmt.Errorf(\"copilot: session.delete failed: %s\", *result.Error)\n\t\t}\n\t\treturn fmt.Errorf(\"copilot: session.delete failed: unknown error\")\n\t}\n\tslog.Info(\"copilot: session deleted\", \"sessionId\", sessionID)\n\treturn nil\n}\n\n// GetSessionHistory implements core.HistoryProvider.","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/copilot/copilot.go#L381-L417","documentation":"DeleteSession sends a JSON-RPC `session/delete` request to the copilot CLI and this error is returned when the RPC response carries an error object whose code is not -32601 (method-not-found) or -32600 (invalid-request) — codes treated as 'feature unsupported, ignore'. Any other code means the CLI actively rejected the delete. The message contains the CLI's own error text.","triggerScenarios":"Calling DeleteSession for a session the copilot process does not know about, an already-deleted/expired session, or a CLI whose session.delete implementation returns an unexpected error code (not -32601/-32600).","commonSituations":"Deleting a session that was already removed server-side; deleting sessions from an older copilot CLI version after an upgrade; stale session IDs cached by cc-connect after the copilot workspace was reset.","solutions":["Refresh the session list with ListSessions and delete using a currently valid session ID","Upgrade the copilot CLI so session/delete error codes match the supported protocol (unsupported is signaled by -32601/-32600)","Ignore or special-case the error if the session is already gone (delete is idempotent in practice)","Check the copilot CLI's own logs for the underlying cause"],"exampleFix":"// before\nif err := a.DeleteSession(ctx, id); err != nil {\n    return fmt.Errorf(\"delete: %w\", err) // hard fail on stale session\n}\n// after\nif err := a.DeleteSession(ctx, id); err != nil {\n    slog.Warn(\"copilot session delete ignored\", \"id\", id, \"err\", err) // tolerate stale IDs\n}","handlingStrategy":"try-catch","validationCode":"// only delete IDs present in a fresh listing\nsessions, err := a.ListSessions(ctx)\nif err != nil { return err }\nvalid := false\nfor _, s := range sessions { if s.ID == sessionID { valid = true } }\nif !valid { return fmt.Errorf(\"session %s not found; skip delete\", sessionID) }","typeGuard":null,"tryCatchPattern":"if err := a.DeleteSession(ctx, id); err != nil {\n    var msg string\n    if errors.As(err, ...) || strings.Contains(err.Error(), \"session.delete\") {\n        slog.Warn(\"copilot delete rejected\", \"id\", id, \"detail\", err)\n        // treat stale session as deleted\n    }\n}","preventionTips":["Refresh session caches from ListSessions before deleting","Treat delete as best-effort/idempotent for stale IDs","Keep copilot CLI current so unsupported methods surface as -32601 (ignored) rather than other codes"],"tags":["jsonrpc","copilot","session","rpc-error"],"backgroundTag":"api-error-response","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}