Skip to content

[Vertex AI] Use ephemeral URLSession config on iOS 18.4 sim #14696

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 11 commits into from
Apr 11, 2025
18 changes: 9 additions & 9 deletions .github/workflows/vertexai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ jobs:
xcode: Xcode_16.2
target: iOS
- os: macos-15
xcode: Xcode_16.2
xcode: Xcode_16.3
target: iOS
- os: macos-15
xcode: Xcode_16.2
xcode: Xcode_16.3
target: tvOS
- os: macos-15
xcode: Xcode_16.2
xcode: Xcode_16.3
target: macOS
- os: macos-15
xcode: Xcode_16.2
xcode: Xcode_16.3
target: watchOS
- os: macos-15
xcode: Xcode_16.2
xcode: Xcode_16.3
target: catalyst
- os: macos-15
xcode: Xcode_16.2
xcode: Xcode_16.3
target: visionOS
runs-on: ${{ matrix.os }}
needs: spm-package-resolved
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
os: [macos-15]
include:
- os: macos-15
xcode: Xcode_16.2
xcode: Xcode_16.3
runs-on: ${{ matrix.os }}
needs: spm-package-resolved
env:
Expand Down Expand Up @@ -137,11 +137,11 @@ jobs:
swift_version: 5.9
warnings:
- os: macos-15
xcode: Xcode_16.2
xcode: Xcode_16.3
swift_version: 5.9
warnings:
- os: macos-15
xcode: Xcode_16.2
xcode: Xcode_16.3
swift_version: 6.0
warnings:
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 2 additions & 0 deletions FirebaseVertexAI/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
change in backwards-incompatible ways.
- [added] Added support for specifying the minimum and maximum number of items
(`minItems` / `maxItems`) to generate in an array `Schema`. (#14671)
- [fixed] Fixed an issue where network requests would fail in the iOS 18.4
simulator due to a `URLSession` bug introduced in Xcode 16.3. (#14677)

# 11.11.0
- [added] Emits a warning when attempting to use an incompatible model with
Expand Down
38 changes: 38 additions & 0 deletions FirebaseVertexAI/Sources/GenAIURLSession.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation

/// A namespace providing `URLSession` instances.
enum GenAIURLSession {
/// The default `URLSession` instance for the SDK; returns `URLSession.shared` by default.
///
/// - Important: On affected simulators (iOS 18.4+, visionOS 2.4+), this returns an ephemeral
/// `URLSession` instance as a workaround for a known system bug.
static let `default` = {
#if targetEnvironment(simulator)
// The iOS 18.4 and visionOS 2.4 simulators (included in Xcode 16.3) contain a bug in
// `URLSession` causing requests to fail. The following workaround, using an ephemeral session
// resolves the issue. See https://developer.apple.com/forums/thread/777999 for more details.
//
// Note: This bug only impacts the simulator, not real devices, and does not impact watchOS
// or tvOS.
if #available(iOS 18.4, tvOS 100.0, watchOS 100.0, visionOS 2.4, *) {
return URLSession(configuration: URLSessionConfiguration.ephemeral)
}
#endif // targetEnvironment(simulator)

return URLSession.shared
}()
}
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Sources/GenerativeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public final class GenerativeModel: Sendable {
toolConfig: ToolConfig? = nil,
systemInstruction: ModelContent? = nil,
requestOptions: RequestOptions,
urlSession: URLSession = .shared) {
urlSession: URLSession = GenAIURLSession.default) {
self.modelName = modelName
self.modelResourceName = modelResourceName
self.apiConfig = apiConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class ImagenModel {
generationConfig: ImagenGenerationConfig?,
safetySettings: ImagenSafetySettings?,
requestOptions: RequestOptions,
urlSession: URLSession = .shared) {
urlSession: URLSession = GenAIURLSession.default) {
self.modelResourceName = modelResourceName
self.apiConfig = apiConfig
generativeAIService = GenerativeAIService(
Expand Down
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Sources/VertexAI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import FirebaseCore
import Foundation

// Avoids exposing internal FirebaseCore APIs to Swift users.
@_implementationOnly import FirebaseCoreExtension
internal import FirebaseCoreExtension

/// The Vertex AI for Firebase SDK provides access to Gemini models directly from your app.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
Expand Down
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Sources/VertexLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import Foundation
import os.log

@_implementationOnly import FirebaseCoreExtension
internal import FirebaseCoreExtension

enum VertexLog {
/// Log message codes for the Vertex AI SDK
Expand Down
5 changes: 2 additions & 3 deletions FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import FirebaseCore
import XCTest

@testable import FirebaseVertexAI
@testable public import FirebaseVertexAI

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
final class GenerativeModelTests: XCTestCase {
Expand Down Expand Up @@ -1566,7 +1566,7 @@
#if os(watchOS)
throw XCTSkip("Custom URL protocols are unsupported in watchOS 2 and later.")
#endif // os(watchOS)
return { request in

Check warning on line 1569 in FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.3, watchOS)

code after 'throw' will never be executed
// This is *not* an HTTPURLResponse
let response = URLResponse(
url: request.url!,
Expand Down Expand Up @@ -1594,7 +1594,7 @@
#if os(watchOS)
throw XCTSkip("Custom URL protocols are unsupported in watchOS 2 and later.")
#endif // os(watchOS)
let bundle = BundleTestUtil.bundle()

Check warning on line 1597 in FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.3, watchOS)

code after 'throw' will never be executed
let fileURL = try XCTUnwrap(
bundle.url(forResource: name, withExtension: ext, subdirectory: subpath)
)
Expand Down Expand Up @@ -1690,8 +1690,7 @@

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension SafetyRating: Swift.Comparable {
public static func < (lhs: FirebaseVertexAI.SafetyRating,
rhs: FirebaseVertexAI.SafetyRating) -> Bool {
public static func < (lhs: SafetyRating, rhs: SafetyRating) -> Bool {
return lhs.category.rawValue < rhs.category.rawValue
}
}
3 changes: 1 addition & 2 deletions FirebaseVertexAI/Tests/Unit/VertexComponentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
// limitations under the License.

@preconcurrency import FirebaseCore
internal import FirebaseCoreExtension
import Foundation
import XCTest

@_implementationOnly import FirebaseCoreExtension

@testable import FirebaseVertexAI

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
Expand Down
Loading