fix(codeagent): validate non-empty output message before printing

Return exit code 1 when backend returns empty result.Message with exit_code=0.
Prevents silent failures where no output is produced.

Generated with SWE-Agent.ai

Co-Authored-By: SWE-Agent.ai <noreply@swe-agent.ai>
This commit is contained in:
cexll
2026-01-23 12:00:47 +08:00
parent 27d4ac8afd
commit cc24d43c8b
2 changed files with 37 additions and 0 deletions

View File

@@ -648,6 +648,12 @@ func runSingleMode(cfg *Config, name string) int {
return result.ExitCode
}
// Validate that we got a meaningful output message
if strings.TrimSpace(result.Message) == "" {
logError(fmt.Sprintf("no output message: backend=%s returned empty result.Message with exit_code=0", cfg.Backend))
return 1
}
fmt.Println(result.Message)
if result.SessionID != "" {
fmt.Printf("\n---\nSESSION_ID: %s\n", result.SessionID)

View File

@@ -1913,6 +1913,37 @@ func TestRun_PassesReasoningEffortToTaskSpec(t *testing.T) {
}
}
func TestRun_NoOutputMessage_ReturnsExitCode1AndWritesStderr(t *testing.T) {
defer resetTestHooks()
cleanupLogsFn = func() (CleanupStats, error) { return CleanupStats{}, nil }
t.Setenv("TMPDIR", t.TempDir())
selectBackendFn = func(name string) (Backend, error) {
return testBackend{name: name, command: "echo"}, nil
}
runTaskFn = func(task TaskSpec, silent bool, timeout int) TaskResult {
return TaskResult{ExitCode: 0, Message: ""}
}
isTerminalFn = func() bool { return true }
stdinReader = strings.NewReader("")
os.Args = []string{"codeagent-wrapper", "task"}
var code int
errOutput := captureStderr(t, func() {
code = run()
})
if code != 1 {
t.Fatalf("run() exit=%d, want 1", code)
}
if !strings.Contains(errOutput, "no output message") {
t.Fatalf("stderr missing sentinel error text; got:\n%s", errOutput)
}
}
func TestRunBuildCodexArgs_NewMode(t *testing.T) {
const key = "CODEX_BYPASS_SANDBOX"
t.Setenv(key, "false")