Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(agent): include JSON-RPC error data field in ACP error messages (#2327)

LinYushenf70105fb1246
diff --git a/server/pkg/agent/hermes.go b/server/pkg/agent/hermes.go
index db35be52e3..af8db9c488 100644
--- a/server/pkg/agent/hermes.go
+++ b/server/pkg/agent/hermes.go
@@ -564,11 +564,31 @@ func (c *hermesClient) handleResponse(raw map[string]json.RawMessage) {
if errData, hasErr := raw["error"]; hasErr {
var rpcErr struct {
- Code int `json:"code"`
- Message string `json:"message"`
+ Code int `json:"code"`
+ Message string `json:"message"`
+ Data json.RawMessage `json:"data"`
}
_ = json.Unmarshal(errData, &rpcErr)
- pr.ch <- rpcResult{err: fmt.Errorf("%s: %s (code=%d)", pr.method, rpcErr.Message, rpcErr.Code)}
+ // JSON-RPC `data` carries the provider-specific reason (e.g. Kiro
+ // returns "No session found with id" for code=-32603). Surface it
+ // in the wrapped error so daemon logs / UI can show *why* the
+ // agent failed instead of a bare "Internal error". `data` may be
+ // any JSON value: render strings unquoted, everything else as raw
+ // JSON.
+ detail := ""
+ if len(rpcErr.Data) > 0 && string(rpcErr.Data) != "null" {
+ var s string
+ if err := json.Unmarshal(rpcErr.Data, &s); err == nil {
+ detail = s
+ } else {
+ detail = string(rpcErr.Data)
+ }
+ }
+ if detail != "" {
+ pr.ch <- rpcResult{err: fmt.Errorf("%s: %s (code=%d, data=%s)", pr.method, rpcErr.Message, rpcErr.Code, detail)}
+ } else {
+ pr.ch <- rpcResult{err: fmt.Errorf("%s: %s (code=%d)", pr.method, rpcErr.Message, rpcErr.Code)}
+ }
} else {
// If this is a prompt response, extract usage and stop reason.
if pr.method == "session/prompt" {
diff --git a/server/pkg/agent/hermes_test.go b/server/pkg/agent/hermes_test.go
index 8eb84a071c..810040f66b 100644
--- a/server/pkg/agent/hermes_test.go
+++ b/server/pkg/agent/hermes_test.go
@@ -223,6 +223,74 @@ func TestHermesClientHandleLineError(t *testing.T) {
}
}
+// TestHermesClientHandleLineErrorWithData guards #2192-class regressions: when
+// an ACP backend returns -32603 (Internal error), the meaningful reason lives
+// in the `data` field. Dropping it leaves operators with a bare "Internal
+// error" and no way to tell apart "session expired", "model unavailable",
+// "auth lost", etc. Kiro CLI 2.2.x emits `data` as a string; some backends use
+// objects/arrays — both must round-trip into the wrapped Go error.
+func TestHermesClientHandleLineErrorWithStringData(t *testing.T) {
+ t.Parallel()
+
+ c := &hermesClient{
+ pending: make(map[int]*pendingRPC),
+ }
+ pr := &pendingRPC{ch: make(chan rpcResult, 1), method: "session/prompt"}
+ c.pending[3] = pr
+
+ c.handleLine(`{"jsonrpc":"2.0","id":3,"error":{"code":-32603,"message":"Internal error","data":"No session found with id"}}`)
+
+ res := <-pr.ch
+ if res.err == nil {
+ t.Fatal("expected error")
+ }
+ want := "session/prompt: Internal error (code=-32603, data=No session found with id)"
+ if got := res.err.Error(); got != want {
+ t.Errorf("error: got %q, want %q", got, want)
+ }
+}
+
+func TestHermesClientHandleLineErrorWithObjectData(t *testing.T) {
+ t.Parallel()
+
+ c := &hermesClient{
+ pending: make(map[int]*pendingRPC),
+ }
+ pr := &pendingRPC{ch: make(chan rpcResult, 1), method: "session/prompt"}
+ c.pending[5] = pr
+
+ c.handleLine(`{"jsonrpc":"2.0","id":5,"error":{"code":-32000,"message":"quota","data":{"reason":"limit","remaining":0}}}`)
+
+ res := <-pr.ch
+ if res.err == nil {
+ t.Fatal("expected error")
+ }
+ want := `session/prompt: quota (code=-32000, data={"reason":"limit","remaining":0})`
+ if got := res.err.Error(); got != want {
+ t.Errorf("error: got %q, want %q", got, want)
+ }
+}
+
+func TestHermesClientHandleLineErrorWithNullData(t *testing.T) {
+ t.Parallel()
+
+ c := &hermesClient{
+ pending: make(map[int]*pendingRPC),
+ }
+ pr := &pendingRPC{ch: make(chan rpcResult, 1), method: "initialize"}
+ c.pending[7] = pr
+
+ c.handleLine(`{"jsonrpc":"2.0","id":7,"error":{"code":-32600,"message":"bad request","data":null}}`)
+
+ res := <-pr.ch
+ if res.err == nil {
+ t.Fatal("expected error")
+ }
+ if got := res.err.Error(); got != "initialize: bad request (code=-32600)" {
+ t.Errorf("error: got %q", got)
+ }
+}
+
// ── agent → client request handling ──
// bufferWriter is a test stand-in for cmd.StdinPipe that captures