fix(tools/tmux): unique per-invocation paste buffer; track auto-submit-drafts.sh
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful

Upstream the 2026-07-09 live hot-fix from web1: send-message.sh used a fixed
tmux buffer name (__mosaic_send) shared by all concurrent senders on one
server — load-buffer overwrote load-buffer and paste-buffer -d deleted
underneath peers, cross-delivering or dropping messages. Bit the fleet during
the simultaneous restart (standing briefs swapped between sessions). Buffer
name is now unique per invocation (PID + nanoseconds).

Also brings auto-submit-drafts.sh (coordinator draft-flush watchdog, until now
only a loose file in the deployed ~/.config/mosaic/tools/tmux/) under source
control, and extends test-send-message-socket.sh with a concurrency lock:
5 parallel sends to distinct panes, asserting no drop and no cross-delivery.
The lock fails 3/3 runs against the pre-fix script and passes post-fix.

Without this, the next framework redeploy would regress the live fix.
This commit is contained in:
enhance
2026-07-09 12:22:13 -05:00
parent 851c67c27b
commit c9c07cdeba
4 changed files with 125 additions and 3 deletions

View File

@@ -77,10 +77,20 @@ snippet=$(printf '%s' "$MSG" | tr '\n' ' ' | tr -s ' ' | sed 's/[^[:print:]]//g'
# 1) Paste the body as a bracketed paste so multi-line content does not submit
# line-by-line. load-buffer/paste-buffer is far safer than `send-keys -l`.
printf '%s' "$MSG" | "${tmux_cmd[@]}" load-buffer -b __mosaic_send -
# Buffer name MUST be unique per invocation: concurrent senders on the shared
# tmux server race a fixed name (load overwrites load, -d deletes underneath),
# cross-delivering or dropping messages — bit the fleet on the 2026-07-09
# simultaneous restart (briefs swapped between sessions).
BUF="__mosaic_send_$$_$(date +%s%N)"
printf '%s' "$MSG" | "${tmux_cmd[@]}" load-buffer -b "$BUF" -
# -p = bracketed paste when the client supports it; fall back if not.
"${tmux_cmd[@]}" paste-buffer -d -p -b __mosaic_send -t "$EFFECTIVE_TARGET" 2>/dev/null \
|| "${tmux_cmd[@]}" paste-buffer -d -b __mosaic_send -t "$EFFECTIVE_TARGET"
"${tmux_cmd[@]}" paste-buffer -d -p -b "$BUF" -t "$EFFECTIVE_TARGET" 2>/dev/null \
|| "${tmux_cmd[@]}" paste-buffer -d -b "$BUF" -t "$EFFECTIVE_TARGET" \
|| "${tmux_cmd[@]}" delete-buffer -b "$BUF" 2>/dev/null
# ^ -d deletes the buffer only on a SUCCESSFUL paste; if both attempts fail
# (e.g. the target vanished since the liveness check), delete explicitly —
# named buffers are exempt from tmux's buffer-limit eviction, so orphans
# would otherwise accumulate forever.
sleep 0.5
# 2) Submit, then verify; flush with another Enter if it is still a draft.