Skip to content

Commit 65f8955

Browse files
authored
fix(adk/filesystem): fix emptyStreamConcatErr when streaming execute command has no output (#790)
1 parent b443cd9 commit 65f8955

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

.github/.commit-rules.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
],
1515
"allowedScopes": [
1616
"adk",
17+
"adk/filesystem",
1718
"callbacks",
1819
"components",
1920
"compose",

.github/workflows/pr-check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
# https://golangci-lint.run/
3838
uses: golangci/golangci-lint-action@v9.2.0
3939
with:
40+
version: v2.8.0
4041
args: --timeout 5m
4142

4243
commit-msg-check:

adk/middlewares/filesystem/filesystem.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,20 +407,45 @@ func newStreamingExecuteTool(sb filesystem.StreamingShellBackend, desc *string)
407407
}
408408
sw.Close()
409409
}()
410+
411+
var hasSentContent bool
412+
var exitCode *int
413+
410414
for {
411415
chunk, recvErr := result.Recv()
412416
if recvErr == io.EOF {
413417
break
414418
}
415419
if recvErr != nil {
416420
sw.Send("", recvErr)
417-
break
421+
return
422+
}
423+
424+
if chunk == nil {
425+
continue
426+
}
427+
if chunk.ExitCode != nil {
428+
exitCode = chunk.ExitCode
418429
}
419430

420-
if str := convExecuteResponse(chunk); str != "" {
421-
sw.Send(str, nil)
431+
parts := make([]string, 0, 2)
432+
if chunk.Output != "" {
433+
parts = append(parts, chunk.Output)
434+
}
435+
if chunk.Truncated {
436+
parts = append(parts, "[Output was truncated due to size limits]")
437+
}
438+
if len(parts) > 0 {
439+
sw.Send(strings.Join(parts, "\n"), nil)
440+
hasSentContent = true
422441
}
423442
}
443+
444+
if exitCode != nil && *exitCode != 0 {
445+
sw.Send(fmt.Sprintf("\n[Command failed with exit code %d]", *exitCode), nil)
446+
} else if !hasSentContent {
447+
sw.Send("[Command executed successfully with no output]", nil)
448+
}
424449
}()
425450

426451
return sr, nil
@@ -436,8 +461,12 @@ func convExecuteResponse(response *filesystem.ExecuteResponse) string {
436461
parts = append(parts, fmt.Sprintf("[Command failed with exit code %d]", *response.ExitCode))
437462
}
438463
if response.Truncated {
439-
parts = append(parts, fmt.Sprintf("[Output was truncated due to size limits]"))
464+
parts = append(parts, "[Output was truncated due to size limits]")
440465
}
441466

442-
return strings.Join(parts, "\n")
467+
result := strings.Join(parts, "\n")
468+
if result == "" && (response.ExitCode == nil || *response.ExitCode == 0) {
469+
return "[Command executed successfully with no output]"
470+
}
471+
return result
443472
}

adk/middlewares/filesystem/filesystem_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,15 @@ func TestExecuteTool(t *testing.T) {
475475
input: `{"command": "failing command"}`,
476476
expected: "error output...\n[Command failed with exit code 2]\n[Output was truncated due to size limits]",
477477
},
478+
{
479+
name: "successful command with no output",
480+
resp: &filesystem.ExecuteResponse{
481+
Output: "",
482+
ExitCode: ptrOf(0),
483+
},
484+
input: `{"command": "mkdir /tmp/test"}`,
485+
expected: "[Command executed successfully with no output]",
486+
},
478487
}
479488

480489
for _, tt := range tests {

0 commit comments

Comments
 (0)