From 108a3e7c1499377894dc47e80af218410cba6a55 Mon Sep 17 00:00:00 2001 From: Elle Najt Date: Wed, 18 Feb 2026 15:51:02 -0800 Subject: [PATCH] Fix heartbeat nil value crash in timer and busy indicator `agent-shell-heartbeat-stop` sets `:value` to nil, but a final timer tick can fire after cancellation and call `(1+ nil)`, causing `(wrong-type-argument number-or-marker-p nil)`. The same nil value propagates to `agent-shell--busy-indicator-frame` via mode-line redisplay, triggering the error there too. Guard both sites with `when-let` to skip when value is nil. Co-Authored-By: Claude Opus 4 --- agent-shell-heartbeat.el | 12 ++++++------ agent-shell.el | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/agent-shell-heartbeat.el b/agent-shell-heartbeat.el index 0474dd41..1a572a4f 100644 --- a/agent-shell-heartbeat.el +++ b/agent-shell-heartbeat.el @@ -84,12 +84,12 @@ Returns the heartbeat alist with the timer started." (map-put! heartbeat :heartbeat-timer (run-at-time 0 (/ 1.0 (map-elt heartbeat :beats-per-second)) (lambda () - (map-put! heartbeat :status 'busy) - (map-put! heartbeat :value - (1+ (map-elt heartbeat :value))) - (funcall (map-elt heartbeat :on-heartbeat) - (map-elt heartbeat :value) - (map-elt heartbeat :status)))))) + (when-let ((value (map-elt heartbeat :value))) + (map-put! heartbeat :status 'busy) + (map-put! heartbeat :value (1+ value)) + (funcall (map-elt heartbeat :on-heartbeat) + (map-elt heartbeat :value) + (map-elt heartbeat :status))))))) heartbeat)) (cl-defun agent-shell-heartbeat-stop (&key heartbeat) diff --git a/agent-shell.el b/agent-shell.el index 6f8bee80..d6d90a0a 100644 --- a/agent-shell.el +++ b/agent-shell.el @@ -5176,9 +5176,9 @@ See https://agentclientprotocol.com/protocol/session-modes for details." ('dots-round '("⢎⡰" "⢎⡡" "⢎⡑" "⢎⠱" "⠎⡱" "⢊⡱" "⢌⡱" "⢆⡱")) ('wide '("░ " "░░ " "░░░ " "░░░░" "░░░ " "░░ " "░ " " ")) ((pred listp) agent-shell-busy-indicator-frames) - (_ '("▁" "▂" "▃" "▄" "▅" "▆" "▇" "█" "▇" "▆" "▅" "▄" "▃" "▂"))))) - (concat " " (seq-elt frames (mod (map-nested-elt (agent-shell--state) '(:heartbeat :value)) - (length frames)))))) + (_ '("▁" "▂" "▃" "▄" "▅" "▆" "▇" "█" "▇" "▆" "▅" "▄" "▃" "▂")))) + (value (map-nested-elt (agent-shell--state) '(:heartbeat :value)))) + (concat " " (seq-elt frames (mod value (length frames)))))) (defun agent-shell--mode-line-format () "Return `agent-shell''s mode-line format.