awslabs / awslabs/llmeter

RuntimeWarning: coroutine 'process_before_invoke_callbacks' was never awaited

Open Beginner friendly
#96 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
41
Forks
5
Avg merge
2m
Merged PRs (30d)
1

Description

## Description

`_invoke_n_no_wait` in `llmeter/runner.py` (line 497) unconditionally creates a coroutine via `asyncio.run(process_before_invoke_callbacks(self.callbacks, p))`, even when `self.callbacks` is `None` or empty. When there is already a running event loop (e.g. in async test contexts or Jupyter notebooks), `asyncio.run()` cannot be called, and the coroutine object is created but never awaited — triggering:

```
RuntimeWarning: coroutine 'process_before_invoke_callbacks' was never awaited
```

## Reproduction

```
pytest tests/unit/test_runner.py::test_invoke_n_no_wait -W error::RuntimeWarning
```

## Suggested fix

Short-circuit the `asyncio.run()` call when there are no callbacks:

```python
if self.callbacks:
p = asyncio.run(process_before_invoke_callbacks(self.callbacks, p))
```

A deeper fix would address the `asyncio.run()` inside an already-running loop (relevant for notebook/async contexts), potentially using `asyncio.get_event_loop().run_until_complete()` or restructuring `_invoke_n_no_wait` to be async-aware.

## Context

Found during multi-Python CI testing — the warning appears on all Python versions (3.10–3.13).

Contributor guide

Open the contributing guide

Research direction

Start with _invoke_n_no_wait in llmeter/runner.py around line 497, then run pytest tests/unit/test_runner.py::test_invoke_n_no_wait -W error::RuntimeWarning. Verify that the no-callback path completes without a RuntimeWarning and that callback processing remains covered when callbacks are present; the broader running-event-loop behavior is a separate deeper concern.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.