Repository navigation
Description
Summary
A session whose turn ends without a normal completion stays running: true
forever. The UI shows "Waiting for model..." indefinitely while the model is
idle and healthy. Only restarting pi-web clears it.
I've hit this twice on separate days, most recently for 19 minutes before I
noticed.
What I observed
A session stopped writing to its .jsonl at 13:40:58. At 14:02:41 — nearly
22 minutes later — the state was still:
GET /api/agent/<session-id> -> {"running": true}
At that same moment, all three of these were true:
| check | result |
|---|---|
GPU utilisation (ioreg -c IOAccelerator, "Device Utilization %") |
0 |
| Direct probe of the model endpoint | HTTP 200 in 1.24s |
Last 4 requests from pi in the inference proxy log |
all status 200, none in flight |
So the model was never blocked and nothing was queued. The session file's last
record was an empty message. Restarting pi-web returned every session to
{"running": false} and the UI recovered; the conversation itself was intact
(46 messages), since sessions are files on disk.
Why I think it happens
From the outside it looks like the running/waiting flag is set when a turn starts
and cleared only on a normal turn-end event. If a turn dies without emitting that
event, nothing ever clears the flag — the UI is faithfully reporting state that
the server never reset. I have not read the source, so treat the mechanism as a
guess; the observations above are measured.
Reproduction
I could not script this: /api/sessions and /api/agent/<id> are the only
endpoints I found, and neither starts a turn, so I can't kill one mid-flight from
outside. Believed trigger, based on both occurrences:
- Start a session in the pi-web UI and send a prompt.
- Cause the turn to die without completing (both my occurrences were long turns
against a local model; killing thepiprocess mid-turn should also do it). GET /api/agent/<id>returns{"running": true}and keeps returning it.- The UI shows "Waiting for model..." with no timeout and no way to clear it
short of restarting the server.
If you can point me at how the UI starts a turn, I'm happy to build a scripted
reproduction and follow up.
Suggestions
Any one of these would be enough from a user's point of view:
- Clear the flag on abnormal turn termination as well as normal completion.
- Treat the flag as stale if the session file hasn't been written in N minutes,
rather than trusting it indefinitely. - Let the UI cancel/reset a stuck session without a server restart.
Workaround
An external watchdog that restarts pi-web when running: true coincides with a
quiet session file and an idle GPU. It's outside the package deliberately so an
upgrade can't revert it, but it's obviously a bandage.
Versions
- pi-web
0.8.9 - pi
0.84.2 - macOS, Apple silicon, local model served over an OpenAI-compatible endpoint
- pi-web bound to
127.0.0.1, reached over a private network
Not the same as #632 — that one is the browser not refreshing while output is
being produced. Here no output is being produced and the server's own state is
wrong.
Activity
agegr commentedon Sep 30, 2026
Thanks for the careful measurements. I checked this against current main (pi SDK 0.87.1) with a fake OpenAI-compatible server. Servers that never answer, stall mid-stream, send [DONE] without closing, reset the socket, return 500 or return an empty completion all end the turn by themselves, and Stop cancels them immediately. Two details explain what you saw:
Every failed model attempt is saved as an assistant message with empty content and an errorMessage, which is the "empty message". With the defaults (300 s HTTP timeout, 3 retries), a dead endpoint shows "Waiting for model..." for about 20 minutes before the run gives up.
GET /api/agent/ → running: true only means the session is loaded in memory, and open sessions stay loaded. For a watchdog, check state.isStreaming || state.isPromptRunning || state.isCompacting, or GET /api/agent/running.
A turn can stay running forever only when an extension handler or tool never returns and ignores the abort signal, which Pi Web cannot cancel safely. Since 0.8.10, pressing Stop tears the session down at the idle timeout (10 minutes by default) so it recovers without a restart; a fix is up for review so this also works with PI_WEB_IDLE_TIMEOUT_MS=0.
fix(sessions): keep the forced cleanup deadline after Stop (#656)
fix(sessions): reap a run Stop cannot unwind when idle shutdown is di…
fix(sessions): reap a run Stop cannot unwind when idle shutdown is di…
fix(sessions): reap a run Stop cannot unwind when idle shutdown is di…