From 48fa2b67fbe72944667ae064afe8f5fbbdd22868 Mon Sep 17 00:00:00 2001 From: g-but <41178744+g-but@users.noreply.github.com> Date: Wed, 20 May 2026 15:23:52 +0200 Subject: [PATCH] fix(daemon): delete stale /tmp/agent-current-prompt- in push loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Companion to the UI staleness gate. Closes the leak at the source so the sentinel doesn't keep getting re-pushed every 2s — fires the same two checks the UI uses (session-mtime newer than prompt-start, OR prompt older than 30min) inside _push_loop, deletes the file, and clears cpk/cpl/cpsat so the JSON pushed to /api/control/runtime-state carries nulls. Verified against live state: - OrangeCat: 3-day-old "echo ui-dispatch-test" prompt → cleared after daemon restart (DB row's current_prompt_started_at went null within one push interval). - revamp-it: 30-min-old "Auto: next_best" → cleared on next push. Companion to: fix(control): stale "Working" defense — gate currentPrompt by session signals + time --- scripts/cockpit-daemon.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/cockpit-daemon.sh b/scripts/cockpit-daemon.sh index 8b590a85b..0ada042e1 100755 --- a/scripts/cockpit-daemon.sh +++ b/scripts/cockpit-daemon.sh @@ -572,6 +572,23 @@ _build_state_json() { [[ "$mts" =~ ^[0-9]+$ ]] && sess_mtime="$mts" fi + # Stale-prompt cleanup: Codex has no Stop hook (interactive TUI), so + # /tmp/agent-current-prompt- lingers indefinitely after the agent + # returns to idle. Without this gate the control UI shows "Codex working + # 61h" on dead tabs. Two signals fire the cleanup: (1) the session file + # was rewritten after the prompt started — the agent wrote a handoff so + # the cycle closed; (2) the prompt is older than 30 min (hard cap for + # agents that never write a session file). + if [ "$cpsat" != "null" ]; then + local _now_s + _now_s=$(date +%s) + if { [ "$sess_mtime" != "null" ] && [ "$sess_mtime" -gt "$((cpsat + 5))" ]; } \ + || [ "$((_now_s - cpsat))" -gt 1800 ]; then + rm -f "$pf" + cpk="" cpl="" cpsat="null" + fi + fi + local proj proj=$(jq -n \ --arg tab "$tab" \