8000 vivarium: move the runner from bare asyncio to anyio structured concurrency · Issue #949 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

vivarium: move the runner from bare asyncio to anyio structured concurrency #949

Closed

Description

@Lillecarl

vivarium's session, CLI and control already use anyio. The runner (pkgs/vivarium-runner) is bare asyncio: about 60 call sites in 9 modules, most in machine.py (29), then arpyc.py, cluster.py, qmp.py.

What to replace, by count: get_running_loop (14), wait_for (10), sleep (9), TimeoutError (7), gather (4), ensure_future (3), Task/Future, Queue, create_subprocess_exec, StreamReader, Lock.

Why it matters:

  • Machine holds loose tasks (ensure_future for the console pump), so a crash in one is invisible until something awaits it. A task group owns them and cancels the rest on failure.
  • wait_for + TimeoutError become fail_after/move_on_after, with anyio's cancellation scopes instead of asyncio's edge cases.
  • The console guests design (docs/design/console-guests.md, Run MikroTik RouterOS as a vivarium guest #945) adds anyio code beside Machine. Mixing the two families is where cancellation stops behaving.

Shape: module by module, machine.py last. A ruff TID251 banned-api rule on asyncio in the runner, so it cannot come back. arpyc keeps its protocol; only its transport moves to anyio streams.

Assisted-By: Claude Opus 5.5

Activity

  1. added
    source: vivarium
    priority: medium
    on Oct 21, 2026
  2. added theissue type on Oct 21, 2026
  3. Lillecarl commented on Nov 17, 2026

    @Lillecarl
    ContributorAuthor

    One more site: pkgs/vivarium/vivarium/cloud.py (Cloud, #1408). It starts its boots and notices with asyncio.ensure_future, waits with asyncio.timeout and asyncio.sleep, and keeps asyncio.Events on Instance. Those tasks outlive the API call that starts them, so the move needs a task group the session owns for its whole life. Its unit tests (pkgs/vivarium/tests/test_cloud.py) run under asyncio.run.


    Assisted-By: Claude Opus 5.5

  4. Lillecarl commented on Nov 17, 2026

    @Lillecarl
    ContributorAuthor

    Measurements from the vivarium review (#1444).

    • M3: nix/shared/ruff-anyio.toml misses asyncio.ensure_future, start_unix_server, open_unix_connection and from asyncio import subprocess. With these unbanned, the lint sees 13 of about 23 unstructured sites in pkgs/. vivarium: lint gates, the anyio ban list, and the house rules they would enforce #1487 extends the list.
    • A9: Backend.launch and storeview.build are synchronous on the loop (S1: about 0.3 s per guest, in series).
    • R7 trap: a launch moved to anyio.to_thread gets its die_with_parent helpers SIGKILLed when the worker thread retires, after 10 s idle.

    Assisted-By: Claude Opus 5.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumsource: vivarium

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0