Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(agent): clarify opaque Kimi turn failures (MUL-8157) (#9431)
Multica Eve4b645a354c80
diff --git a/server/pkg/agent/kimi.go b/server/pkg/agent/kimi.goindex 92cb5d66d1..d162a979e6 100644--- a/server/pkg/agent/kimi.go+++ b/server/pkg/agent/kimi.go@@ -540,7 +540,7 @@ func (b *kimiBackend) Execute(ctx context.Context, prompt string, opts ExecOptiofallbackModel: fallbackModel,}); failed {finalStatus = "failed"- finalError = "kimi turn failed"+ finalError = "kimi turn failed: runtime did not record error details (error category unknown)"if turnErr != "" {finalError = fmt.Sprintf("kimi turn failed: %s", turnErr)}@@ -794,10 +794,39 @@ const kimiTurnEndedRecordType = "agent.turn.ended"// Turn ids alternate between number and string across kimi builds, so they// are deliberately not modeled — only the outcome and diagnostic matter.type kimiWireTurnEnd struct {- Type string `json:"type"`- Outcome string `json:"outcome"`- ErrorMessage string `json:"errorMessage"`- Time int64 `json:"time"`+ Type string `json:"type"`+ Outcome string `json:"outcome"`+ ErrorMessage json.RawMessage `json:"errorMessage"`+ Time int64 `json:"time"`+}++// kimiWireErrorMessage accepts string diagnostics and structured error payloads.+// An unsupported diagnostic shape must not hide an otherwise valid failed turn.+// Only code/message are surfaced; details may contain private provider context.+func kimiWireErrorMessage(raw json.RawMessage) string {+ text := func(value json.RawMessage) string {+ var s string+ if err := json.Unmarshal(value, &s); err != nil {+ return ""+ }+ s = strings.TrimSpace(sanitizeAgentDiagnostic(s))+ if s == "[object Object]" {+ return ""+ }+ return s+ }+ var payload struct {+ Code json.RawMessage `json:"code"`+ Message json.RawMessage `json:"message"`+ }+ if err := json.Unmarshal(raw, &payload); err != nil {+ return text(raw)+ }+ code, message := text(payload.Code), text(payload.Message)+ if code == "" {+ return message+ }+ return strings.TrimSpace(fmt.Sprintf("[%s] %s", code, message))}// scanKimiMainTurnFailure reports whether the main agent's wire log recorded@@ -862,7 +891,7 @@ func kimiWireTurnFailure(path string, scan kimiUsageScan) (string, bool) {// the raw string and the shared redact.Text, so it takes// the same sanitize pass as every child-process diagnostic// before this reaches Result.Error (review on #9057).- detail = sanitizeAgentDiagnostic(record.ErrorMessage)+ detail = kimiWireErrorMessage(record.ErrorMessage)found = true}}diff --git a/server/pkg/agent/kimi_test.go b/server/pkg/agent/kimi_test.goindex aeed36adda..c4472f1ef8 100644--- a/server/pkg/agent/kimi_test.go+++ b/server/pkg/agent/kimi_test.go@@ -1656,6 +1656,48 @@ func TestScanKimiMainTurnFailureSanitizesWireDiagnostic(t *testing.T) {}}+func TestScanKimiMainTurnFailureErrorMessageFormats(t *testing.T) {+ t.Parallel()++ for _, tc := range []struct {+ name string+ raw string+ want string+ }{+ {name: "string", raw: `"Connection error."`, want: "Connection error."},+ {name: "opaque string", raw: `" [object Object] "`},+ {name: "empty string", raw: `""`},+ {name: "null", raw: `null`},+ {name: "object", raw: `{"code":"provider.failure","message":"Connection error.","details":"private-details","retryable":true}`, want: "[provider.failure] Connection error."},+ {name: "message only", raw: `{"message":"Connection error."}`, want: "Connection error."},+ {name: "code only", raw: `{"code":"provider.failure","message":"[object Object]"}`, want: "[provider.failure]"},+ {name: "invalid code", raw: `{"code":{},"message":"Connection error."}`, want: "Connection error."},+ {name: "empty object", raw: `{}`},+ {name: "invalid message", raw: `{"message":{"secret":"private-details"}}`},+ {name: "array", raw: `["private-details"]`},+ {name: "number", raw: `42`},+ {name: "boolean", raw: `true`},+ {name: "redacted object", raw: `{"code":"provider.failure","message":"api_key=fixture-secret","details":"private-details"}`, want: "[provider.failure] [REDACTED CREDENTIAL]"},+ } {+ t.Run(tc.name, func(t *testing.T) {+ t.Parallel()+ home := t.TempDir()+ now := time.Now()+ line := fmt.Sprintf(`{"type":"agent.turn.ended","outcome":"failed","time":%d,"errorMessage":%s}`, now.UnixMilli(), tc.raw)+ writeKimiWireLog(t, home, "session_formats", "main", line)+ detail, failed := scanKimiMainTurnFailure(kimiUsageScan{+ startTime: now.Add(-time.Minute), kimiHome: home, sessionID: "session_formats",+ })+ if !failed {+ t.Fatal("errorMessage shape must not hide the failed terminal event")+ }+ if detail != tc.want {+ t.Errorf("detail = %q, want %q", detail, tc.want)+ }+ })+ }+}+// TestScanKimiMainTurnFailureIgnoresHealthyStaleAndDelegated guards the flip// against false positives: a successful main turn stays completed, a failed// record from a previous task on a resumed session is outside the turn@@ -1817,6 +1859,40 @@ func TestKimiBackendWireTurnFailureFailsCompletedRun(t *testing.T) {}}+func TestKimiBackendWireTurnFailureDiagnostics(t *testing.T) {+ t.Parallel()++ for _, tc := range []struct {+ name string+ raw string+ want string+ }{+ {name: "opaque", raw: `"[object Object]"`, want: "kimi turn failed: runtime did not record error details (error category unknown)"},+ {name: "empty", raw: `""`, want: "kimi turn failed: runtime did not record error details (error category unknown)"},+ {name: "object", raw: `{"code":"provider.failure","message":"Unspecified failure","details":"private-details"}`, want: "kimi turn failed: [provider.failure] Unspecified failure"},+ } {+ t.Run(tc.name, func(t *testing.T) {+ t.Parallel()+ home := t.TempDir()+ fakePath := filepath.Join(t.TempDir(), "kimi")+ script := fakeKimiWireTurnFailureScript("ses_diagnostic")+ script = strings.Replace(script,+ `"OAuthConnectionError: OAuth request to https://auth.kimi.com/api/oauth/token failed: fetch failed: Connect Timeout Error"`, tc.raw, 1)+ writeTestExecutable(t, fakePath, []byte(script))+ result := runKimiThinkingTest(t, fakePath, map[string]string{"KIMI_CODE_HOME": home}, ExecOptions{})+ if result.Status != "failed" || result.Error != tc.want {+ t.Fatalf("status=%q error=%q, want failed with %q", result.Status, result.Error, tc.want)+ }+ if !strings.Contains(result.Output, "partial narration") || result.ResumeRejected {+ t.Errorf("partial output or session state changed: output=%q resumeRejected=%v", result.Output, result.ResumeRejected)+ }+ if got := taskfailure.Classify(result.Error); got != taskfailure.ReasonAgentUnknown {+ t.Errorf("unspecified failure classified as %q, want unknown", got)+ }+ })+ }+}+// TestKimiBackendWireTurnFailurePastOversizedRecord reproduces the review's// offline repro on #9057: a valid context.append record at the scan's 32 MiB// bound sits ahead of the failed agent.turn.ended record. With the old