AppIntent initiated URLSession - how to continue without NSURLErrorNetworkConnectionLost on requestConfirmation?

We have an AppIntent that starts streaming data in its perform() function with a URLSession.

This may be a quick operation, or it may take some time (more than 30 seconds but less than a minute).

Is there any way we can keep that streaming data URLSession active when the AppIntent asks the user to continue with requestConfirmation?

What we have seen so far is that any operation the AppIntent takes in its perform() function that interacts with the user causes the URLSession to be abruptly terminated with a NSURLErrorNetworkConnectionLost error when the app is not in the foreground.

If the app is currently running in the foreground then the session does remain active and data continues to stream in.

Sadly, our primary use case is for the Siri/Shortcuts interaction to happen with openAppWhenRun set to false and not require the user to open the app. In that case (with the AppIntent invoked while the app is in the background) the network connection is dropped.

It has been frustrating in initial development because on the simulator the connection is not dropped and data continues to stream in, even while the app is in the background. On a physical device, this is not the case. The only condition we have found to have the network connection maintained is with the app in the foreground when the AppIntent is run.

Here is what we have now:

struct AskAI: AppIntent {
    static var title: LocalizedStringResource = "Ask"
    static var description: IntentDescription = IntentDescription("This will ask the A.I. app")
    static var openAppWhenRun = false
    
    @Parameter(title: "Prompt", description: "The prompt to send", requestValueDialog: IntentDialog("What would you like to ask?"))
    var prompt: String
    
    @MainActor
    func perform() async throws -> some IntentResult & ProvidesDialog & ShowsSnippetView & ReturnsValue<String> {
        var continuationCalled = false
       
        //Start the streaming data URLSession task
        Task<String, Never> {
            await withCheckedContinuation { continuation in
                Brain.shared.requestIntentStream(prompt: prompt, model: Brain.shared.appSettings.textModel, timeoutInterval: TimeInterval(Brain.shared.appSettings.requestTimeout )) { result in
                    if !continuationCalled {
                        continuationCalled = true
                        continuation.resume(returning: Brain.stripMarkdown(result))
                    }
                }
            }
        }
        
        //Start the intentTimeout timer and early out if continuationCalled changed
        let startTime = Date()
        let timeout = Brain.shared.appSettings.intentTimeout
        while !continuationCalled && Date().timeIntervalSince(startTime) < timeout {
            try? await Task.sleep(nanoseconds: 1_000_000_000)
        }
        
//At this point either the intentTimeout was reached (data still streaming) or continuationCalled is true (data stream complete)

        //best effort for Siri to read the first part and continue as more is received
        var allReadResponse = ""
        var partialResponse = ""
        
        while !continuationCalled {
            partialResponse = Brain.shared.responseText.replacingOccurrences(of: allReadResponse, with: "")
            
            allReadResponse += partialResponse
            
            do {
                let dialogResponse = partialResponse + " --- There is more, would you like to continue?"
//THIS WILL TERMINATE THE URLSession if the app is not in the foreground!
                try await requestConfirmation(result: .result(dialog: "\(dialogResponse)") {
                    AISnippetView()
                })
            } catch {
                return .result(
                    value: Brain.shared.responseText,
                    dialog: "", //user cancelled, return what we have so far but we've already spoken the dialog
                    view: AISnippetView()
                )
            }
        }

        //Read the last part (or the whole thing it it was retrieved within the intentTimeout)
        let remainingResponse = Brain.shared.responseText.replacingOccurrences(of: allReadResponse, with: "")
        return .result(
            value: Brain.shared.responseText,
            dialog: "\(remainingResponse)",
            view: AISnippetView()
        )
    }
}

With this logic, Siri will read the first part of the response data when the timer expires and continuationCalled is false. The data is still streaming and will continue to come in while she is speaking - ONLY IF THE APP IS IN THE FOREGROUND. Otherwise the call to requestConfirmation will terminate the connection.

Is there any way to get the task with the requestIntentStream URLSession to stay active?