From 4db322146ca21d898ca66f49df3e03c9ea5248a9 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 1 Jul 2026 18:49:39 +0900 Subject: [PATCH] Document stale-final race in wait unblock Explain why unblocking on any final result is acceptable. --- src/terminal.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/terminal.go b/src/terminal.go index 9c582eaf..517deee9 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -1889,7 +1889,13 @@ func (t *Terminal) UpdateList(result MatchResult) { wakeUp := false if result.final() { t.searchInProgress = false - // If waiting, unblock so main loop can execute pending actions + // If waiting, unblock so main loop can execute pending actions. + // Note: we unblock on any final result, not the specific search that + // armed the wait. In normal use only one search runs per action batch, + // so a stale final from an earlier search can only race in when separate + // searches are dispatched back-to-back (e.g. via --listen). The worst + // case is an early unblock, not incorrect data, so we accept it rather + // than thread a per-search generation token through the matcher. if t.waitBlocked { t.unblockWait() wakeUp = len(t.pendingActions) > 0