From 02ba4dc61d47de8d6dc43f7250399e3cc1148c04 Mon Sep 17 00:00:00 2001 From: AMATH <116212274+amathxbt@users.noreply.github.com> Date: Sat, 18 Apr 2026 10:15:07 +0100 Subject: [PATCH] Make async examples non-blocking during OPG approval Updated async examples to avoid blocking the event loop during Permit2 approval by using await asyncio.to_thread for the approval step. Signed-off-by: AMATH <116212274+amathxbt@users.noreply.github.com> --- ...id blocking event loop during OPG approval | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 fix(examples): avoid blocking event loop during OPG approval diff --git a/fix(examples): avoid blocking event loop during OPG approval b/fix(examples): avoid blocking event loop during OPG approval new file mode 100644 index 0000000..cc6fc17 --- /dev/null +++ b/fix(examples): avoid blocking event loop during OPG approval @@ -0,0 +1,21 @@ +## Summary + +Makes the async example scripts non-blocking during Permit2 approval. + +Several examples call `llm.ensure_opg_approval(...)` inside `async def main()`. That method is synchronous, and its approval polling path uses blocking sleep internally. In async examples, this can block the event loop and propagate a bad asyncio usage pattern to users copying the official examples. + +This PR updates the async examples to run the approval step with `await asyncio.to_thread(...)`, keeping the examples event-loop-safe without changing SDK behavior. + +## Problem + +The following example scripts are async: + +- `examples/llm_chat.py` +- `examples/llm_chat_streaming.py` +- `examples/llm_tool_calling.py` +- `examples/llm_multi_turn_conversation.py` + +Each of them called: + +```python +llm.ensure_opg_approval(...)