Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(codex): handle MCP elicitation server requests correctly (#1944)
Kagura629f4136ac63
diff --git a/server/pkg/agent/codex.go b/server/pkg/agent/codex.goindex 13207b6909..72d7a5691a 100644--- a/server/pkg/agent/codex.go+++ b/server/pkg/agent/codex.go@@ -552,6 +552,20 @@ func (c *codexClient) respond(id int, result any) {_, _ = c.stdin.Write(data)}+func (c *codexClient) respondError(id int, code int, message string) {+ msg := map[string]any{+ "jsonrpc": "2.0",+ "id": id,+ "error": map[string]any{+ "code": code,+ "message": message,+ },+ }+ data, _ := json.Marshal(msg)+ data = append(data, '\n')+ _, _ = c.stdin.Write(data)+}+func (c *codexClient) closeAllPending(err error) {c.mu.Lock()defer c.mu.Unlock()@@ -632,8 +646,11 @@ func (c *codexClient) handleServerRequest(raw map[string]json.RawMessage) {c.respond(id, map[string]any{"decision": "accept"})case "item/fileChange/requestApproval", "applyPatchApproval":c.respond(id, map[string]any{"decision": "accept"})+ case "mcpServer/elicitation/request":+ c.respond(id, map[string]any{"action": "accept", "content": nil, "_meta": nil})default:- c.respond(id, map[string]any{})+ c.cfg.Logger.Warn("codex: unhandled server request", "method", method, "id", id)+ c.respondError(id, -32601, fmt.Sprintf("unhandled server request: %s", method))}}diff --git a/server/pkg/agent/codex_test.go b/server/pkg/agent/codex_test.goindex 9592a44db1..7e6d88a63e 100644--- a/server/pkg/agent/codex_test.go+++ b/server/pkg/agent/codex_test.go@@ -168,6 +168,68 @@ func TestCodexHandleServerRequestFileChangeApproval(t *testing.T) {}}+func TestCodexHandleServerRequestMCPElicitation(t *testing.T) {+ t.Parallel()++ c, fs, _ := newTestCodexClient(t)++ c.handleLine(`{"jsonrpc":"2.0","id":12,"method":"mcpServer/elicitation/request","params":{}}`)++ lines := fs.Lines()+ if len(lines) != 1 {+ t.Fatalf("expected 1 response, got %d", len(lines))+ }++ var resp map[string]any+ if err := json.Unmarshal([]byte(lines[0]), &resp); err != nil {+ t.Fatalf("unmarshal: %v", err)+ }+ if resp["id"] != float64(12) {+ t.Fatalf("expected id=12, got %v", resp["id"])+ }+ result := resp["result"].(map[string]any)+ if result["action"] != "accept" {+ t.Fatalf("expected action=accept, got %v", result["action"])+ }+ if _, ok := result["content"]; !ok {+ t.Fatal("expected content key in response")+ }+ if _, ok := result["_meta"]; !ok {+ t.Fatal("expected _meta key in response")+ }+}++func TestCodexHandleServerRequestUnknownReturnsError(t *testing.T) {+ t.Parallel()++ c, fs, _ := newTestCodexClient(t)++ c.handleLine(`{"jsonrpc":"2.0","id":13,"method":"some/unknown/method","params":{}}`)++ lines := fs.Lines()+ if len(lines) != 1 {+ t.Fatalf("expected 1 response, got %d", len(lines))+ }++ var resp map[string]any+ if err := json.Unmarshal([]byte(lines[0]), &resp); err != nil {+ t.Fatalf("unmarshal: %v", err)+ }+ if resp["id"] != float64(13) {+ t.Fatalf("expected id=13, got %v", resp["id"])+ }+ if resp["result"] != nil {+ t.Fatalf("expected no result for error response, got %v", resp["result"])+ }+ errObj, ok := resp["error"].(map[string]any)+ if !ok {+ t.Fatal("expected error object in response")+ }+ if errObj["code"] != float64(-32601) {+ t.Fatalf("expected error code -32601, got %v", errObj["code"])+ }+}+func TestCodexLegacyEventTaskStarted(t *testing.T) {t.Parallel()