Public `JobContext.create_task()` for background tasks that end with the job
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 62/100
Línea de trabajo
Empieza por el contexto del job y su método privado _track_pending_task(), así como por la ruta de apagado que cancela las tareas rastreadas tras los callbacks de shutdown. Lee cómo delete_room y add_sip_participant usan ese rastreo. Está terminado cuando existe un create_task() público que mantiene una referencia, registra los fallos y se cancela al apagar, con pruebas para el orden de cancelación y el registro de errores.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Feature Type: Would make my life easier
What we're trying to do
Our voice agent starts many small background tasks during a call. For example: a silence
watchdog, a loop that saves call quality stats, and a prefetch of some data.
When the job ends, these tasks should stop too. If a task fails, we want to see the error
in the logs.
What we do today
The framework already does this for its own tasks (delete_room, add_sip_participant).
It uses JobContext._track_pending_task(). That method is private, so we copy the idea in
our own code:
bg_tasks: set[asyncio.Task] = set()
def track_task(coro):
task = asyncio.ensure_future(coro)
bg_tasks.add(task)
task.add_done_callback(bg_tasks.discard)
return task
# later, in our shutdown code
for task in bg_tasks:
task.cancel()
We have this in two entrypoints. It works, but every user has to write it, and it is easy
to get wrong. Ours does not log errors, for example.
The small API we'd like
task = ctx.create_task(watch_silence(), name="silence_watchdog")
It would just call asyncio.create_task() and then self._track_pending_task(). So the job:
- keeps a reference to the task, so it is not garbage collected,
- logs the error if the task fails,
- cancels the task if it is still running when the job ends.
It returns the normal asyncio.Task, so you can still await or cancel it yourself.
The job already cancels these tasks at the end of shutdown, after the shutdown callbacks.
This new method uses that same step. Nothing about shutdown changes.
utils.aio.TaskSet is close, but it is not tied to the job, so nothing cancels its tasks
at the end.
Question
Would you accept a PR for this? I have a small change ready: the method with a
docstring, plus two tests (the task is cancelled after the shutdown callbacks, and a failing
task is logged). Happy to change the name or put it somewhere else if you prefer.
- Lenguaje dominante
- Python
- Estrellas
- 14.6k
- Forks
- 3.9k
- Merge medio
- 2 d 23 h
- PR fusionados (30 d)
- 263
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de livekit/agents
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
livekit/agents#8284 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
ci: unit tests pin Python 3.12 while the package advertises 3.14 supportQuizá libre de nuevo @huong8373tt-beep la tomó hace 8 días y no hay ningún pull request abierto. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
livekit/agents#8231 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Assistant markup is stripped from chat history when expressive mode is offPosiblemente ocupada @ShivamSharma43 la tomó hace 29 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
livekit/agents#7647 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
docs: openai.LLM vs openai.responses.LLM for HTTP OpenAI-compat hostsQuizá libre de nuevo @AbarnaaSree la tomó hace 69 días y no hay ningún pull request abierto. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
livekit/agents#7022 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
Los mantenedores suelen responder en 1 día
Todos los issues de livekit/agents
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
strawberry-graphql/strawberry#4794 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
dataforgoodfr/cetolog#21 ·
-
security_citations_test fails against ecc 2026.11.6: SECURITY.md quotes ecc v2026.11.2's linesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
btclib-org/btclib#2932 ·
Los mantenedores suelen responder en 1 día
-
metrics priority: medium
Dificultad 1/5 1-3 horas Aptitud para principiantes 86/100
LearningCircuit/local-deep-research#8336 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100