Skip to content

ci: lint async code for blocking calls and unreferenced tasks - #848

Merged
andrewpark-scaleai merged 3 commits into
mainfrom
andrewpark/async-lint
Nov 22, 2026
Merged

andrewpark-scaleai merged 3 commits into
mainfrom
andrewpark/async-lint

Conversation

@andrewpark-scaleai

@andrewpark-scaleai andrewpark-scaleai commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Why

ruff check runs only pyflakes today. Nothing stops a blocking call, like time.sleep, subprocess.run or a sync HTTP request, from landing in an async function and stalling the event loop for every run it serves. This PR adds the async checks that catch those mistakes, and changes the one line in src/ they flag.

What changes

  • pyproject.toml selects ruff's ASYNC rules and RUF006 (a task with no reference, which the garbage collector may drop before it finishes).
  • Four rules stay off, because their hits here are deliberate:
    • ASYNC109 objects to a timeout parameter, which is this codebase's style.
    • ASYNC110 flags polling loops. Ours poll processes, files and other threads, which no asyncio.Event can signal.
    • ASYNC230 and ASYNC240 flag sync file I/O. Ours is small writes and chunked streams.
  • Tests may block the loop (ASYNC2xx) and fire tasks without keeping them, since several do that on purpose.
  • Lume's provider may use subprocess.Popen (ASYNC220). Its VM and port relay are detached processes that outlive the call.
  • site_proxy.Resolver keeps each DNS answer task in a set until it finishes, as the asyncio docs require for fire-and-forget tasks. This doesn't fix an observed failure. While a forwarded query is pending, the loop's selector holds the socket's callback, which keeps the task alive. 200 queries against a nameserver that answers after 0.5 s, with gc.collect() forced every 50 ms, all got answers on main too, while a control that awaits an unreferenced future lost all 200 tasks. The change makes the resolver rely on asyncio's documented contract rather than on that selector detail, and lets RUF006 run without an exception.

With this config, src/ and packages/agentenv-protocol/src have no hits for blocking HTTP, subprocess.run/check_output, time.sleep or input() in async functions, so these rules guard new code without a backlog.

Testing

  • ruff check passes on the whole repo.
  • tst/unit/env/envs/test_computer_site_proxy.py passes (74 tests). The earlier DNS tests call Resolver._answer() directly, so a new test binds the resolver to a UDP socket and sends it 21 queries while a slow stand-in nameserver holds 20 of them open and gc.collect() runs. It fails when datagram_received drops a query, and passed 5 runs out of 5.
  • A scratch module with time.sleep, subprocess.run and a dropped create_task inside an async function fails the new config with ASYNC251, ASYNC221 and RUF006. The old select = ["F"] config passes it.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new actionable issues were found.

Summary

Adds Ruff async checks and keeps DNS answer tasks referenced until they finish.

  • Ruff now checks async code for blocking calls and unreferenced tasks.
  • DNS answer tasks stay referenced while forwarded queries wait upstream.

Reviews (7) · Last reviewed commit: "test(site-proxy): name the UDP test's qu..." · Reviewed by Greptile

Turn on ruff's ASYNC rules and RUF006 next to pyflakes. The DNS resolver
in site_proxy.py now keeps a reference to each answer task.
@andrewpark-scaleai
andrewpark-scaleai requested a review from a team as a code owner November 20, 2026 17:29
@andrewpark-scaleai
andrewpark-scaleai enabled auto-merge (squash) November 20, 2026 22:54
@andrewpark-scaleai
andrewpark-scaleai merged commit 5973a48 into main Nov 22, 2026
58 checks passed
@andrewpark-scaleai
andrewpark-scaleai deleted the andrewpark/async-lint branch November 22, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants