Commit 6a90cc0
fix: Async correctness - avoid asyncio.run() from sync context reachable by async callers (#1176)
* fix: async correctness in tool approval - prevent RuntimeError in async workflows
* Add event loop detection in _check_tool_approval_sync()
* Use thread pool fallback when already in async context
* Prevents 'asyncio.run() cannot be called from a running event loop' crash
* Maintains backward compatibility with sync usage
* Follows existing pattern from registry.py and backends.py
Fixes #1165
Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
* fix: address reviewer feedback on async correctness fix
- Add concurrent.futures import to top of agent.py (per Gemini review)
- Create shared approval/utils.py to eliminate code duplication (per Qodo/Coderabbit)
- Fix timeout configuration to respect agent's _approval_timeout semantics (per all reviewers)
- Replace ThreadPoolExecutor context manager with proper shutdown handling (per Coderabbit)
- Remove redundant loop.is_running() check (per Copilot)
- Consolidate async-to-sync bridging logic across approval system
Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
---------
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>1 parent ffb9bd1 commit 6a90cc0
4 files changed
Lines changed: 92 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
4918 | 4919 | | |
4919 | 4920 | | |
4920 | 4921 | | |
4921 | | - | |
4922 | 4922 | | |
4923 | 4923 | | |
4924 | 4924 | | |
| |||
5170 | 5170 | | |
5171 | 5171 | | |
5172 | 5172 | | |
5173 | | - | |
| 5173 | + | |
| 5174 | + | |
| 5175 | + | |
| 5176 | + | |
| 5177 | + | |
| 5178 | + | |
| 5179 | + | |
| 5180 | + | |
| 5181 | + | |
| 5182 | + | |
| 5183 | + | |
| 5184 | + | |
| 5185 | + | |
| 5186 | + | |
| 5187 | + | |
| 5188 | + | |
5174 | 5189 | | |
5175 | 5190 | | |
5176 | 5191 | | |
| |||
Lines changed: 2 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
| 240 | + | |
| 241 | + | |
252 | 242 | | |
253 | 243 | | |
254 | 244 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
222 | 219 | | |
223 | 220 | | |
224 | 221 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
0 commit comments