fix(gateway): restore safe search fallback
CI / verify (push) Has been cancelled
CI / publish (push) Has been cancelled

Fall back to guarded Chat Completions answers when DeepSeek web search fails so grounded current-information hints do not surface generic provider errors.
This commit is contained in:
Rocky
2026-08-23 14:32:43 +08:00
parent 03eac71905
commit 51c37e6206
2 changed files with 36 additions and 20 deletions
@@ -9,6 +9,7 @@ import com.osglab.account.features.gateway.models.ProviderOutput
import com.osglab.account.features.gateway.models.ProviderUsage
import com.osglab.account.features.gateway.models.TextProviderRequest
import com.osglab.account.features.gateway.models.UsageMeter
import com.osglab.account.features.gateway.providers.ProviderUpstreamException
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.bearerAuth
@@ -72,16 +73,16 @@ internal class DeepSeekSearchFallbackClient(
} catch (failure: CancellationException) {
throw failure
} catch (failure: Exception) {
val upstreamStatus = (failure as? ProviderUpstreamException)?.upstreamStatus
LOG.warn(
"DeepSeek search path failed requestId={} taskKind={} searchMode={} failureType={}",
"DeepSeek search path failed requestId={} taskKind={} searchMode={} " +
"failureType={} upstreamStatus={} fallback=chat_completions",
request.requestId,
request.executionPolicy.taskKind.name,
request.executionPolicy.webSearch.name,
failure::class.simpleName ?: "Exception",
upstreamStatus ?: "unknown",
)
if (request.executionPolicy.webSearch == GatewayWebSearchMode.REQUIRED) {
throw failure
}
return fallback.complete(
request.copy(
executionPolicy = request.executionPolicy.copy(