Skip to content

Commit d8c8bfb

Browse files
fluffy314cursoragent
authored andcommitted
fix(prefill): isolate progress HTTP event loop
Run dashboard telemetry on a dedicated thread so blocking model RPCs cannot hide segmented Prefill progress or stale the Terminal ETA. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e463fda commit d8c8bfb

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

scripts/start_grpc_runtime_server.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import argparse
3636
import asyncio
37+
import threading
3738
import logging
3839
import signal
3940
import sys
@@ -565,7 +566,7 @@ async def _serve(args: argparse.Namespace) -> int:
565566
_LOG.info("kakeya gRPC RuntimeService listening on %s", args.bind)
566567

567568
http_server = None
568-
http_task = None
569+
http_thread = None
569570
if args.network_http_port:
570571
if registry is None or prefill_store is None:
571572
raise SystemExit(
@@ -594,7 +595,12 @@ async def _serve(args: argparse.Namespace) -> int:
594595
port=args.network_http_port,
595596
log_level=args.log_level.lower(),
596597
))
597-
http_task = asyncio.create_task(http_server.serve())
598+
http_thread = threading.Thread(
599+
target=http_server.run,
600+
name="kakeya-network-http",
601+
daemon=True,
602+
)
603+
http_thread.start()
598604
_LOG.info(
599605
"inference-network dashboard listening on http://%s:%d/network",
600606
args.network_http_host,
@@ -641,8 +647,8 @@ def _on_signal(sig: int) -> None:
641647
pass
642648
if http_server is not None:
643649
http_server.should_exit = True
644-
if http_task is not None:
645-
await http_task
650+
if http_thread is not None:
651+
await asyncio.to_thread(http_thread.join, args.shutdown_grace_s)
646652
if prefill_hook is not None:
647653
prefill_hook.close()
648654
await server.stop(grace=args.shutdown_grace_s)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pathlib import Path
2+
3+
4+
ROOT = Path(__file__).resolve().parents[3]
5+
RUNTIME = ROOT / "scripts" / "start_grpc_runtime_server.py"
6+
7+
8+
def test_network_http_runs_outside_blocking_grpc_event_loop():
9+
source = RUNTIME.read_text()
10+
assert 'name="kakeya-network-http"' in source
11+
assert "target=http_server.run" in source
12+
assert "http_thread.start()" in source
13+
assert "asyncio.create_task(http_server.serve())" not in source
14+
assert "asyncio.to_thread(http_thread.join" in source

0 commit comments

Comments
 (0)