Repository navigation
Bug: prime-agent -p never exits after printing the response (telemetry-dependent; disabling telemetry exits in ~1s)
#3727
Replies: 4 comments 2 replies
|
I tried to reproduce this on macOS with a release build of current main (7e3117b, same telemetry and print-exit code as 0.10.1) and couldn't. To make telemetry stall, I pointed
In the code, I can see one way it could still hang. The runtime drop waits for any blocking-pool thread that is still running, with no time limit. A telemetry POST that's in flight at that moment has its DNS lookup on such a thread. On a machine where Something else holds the exit the same way: the first-run Python kernel setup. Could you check these?
Separate from the hang: since |
|
Thanks for the detailed repro attempt. I ran your three checks on Windows (0.10.1), plus one extra scenario. 1. Same sandbox, telemetry on, three runs back to back: all three hang (120 s / 60 s / 60 s, killed). In each run the reply prints first ("OK"), then the process stays alive. So it is not first-run-only. Additionally, the kernel venv was already fully built before these runs (they share one 2. Fresh sandbox, 3. A data point that weakens the DNS hypothesis: I forced all outbound HTTP through an instant-refusing local proxy ( Your code reading matches what I see on this side too (no exit-time flush, 1.5 s sink timeout, |
|
Follow-up on the proxy angle: I tested whether a local proxy could be the trigger (this machine has a system-wide proxy at Proxy disabled entirely (registry Full matrix on this machine (Windows, 0.10.1):
So the hang is independent of network conditions and of request success/failure: telemetry on hangs on Windows even when every request would have completed instantly; telemetry off exits promptly in every configuration. This points at the telemetry task's teardown on the blocking pool during |
|
Test 1 (which sink): done. With Test 2 (what the stuck threads are doing): done, best-effort. No WinDbg/ Approximate stack scan of all 11 threads in the hung process:
Notable: no thread is executing inside Two things that would nail it if you have the symbols:
I can send the dump, or re-run |
Uh oh!
There was an error while loading. Please reload this page.
Summary
prime-agent -pprints the response and then never exits — it must be killed externally. The hang is telemetry-dependent: with telemetry disabled the same command exits cleanly in about 1 second.Verified on 0.10.1 (Windows). Four reproducible runs below.
Reproduction
Command (any prompt works; the response is produced correctly):
OKprinted, process hangs (killed at 25 s)PRIME_AGENT_TELEMETRY=0+DO_NOT_TRACK=1rc 0, 1.0 sPI_OFFLINE=1also exits cleanly (0.8 s), consistent with the same root: offline mode disables telemetry.Earlier A/B comparison (same command, 30 s kill):
OKalready delivered)OKalready delivered)so it is not a stdout handle-inheritance artifact; the process itself refuses to exit.
Expected
-pshould exit right after printing the response (exit code 0), like run #4.Impact
-pis the headless entry point. Piping (| head),timeoutwrappers, CI scripts and any automation that callsprime-agent -pwill hang forever. This is also why many users see "prime-agent doesn't terminate" and start killing processes manually.Diagnosis (hypothesis)
The hang correlates exactly with telemetry being enabled, so the likely culprit is the exit-time telemetry flush/shutdown blocking (e.g. a network flush without a bounded timeout, or a task the process waits on that never completes).
Relevant source (0.10.1):
pa-cli/src/print_runtime.rs::with_print_runtimebuilds a tokio runtime, runsprint_mode_main, thendrop(rt)which joins remaining tasks — a stuck telemetry task here would block exit exactly like this.pa-telemetry/src/client.rs:shutdown/flush_final/shutdown_flushes_and_stops— the exit flush path./telemetry off,telemetry.enabled=false,PRIME_AGENT_TELEMETRY=0,DO_NOT_TRACK=1, offline mode); all of them make the hang disappear, which matches the "flush at exit" theory.I have not stepped through the flush call itself, so the exact blocking call is unconfirmed — happy to run more targeted probes if useful.
Workaround
Set
PRIME_AGENT_TELEMETRY=0(orDO_NOT_TRACK=1, ortelemetry.enabled=falsein settings), or run with--offline/PI_OFFLINE=1.Suggested fix
Bound the exit-time telemetry flush with a timeout (or make it fire-and-forget), so
-pexits promptly even when the telemetry endpoint is slow/unreachable; an unflushed batch is strictly better than a hung process.All reactions