Skip to content

Add local watchdog for sessions stuck in streaming/compacting (no signal when pi wedges a turn) #253

Description

@yangge

Summary

There's no local watchdog for a session stuck in streaming/compacting. If the underlying pi process ever wedges a turn without emitting a terminal lifecycle event (agent_end/turn_end) — see earendil-works/pi#7336 for a concrete repro on the pi side — pi-coding-agent--status stays streaming/compacting forever with zero feedback to the user, since it's purely driven by events arriving from the RPC stream.

What happened

I had two chat buffers (different working directories / worktrees of the same repo, same Emacs daemon) both silently stuck for 38 and 44 minutes with no CPU/network activity in the underlying pi process (confirmed via sample/lsof on the OS process). Nothing in the UI indicated anything was wrong beyond the eternal "thinking" state — no timeout, no message, nothing in the *pi-coding-agent-stderr* buffer either.

Running M-x pi-coding-agent-abort (C-c C-k) on each buffer immediately un-wedged both sessions back to idle. So the fix, once you know about it, is trivial — the problem is discovering that you need to do it, especially when the buffer just looks like Pi is still working.

Suggestion

Add a simple local heartbeat/watchdog: if pi-coding-agent--status is streaming or compacting and no new process output/event has been observed for N minutes (configurable, maybe default 3–5 min), surface a message, e.g.:

Pi: no activity for 5 min — session may be stuck. Try C-c C-k to abort.

This doesn't need to auto-abort (that could be surprising/destructive for legitimately long-running turns) — just a visible nudge so the user knows to check, instead of waiting indefinitely without any signal.

There's already a similar concept in the codebase for the idle state (pi-coding-agent--state-needs-verification-p / pi-coding-agent--state-verify-interval, 30s periodic re-verification) — maybe a comparable idle-timer could be reused/extended to cover the busy states too, just checking "time since last process output" instead of "time since last state fetch."

Environment

  • pi-coding-agent 20260721.810 (ELPA)
  • Emacs 30.2, macOS
  • @earendil-works/pi-coding-agent 0.82.1, --mode rpc, :connection-type 'pipe

Happy to provide more diagnostic detail if useful — I have the full session logs from the two stuck instances (see the linked pi-side issue for excerpts).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions