mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 10:48:20 +01:00
The 10-second STALE_CLAIM_SECONDS recovery in
reclaimStalePendingCommands closes the visible symptom of a daemon
crash mid-dispatch — the row becomes claimable again. But it opens a
worse failure: if the first daemon already typed keystrokes into the
terminal before crashing, the second daemon will replay execute_inject
and double-type. This is the actual race A1 was masking, not fixing.
Fix is a 23-line addition to the dispatch loop. Before entering the
case statement, write /tmp/<brand>-attempted-<id> with the current
timestamp. On every dispatch iteration, first check whether that file
exists — if it does, this row was already attempted by some earlier
process (this one or a crashed predecessor). Refuse to re-execute;
PATCH mark_done with a structured "abandoned mid-execution" reason so
the user sees what happened in /control and can retry explicitly. On
clean completion (after esac), remove the marker.
Why a /tmp marker instead of a DB column: tmpfs survives daemon
process death but not machine reboot. That matches the failure modes
we care about — a daemon crash leaves zellij + tmpfs intact (so the
keystrokes really did land, and we must NOT replay), while a machine
reboot wipes both (so the keystrokes never landed, and we MUST be
able to replay). Adding a column to pending_commands would persist
the marker across reboots and prevent legitimate replay.
No double-execution observed in production yet — this closes the
window before it bites. Pairs with Phase 2 (?types= filter) and
Phase 3 (runId sentinel) shipped in cdc042a.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>