PrimeIntellect/SWE-rebench-V2-Filtered-Easy-Verified huggingface dataset:
Repository: opensistemas-hub/osbrain (python)
Issue: Agents receive async replies even after maximum `wait`
After the maximum wait time expires, the `on_error` handler is executed correctly, but agents still receive the reply and will process it as usual, which is not the expected behavior.

The request should be removed from `_pending_requests` after the timeout has expired so agents ignore the replies if they come in too late.
Pull request description: Ignore async replies after maximum wait
Fixes #280 

Patch:
diff --git a/osbrain/agent.py b/osbrain/agent.py
index 82fa0a3..afe1bbd 100644
--- a/osbrain/agent.py
+++ b/osbrain/agent.py
@@ -1602,6 +1602,8 @@ class Agent():
         """
         if uuid not in self._pending_requests:
             return
+
+        del self._pending_requests[uuid]
         if not on_error:
             warning = 'Did not receive request {} after {} seconds'.format(
                 uuid, wait)


Test patch:
diff --git a/osbrain/tests/test_agent_async_requests.py b/osbrain/tests/test_agent_async_requests.py
index 259ce65..f959290 100644
--- a/osbrain/tests/test_agent_async_requests.py
+++ b/osbrain/tests/test_agent_async_requests.py
@@ -165,10 +165,17 @@ def test_wait(nsproxy, server_client_late_reply_delay):
 
     # Response not received in time
     client.send('async', 2, wait=1)
+    assert len(client.get_attr('_pending_requests')) == 1
     assert logger_received(logger,
                            log_name='log_history_warning',
                            message='not receive req',
                            timeout=1.1)
+
+    assert logger_received(logger,
+                           log_name='log_history_warning',
+                           message='Received response for an unknown request!',
+                           timeout=2)
+    assert len(client.get_attr('_pending_requests')) == 0
     assert server.get_attr('received') == [1, 2]
     assert client.get_attr('received') == ['x1']