Skip to content

Fix Desktop connection: Add ContentNegotiation, SLF4J, and native access#45

Merged
paulpv merged 2 commits into
mainfrom
copilot/fix-desktop-connection-issues
Dec 23, 2025
Merged

Fix Desktop connection: Add ContentNegotiation, SLF4J, and native access#45
paulpv merged 2 commits into
mainfrom
copilot/fix-desktop-connection-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 23, 2025

Desktop failed to connect to OpenAI Realtime API due to missing Ktor ContentNegotiation plugin, causing JSON serialization errors when requesting ephemeral tokens. Additional warnings from missing SLF4J provider and Skiko native access permissions cluttered logs.

Changes

  • Add ContentNegotiation to Desktop HttpClient (core/src/desktopMain/.../RealtimeClientImpl.kt)

    • Changed from bare HttpClient() to HttpClient(CIO) with ContentNegotiation plugin
    • Mirrors Android's existing configuration (HttpClient(OkHttp) with ContentNegotiation)
  • Add SLF4J implementation (app-desktop/build.gradle.kts, gradle/libs.versions.toml)

    • Added slf4j-simple:2.0.16 dependency to suppress NOP logger warnings
  • Configure native access (app-desktop/build.gradle.kts)

    • Added --enable-native-access=ALL-UNNAMED JVM arg for Skiko library

Before/After

Before:

// Desktop - no serialization support
override val httpClient = HttpClient()

After:

// Desktop - matches Android pattern
override val httpClient = HttpClient(CIO) {
    install(ContentNegotiation) {
        json(Json {
            ignoreUnknownKeys = true
            isLenient = true
        })
    }
}

Error that should no longer occur:

[RealtimeClientImpl] ERROR: getEphemeralToken: Failed to get ephemeral token
java.lang.IllegalStateException: Fail to prepare request body for sending. 
The body type is: class kotlinx.serialization.json.JsonObject
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: Desktop has never successfully connected and logs serialization and connection errors</issue_title>
<issue_description>## Description
Desktop has never been able to establish a connection. When attempting to run, multiple errors and warnings are logged regarding Java system access, SLF4J, and failures getting an ephemeral token due to a serialization issue in Ktor (Fail to prepare request body for sending).

Steps to Reproduce

  1. Start the Desktop application via Gradle (:app-desktop:run)
  2. Observe the logs in the terminal and application
  3. Notice connection never completes and error stacktraces are output

Expected Behavior

Desktop should connect successfully to the server/API and not emit serialization or connection errors.

Actual Behavior

  • Multiple warnings about restricted Java system calls and native access.
  • SLF4J provider not found warning.
  • Fails to obtain ephemeral token. Stacktrace shows:
WARNING: A restricted method in java.lang.System has been called
A restricted method in java.lang.System has been called

WARNING: java.lang.System::load has been called by org.jetbrains.skiko.Library in an unnamed module (file:/Users/pv/.gradle/caches/modules-2/files-2.1/org.jetbrains.skiko/skiko-awt/0.9.22.2/f1dab255d499b8ef215b308b531de32029c41dd6/skiko-awt-0.9.22.2.jar)
java.lang.System::load has been called by org.jetbrains.skiko.Library in an unnamed module (file:/Users/pv/.gradle/caches/modules-2/files-2.1/org.jetbrains.skiko/skiko-awt/0.9.22.2/f1dab255d499b8ef215b308b531de32029c41dd6/skiko-awt-0.9.22.2.jar)

WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module

WARNING: Restricted methods will be blocked in a future release unless native access is enabled
Restricted methods will be blocked in a future release unless native access is enabled

SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
[RealtimeClientImpl] DEBUG: Connecting to https://api.openai.com/v1/realtime with model gpt-realtime-mini
[RealtimeClientImpl] DEBUG: Requesting ephemeral token...
[RealtimeClient] DEBUG: getEphemeralToken: Requesting ephemeral token for model: gpt-realtime-mini, voice: alloy
[RealtimeClientImpl] ERROR: getEphemeralToken: Failed to get ephemeral token
java.lang.IllegalStateException: Fail to prepare request body for sending. 
The body type is: class kotlinx.serialization.json.JsonObject (Kotlin reflection is not available), with Content-Type: application/json.

If you expect serialized body, please check that you have installed the corresponding plugin(like `ContentNegotiation`) and set `Content-Type` header.
    at io.ktor.client.plugins.HttpSend$Plugin$install$1.invokeSuspend(HttpSend.kt:83)
    ...
Caused by: java.lang.IllegalStateException: Fail to prepare request body for sending. 
The body type is: class kotlinx.serialization.json.JsonObject (Kotlin reflection is not available), with Content-Type: application/json.

If you expect serialized body, please check that you have installed the corresponding plugin(like `ContentNegotiation`) and set `Content-Type` header.
    at io.ktor.client.plugins.HttpSend$Plugin$install$1.invokeSuspend(HttpSend.kt:83)
    ...

Environment

  • Platform: Desktop
  • OS: [e.g., macOS Sonoma 14.2.1]
  • App Version: [e.g., latest main branch]

Logs/Screenshots

See above log output and stacktrace.

Possible Fix

  • Check/review Ktor client configuration (is ContentNegotiation plugin installed and set properly for JSON serialization?).
  • Pass --enable-native-access=ALL-UNNAMED to the JVM as recommended.
  • Add an SLF4J provider to resolve NOP logger warnings.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

… args

Co-authored-by: paulpv <1393897+paulpv@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix serialization and connection errors in desktop application Fix Desktop connection: Add ContentNegotiation, SLF4J, and native access Dec 23, 2025
Copilot AI requested a review from paulpv December 23, 2025 18:13
@paulpv paulpv marked this pull request as ready for review December 23, 2025 18:20
Copilot AI review requested due to automatic review settings December 23, 2025 18:20
@paulpv paulpv merged commit 17dbf76 into main Dec 23, 2025
14 checks passed
@paulpv paulpv deleted the copilot/fix-desktop-connection-issues branch December 23, 2025 18:21
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Desktop's inability to connect to the OpenAI Realtime API by adding missing Ktor ContentNegotiation plugin, SLF4J logging implementation, and JVM native access permissions. The Desktop platform now mirrors Android's HTTP client configuration pattern, enabling proper JSON serialization for ephemeral token requests.

  • Added ContentNegotiation plugin to Desktop's HttpClient with JSON serialization support
  • Added SLF4J simple implementation dependency to suppress NOP logger warnings
  • Configured JVM arguments to enable native access for Skiko library

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
gradle/libs.versions.toml Added SLF4J version definition (2.0.16) and library declaration for slf4j-simple
core/src/desktopMain/kotlin/llc/lookatwhataicando/codeoba/core/data/realtime/RealtimeClientImpl.kt Changed HttpClient from bare instantiation to CIO engine with ContentNegotiation plugin, matching Android's pattern with ignoreUnknownKeys and isLenient JSON configuration
app-desktop/build.gradle.kts Added slf4j-simple dependency implementation and JVM argument --enable-native-access=ALL-UNNAMED to suppress Skiko native library warnings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Desktop has never successfully connected and logs serialization and connection errors

3 participants