Skip to content

Commit a9b75c4

Browse files
committed
Improve error recovery during message deserialization and update workflows
Signed-off-by: Sergey Karpov <[email protected]>
1 parent 6f9bf7c commit a9b75c4

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

.github/workflows/validate-pr.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,38 @@ name: Validate PR
33
on:
44
workflow_dispatch:
55
pull_request:
6-
branches: [main]
6+
branches: [ main ]
77

88
concurrency:
9-
group: ${{ github.workflow }}-${{ github.ref }}
10-
cancel-in-progress: true
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
1111

1212
jobs:
1313
validate-pr:
1414
runs-on: macos-latest
1515
name: Validate PR
1616
steps:
1717
- uses: actions/checkout@v4
18+
1819
- name: Set up JDK 21
1920
uses: actions/setup-java@v4
2021
with:
2122
java-version: '21'
2223
distribution: 'temurin'
24+
2325
- name: Setup Gradle
2426
uses: gradle/actions/setup-gradle@v4
2527

2628
- name: Clean Build with Gradle
2729
run: ./gradlew clean build
2830

31+
- name: Upload JUnit test results
32+
if: always()
33+
uses: actions/upload-artifact@v4
34+
with:
35+
name: junit-results
36+
path: '**/build/test-results/test/*.xml'
37+
2938
- name: Disable Auto-Merge on Fail
3039
if: failure()
3140
run: gh pr merge --disable-auto "$PR_URL"

kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/shared/ReadBuffer.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,17 @@ public class ReadBuffer {
4444
try {
4545
return deserializeMessage(line)
4646
} catch (e: Exception) {
47-
logger.error(e) { "Failed to deserialize message from line: $line\nSkipping..." }
47+
logger.error(e) { "Failed to deserialize message from line: $line\nAttempting to recover..." }
48+
// if there is a non-JSON object prefix, try to parse from the first '{' onward.
49+
val braceIndex = line.indexOf('{')
50+
if (braceIndex != -1) {
51+
val trimmed = line.substring(braceIndex)
52+
try {
53+
return deserializeMessage(trimmed)
54+
} catch (ignored: Exception) {
55+
logger.error(ignored) { "Recovery failed for line: $line\nSkipping..." }
56+
}
57+
}
4858
}
4959

5060
return null

kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StdioClientTransportTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import org.junit.jupiter.api.Test
1010
class StdioClientTransportTest : BaseTransportTest() {
1111
@Test
1212
fun `should start then close cleanly`() = runTest {
13-
// Run process "/usr/bin/tee"
1413
val processBuilder = ProcessBuilder("/usr/bin/tee")
1514
val process = processBuilder.start()
1615

@@ -24,6 +23,7 @@ class StdioClientTransportTest : BaseTransportTest() {
2423

2524
testClientOpenClose(client)
2625

26+
process.waitFor()
2727
process.destroy()
2828
}
2929

0 commit comments

Comments
 (0)