Skip to content

Commit d4665d3

Browse files
committed
Add pi-coding-agent-force-idle recovery command
When the session gets stuck (e.g., status stuck at "thinking" after compaction or retry), M-x pi-coding-agent-force-idle resets the local status back to idle, cancels pending timers, and restores any queued follow-ups to the input buffer.
1 parent 6b571a8 commit d4665d3

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

pi-coding-agent-menu.el

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,30 @@ chat buffer from session history."
521521
(message "Pi: Failed to reload - %s"
522522
(or (plist-get response :error) "unknown error"))))))))))))
523523

524+
;;;###autoload
525+
(defun pi-coding-agent-force-idle ()
526+
"Force the session status back to idle.
527+
528+
Use this when the session appears stuck with no activity occurring.
529+
Resets the local status and activity phase, cancels any pending timers,
530+
and restores the follow-up queue to the input buffer.
531+
532+
This does NOT kill the pi process. If the server is still processing, it
533+
may send events that override this reset. For a full recovery, use
534+
`pi-coding-agent-reload' instead."
535+
(interactive)
536+
(let ((chat-buf (pi-coding-agent--get-chat-buffer)))
537+
(if (not chat-buf)
538+
(message "Pi: No session to reset")
539+
(with-current-buffer chat-buf
540+
(pi-coding-agent--cancel-followup-drain-timer)
541+
(pi-coding-agent--invalidate-prompt-start-wait)
542+
(setq pi-coding-agent--status 'idle
543+
pi-coding-agent--pre-compaction-status nil)
544+
(pi-coding-agent--set-activity-phase "idle" 'reset t)
545+
(pi-coding-agent--restore-followup-queue-to-input)
546+
(message "Pi: Status reset to idle")))))
547+
524548
(defun pi-coding-agent--resume-selected-session (proc chat-buf selected-path)
525549
"Resume SELECTED-PATH using PROC and rebuild CHAT-BUF from its history."
526550
(pi-coding-agent--rpc-async

0 commit comments

Comments
 (0)