# Potential bug in client server setup with policy mapping functions

**URL:** <https://discuss.ray.io/t/potential-bug-in-client-server-setup-with-policy-mapping-functions/7248>\
**Category:** RLlib\
**Created:** [August 18, 2022, 1:51pm UTC](https://discuss.ray.io/t/potential-bug-in-client-server-setup-with-policy-mapping-functions/7248 "2022-08-18T13:51:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blubberblub](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/blubberblub/32/1396_2.png) [@Blubberblub](https://discuss.ray.io/u/Blubberblub)\
**Post date:** [August 18, 2022, 1:51pm UTC](https://discuss.ray.io/t/potential-bug-in-client-server-setup-with-policy-mapping-functions/7248/1 "2022-08-18T13:51:23Z")

</div>

**How severe does this issue affect your experience of using Ray?**

- Medium: It contributes to significant difficulty to complete my task, but I can work around it.

It set up a client server training setup that follows the cartpole client/server example. The environment is a multi agent setup and therefore uses a policy mapping function. When i run the client and the server setup on the same machine everthing works perfectly for remote and local action inference.

**Problem:**  
When i run the client on another machine it works in remote inference mode but not in local mode. I get:  
KeyError: “policy\_mapping\_fn returned invalid policy id ‘None’!”

My policy function looks like this:

```auto
def policy_mapping_fn(agent_id, episode, worker, **kwargs):
    if agent_id.startswith("p_d_"):
        return "pot_decider_policy"
    elif agent_id.startswith("p_m_"):
        return "pot_move_policy"

```

Theoretically it is possible that it returns None (if the agent\_id isn’t matching the patterns in my if statements) but when i add an additional else statement to my mapping function to catch the agent\_id that caused the problem i get an agent\_id that should actually match my if-statements…

Debugging attempt:

```auto
def policy_mapping_fn(agent_id, episode, worker, **kwargs):
    if agent_id.startswith("p_d_"):
        return "pot_decider_policy"
    elif agent_id.startswith("p_m_"):
        return "pot_move_policy"
    else:
        print(agent_id)

```

Result:  
The else statement prints “p\_m\_0\_0” before the error is thrown.

I have no idea what could cause the issue here so if anyone could provide help or a hint where to look it would help me out a lot! Thanks in advance!

---

<div class="post-metadata">

**Author:** ![mannyv](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mannyv/32/606_2.png) [@mannyv](https://discuss.ray.io/u/mannyv)\
**Post date:** [August 26, 2022, 2:01pm UTC](https://discuss.ray.io/t/potential-bug-in-client-server-setup-with-policy-mapping-functions/7248/2 "2022-08-26T14:01:24Z")

</div>

HI @Blubberblub,

Is this still an issue or did you figure it out?

Do you have a reproduction script or error stack trace you could share?

---

<div class="post-metadata">

**Author:** ![Blubberblub](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/blubberblub/32/1396_2.png) [@Blubberblub](https://discuss.ray.io/u/Blubberblub)\
**Post date:** [August 29, 2022, 6:18am UTC](https://discuss.ray.io/t/potential-bug-in-client-server-setup-with-policy-mapping-functions/7248/3 "2022-08-29T06:18:50Z")

</div>

@mannyv I didn’t finde the issue so far. So i settled with server-side action generation for now. I didn’t yet find the time to build a reproduction script using the server client example and replacing the env with a multi agent env that actually has a policy\_mapping\_fn. If the problem occurs as well in this case i will create an issue on github.

---

<div class="post-metadata">

**Author:** ![Blubberblub](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/blubberblub/32/1396_2.png) [@Blubberblub](https://discuss.ray.io/u/Blubberblub)\
**Post date:** [September 1, 2022, 1:22pm UTC](https://discuss.ray.io/t/potential-bug-in-client-server-setup-with-policy-mapping-functions/7248/4 "2022-09-01T13:22:05Z")

</div>

Problem was solved by upgrading to ray 2.0.
